ReactOS 0.4.15-dev-8109-gd7be748
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
14extern "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}
DECLSPEC_IMPORT LPWSTR WINAPI AddCommasW(DWORD lValue, LPWSTR lpNumber)
Definition: shell32.cpp:33
BOOLEAN Expected
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
wchar_t * AddCommas(wchar_t *Result, uint64 Number)
Definition: Unfrag.cpp:48
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1665
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define LOCALE_USER_DEFAULT
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#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 DECLSPEC_IMPORT
Definition: rpc.h:78
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
uint16_t * PWSTR
Definition: typedefs.h:56
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define LOCALE_SGROUPING
Definition: winnls.h:44
#define LOCALE_STHOUSAND
Definition: winnls.h:43
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184