Index: apitests/CMakeLists.txt =================================================================== --- apitests/CMakeLists.txt (revision 71949) +++ apitests/CMakeLists.txt (working copy) @@ -17,6 +17,7 @@ endif() add_subdirectory(msgina) add_subdirectory(msvcrt) +add_subdirectory(netshell) add_subdirectory(ntdll) add_subdirectory(ole32) add_subdirectory(pefile) Index: apitests/netshell/CMakeLists.txt =================================================================== --- apitests/netshell/CMakeLists.txt (revision 0) +++ apitests/netshell/CMakeLists.txt (working copy) @@ -0,0 +1,5 @@ + +add_executable(netshell_apitest NcIsValidConnectionName.c testlist.c) +set_module_type(netshell_apitest win32cui) +add_importlibs(netshell_apitest msvcrt kernel32) +add_cd_file(TARGET netshell_apitest DESTINATION reactos/bin FOR all) Index: apitests/netshell/NcIsValidConnectionName.c =================================================================== --- apitests/netshell/NcIsValidConnectionName.c (revision 0) +++ apitests/netshell/NcIsValidConnectionName.c (working copy) @@ -0,0 +1,165 @@ +/* + * Copyright 2016 Jared Smudde + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366197%28v=vs.85%29.aspx */ + +#include + +static const WCHAR validname[] = L"Network"; +static const WCHAR invalidname[] = L"Network?"; +static const WCHAR validname1[] = L"Wireless"; +static const WCHAR invalidname1[] = L"Wireless:1"; +static const WCHAR validname2[] = L"Intranet"; +static const WCHAR invalidname2[] = L"Intranet<"; +static const WCHAR validname3[] = L"Network Connection"; +static const WCHAR backslash[] = L"\\"; +static const WCHAR forwardslash[] = L"/"; +static const WCHAR colon[] = L":"; +static const WCHAR asterik[] = L"*"; +static const WCHAR questionmark[] = L"?"; +static const WCHAR openbracket[] = L"<"; +static const WCHAR closebracket[] = L">"; +static const WCHAR seperator[] = L"|"; +static HMODULE hDll; +static BOOL (WINAPI *pNcIsValidConnectionName)(PCWSTR); + +static void test_TestValidName(void) +{ + BOOL ret; + + ret = pNcIsValidConnectionName(validname); + ok(ret == TRUE, "Expected %S to succeed.\n", validname); +} + +static void test_TestInvalidName(void) +{ + BOOL ret; + + ret = pNcIsValidConnectionName(invalidname); + ok(ret == FALSE, "Expected %S to fail.\n", invalidname); +} + +static void test_TestSingleCharacter(void) +{ + BOOL ret; + + ret = pNcIsValidConnectionName(backslash); + ok(ret == FALSE, "Expected %S to fail.\n", backslash); + + ret = pNcIsValidConnectionName(forwardslash); + ok(ret == FALSE, "Expected %S to fail.\n", forwardslash); + + ret = pNcIsValidConnectionName(colon); + ok(ret == FALSE, "Expected %S to fail.\n", colon); + + ret = pNcIsValidConnectionName(asterik); + ok(ret == FALSE, "Expected %S to fail.\n", asterik); + + ret = pNcIsValidConnectionName(questionmark); + ok(ret == FALSE, "Expected %S to fail.\n", questionmark); + + ret = pNcIsValidConnectionName(openbracket); + ok(ret == FALSE, "Expected %S to fail.\n", openbracket); + + ret = pNcIsValidConnectionName(closebracket); + ok(ret == FALSE, "Expected %S to fail.\n", closebracket); + + ret = pNcIsValidConnectionName(seperator); + ok(ret == FALSE, "Expected %S to fail.\n", seperator); +} + +static void test_NullName(void) +{ + BOOL ret; + + ret = pNcIsValidConnectionName(NULL); + ok(ret == FALSE, "Expected NULL name to fail.\n"); +} + +static void test_InvalidPointer(void) +{ + BOOL ret; + + ret = pNcIsValidConnectionName(NULL); + ok(ret == FALSE, "Invalid pointer.\n"); +} + +static void test_SingleLetter(void) +{ + BOOL ret; + + WCHAR buf[2] = {0}; + WCHAR i; + + for(i = 1; i <= 255; ++i) + { + buf[0] = i; + + if (wcspbrk(buf, L"\\/:\t*? <>|\"") != NULL) + { + + ret = pNcIsValidConnectionName(buf); + ok(ret == FALSE, "Expected %S (%i) to fail.\n", buf, (int)i); + } + else + { + ret = pNcIsValidConnectionName(buf); + ok(ret == TRUE, "Expected %S (%i) to succeed.\n", buf, (int)i); + } + } + +} + +static void test_Morestrings(void) +{ + BOOL ret; + + ret = pNcIsValidConnectionName(validname1); + ok(ret == TRUE, "Expected %S to succeed.\n", validname1); + + ret = pNcIsValidConnectionName(invalidname1); + ok(ret == FALSE, "Expected %S to fail.\n", invalidname1); + + ret = pNcIsValidConnectionName(validname2); + ok(ret == TRUE, "Expected %S to succeed.\n", validname2); + + ret = pNcIsValidConnectionName(invalidname2); + ok(ret == FALSE, "Expected %S to fail.\n", invalidname2); + + ret = pNcIsValidConnectionName(validname3); + ok(ret == TRUE, "Expected %S to succeed.\n", validname3); +} + +START_TEST(isvalidname) +{ + hDll = LoadLibraryA("netshell.dll"); + pNcIsValidConnectionName = GetProcAddress(hDll, "NcIsValidConnectionName"); + if (!hDll || !pNcIsValidConnectionName) + { + skip("netshell.dll or export NcIsValidConnectionName not found! Tests will be skipped\n"); + return; + } + + test_TestValidName(); + test_TestInvalidName(); + test_TestSingleCharacter(); + test_NullName(); + test_InvalidPointer(); + test_SingleLetter(); + test_Morestrings(); +} Index: apitests/netshell/testlist.c =================================================================== --- apitests/netshell/testlist.c (revision 0) +++ apitests/netshell/testlist.c (working copy) @@ -0,0 +1,10 @@ +#define STANDALONE +#include + +extern void func_isvalidname(void); + +const struct test winetest_testlist[] = +{ + { "NcIsValidConnectionName", func_isvalidname }, + { 0, 0 } +};