Author: mjansen Date: Wed Nov 30 20:31:50 2016 New Revision: 73409
URL: http://svn.reactos.org/svn/reactos?rev=73409&view=rev Log: [NETSHELL] Implement NcIsValidConnectionName + tests. Patch by Jared Smudde, modified by me. CORE-11320 #resolve
Added: trunk/rostests/apitests/netshell/ trunk/rostests/apitests/netshell/CMakeLists.txt (with props) trunk/rostests/apitests/netshell/NcIsValidConnectionName.c (with props) trunk/rostests/apitests/netshell/testlist.c (with props) Modified: trunk/reactos/dll/shellext/netshell/netshell.cpp trunk/reactos/dll/shellext/netshell/netshell.spec trunk/rostests/apitests/CMakeLists.txt
Modified: trunk/reactos/dll/shellext/netshell/netshell.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/netshell/netsh... ============================================================================== --- trunk/reactos/dll/shellext/netshell/netshell.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/netshell/netshell.cpp [iso-8859-1] Wed Nov 30 20:31:50 2016 @@ -70,4 +70,37 @@ CoTaskMemFree(pProps); }
+BOOL +WINAPI +NcIsValidConnectionName(_In_ PCWSTR pszwName) +{ + if (!pszwName) + return FALSE; + + BOOL nonSpace = FALSE; + while (*pszwName) + { + switch(*(pszwName++)) + { + case L'\': + case L'/': + case L':': + case L'*': + case L'\t': + case L'?': + case L'<': + case L'>': + case L'|': + case L'"': + return FALSE; + case L' ': + break; + default: + nonSpace = TRUE; + break; + } + } + return nonSpace; +} + } // extern "C"
Modified: trunk/reactos/dll/shellext/netshell/netshell.spec URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/netshell/netsh... ============================================================================== --- trunk/reactos/dll/shellext/netshell/netshell.spec [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/netshell/netshell.spec [iso-8859-1] Wed Nov 30 20:31:50 2016 @@ -21,7 +21,7 @@ 20 stub HrRunWizard 21 stub InvokeDunFile 22 stdcall NcFreeNetconProperties(ptr) -23 stub NcIsValidConnectionName +23 stdcall NcIsValidConnectionName(wstr) 24 stub NetSetupAddRasConnection 25 stub NetSetupFinishInstall 26 stub NetSetupInstallSoftware
Modified: trunk/rostests/apitests/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/CMakeLists.txt?re... ============================================================================== --- trunk/rostests/apitests/CMakeLists.txt [iso-8859-1] (original) +++ trunk/rostests/apitests/CMakeLists.txt [iso-8859-1] Wed Nov 30 20:31:50 2016 @@ -18,6 +18,7 @@ add_subdirectory(localspl) add_subdirectory(msgina) add_subdirectory(msvcrt) +add_subdirectory(netshell) add_subdirectory(ntdll) add_subdirectory(ole32) add_subdirectory(pefile)
Added: trunk/rostests/apitests/netshell/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/netshell/CMakeLis... ============================================================================== --- trunk/rostests/apitests/netshell/CMakeLists.txt (added) +++ trunk/rostests/apitests/netshell/CMakeLists.txt [iso-8859-1] Wed Nov 30 20:31:50 2016 @@ -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)
Propchange: trunk/rostests/apitests/netshell/CMakeLists.txt ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/rostests/apitests/netshell/NcIsValidConnectionName.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/netshell/NcIsVali... ============================================================================== --- trunk/rostests/apitests/netshell/NcIsValidConnectionName.c (added) +++ trunk/rostests/apitests/netshell/NcIsValidConnectionName.c [iso-8859-1] Wed Nov 30 20:31:50 2016 @@ -0,0 +1,121 @@ +/* + * 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%... */ + +#include <apitest.h> + +static BOOL (WINAPI *pNcIsValidConnectionName)(PCWSTR); + +#define CALL_NC(exp, str) \ + do { \ + BOOL ret = pNcIsValidConnectionName((str)); \ + ok(ret == (exp), "Expected %s to be %d, was %d\n", wine_dbgstr_w((str)), (exp), ret); \ + } while (0) + + + +static void test_BadLetters(void) +{ + BOOL ret; + + WCHAR buf[3] = { 0 }; + int i; + + for (i = 1; i <= 0xFFFF; ++i) + { + buf[0] = (WCHAR)i; + buf[1] = buf[2] = L'\0'; + + if (wcspbrk(buf, L"\/:\t*? <>|"") != NULL) + { + ret = pNcIsValidConnectionName(buf); + ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i); + + /* How about two of a kind? */ + buf[1] = (WCHAR)i; + ret = pNcIsValidConnectionName(buf); + ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i); + + /* And something (bad) combined with a space? */ + buf[1] = L' '; + ret = pNcIsValidConnectionName(buf); + ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i); + + + /* Something bad combined with a letter */ + buf[1] = L'a'; + ret = pNcIsValidConnectionName(buf); + if ((WCHAR)i == L' ') + ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i); + else + ok(ret == FALSE, "Expected %s (%i) to fail.\n", wine_dbgstr_w(buf), i); + } + else + { + ret = pNcIsValidConnectionName(buf); + ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i); + + buf[1] = (WCHAR)i; + ret = pNcIsValidConnectionName(buf); + ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i); + + buf[1] = L'a'; + ret = pNcIsValidConnectionName(buf); + ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i); + + buf[1] = L' '; + ret = pNcIsValidConnectionName(buf); + ok(ret == TRUE, "Expected %s (%i) to succeed.\n", wine_dbgstr_w(buf), i); + } + } +} + +START_TEST(isvalidname) +{ + HMODULE hDll = LoadLibraryA("netshell.dll"); + + pNcIsValidConnectionName = (void*)GetProcAddress(hDll, "NcIsValidConnectionName"); + if (!hDll || !pNcIsValidConnectionName) + { + skip("netshell.dll or export NcIsValidConnectionName not found! Tests will be skipped\n"); + return; + } + + CALL_NC(TRUE, L"Network"); + CALL_NC(FALSE, L"Network?"); + + CALL_NC(FALSE, L"\"); + CALL_NC(FALSE, L"/"); + CALL_NC(FALSE, L":"); + CALL_NC(FALSE, L"*"); + CALL_NC(FALSE, L"?"); + CALL_NC(FALSE, L"<"); + CALL_NC(FALSE, L">"); + CALL_NC(FALSE, L"|"); + + CALL_NC(FALSE, NULL); + + CALL_NC(TRUE, L"Wireless"); + CALL_NC(FALSE, L"Wireless:1"); + CALL_NC(TRUE, L"Intranet"); + CALL_NC(FALSE, L"Intranet<"); + CALL_NC(TRUE, L"Network Connection"); + + test_BadLetters(); +}
Propchange: trunk/rostests/apitests/netshell/NcIsValidConnectionName.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/rostests/apitests/netshell/testlist.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/netshell/testlist... ============================================================================== --- trunk/rostests/apitests/netshell/testlist.c (added) +++ trunk/rostests/apitests/netshell/testlist.c [iso-8859-1] Wed Nov 30 20:31:50 2016 @@ -0,0 +1,11 @@ +#define STANDALONE +#include "R:\hook\base_hk.h" +#include <apitest.h> + +extern void func_isvalidname(void); + +const struct test winetest_testlist[] = +{ + { "NcIsValidConnectionName", func_isvalidname }, + { 0, 0 } +};
Propchange: trunk/rostests/apitests/netshell/testlist.c ------------------------------------------------------------------------------ svn:eol-style = native