push 0f15bbd80d260bbd8adf052e820484a405c49375
[wine/hacks.git] / dlls / credui / tests / credui.c
blob969b096a766d37b9d42b2159c289fa9d7902aeca
1 /*
2 * Credentials User Interface Tests
4 * Copyright 2007 Robert Shearman for CodeWeavers
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.
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.
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wincred.h"
27 #include "wine/test.h"
29 static void test_CredUIPromptForCredentials(void)
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;
38 credui_info.cbSize = sizeof(credui_info);
39 credui_info.hwndParent = NULL;
40 credui_info.pszMessageText = NULL;
41 credui_info.hbmBanner = NULL;
43 ret = CredUIConfirmCredentialsW(NULL, TRUE);
44 ok(ret == ERROR_INVALID_PARAMETER /* 2003 + */ || ret == ERROR_NOT_FOUND /* XP */,
45 "CredUIConfirmCredentials should have returned ERROR_INVALID_PARAMETER or ERROR_NOT_FOUND instead of %d\n", ret);
47 ret = CredUIConfirmCredentialsW(wszServerName, TRUE);
48 ok(ret == ERROR_NOT_FOUND, "CredUIConfirmCredentials should have returned ERROR_NOT_FOUND instead of %d\n", ret);
50 username[0] = '\0';
51 password[0] = '\0';
52 ret = CredUIPromptForCredentialsW(NULL, NULL, NULL, 0, username,
53 sizeof(username)/sizeof(username[0]),
54 password, sizeof(password)/sizeof(password[0]),
55 NULL, CREDUI_FLAGS_ALWAYS_SHOW_UI);
56 ok(ret == ERROR_INVALID_FLAGS, "CredUIPromptForCredentials should have returned ERROR_INVALID_FLAGS instead of %d\n", ret);
58 ret = CredUIPromptForCredentialsW(NULL, NULL, NULL, 0, username,
59 sizeof(username)/sizeof(username[0]),
60 password, sizeof(password)/sizeof(password[0]),
61 NULL, CREDUI_FLAGS_ALWAYS_SHOW_UI | CREDUI_FLAGS_GENERIC_CREDENTIALS);
62 ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
64 ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
65 sizeof(username)/sizeof(username[0]),
66 password, sizeof(password)/sizeof(password[0]),
67 NULL, CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX);
68 ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_FLAGS instead of %d\n", ret);
70 if (winetest_interactive)
72 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};
73 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','|',
74 '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};
75 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','|',
76 '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};
77 static const WCHAR wszCaption4[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','P','E','R','S','I','S','T','|',
78 '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};
80 ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
81 sizeof(username)/sizeof(username[0]),
82 password, sizeof(password)/sizeof(password[0]),
83 &save, CREDUI_FLAGS_EXPECT_CONFIRMATION);
84 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
85 if (ret == ERROR_SUCCESS)
86 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
88 credui_info.pszCaptionText = wszCaption1;
89 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL,
90 ERROR_ACCESS_DENIED,
91 username, sizeof(username)/sizeof(username[0]),
92 password, sizeof(password)/sizeof(password[0]),
93 &save, CREDUI_FLAGS_EXPECT_CONFIRMATION);
94 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
95 if (ret == ERROR_SUCCESS)
96 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
98 credui_info.pszCaptionText = wszCaption2;
99 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
100 username, sizeof(username)/sizeof(username[0]),
101 password, sizeof(password)/sizeof(password[0]),
102 NULL, CREDUI_FLAGS_INCORRECT_PASSWORD|CREDUI_FLAGS_EXPECT_CONFIRMATION);
103 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
104 if (ret == ERROR_SUCCESS)
105 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
107 save = TRUE;
108 credui_info.pszCaptionText = wszCaption3;
109 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
110 username, sizeof(username)/sizeof(username[0]),
111 password, sizeof(password)/sizeof(password[0]),
112 &save, CREDUI_FLAGS_DO_NOT_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION);
113 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
114 ok(save, "save flag should have been untouched\n");
116 save = FALSE;
117 credui_info.pszCaptionText = wszCaption4;
118 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
119 username, sizeof(username)/sizeof(username[0]),
120 password, sizeof(password)/sizeof(password[0]),
121 &save, CREDUI_FLAGS_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION);
122 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
123 ok(!save, "save flag should have been untouched\n");
124 if (ret == ERROR_SUCCESS)
125 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
129 START_TEST(credui)
131 test_CredUIPromptForCredentials();