ReactOS 0.4.15-dev-7953-g1f49173
NcIsValidConnectionName.c
Go to the documentation of this file.
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
23static 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
33static 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
89START_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
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
121}
static void test_BadLetters(void)
#define CALL_NC(exp, str)
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define wine_dbgstr_w
Definition: kernel32.h:34
#define BOOL
Definition: nt_native.h:43
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
const uint16_t * PCWSTR
Definition: typedefs.h:57
int ret
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180