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