ReactOS 0.4.15-dev-8076-g06e89b2
CString.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for CString
5 * COPYRIGHT: Copyright 2016-2017 Mark Jansen (mark.jansen@reactos.org)
6 * Copyright 2017 Katayama Hirofumi MZ
7 */
8
9#include <atlstr.h>
10#include "resource.h"
11
12#ifdef HAVE_APITEST
13 #include <apitest.h>
14#else
15 #include "atltest.h"
16#endif
17
19{
20 const char* strA;
21 const wchar_t* strW;
24};
25
27 // inputs outputs
28 { NULL, NULL, 0, 0, 0, -1, 0 },
29 { NULL, NULL, -1, 0, -1, -1, 0 },
30 { NULL, NULL, 1, 0, 1, -1, 0 },
31
32 { "", L"", 0, 0, 0, 0, 0 },
33 { "", L"", -1, 0, -1, 0, 1 },
34 { "", L"", 1, 0, 1, 0, 1 },
35
36 { "AAABBB", L"AAABBB", 0, 6, 0, 6, 0 },
37 { "AAABBB", L"AAABBB", 3, 6, 3, 6, 3 },
38 { "AAABBB", L"AAABBB", -1, 6, -1, 6, 7 },
39};
40
41static void test_basetypes()
42{
43 int len;
44 char bufA[10];
45 wchar_t bufW[10];
46
47 for (size_t n = 0; n < _countof(g_Tests); ++n)
48 {
50 ok(len == g_Tests[n].exp_1, "Expected len to be %i, was %i for %u (A)\n", g_Tests[n].exp_1, len, n);
51
53 ok(len == g_Tests[n].exp_2, "Expected len to be %i, was %i for %u (A,len)\n", g_Tests[n].exp_2, len, n);
54
56 ok(len == g_Tests[n].exp_3, "Expected len to be %i, was %i for %u (W)\n", g_Tests[n].exp_3, len, n);
57
59 ok(len == g_Tests[n].exp_4, "Expected len to be %i, was %i for %u (W,len)\n", g_Tests[n].exp_4, len, n);
60
61 if (g_Tests[n].strA && g_Tests[n].strW)
62 {
63 memset(bufA, 'x', sizeof(bufA));
65 char ch = bufA[g_Tests[n].exp_1];
66 ok(ch == '\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
67 ok(!strcmp(bufA, g_Tests[n].strA), "Expected bufA to be %s, was: %s for %u\n", g_Tests[n].strA, bufA, n);
68 ch = bufA[g_Tests[n].exp_1+1];
69 ok(ch == 'x', "Expected %i to be 'x', was: %c (%i) for %u\n", g_Tests[n].exp_1+1, ch, (int)ch, n);
70 }
71
72 if (g_Tests[n].strA && g_Tests[n].strW)
73 {
74 memset(bufA, 'x', sizeof(bufA));
76 char ch = bufA[g_Tests[n].exp_1];
77 ok(ch == '\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
78 ok(!strcmp(bufA, g_Tests[n].strA), "Expected bufA to be %s, was: %s for %u\n", g_Tests[n].strA, bufA, n);
79 ch = bufA[g_Tests[n].exp_1+1];
80 ok(ch == 'x', "Expected %i to be 'x', was: %c (%i) for %u\n", g_Tests[n].exp_1+1, ch, (int)ch, n);
81 }
82
83 // wchar_t --> please note, swapped the expectations from 2 and 4 !
85 ok(len == g_Tests[n].exp_1, "Expected len to be %i, was %i for %u (A)\n", g_Tests[n].exp_1, len, n);
86
88 ok(len == g_Tests[n].exp_4, "Expected len to be %i, was %i for %u (A,len)\n", g_Tests[n].exp_4, len, n);
89
91 ok(len == g_Tests[n].exp_3, "Expected len to be %i, was %i for %u (W)\n", g_Tests[n].exp_3, len, n);
92
94 ok(len == g_Tests[n].exp_2, "Expected len to be %i, was %i for %u (W,len)\n", g_Tests[n].exp_2, len, n);
95
96 if (g_Tests[n].strA && g_Tests[n].strW)
97 {
98 memset(bufW, 'x', sizeof(bufW));
100 wchar_t ch = bufW[g_Tests[n].exp_1];
101 ok(ch == L'\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
102 ok(!wcscmp(bufW, g_Tests[n].strW), "Expected bufW to be %s, was: %s for %u\n", wine_dbgstr_w(g_Tests[n].strW), wine_dbgstr_w(bufW), n);
103 ch = bufW[g_Tests[n].exp_1+1];
104 ok(ch == 30840, "Expected %i to be %i for %u\n", g_Tests[n].exp_1+1, (int)ch, n);
105 }
106
107 if (g_Tests[n].strA && g_Tests[n].strW)
108 {
109 memset(bufW, 'x', sizeof(bufW));
111 wchar_t ch = bufW[g_Tests[n].exp_1];
112 ok(ch == '\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
113 ok(!wcscmp(bufW, g_Tests[n].strW), "Expected bufW to be %s, was: %s for %u\n", wine_dbgstr_w(g_Tests[n].strW), wine_dbgstr_w(bufW), n);
114 ch = bufW[g_Tests[n].exp_1+1];
115 ok(ch == 30840, "Expected %i to be %i for %u\n", g_Tests[n].exp_1+1, (int)ch, n);
116 }
117 }
118}
119
120#undef ok
121#undef _T
122
123#define TEST_NAMEX(name) void test_##name##W()
124#define CStringX CStringW
125#define _X(x) L ## x
126#define XCHAR WCHAR
127#define YCHAR CHAR
128#define dbgstrx(x) wine_dbgstr_w(x)
129#define ok ok_("CStringW:\n" __FILE__, __LINE__)
130#define GetWindowsDirectoryX GetWindowsDirectoryW
131#define MAKEINTRESOURCEX(x) MAKEINTRESOURCEW(x)
132#define MAKEINTRESOURCEY(x) MAKEINTRESOURCEA(x)
133#include "CString.inl"
134
135
136#undef CStringX
137#undef TEST_NAMEX
138#undef _X
139#undef XCHAR
140#undef YCHAR
141#undef dbgstrx
142#undef ok
143#undef GetWindowsDirectoryX
144#undef MAKEINTRESOURCEX
145#undef MAKEINTRESOURCEY
146
147#define TEST_NAMEX(name) void test_##name##A()
148#define CStringX CStringA
149#define _X(x) x
150#define XCHAR CHAR
151#define YCHAR WCHAR
152#define dbgstrx(x) (const char*)x
153#define ok ok_("CStringA:\n" __FILE__, __LINE__)
154#define GetWindowsDirectoryX GetWindowsDirectoryA
155#define MAKEINTRESOURCEX(x) MAKEINTRESOURCEA(x)
156#define MAKEINTRESOURCEY(x) MAKEINTRESOURCEW(x)
157#include "CString.inl"
158
159
161{
163
164 test_operators_initW();
165 test_operators_initA();
166
167 test_compareW();
168 test_compareA();
169
170 test_findW();
171 test_findA();
172
173 test_formatW();
174 test_formatA();
175
176 test_substrW();
177 test_substrA();
178
179 test_replaceW();
180 test_replaceA();
181
182 test_trimW();
183 test_trimA();
184
185 test_envW();
186 test_envA();
187
188 test_load_strW();
189 test_load_strA();
190
191 test_bstrW();
192 test_bstrA();
193
194 test_tokenizeW();
195 test_tokenizeA();
196}
traits_test g_Tests[]
Definition: CString.cpp:26
static void test_basetypes()
Definition: CString.cpp:41
#define ok
Definition: CString.cpp:153
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define START_TEST(x)
Definition: atltest.h:75
static int __cdecl GetBaseTypeLength(_In_z_ LPCWSTR pszSource) noexcept
Definition: cstringt.h:29
static void __cdecl ConvertToBaseType(_Out_writes_(nDestLength) LPWSTR pszDest, _In_ int nDestLength, _In_ LPCWSTR pszSrc, _In_ int nSrcLength=-1)
Definition: cstringt.h:55
#define NULL
Definition: types.h:112
GLdouble n
Definition: glext.h:7729
GLenum GLsizei len
Definition: glext.h:6722
#define wine_dbgstr_w
Definition: kernel32.h:34
WCHAR strW[12]
Definition: clipboard.c:2029
char strA[12]
Definition: clipboard.c:2028
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define memset(x, y, z)
Definition: compat.h:39
#define _countof(array)
Definition: sndvol32.h:68
const char * strA
Definition: CString.cpp:20
int str_len
Definition: CString.cpp:22
const wchar_t * strW
Definition: CString.cpp:21
#define str_len
Definition: treelist.c:89