wined3d: Remove the conditional from texdepth.
[wine] / dlls / credui / tests / credui.c
1 /*
2  * Credentials User Interface Tests
3  *
4  * Copyright 2007 Robert Shearman for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wincred.h"
26
27 #include "wine/test.h"
28
29 static void test_CredUIPromptForCredentials(void)
30 {
31     static const WCHAR wszServerName[] = {'W','i','n','e','T','e','s','t',0};
32     DWORD ret;
33     WCHAR username[256];
34     WCHAR password[256];
35     CREDUI_INFOW credui_info;
36     BOOL save = FALSE;
37
38     credui_info.cbSize = sizeof(credui_info);
39     credui_info.hwndParent = NULL;
40     credui_info.pszMessageText = NULL;
41     credui_info.hbmBanner = NULL;
42
43     ret = CredUIConfirmCredentialsW(NULL, TRUE);
44     ok(ret == ERROR_INVALID_PARAMETER, "CredUIConfirmCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
45
46     ret = CredUIConfirmCredentialsW(wszServerName, TRUE);
47     ok(ret == ERROR_NOT_FOUND, "CredUIConfirmCredentials should have returned ERROR_NOT_FOUND instead of %d\n", ret);
48
49     username[0] = '\0';
50     password[0] = '\0';
51     ret = CredUIPromptForCredentialsW(NULL, NULL, NULL, 0, username,
52                                       sizeof(username)/sizeof(username[0]),
53                                       password, sizeof(password)/sizeof(password[0]),
54                                       NULL, CREDUI_FLAGS_ALWAYS_SHOW_UI);
55     ok(ret == ERROR_INVALID_FLAGS, "CredUIPromptForCredentials should have returned ERROR_INVALID_FLAGS instead of %d\n", ret);
56
57     ret = CredUIPromptForCredentialsW(NULL, NULL, NULL, 0, username,
58                                       sizeof(username)/sizeof(username[0]),
59                                       password, sizeof(password)/sizeof(password[0]),
60                                       NULL, CREDUI_FLAGS_ALWAYS_SHOW_UI | CREDUI_FLAGS_GENERIC_CREDENTIALS);
61     ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
62
63     ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
64                                       sizeof(username)/sizeof(username[0]),
65                                       password, sizeof(password)/sizeof(password[0]),
66                                       NULL, CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX);
67     ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_FLAGS instead of %d\n", ret);
68
69     if (winetest_interactive)
70     {
71         static const WCHAR wszCaption1[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
72         static const WCHAR wszCaption2[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','I','N','C','O','R','R','E','C','T','_','P','A','S','S','W','O','R','D','|',
73             'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
74         static const WCHAR wszCaption3[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','D','O','_','N','O','T','_','P','E','R','S','I','S','T','|',
75             'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
76         static const WCHAR wszCaption4[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','P','E','R','S','I','S','T','|',
77             'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
78
79         ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
80                                           sizeof(username)/sizeof(username[0]),
81                                           password, sizeof(password)/sizeof(password[0]),
82                                           &save, CREDUI_FLAGS_EXPECT_CONFIRMATION);
83         ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
84         if (ret == ERROR_SUCCESS)
85             ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
86
87         credui_info.pszCaptionText = wszCaption1;
88         ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL,
89                                           ERROR_ACCESS_DENIED,
90                                           username, sizeof(username)/sizeof(username[0]),
91                                           password, sizeof(password)/sizeof(password[0]),
92                                           &save, CREDUI_FLAGS_EXPECT_CONFIRMATION);
93         ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
94         if (ret == ERROR_SUCCESS)
95             ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
96
97         credui_info.pszCaptionText = wszCaption2;
98         ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
99                                           username, sizeof(username)/sizeof(username[0]),
100                                           password, sizeof(password)/sizeof(password[0]),
101                                           NULL, CREDUI_FLAGS_INCORRECT_PASSWORD|CREDUI_FLAGS_EXPECT_CONFIRMATION);
102         ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
103         if (ret == ERROR_SUCCESS)
104             ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
105
106         save = TRUE;
107         credui_info.pszCaptionText = wszCaption3;
108         ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
109                                           username, sizeof(username)/sizeof(username[0]),
110                                           password, sizeof(password)/sizeof(password[0]),
111                                           &save, CREDUI_FLAGS_DO_NOT_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION);
112         ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
113         ok(save, "save flag should have been untouched\n");
114
115         save = FALSE;
116         credui_info.pszCaptionText = wszCaption4;
117         ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
118                                           username, sizeof(username)/sizeof(username[0]),
119                                           password, sizeof(password)/sizeof(password[0]),
120                                           &save, CREDUI_FLAGS_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION);
121         ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
122         ok(!save, "save flag should have been untouched\n");
123         if (ret == ERROR_SUCCESS)
124             ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
125     }
126 }
127
128 START_TEST(credui)
129 {
130     test_CredUIPromptForCredentials();
131 }