[EXPLORER] -Use WM_POPUPSYSTEMMENU to open the system menu of a window. CORE-13400
[reactos.git] / rostests / apitests / netshell / NcIsValidConnectionName.c
1 /*
2 * Copyright 2016 Jared Smudde
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 /* Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366197%28v=vs.85%29.aspx */
20
21 #include <apitest.h>
22
23 static BOOL (WINAPI *pNcIsValidConnectionName)(PCWSTR);
24
25 #define CALL_NC(exp, str) \
26 do { \
27 BOOL ret = pNcIsValidConnectionName((str)); \
28 ok(ret == (exp), "Expected %s to be %d, was %d\n", wine_dbgstr_w((str)), (exp), ret); \
29 } while (0)
30
31
32
33 static void test_BadLetters(void)
34 {
35 BOOL ret;
36
37 WCHAR buf[3] = { 0 };
38 int i;
39
40 for (i = 1; i <= 0xFFFF; ++i)
41 {
42 buf[0] = (WCHAR)i;
43 buf[1] = buf[2] = L'\0';
44
45 if (wcspbrk(buf, L"\\/:\t*? <>|\"") != NULL)
46 {
47 ret = pNcIsValidConnectionName(buf);
48 ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i);
49
50 /* How about two of a kind? */
51 buf[1] = (WCHAR)i;
52 ret = pNcIsValidConnectionName(buf);
53 ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i);
54
55 /* And something (bad) combined with a space? */
56 buf[1] = L' ';
57 ret = pNcIsValidConnectionName(buf);
58 ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i);
59
60
61 /* Something bad combined with a letter */
62 buf[1] = L'a';
63 ret = pNcIsValidConnectionName(buf);
64 if ((WCHAR)i == L' ')
65 ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i);
66 else
67 ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i);
68 }
69 else
70 {
71 ret = pNcIsValidConnectionName(buf);
72 ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i);
73
74 buf[1] = (WCHAR)i;
75 ret = pNcIsValidConnectionName(buf);
76 ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i);
77
78 buf[1] = L'a';
79 ret = pNcIsValidConnectionName(buf);
80 ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i);
81
82 buf[1] = L' ';
83 ret = pNcIsValidConnectionName(buf);
84 ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i);
85 }
86 }
87 }
88
89 START_TEST(isvalidname)
90 {
91 HMODULE hDll = LoadLibraryA("netshell.dll");
92
93 pNcIsValidConnectionName = (void*)GetProcAddress(hDll, "NcIsValidConnectionName");
94 if (!hDll || !pNcIsValidConnectionName)
95 {
96 skip("netshell.dll or export NcIsValidConnectionName not found! Tests will be skipped\n");
97 return;
98 }
99
100 CALL_NC(TRUE, L"Network");
101 CALL_NC(FALSE, L"Network?");
102
103 CALL_NC(FALSE, L"\\");
104 CALL_NC(FALSE, L"/");
105 CALL_NC(FALSE, L":");
106 CALL_NC(FALSE, L"*");
107 CALL_NC(FALSE, L"?");
108 CALL_NC(FALSE, L"<");
109 CALL_NC(FALSE, L">");
110 CALL_NC(FALSE, L"|");
111
112 CALL_NC(FALSE, NULL);
113
114 CALL_NC(TRUE, L"Wireless");
115 CALL_NC(FALSE, L"Wireless:1");
116 CALL_NC(TRUE, L"Intranet");
117 CALL_NC(FALSE, L"Intranet<");
118 CALL_NC(TRUE, L"Network Connection");
119
120 test_BadLetters();
121 }