[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
This commit is contained in:
Mark Jansen 2017-03-15 19:17:44 +00:00
parent 14e5cfe8eb
commit 447c0daf7d
6 changed files with 347 additions and 29 deletions

View file

@ -326,48 +326,52 @@ public:
*this = static_cast<const YCHAR*>(strSrc);
}
CStringT(_In_opt_z_ const XCHAR* pszSrc) :
CThisSimpleString( StringTraits::GetDefaultManager() )
protected:
/* helper function */
template <typename T_CHAR>
void LoadFromPtr_(_In_opt_z_ const T_CHAR* pszSrc)
{
// FIXME: Check whether pszSrc is not a resource string ID!
*this = pszSrc;
if (pszSrc == NULL)
return;
if (IS_INTRESOURCE(pszSrc))
LoadString(LOWORD(pszSrc));
else
*this = pszSrc;
}
CStringT(
_In_opt_z_ const XCHAR* pszSrc,
_In_ IAtlStringMgr* pStringMgr) :
CThisSimpleString( pStringMgr )
public:
CStringT(_In_opt_z_ const XCHAR* pszSrc) :
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)
{
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())
{
}

View file

@ -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)

View file

@ -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 <atlstr.h>
#include <apitest.h>
#include "resource.h"
#ifdef __REACTOS__
#include <apitest.h>
#else
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <windows.h>
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
}

View file

@ -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));
}

View file

@ -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

View file

@ -0,0 +1,189 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}</ProjectGuid>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<Keyword>AtlProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<ResourceCompile>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RegisterOutput>true</RegisterOutput>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<ResourceCompile>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RegisterOutput>true</RegisterOutput>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<ResourceCompile>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<RegisterOutput>true</RegisterOutput>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<ResourceCompile>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<RegisterOutput>true</RegisterOutput>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="../CString.cpp">
<RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MultiThreaded</RuntimeLibrary>
<RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MultiThreaded</RuntimeLibrary>
<RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MultiThreadedDebug</RuntimeLibrary>
<RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\atl_apitest.rc" />
</ItemGroup>
<ItemGroup>
<None Include="..\cstring.inl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>