ReactOS  0.4.14-dev-115-g4576127
AddCommas.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Test for AddCommas
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "shelltest.h"
9 
10 #include <winnls.h>
11 #include <bcrypt.h>
12 #include <strsafe.h>
13 
14 extern "C" DECLSPEC_IMPORT LPWSTR WINAPI AddCommasW(DWORD lValue, LPWSTR lpNumber);
15 
17 {
18  WCHAR Separator[4];
19  WCHAR Grouping[11];
20  WCHAR Number[32];
21  WCHAR Expected[32];
22  PWSTR Ptr;
23  int Ret;
24 
25  StartSeh()
26  AddCommasW(0, NULL);
28 
29  RtlFillMemory(Number, sizeof(Number), 0x55);
30  Ptr = AddCommasW(0, Number);
31  ok(Ptr == Number, "Ptr = %p, expected %p\n", Ptr, Number);
32  ok(Number[0] == L'0', "Number[0] = 0x%x\n", Number[0]);
33  ok(Number[1] == 0, "Number[1] = 0x%x\n", Number[1]);
34  ok(Number[2] == 0x5555, "Number[2] = 0x%x\n", Number[2]);
35 
38  Separator,
39  RTL_NUMBER_OF(Separator));
40  if (!Ret)
41  {
42  skip("GetLocaleInfoW failed with %lu\n", GetLastError());
43  return;
44  }
47  Grouping,
48  RTL_NUMBER_OF(Grouping));
49  if (!Ret)
50  {
51  skip("GetLocaleInfoW failed with %lu\n", GetLastError());
52  return;
53  }
54 
55  if (wcscmp(Grouping, L"3;0"))
56  {
57  skip("Skipping remaining tests due to incompatible locale (separator '%ls', grouping '%ls')\n",
58  Separator, Grouping);
59  return;
60  }
61 
62  RtlFillMemory(Number, sizeof(Number), 0x55);
63  Ptr = AddCommasW(123456789, Number);
64  ok(Ptr == Number, "Ptr = %p, expected %p\n", Ptr, Number);
65  StringCbPrintfW(Expected, sizeof(Expected), L"123%ls456%ls789", Separator, Separator);
66  ok(!wcscmp(Number, Expected), "Number = '%ls', expected %ls\n", Number, Expected);
67  ok(Number[wcslen(Number) + 1] == 0x5555, "Number[N] = 0x%x\n", Number[wcslen(Number) + 1]);
68 
69  RtlFillMemory(Number, sizeof(Number), 0x55);
70  Ptr = AddCommasW(4294967295U, Number);
71  ok(Ptr == Number, "Ptr = %p, expected %p\n", Ptr, Number);
72  StringCbPrintfW(Expected, sizeof(Expected), L"4%ls294%ls967%ls295", Separator, Separator, Separator);
73  ok(!wcscmp(Number, Expected), "Number = '%ls', expected %ls\n", Number, Expected);
74  ok(Number[wcslen(Number) + 1] == 0x5555, "Number[N] = 0x%x\n", Number[wcslen(Number) + 1]);
75 }
#define LOCALE_SGROUPING
Definition: winnls.h:44
uint16_t * PWSTR
Definition: typedefs.h:54
#define LOCALE_USER_DEFAULT
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define U(x)
Definition: wordpad.c:44
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define StartSeh()
Definition: _sntprintf.h:16
wchar_t * AddCommas(wchar_t *Result, uint64 Number)
Definition: Unfrag.cpp:48
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: lang.c:1098
#define LOCALE_STHOUSAND
Definition: winnls.h:43
DECLSPEC_IMPORT LPWSTR WINAPI AddCommasW(DWORD lValue, LPWSTR lpNumber)
Definition: shell32.cpp:33
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
START_TEST(AddCommas)
Definition: AddCommas.cpp:16
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define DECLSPEC_IMPORT
Definition: hal.h:20
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOLEAN Expected
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17