ReactOS  0.4.13-dev-73-gcfe54aa
CString.cpp File Reference
#include <atlstr.h>
#include "resource.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <windows.h>
#include "CString.inl"
Include dependency graph for CString.cpp:

Go to the source code of this file.

Classes

struct  traits_test
 

Macros

#define ok(value, ...)
 
#define ok_(x1, x2)   set_location(x1,x2); ok_func
 
#define skip(...)
 
#define START_TEST(x)   int main(void)
 
#define ALLOC_EXPECT(a, b)   a
 
#define TEST_NAMEX(name)   void test_##name##W()
 
#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)
 
#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)
 

Functions

void set_location (const char *file, int line)
 
void ok_func (int value, const char *fmt,...)
 
void skip_func (const char *fmt,...)
 
charwine_dbgstr_w (const wchar_t *wstr)
 
static void test_basetypes ()
 
 START_TEST (CString)
 

Variables

int g_tests_executed = 0
 
int g_tests_failed = 0
 
int g_tests_skipped = 0
 
const charg_file = NULL
 
int g_line = 0
 
traits_test g_Tests []
 

Macro Definition Documentation

◆ _X [1/2]

#define _X (   x)    L ## x

Definition at line 210 of file CString.cpp.

◆ _X [2/2]

#define _X (   x)    x

Definition at line 210 of file CString.cpp.

◆ ALLOC_EXPECT

#define ALLOC_EXPECT (   a,
  b 
)    a

Definition at line 177 of file CString.cpp.

◆ CStringX [1/2]

#define CStringX   CStringW

Definition at line 209 of file CString.cpp.

◆ CStringX [2/2]

#define CStringX   CStringA

Definition at line 209 of file CString.cpp.

◆ dbgstrx [1/2]

#define dbgstrx (   x)    wine_dbgstr_w(x)

Definition at line 213 of file CString.cpp.

◆ dbgstrx [2/2]

#define dbgstrx (   x)    (const char*)x

Definition at line 213 of file CString.cpp.

◆ GetWindowsDirectoryX [1/2]

#define GetWindowsDirectoryX   GetWindowsDirectoryW

Definition at line 215 of file CString.cpp.

◆ GetWindowsDirectoryX [2/2]

#define GetWindowsDirectoryX   GetWindowsDirectoryA

Definition at line 215 of file CString.cpp.

◆ MAKEINTRESOURCEX [1/2]

#define MAKEINTRESOURCEX (   x)    MAKEINTRESOURCEW(x)

Definition at line 216 of file CString.cpp.

◆ MAKEINTRESOURCEX [2/2]

#define MAKEINTRESOURCEX (   x)    MAKEINTRESOURCEA(x)

Definition at line 216 of file CString.cpp.

◆ MAKEINTRESOURCEY [1/2]

#define MAKEINTRESOURCEY (   x)    MAKEINTRESOURCEA(x)

Definition at line 217 of file CString.cpp.

◆ MAKEINTRESOURCEY [2/2]

#define MAKEINTRESOURCEY (   x)    MAKEINTRESOURCEW(x)

Definition at line 217 of file CString.cpp.

◆ ok [1/3]

#define ok (   value,
  ... 
)
Value:
do { \
set_location(__FILE__, __LINE__); \
ok_func(value, __VA_ARGS__); \
} while (0)

Definition at line 214 of file CString.cpp.

◆ ok [2/3]

#define ok   ok_("CStringW:\n" __FILE__, __LINE__)

Definition at line 214 of file CString.cpp.

◆ ok [3/3]

#define ok   ok_("CStringA:\n" __FILE__, __LINE__)

Definition at line 214 of file CString.cpp.

◆ ok_

#define ok_ (   x1,
  x2 
)    set_location(x1,x2); ok_func

Definition at line 56 of file CString.cpp.

◆ skip

#define skip (   ...)
Value:
do { \
set_location(__FILE__, __LINE__); \
skip_func(__VA_ARGS__); \
} while (0)

Definition at line 57 of file CString.cpp.

◆ START_TEST

#define START_TEST (   x)    int main(void)

Definition at line 61 of file CString.cpp.

◆ TEST_NAMEX [1/2]

#define TEST_NAMEX (   name)    void test_##name##W()

Definition at line 208 of file CString.cpp.

◆ TEST_NAMEX [2/2]

#define TEST_NAMEX (   name)    void test_##name##A()

Definition at line 208 of file CString.cpp.

◆ XCHAR [1/2]

#define XCHAR   WCHAR

Definition at line 211 of file CString.cpp.

◆ XCHAR [2/2]

#define XCHAR   CHAR

Definition at line 211 of file CString.cpp.

◆ YCHAR [1/2]

#define YCHAR   CHAR

Definition at line 212 of file CString.cpp.

◆ YCHAR [2/2]

#define YCHAR   WCHAR

Definition at line 212 of file CString.cpp.

Function Documentation

◆ ok_func()

void ok_func ( int  value,
const char fmt,
  ... 
)

Definition at line 29 of file CString.cpp.

30  {
31  va_list va;
32  va_start(va, fmt);
33  if (!value)
34  {
35  printf("%s (%d): ", g_file, g_line);
36  vprintf(fmt, va);
38  }
40  va_end(va);
41  }
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
const char * g_file
Definition: CString.cpp:22
int g_tests_executed
Definition: CString.cpp:19
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
int g_line
Definition: CString.cpp:23
#define va_start(ap, A)
Definition: acmsvcex.h:91
int g_tests_failed
Definition: CString.cpp:20
Definition: dsound.c:943
#define printf
Definition: config.h:203

◆ set_location()

void set_location ( const char file,
int  line 
)

Definition at line 24 of file CString.cpp.

25  {
26  g_file = file;
27  g_line = line;
28  }
const char * g_file
Definition: CString.cpp:22
const char file[]
Definition: icontest.c:11
int g_line
Definition: CString.cpp:23
char line[200]
Definition: main.c:97

◆ skip_func()

void skip_func ( const char fmt,
  ... 
)

Definition at line 42 of file CString.cpp.

43  {
44  va_list va;
45  va_start(va, fmt);
46  printf("%s (%d): test skipped: ", g_file, g_line);
47  vprintf(fmt, va);
49  va_end(va);
50  }
#define va_end(ap)
Definition: acmsvcex.h:90
int g_tests_skipped
Definition: CString.cpp:21
char * va_list
Definition: acmsvcex.h:78
const char * g_file
Definition: CString.cpp:22
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
int g_line
Definition: CString.cpp:23
#define va_start(ap, A)
Definition: acmsvcex.h:91
Definition: dsound.c:943
#define printf
Definition: config.h:203

◆ START_TEST()

START_TEST ( CString  )

Definition at line 221 of file CString.cpp.

222 {
223  test_basetypes();
224 
225  if ((ALLOC_EXPECT(1, 2)) == 2)
226  {
227  skip("Ignoring real GetAllocLength() lenght\n");
228  }
229 
230  test_operators_initW();
231  test_operators_initA();
232 
233  test_compareW();
234  test_compareA();
235 
236  test_findW();
237  test_findA();
238 
239  test_formatW();
240  test_formatA();
241 
242  test_substrW();
243  test_substrA();
244 
245  test_replaceW();
246  test_replaceA();
247 
248  test_trimW();
249  test_trimA();
250 
251  test_envW();
252  test_envA();
253 
254  test_load_strW();
255  test_load_strA();
256 
257  test_bstrW();
258  test_bstrA();
259 
260 #ifndef HAVE_APITEST
261  printf("CString: %i tests executed (0 marked as todo, %i failures), %i skipped.\n", g_tests_executed, g_tests_failed, g_tests_skipped);
262  return g_tests_failed;
263 #endif
264 }
int g_tests_skipped
Definition: CString.cpp:21
int g_tests_executed
Definition: CString.cpp:19
static void test_basetypes()
Definition: CString.cpp:93
#define ALLOC_EXPECT(a, b)
Definition: CString.cpp:177
#define skip(...)
Definition: CString.cpp:57
int g_tests_failed
Definition: CString.cpp:20
#define printf
Definition: config.h:203

◆ test_basetypes()

static void test_basetypes ( )
static

Definition at line 93 of file CString.cpp.

94 {
95  int len;
96  char bufA[10];
97  wchar_t bufW[10];
98 
99  for (size_t n = 0; n < _countof(g_Tests); ++n)
100  {
102  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);
103 
105  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);
106 
108  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);
109 
111  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);
112 
113  if (g_Tests[n].strA && g_Tests[n].strW)
114  {
115  memset(bufA, 'x', sizeof(bufA));
117  char ch = bufA[g_Tests[n].exp_1];
118  ok(ch == '\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
119  ok(!strcmp(bufA, g_Tests[n].strA), "Expected bufA to be %s, was: %s for %u\n", g_Tests[n].strA, bufA, n);
120  ch = bufA[g_Tests[n].exp_1+1];
121  ok(ch == 'x', "Expected %i to be 'x', was: %c (%i) for %u\n", g_Tests[n].exp_1+1, ch, (int)ch, n);
122  }
123 
124  if (g_Tests[n].strA && g_Tests[n].strW)
125  {
126  memset(bufA, 'x', sizeof(bufA));
128  char ch = bufA[g_Tests[n].exp_1];
129  ok(ch == '\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
130  ok(!strcmp(bufA, g_Tests[n].strA), "Expected bufA to be %s, was: %s for %u\n", g_Tests[n].strA, bufA, n);
131  ch = bufA[g_Tests[n].exp_1+1];
132  ok(ch == 'x', "Expected %i to be 'x', was: %c (%i) for %u\n", g_Tests[n].exp_1+1, ch, (int)ch, n);
133  }
134 
135  // wchar_t --> please note, swapped the expectations from 2 and 4 !
137  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);
138 
140  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);
141 
143  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);
144 
146  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);
147 
148  if (g_Tests[n].strA && g_Tests[n].strW)
149  {
150  memset(bufW, 'x', sizeof(bufW));
152  wchar_t ch = bufW[g_Tests[n].exp_1];
153  ok(ch == L'\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
154  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);
155  ch = bufW[g_Tests[n].exp_1+1];
156  ok(ch == 30840, "Expected %i to be %i for %u\n", g_Tests[n].exp_1+1, (int)ch, n);
157  }
158 
159  if (g_Tests[n].strA && g_Tests[n].strW)
160  {
161  memset(bufW, 'x', sizeof(bufW));
163  wchar_t ch = bufW[g_Tests[n].exp_1];
164  ok(ch == '\0', "Expected %i to be \\0, was: %c (%i) for %u\n", g_Tests[n].exp_1, ch, (int)ch, n);
165  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);
166  ch = bufW[g_Tests[n].exp_1+1];
167  ok(ch == 30840, "Expected %i to be %i for %u\n", g_Tests[n].exp_1+1, (int)ch, n);
168  }
169  }
170 }
char strA[12]
Definition: clipboard.c:2028
#define _countof(array)
Definition: fontsub.cpp:30
#define str_len
Definition: treelist.c:89
GLdouble n
Definition: glext.h:7729
traits_test g_Tests[]
Definition: CString.cpp:78
WCHAR strW[12]
Definition: clipboard.c:2029
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: CString.cpp:62
#define ok(value,...)
Definition: CString.cpp:214
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

◆ wine_dbgstr_w()

char* wine_dbgstr_w ( const wchar_t wstr)

Definition at line 62 of file CString.cpp.

63  {
64  static char buf[512];
65  WideCharToMultiByte(CP_ACP, 0, wstr, -1, buf, _countof(buf), NULL, NULL);
66  return buf;
67  }
#define WideCharToMultiByte
Definition: compat.h:101
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CP_ACP
Definition: compat.h:99
#define _countof(array)
Definition: fontsub.cpp:30
smooth NULL
Definition: ftsmooth.c:416

Referenced by test_basetypes().

Variable Documentation

◆ g_file

const char* g_file = NULL

Definition at line 22 of file CString.cpp.

Referenced by ok_func(), set_location(), and skip_func().

◆ g_line

int g_line = 0

Definition at line 23 of file CString.cpp.

Referenced by ok_func(), set_location(), and skip_func().

◆ g_Tests

traits_test g_Tests[]
Initial value:
= {
{ NULL, NULL, 0, 0, 0, -1, 0 },
{ NULL, NULL, -1, 0, -1, -1, 0 },
{ NULL, NULL, 1, 0, 1, -1, 0 },
{ "", L"", 0, 0, 0, 0, 0 },
{ "", L"", -1, 0, -1, 0, 1 },
{ "", L"", 1, 0, 1, 0, 1 },
{ "AAABBB", L"AAABBB", 0, 6, 0, 6, 0 },
{ "AAABBB", L"AAABBB", 3, 6, 3, 6, 3 },
{ "AAABBB", L"AAABBB", -1, 6, -1, 6, 7 },
}
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250

Definition at line 78 of file CString.cpp.

Referenced by test_basetypes().

◆ g_tests_executed

int g_tests_executed = 0

Definition at line 19 of file CString.cpp.

Referenced by ok_func(), and START_TEST().

◆ g_tests_failed

int g_tests_failed = 0

Definition at line 20 of file CString.cpp.

Referenced by ok_func(), and START_TEST().

◆ g_tests_skipped

int g_tests_skipped = 0

Definition at line 21 of file CString.cpp.

Referenced by skip_func(), and START_TEST().