ReactOS 0.4.15-dev-7670-g69b08be
AddCommas.cpp File Reference
#include "shelltest.h"
#include <winnls.h>
#include <bcrypt.h>
#include <strsafe.h>
Include dependency graph for AddCommas.cpp:

Go to the source code of this file.

Functions

DECLSPEC_IMPORT LPWSTR WINAPI AddCommasW (DWORD lValue, LPWSTR lpNumber)
 
 START_TEST (AddCommas)
 

Function Documentation

◆ AddCommasW()

DECLSPEC_IMPORT LPWSTR WINAPI AddCommasW ( DWORD  lValue,
LPWSTR  lpNumber 
)

Definition at line 33 of file shell32.cpp.

34{
35 WCHAR szValue[MAX_PATH], szSeparator[8 + 1];
36 NUMBERFMTW numFormat;
37
40 szSeparator,
41 _countof(szSeparator));
42
43 numFormat.NumDigits = 0;
44 numFormat.LeadingZero = 0;
45 numFormat.Grouping = 3; // FIXME! Use GetLocaleInfoW with LOCALE_SGROUPING and interpret the result.
46 numFormat.lpDecimalSep = szSeparator;
47 numFormat.lpThousandSep = szSeparator;
48 numFormat.NegativeOrder = 0;
49
50 swprintf(szValue, L"%lu", lValue);
51
53 0,
54 szValue,
55 &numFormat,
56 lpNumber,
57 MAX_PATH) != 0)
58 {
59 return lpNumber;
60 }
61
62 wcscpy(lpNumber, szValue);
63 return lpNumber;
64}
#define MAX_PATH
Definition: compat.h:34
#define swprintf
Definition: precomp.h:40
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: lang.c:1108
INT WINAPI GetNumberFormatW(LCID lcid, DWORD dwFlags, LPCWSTR lpszValue, const NUMBERFMTW *lpFormat, LPWSTR lpNumberStr, int cchOut)
Definition: lcformat.c:1212
#define LOCALE_USER_DEFAULT
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define _countof(array)
Definition: sndvol32.h:68
UINT NumDigits
Definition: winnls.h:642
LPWSTR lpDecimalSep
Definition: winnls.h:645
UINT Grouping
Definition: winnls.h:644
UINT NegativeOrder
Definition: winnls.h:647
LPWSTR lpThousandSep
Definition: winnls.h:646
UINT LeadingZero
Definition: winnls.h:643
#define LOCALE_STHOUSAND
Definition: winnls.h:43
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( AddCommas  )

Definition at line 16 of file AddCommas.cpp.

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
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
#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 NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
if(dx< 0)
Definition: linetemp.h:194
BOOL expected
Definition: store.c:2063
_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
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
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 LOCALE_SGROUPING
Definition: winnls.h:44
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList