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 
16 START_TEST(AddCommas)
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);
27     EndSeh(STATUS_ACCESS_VIOLATION);
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 
36     Ret = GetLocaleInfoW(LOCALE_USER_DEFAULT,
37                          LOCALE_STHOUSAND,
38                          Separator,
39                          RTL_NUMBER_OF(Separator));
40     if (!Ret)
41     {
42         skip("GetLocaleInfoW failed with %lu\n", GetLastError());
43         return;
44     }
45     Ret = GetLocaleInfoW(LOCALE_USER_DEFAULT,
46                          LOCALE_SGROUPING,
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 }
76