Also simplify testing all the NegativeOrder values.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- dlls/kernel32/tests/locale.c | 305 +++++++++++++---------------------- 1 file changed, 110 insertions(+), 195 deletions(-)
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c index e6514f0b11f..ca8ac4d8f0e 100644 --- a/dlls/kernel32/tests/locale.c +++ b/dlls/kernel32/tests/locale.c @@ -1144,92 +1144,104 @@ static void test_GetCurrencyFormatA(void) static char szDot[] = { '.', '\0' }; static char szComma[] = { ',', '\0' }; static char szDollar[] = { '$', '\0' }; - int ret; + static const char* const negative_order[] = + {"($1.0)", /* 0 */ + "-$1.0", + "$-1.0", + "$1.0-", + "(1.0$)", + "-1.0$", /* 5 */ + "1.0-$", + "1.0$-", + "-1.0 $", + "-$ 1.0", + "1.0 $-", /* 10 */ + "$ 1.0-", + "$ -1.0", + "1.0- $", + "($ 1.0)", + "(1.0 $)", /* 15 */ + }; + int ret, o; LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT); - char buffer[BUFFER_SIZE], Expected[BUFFER_SIZE], input[BUFFER_SIZE]; + char buffer[BUFFER_SIZE]; CURRENCYFMTA format;
- 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 */ + /* NULL output, length > 0 --> Error */ + ret = GetCurrencyFormatA(lcid, 0, "23", NULL, NULL, ARRAY_SIZE(buffer)); + expect_err(ret, NULL, ERROR_INVALID_PARAMETER); 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 */ + /* Invalid character --> Error */ + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, 0, "23,53", NULL, buffer, ARRAY_SIZE(buffer)); + expect_err(ret, buffer, ERROR_INVALID_PARAMETER); 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 */ + /* Double '-' --> Error */ + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, 0, "--", NULL, buffer, ARRAY_SIZE(buffer)); + expect_err(ret, buffer, ERROR_INVALID_PARAMETER); 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 */ + /* Trailing '-' --> Error */ + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, 0, "0-", NULL, buffer, ARRAY_SIZE(buffer)); + expect_err(ret, buffer, ERROR_INVALID_PARAMETER); 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 */ + /* Double '.' --> Error */ + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, 0, "0..", NULL, buffer, ARRAY_SIZE(buffer)); + expect_err(ret, buffer, ERROR_INVALID_PARAMETER); 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 */ + /* Leading space --> Error */ + ret = GetCurrencyFormatA(lcid, 0, " 0.1", NULL, buffer, ARRAY_SIZE(buffer)); + expect_err(ret, buffer, ERROR_INVALID_PARAMETER); 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 */ + /* Length too small --> Write up to length chars */ + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, NUO, "1234", NULL, buffer, 2); + /* there is no guarantee on the buffer content, see GetTimeFormatA() */ + expect_err(ret, NULL, ERROR_INSUFFICIENT_BUFFER); 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, - "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()); + /* Valid number */ + ret = GetCurrencyFormatA(lcid, NUO, "2353", NULL, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$2,353.00");
- STRINGSA("2353","$2,353.00"); /* Valid number */ - ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* Valid negative number */ + ret = GetCurrencyFormatA(lcid, NUO, "-2353", NULL, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "($2,353.00)");
- STRINGSA("-2353","($2,353.00)"); /* Valid negative number */ - ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* Valid real number */ + ret = GetCurrencyFormatA(lcid, NUO, "2353.1", NULL, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$2,353.10");
- STRINGSA("2353.1","$2,353.10"); /* Valid real number */ - ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* Too many DP --> Truncated */ + ret = GetCurrencyFormatA(lcid, NUO, "2353.111", NULL, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$2,353.11");
- STRINGSA("2353.111","$2,353.11"); /* Too many DP --> Truncated */ - ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* Too many DP --> Rounded */ + ret = GetCurrencyFormatA(lcid, NUO, "2353.119", NULL, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$2,353.12");
- STRINGSA("2353.119","$2,353.12"); /* Too many DP --> Rounded */ - ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* Format and flags given --> Error */ + memset(&format, 0, sizeof(format)); + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, NUO, "2353", &format, buffer, ARRAY_SIZE(buffer)); + expect_err(ret, buffer, ERROR_INVALID_FLAGS); + SetLastError(0xdeadbeef); + + /* Invalid format --> Error */ + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, 0, "2353", &format, buffer, ARRAY_SIZE(buffer)); + expect_err(ret, buffer, ERROR_INVALID_PARAMETER); + SetLastError(0xdeadbeef);
format.NumDigits = 0; /* No decimal separator */ format.LeadingZero = 0; @@ -1240,154 +1252,57 @@ static void test_GetCurrencyFormatA(void) format.lpThousandSep = szComma; format.lpCurrencySymbol = szDollar;
- STRINGSA("2353","$2353"); /* No decimal or grouping chars expected */ - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* No decimal or grouping chars expected */ + ret = GetCurrencyFormatA(lcid, 0, "2353", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$2353");
- format.NumDigits = 1; /* 1 DP --> Expect decimal separator */ - STRINGSA("2353","$2353.0"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* 1 DP --> Expect decimal separator */ + format.NumDigits = 1; + ret = GetCurrencyFormatA(lcid, 0, "2353", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$2353.0");
- format.Grouping = 2; /* Group by 100's */ - STRINGSA("2353","$23,53.0"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* Group by 100's */ + format.Grouping = 2; + ret = GetCurrencyFormatA(lcid, 0, "2353", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$23,53.0");
- STRINGSA("235","$235.0"); /* Grouping of a positive number */ + /* Grouping of a positive number */ format.Grouping = 3; - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + ret = GetCurrencyFormatA(lcid, 0, "235", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$235.0");
- STRINGSA("-235","$-235.0"); /* Grouping of a negative number */ + /* Grouping of a negative number */ format.NegativeOrder = 2; - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + ret = GetCurrencyFormatA(lcid, 0, "-235", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$-235.0");
- format.LeadingZero = 1; /* Always provide leading zero */ - STRINGSA(".5","$0.5"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + /* Always provide leading zero */ + format.LeadingZero = 1; + ret = GetCurrencyFormatA(lcid, 0, ".5", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$0.5");
format.PositiveOrder = CY_POS_RIGHT; - STRINGSA("1","1.0$"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + ret = GetCurrencyFormatA(lcid, 0, "1", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "1.0$");
format.PositiveOrder = CY_POS_LEFT_SPACE; - STRINGSA("1","$ 1.0"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + ret = GetCurrencyFormatA(lcid, 0, "1", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "$ 1.0");
format.PositiveOrder = CY_POS_RIGHT_SPACE; - STRINGSA("1","1.0 $"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 0; - STRINGSA("-1","($1.0)"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 1; - STRINGSA("-1","-$1.0"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + ret = GetCurrencyFormatA(lcid, 0, "1", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, "1.0 $");
- format.NegativeOrder = 2; - STRINGSA("-1","$-1.0"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA;
- format.NegativeOrder = 3; - STRINGSA("-1","$1.0-"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 4; - STRINGSA("-1","(1.0$)"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 5; - STRINGSA("-1","-1.0$"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 6; - STRINGSA("-1","1.0-$"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 7; - STRINGSA("-1","1.0$-"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 8; - STRINGSA("-1","-1.0 $"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 9; - STRINGSA("-1","-$ 1.0"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 10; - STRINGSA("-1","1.0 $-"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 11; - STRINGSA("-1","$ 1.0-"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 12; - STRINGSA("-1","$ -1.0"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 13; - STRINGSA("-1","1.0- $"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 14; - STRINGSA("-1","($ 1.0)"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; - - format.NegativeOrder = 15; - STRINGSA("-1","(1.0 $)"); - ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); - ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); - EXPECT_LENA; EXPECT_EQA; + for (o = 0; o <= 15; o++) + { + winetest_push_context("%d", o); + format.NegativeOrder = o; + strcpy(buffer, "pristine"); + ret = GetCurrencyFormatA(lcid, 0, "-1", &format, buffer, ARRAY_SIZE(buffer)); + expect_str(ret, buffer, negative_order[o]); + winetest_pop_context(); + } }
#define NEG_PARENS 0 /* "(1.1)" */