From 447c0daf7de4e2dd10df3484b6f279e9f9293e51 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Wed, 15 Mar 2017 19:17:44 +0000 Subject: [PATCH] [ATL][ATL_APITEST] Allow CString to be initialized with a resource ID + add tests for this. Patch by Katayama Hirofumi MZ. CORE-12917 #resolve #comment Thanks! svn path=/trunk/; revision=74177 --- reactos/sdk/lib/atl/cstringt.h | 52 ++--- rostests/apitests/atl/CMakeLists.txt | 2 +- rostests/apitests/atl/CString.cpp | 85 ++++++++- rostests/apitests/atl/CString.inl | 36 ++++ rostests/apitests/atl/devenv/ATLTest.sln | 12 +- rostests/apitests/atl/devenv/CString.vcxproj | 189 +++++++++++++++++++ 6 files changed, 347 insertions(+), 29 deletions(-) create mode 100644 rostests/apitests/atl/devenv/CString.vcxproj diff --git a/reactos/sdk/lib/atl/cstringt.h b/reactos/sdk/lib/atl/cstringt.h index 2e7460b7994..a8918b09617 100644 --- a/reactos/sdk/lib/atl/cstringt.h +++ b/reactos/sdk/lib/atl/cstringt.h @@ -326,48 +326,52 @@ public: *this = static_cast(strSrc); } +protected: + /* helper function */ + template + void LoadFromPtr_(_In_opt_z_ const T_CHAR* pszSrc) + { + if (pszSrc == NULL) + return; + if (IS_INTRESOURCE(pszSrc)) + LoadString(LOWORD(pszSrc)); + else + *this = pszSrc; + } + +public: CStringT(_In_opt_z_ const XCHAR* pszSrc) : - CThisSimpleString( StringTraits::GetDefaultManager() ) + CThisSimpleString(StringTraits::GetDefaultManager()) { - // FIXME: Check whether pszSrc is not a resource string ID! - *this = pszSrc; + LoadFromPtr_(pszSrc); } - CStringT( - _In_opt_z_ const XCHAR* pszSrc, - _In_ IAtlStringMgr* pStringMgr) : - CThisSimpleString( pStringMgr ) + CStringT(_In_opt_z_ const XCHAR* pszSrc, + _In_ IAtlStringMgr* pStringMgr) : CThisSimpleString(pStringMgr) { - // FIXME: Check whether pszSrc is not a resource string ID! - *this = pszSrc; + LoadFromPtr_(pszSrc); } CStringT(_In_opt_z_ const YCHAR* pszSrc) : - CThisSimpleString( StringTraits::GetDefaultManager() ) + CThisSimpleString(StringTraits::GetDefaultManager()) { - // FIXME: Check whether pszSrc is not a resource string ID! - *this = pszSrc; + LoadFromPtr_(pszSrc); } - CStringT( - _In_opt_z_ const YCHAR* pszSrc, - _In_ IAtlStringMgr* pStringMgr) : - CThisSimpleString( pStringMgr ) + CStringT(_In_opt_z_ const YCHAR* pszSrc, + _In_ IAtlStringMgr* pStringMgr) : CThisSimpleString(pStringMgr) { - // FIXME: Check whether pszSrc is not a resource string ID! - *this = pszSrc; + LoadFromPtr_(pszSrc); } - CStringT( - _In_reads_z_(nLength) const XCHAR* pch, - _In_ int nLength) : + CStringT(_In_reads_z_(nLength) const XCHAR* pch, + _In_ int nLength) : CThisSimpleString(pch, nLength, StringTraits::GetDefaultManager()) { } - CStringT( - _In_reads_z_(nLength) const YCHAR* pch, - _In_ int nLength) : + CStringT(_In_reads_z_(nLength) const YCHAR* pch, + _In_ int nLength) : CThisSimpleString(pch, nLength, StringTraits::GetDefaultManager()) { } diff --git a/rostests/apitests/atl/CMakeLists.txt b/rostests/apitests/atl/CMakeLists.txt index 99e526adfa6..d5428d9fd22 100644 --- a/rostests/apitests/atl/CMakeLists.txt +++ b/rostests/apitests/atl/CMakeLists.txt @@ -17,7 +17,7 @@ add_executable(atl_apitest testlist.c atl_apitest.rc) -target_link_libraries(atl_apitest wine uuid) +target_link_libraries(atl_apitest wine atlnew uuid) set_module_type(atl_apitest win32cui) add_importlibs(atl_apitest rpcrt4 ole32 oleaut32 msimg32 gdi32 advapi32 user32 msvcrt kernel32 ntdll) add_rostests_file(TARGET atl_apitest) diff --git a/rostests/apitests/atl/CString.cpp b/rostests/apitests/atl/CString.cpp index 79dc3873163..6f958dc825f 100644 --- a/rostests/apitests/atl/CString.cpp +++ b/rostests/apitests/atl/CString.cpp @@ -2,12 +2,70 @@ * PROJECT: ReactOS api tests * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory * PURPOSE: Test for CString - * PROGRAMMER: Mark Jansen + * PROGRAMMERS: Mark Jansen + * Katayama Hirofumi MZ */ #include -#include - +#include "resource.h" + +#ifdef __REACTOS__ + #include +#else + #include + #include + #include + #include + int g_tests_executed = 0; + int g_tests_failed = 0; + int g_tests_skipped = 0; + const char *g_file = NULL; + int g_line = 0; + void set_location(const char *file, int line) + { + g_file = file; + g_line = line; + } + void ok_func(int value, const char *fmt, ...) + { + va_list va; + va_start(va, fmt); + if (!value) + { + printf("%s (%d): ", g_file, g_line); + vprintf(fmt, va); + g_tests_failed++; + } + g_tests_executed++; + va_end(va); + } + void skip_func(const char *fmt, ...) + { + va_list va; + va_start(va, fmt); + printf("%s (%d): test skipped: ", g_file, g_line); + vprintf(fmt, va); + g_tests_skipped++; + va_end(va); + } + #undef ok + #define ok(value, ...) do { \ + set_location(__FILE__, __LINE__); \ + ok_func(value, __VA_ARGS__); \ + } while (0) + #define ok_(x1,x2) set_location(x1,x2); ok_func + #define skip(...) do { \ + set_location(__FILE__, __LINE__); \ + skip_func(__VA_ARGS__); \ + } while (0) + #define START_TEST(x) int main(void) + char *wine_dbgstr_w(const wchar_t *wstr) + { + static char buf[512]; + WideCharToMultiByte(CP_ACP, 0, wstr, -1, buf, _countof(buf), NULL, NULL); + return buf; + } +#endif struct traits_test { @@ -113,7 +171,11 @@ static void test_basetypes() // Allocation strategy seems to differ a bit between us and MS's atl. // if someone cares enough to find out why, feel free to change the macro below. +#ifdef __REACTOS__ #define ALLOC_EXPECT(a, b) b +#else +#define ALLOC_EXPECT(a, b) a +#endif #undef ok @@ -123,9 +185,12 @@ static void test_basetypes() #define CStringX CStringW #define _X(x) L ## x #define XCHAR WCHAR +#define YCHAR CHAR #define dbgstrx(x) wine_dbgstr_w(x) #define ok ok_("CStringW:\n" __FILE__, __LINE__) #define GetWindowsDirectoryX GetWindowsDirectoryW +#define MAKEINTRESOURCEX(x) MAKEINTRESOURCEW(x) +#define MAKEINTRESOURCEY(x) MAKEINTRESOURCEA(x) #include "CString.inl" @@ -133,17 +198,23 @@ static void test_basetypes() #undef TEST_NAMEX #undef _X #undef XCHAR +#undef YCHAR #undef dbgstrx #undef ok #undef GetWindowsDirectoryX +#undef MAKEINTRESOURCEX +#undef MAKEINTRESOURCEY #define TEST_NAMEX(name) void test_##name##A() #define CStringX CStringA #define _X(x) x #define XCHAR CHAR +#define YCHAR WCHAR #define dbgstrx(x) (const char*)x #define ok ok_("CStringA:\n" __FILE__, __LINE__) #define GetWindowsDirectoryX GetWindowsDirectoryA +#define MAKEINTRESOURCEX(x) MAKEINTRESOURCEA(x) +#define MAKEINTRESOURCEY(x) MAKEINTRESOURCEW(x) #include "CString.inl" @@ -179,4 +250,12 @@ START_TEST(CString) test_envW(); test_envA(); + + test_load_strW(); + test_load_strA(); + +#ifndef __REACTOS__ + printf("CString: %i tests executed (0 marked as todo, %i failures), %i skipped.\n", g_tests_executed, g_tests_failed, g_tests_skipped); + return 0; +#endif } diff --git a/rostests/apitests/atl/CString.inl b/rostests/apitests/atl/CString.inl index 28ed04d02c4..cd016ade1d3 100644 --- a/rostests/apitests/atl/CString.inl +++ b/rostests/apitests/atl/CString.inl @@ -388,3 +388,39 @@ TEST_NAMEX(env) ok(test.IsEmpty() == true, "Expected test to be empty\n"); ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength()); } + +TEST_NAMEX(load_str) +{ + CStringX str; + + ok(str.LoadString(0) == FALSE, "LoadString should fail.\n"); + + ok(str.LoadString(IDS_TEST1) == TRUE, "LoadString failed.\n"); + ok(str == _X("Test string one."), "The value was '%s'\n", dbgstrx(str)); + + ok(str.LoadString(IDS_TEST2) == TRUE, "LoadString failed.\n"); + ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str)); + + ok(str.LoadString(0) == FALSE, "LoadString should fail.\n"); + ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str)); + + XCHAR *xNULL = NULL; + CStringX str0(xNULL); + ok(str0.IsEmpty(), "str0 should be empty.\n"); + + YCHAR *yNULL = NULL; + CStringX str1(yNULL); + ok(str1.IsEmpty(), "str1 should be empty.\n"); + + CStringX str2(MAKEINTRESOURCEX(IDS_TEST1)); + ok(str2 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str2)); + + CStringX str3(MAKEINTRESOURCEX(IDS_TEST2)); + ok(str3 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str3)); + + CStringX str4(MAKEINTRESOURCEY(IDS_TEST1)); + ok(str4 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str4)); + + CStringX str5(MAKEINTRESOURCEY(IDS_TEST2)); + ok(str5 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str5)); +} diff --git a/rostests/apitests/atl/devenv/ATLTest.sln b/rostests/apitests/atl/devenv/ATLTest.sln index 76dd5427111..9c83ff2ba97 100644 --- a/rostests/apitests/atl/devenv/ATLTest.sln +++ b/rostests/apitests/atl/devenv/ATLTest.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CImage", "CImage.vcxproj", "{AE520E17-2DAE-40FF-B082-F32A7A935FB2}" EndProject @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSimpleArray", "CSimpleArra EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSimpleMap", "CSimpleMap.vcxproj", "{EC560DE6-6DB3-437D-85CA-582491FE6F95}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CString", "CString.vcxproj", "{FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -41,6 +43,14 @@ Global {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Release|x64.Build.0 = Release|x64 {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Release|x86.ActiveCfg = Release|Win32 {EC560DE6-6DB3-437D-85CA-582491FE6F95}.Release|x86.Build.0 = Release|Win32 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Debug|x64.ActiveCfg = Debug|x64 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Debug|x64.Build.0 = Debug|x64 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Debug|x86.ActiveCfg = Debug|Win32 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Debug|x86.Build.0 = Debug|Win32 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Release|x64.ActiveCfg = Release|x64 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Release|x64.Build.0 = Release|x64 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Release|x86.ActiveCfg = Release|Win32 + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/rostests/apitests/atl/devenv/CString.vcxproj b/rostests/apitests/atl/devenv/CString.vcxproj new file mode 100644 index 00000000000..89cd8d3273d --- /dev/null +++ b/rostests/apitests/atl/devenv/CString.vcxproj @@ -0,0 +1,189 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD} + 8.1 + AtlProj + + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + + + + + + + + + + + + + + + + + + + true + true + + + true + true + + + true + false + + + true + false + + + + NotUsing + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + true + + + + + NotUsing + Level3 + Disabled + _WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + true + + + + + NotUsing + Level3 + MaxSpeed + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + MultiThreaded + MultiThreaded + MultiThreadedDebug + MultiThreadedDebug + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + + + + + + + + + + \ No newline at end of file -- 2.17.1