[SHELL32]
authorThomas Faber <thomas.faber@reactos.org>
Tue, 9 May 2017 07:45:30 +0000 (07:45 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Tue, 9 May 2017 07:45:30 +0000 (07:45 +0000)
- Fix AddCommasW

svn path=/trunk/; revision=74510

reactos/dll/win32/shell32/shell32.cpp
rostests/apitests/shell32/AddCommas.c [new file with mode: 0644]
rostests/apitests/shell32/CMakeLists.txt
rostests/apitests/shell32/testlist.c

index ea8af8a..a4a363e 100644 (file)
@@ -42,20 +42,19 @@ AddCommasW(DWORD lValue, LPWSTR lpNumber)
 
     numFormat.NumDigits     = 0;
     numFormat.LeadingZero   = 0;
-    numFormat.Grouping      = 0; // FIXME! Use GetLocaleInfoW with LOCALE_SGROUPING and interpret the result.
+    numFormat.Grouping      = 3; // FIXME! Use GetLocaleInfoW with LOCALE_SGROUPING and interpret the result.
     numFormat.lpDecimalSep  = szSeparator;
     numFormat.lpThousandSep = szSeparator;
     numFormat.NegativeOrder = 0;
 
-    swprintf(szValue, L"%llu", lValue);
-    //_ultow(lValue, szValue, 10);
+    swprintf(szValue, L"%lu", lValue);
 
     if (GetNumberFormatW(LOCALE_USER_DEFAULT,
                          0,
                          szValue,
                          &numFormat,
                          lpNumber,
-                         wcslen(lpNumber)) != 0)
+                         MAX_PATH) != 0)
     {
         return lpNumber;
     }
diff --git a/rostests/apitests/shell32/AddCommas.c b/rostests/apitests/shell32/AddCommas.c
new file mode 100644 (file)
index 0000000..4bc7cd0
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * PROJECT:         ReactOS API tests
+ * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE:         Test for AddCommas
+ * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
+ */
+
+#include <apitest.h>
+#include <windef.h>
+#include <winnls.h>
+#include <bcrypt.h>
+#include <ntstatus.h>
+#include <strsafe.h>
+
+DECLSPEC_IMPORT LPWSTR WINAPI AddCommasW(DWORD lValue, LPWSTR lpNumber);
+
+START_TEST(AddCommas)
+{
+    WCHAR Separator[4];
+    WCHAR Grouping[11];
+    WCHAR Number[32];
+    WCHAR Expected[32];
+    PWSTR Ptr;
+    int Ret;
+
+    StartSeh()
+        AddCommasW(0, NULL);
+    EndSeh(STATUS_ACCESS_VIOLATION);
+
+    RtlFillMemory(Number, sizeof(Number), 0x55);
+    Ptr = AddCommasW(0, Number);
+    ok(Ptr == Number, "Ptr = %p, expected %p\n", Ptr, Number);
+    ok(Number[0] == L'0', "Number[0] = 0x%x\n", Number[0]);
+    ok(Number[1] == 0, "Number[1] = 0x%x\n", Number[1]);
+    ok(Number[2] == 0x5555, "Number[2] = 0x%x\n", Number[2]);
+
+    Ret = GetLocaleInfoW(LOCALE_USER_DEFAULT,
+                         LOCALE_STHOUSAND,
+                         Separator,
+                         RTL_NUMBER_OF(Separator));
+    if (!Ret)
+    {
+        skip("GetLocaleInfoW failed with %lu\n", GetLastError());
+        return;
+    }
+    Ret = GetLocaleInfoW(LOCALE_USER_DEFAULT,
+                         LOCALE_SGROUPING,
+                         Grouping,
+                         RTL_NUMBER_OF(Grouping));
+    if (!Ret)
+    {
+        skip("GetLocaleInfoW failed with %lu\n", GetLastError());
+        return;
+    }
+
+    if (wcscmp(Grouping, L"3;0"))
+    {
+        skip("Skipping remaining tests due to incompatible locale (separator '%ls', grouping '%ls')\n",
+             Separator, Grouping);
+        return;
+    }
+
+    RtlFillMemory(Number, sizeof(Number), 0x55);
+    Ptr = AddCommasW(123456789, Number);
+    ok(Ptr == Number, "Ptr = %p, expected %p\n", Ptr, Number);
+    StringCbPrintfW(Expected, sizeof(Expected), L"123%ls456%ls789", Separator, Separator);
+    ok(!wcscmp(Number, Expected), "Number = '%ls', expected %ls\n", Number, Expected);
+    ok(Number[wcslen(Number) + 1] == 0x5555, "Number[N] = 0x%x\n", Number[wcslen(Number) + 1]);
+
+    RtlFillMemory(Number, sizeof(Number), 0x55);
+    Ptr = AddCommasW(4294967295U, Number);
+    ok(Ptr == Number, "Ptr = %p, expected %p\n", Ptr, Number);
+    StringCbPrintfW(Expected, sizeof(Expected), L"4%ls294%ls967%ls295", Separator, Separator, Separator);
+    ok(!wcscmp(Number, Expected), "Number = '%ls', expected %ls\n", Number, Expected);
+    ok(Number[wcslen(Number) + 1] == 0x5555, "Number[N] = 0x%x\n", Number[wcslen(Number) + 1]);
+}
index a9b8bfa..713398a 100644 (file)
@@ -4,6 +4,7 @@ set_cpp(WITH_RUNTIME)
 include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/atl)
 
 add_executable(shell32_apitest
+    AddCommas.c
     CFSFolder.cpp
     CMyComputer.cpp
     CShellDesktop.cpp
index 54a2171..bffd029 100644 (file)
@@ -3,6 +3,7 @@
 #define STANDALONE
 #include <wine/test.h>
 
+extern void func_AddCommas(void);
 extern void func_CFSFolder(void);
 extern void func_CMyComputer(void);
 extern void func_CShellDesktop(void);
@@ -13,6 +14,7 @@ extern void func_SHParseDisplayName(void);
 
 const struct test winetest_testlist[] =
 {
+    { "AddCommas", func_AddCommas },
     { "CFSFolder", func_CFSFolder },
     { "CMyComputer", func_CMyComputer },
     { "CShellDesktop", func_CShellDesktop },