[PATCH] kernel32/tests: Remove redundant calls to SetLastError() in the locale tests.

Francois Gouget fgouget at codeweavers.com
Tue Aug 17 10:43:17 CDT 2021


In addition to setting the input, output and expected buffer strings
the STRINGS{A,W} macros also call SetLastError().

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
STRINGSW() was useful when we did not have support for L"" strings.
Now they could potentially both be removed in favor of plugging the 
format string straight into the relevant API and the expected string 
into some sort of 'expected' macro. 
That would leave the buffer initialisation and SetLastError() call to 
sprinkle in most places.

Let me know if converting things that way would be preferred.

...or if some other approach would be better, e.g. remove the 
SetLastError() calls from the macro and only add it wherever it's 
missing before a GetLastError() check.
---
 dlls/kernel32/tests/locale.c | 39 ------------------------------------
 1 file changed, 39 deletions(-)

diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c
index 75c86bbaf21..a518aa15888 100644
--- a/dlls/kernel32/tests/locale.c
+++ b/dlls/kernel32/tests/locale.c
@@ -440,7 +440,6 @@ static void test_GetTimeFormatA(void)
 
   memset(&curtime, 2, sizeof(SYSTEMTIME));
   STRINGSA("tt HH':'mm'@'ss", ""); /* Invalid time */
-  SetLastError(0xdeadbeef);
   ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -450,7 +449,6 @@ static void test_GetTimeFormatA(void)
   curtime.wSecond = 13;
   curtime.wMilliseconds = 22;
   STRINGSA("tt HH':'mm'@'ss", "AM 08:56 at 13"); /* Valid time */
-  SetLastError(0xdeadbeef);
   ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError());
   EXPECT_LENA; EXPECT_EQA;
@@ -462,7 +460,6 @@ static void test_GetTimeFormatA(void)
      "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
 
   STRINGSA("tt HH':'mm'@'ss", "A"); /* Insufficient buffer */
-  SetLastError(0xdeadbeef);
   ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, input, buffer, 2);
   ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
       "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
@@ -613,7 +610,6 @@ static void test_GetTimeFormatA(void)
 
   curtime.wHour = 25;
   STRINGSA("'123'tt", ""); /* Invalid time */
-  SetLastError(0xdeadbeef);
   ret = GetTimeFormatA(lcid, 0, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -640,7 +636,6 @@ static void test_GetTimeFormatEx(void)
 
   memset(&curtime, 2, sizeof(SYSTEMTIME));
   STRINGSW("tt HH':'mm'@'ss", ""); /* Invalid time */
-  SetLastError(0xdeadbeef);
   ret = pGetTimeFormatEx(localeW, TIME_FORCE24HOURFORMAT, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -650,7 +645,6 @@ static void test_GetTimeFormatEx(void)
   curtime.wSecond = 13;
   curtime.wMilliseconds = 22;
   STRINGSW("tt HH':'mm'@'ss", "AM 08:56 at 13"); /* Valid time */
-  SetLastError(0xdeadbeef);
   ret = pGetTimeFormatEx(localeW, TIME_FORCE24HOURFORMAT, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError());
   EXPECT_LENW; EXPECT_EQW;
@@ -662,7 +656,6 @@ static void test_GetTimeFormatEx(void)
      "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
 
   STRINGSW("tt HH':'mm'@'ss", "A"); /* Insufficient buffer */
-  SetLastError(0xdeadbeef);
   ret = pGetTimeFormatEx(localeW, TIME_FORCE24HOURFORMAT, &curtime, input, buffer, 2);
   ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
       "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
@@ -809,7 +802,6 @@ static void test_GetTimeFormatEx(void)
 
   curtime.wHour = 25;
   STRINGSW("'123'tt", ""); /* Invalid time */
-  SetLastError(0xdeadbeef);
   ret = pGetTimeFormatEx(localeW, 0, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -834,7 +826,6 @@ static void test_GetDateFormatA(void)
 
   memset(&curtime, 2, sizeof(SYSTEMTIME)); /* Invalid time */
   STRINGSA("ddd',' MMM dd yy","");
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatA(lcid, 0, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -850,7 +841,6 @@ static void test_GetDateFormatA(void)
 
   /* Same as above but with LOCALE_NOUSEROVERRIDE */
   STRINGSA("ddd',' MMM dd yy",""); /* Simple case */
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatA(lcid, NUO, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok(!ret && GetLastError() == ERROR_INVALID_FLAGS,
      "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
@@ -873,7 +863,6 @@ static void test_GetDateFormatA(void)
   EXPECT_EQA;
 
   STRINGSA("ddd',' MMM dd ''''yy",""); /* Buffer too small */
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatA(lcid, 0, &curtime, input, buffer, 2);
   ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
       "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
@@ -894,7 +883,6 @@ static void test_GetDateFormatA(void)
   /* test for expected DATE_YEARMONTH behavior with null format */
   /* NT4 returns ERROR_INVALID_FLAGS for DATE_YEARMONTH */
   STRINGSA("ddd',' MMM dd ''''yy", ""); /* DATE_YEARMONTH */
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatA(lcid, NUO|DATE_YEARMONTH, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok(!ret && GetLastError() == ERROR_INVALID_FLAGS,
      "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
@@ -903,7 +891,6 @@ static void test_GetDateFormatA(void)
   /* Test that using invalid DATE_* flags results in the correct error */
   /* and return values */
   STRINGSA("m/d/y", ""); /* Invalid flags */
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatA(lcid, DATE_YEARMONTH|DATE_SHORTDATE|DATE_LONGDATE, &curtime, input,
                        buffer, ARRAY_SIZE(buffer));
   ok(!ret && GetLastError() == ERROR_INVALID_FLAGS,
@@ -1002,14 +989,12 @@ static void test_GetDateFormatEx(void)
   }
 
   STRINGSW("",""); /* If flags are set, then format must be NULL */
-  SetLastError(0xdeadbeef);
   ret = pGetDateFormatEx(localeW, DATE_LONGDATE, NULL, input, buffer, ARRAY_SIZE(buffer), NULL);
   ok(!ret && GetLastError() == ERROR_INVALID_FLAGS,
      "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
   EXPECT_EQW;
 
   STRINGSW("",""); /* NULL buffer, len > 0 */
-  SetLastError(0xdeadbeef);
   ret = pGetDateFormatEx(localeW, 0, NULL, input, NULL, ARRAY_SIZE(buffer), NULL);
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -1020,7 +1005,6 @@ static void test_GetDateFormatEx(void)
   EXPECT_LENW; EXPECT_EQW;
 
   STRINGSW("",""); /* Invalid flag combination */
-  SetLastError(0xdeadbeef);
   ret = pGetDateFormatEx(localeW, DATE_LONGDATE|DATE_SHORTDATE, NULL,
                        input, NULL, 0, NULL);
   ok(!ret && GetLastError() == ERROR_INVALID_FLAGS,
@@ -1064,7 +1048,6 @@ static void test_GetDateFormatEx(void)
   curtime.wSecond = 0;
   curtime.wMilliseconds = 0;
   STRINGSW("dddd d MMMM yyyy","Monday 1 January 1601");
-  SetLastError(0xdeadbeef);
   ret = pGetDateFormatEx(localeW, 0, &curtime, input, buffer, ARRAY_SIZE(buffer), NULL);
   ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError());
   EXPECT_LENW; EXPECT_EQW;
@@ -1078,7 +1061,6 @@ static void test_GetDateFormatEx(void)
   curtime.wSecond = 59;
   curtime.wMilliseconds = 999;
   STRINGSW("dddd d MMMM yyyy","Friday 31 December 1600");
-  SetLastError(0xdeadbeef);
   ret = pGetDateFormatEx(localeW, 0, &curtime, input, buffer, ARRAY_SIZE(buffer), NULL);
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -1103,7 +1085,6 @@ static void test_GetDateFormatW(void)
   EXPECT_EQW;
 
   STRINGSW("",""); /* NULL buffer, len > 0 */
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatW (lcid, 0, NULL, input, NULL, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -1137,7 +1118,6 @@ static void test_GetDateFormatW(void)
   curtime.wSecond = 0;
   curtime.wMilliseconds = 0;
   STRINGSW("dddd d MMMM yyyy","Monday 1 January 1601");
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatW (lcid, 0, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError());
   EXPECT_LENW; EXPECT_EQW;
@@ -1151,7 +1131,6 @@ static void test_GetDateFormatW(void)
   curtime.wSecond = 59;
   curtime.wMilliseconds = 999;
   STRINGSW("dddd d MMMM yyyy","Friday 31 December 1600");
-  SetLastError(0xdeadbeef);
   ret = GetDateFormatW (lcid, 0, &curtime, input, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -1176,56 +1155,47 @@ static void test_GetCurrencyFormatA(void)
   memset(&format, 0, sizeof(format));
 
   STRINGSA("23",""); /* NULL output, length > 0 --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, 0, input, NULL, NULL, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("23,53",""); /* Invalid character --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("--",""); /* Double '-' --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("0-",""); /* Trailing '-' --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("0..",""); /* Double '.' --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA(" 0.1",""); /* Leading space --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("1234","$"); /* Length too small --> Write up to length chars */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, 2);
   ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
       "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
 
   STRINGSA("2353",""); /* Format and flags given --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, NUO, input, &format, buffer, ARRAY_SIZE(buffer));
   ok( !ret, "Expected ret == 0, got %d\n", ret);
   ok( GetLastError() == ERROR_INVALID_FLAGS || GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
 
   STRINGSA("2353",""); /* Invalid format --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
@@ -1432,56 +1402,47 @@ static void test_GetNumberFormatA(void)
   memset(&format, 0, sizeof(format));
 
   STRINGSA("23",""); /* NULL output, length > 0 --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, 0, input, NULL, NULL, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("23,53",""); /* Invalid character --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("--",""); /* Double '-' --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("0-",""); /* Trailing '-' --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("0..",""); /* Double '.' --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA(" 0.1",""); /* Leading space --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
   STRINGSA("1234","1"); /* Length too small --> Write up to length chars */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, NUO, input, NULL, buffer, 2);
   ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
       "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
 
   STRINGSA("2353",""); /* Format and flags given --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, NUO, input, &format, buffer, ARRAY_SIZE(buffer));
   ok( !ret, "Expected ret == 0, got %d\n", ret);
   ok( GetLastError() == ERROR_INVALID_FLAGS || GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
 
   STRINGSA("2353",""); /* Invalid format --> Error */
-  SetLastError(0xdeadbeef);
   ret = GetNumberFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer));
   ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
       "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
-- 
2.20.1




More information about the wine-devel mailing list