ReactOS  0.4.14-dev-358-gbef841c
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 }
LPWSTR lpThousandSep
Definition: winnls.h:643
LPWSTR lpDecimalSep
Definition: winnls.h:642
#define _countof(array)
Definition: fontsub.cpp:30
#define LOCALE_USER_DEFAULT
UINT Grouping
Definition: winnls.h:641
UINT NegativeOrder
Definition: winnls.h:644
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: lang.c:1098
#define LOCALE_STHOUSAND
Definition: winnls.h:43
UINT NumDigits
Definition: winnls.h:639
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
UINT LeadingZero
Definition: winnls.h:640
INT WINAPI GetNumberFormatW(LCID lcid, DWORD dwFlags, LPCWSTR lpszValue, const NUMBERFMTW *lpFormat, LPWSTR lpNumberStr, int cchOut)
Definition: lcformat.c:1198

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 }
#define LOCALE_SGROUPING
Definition: winnls.h:44
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
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
GLdouble n
Definition: glext.h:7729
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define StartSeh()
Definition: _sntprintf.h:16
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
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
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 ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN Expected
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL expected
Definition: store.c:2063
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17