Commit b8f1435a authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

kernel32/tests: Remove the macros from the GetCurrencyFormatA() tests.

Also simplify testing all the NegativeOrder values. Signed-off-by: 's avatarFrancois Gouget <fgouget@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 877d12f8
...@@ -1150,92 +1150,104 @@ static void test_GetCurrencyFormatA(void) ...@@ -1150,92 +1150,104 @@ static void test_GetCurrencyFormatA(void)
static char szDot[] = { '.', '\0' }; static char szDot[] = { '.', '\0' };
static char szComma[] = { ',', '\0' }; static char szComma[] = { ',', '\0' };
static char szDollar[] = { '$', '\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); 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; CURRENCYFMTA format;
memset(&format, 0, sizeof(format));
STRINGSA("23",""); /* NULL output, length > 0 --> Error */
SetLastError(0xdeadbeef); 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); 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); 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); 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); 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); 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); 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); 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 */ /* Valid number */
SetLastError(0xdeadbeef); ret = GetCurrencyFormatA(lcid, NUO, "2353", NULL, buffer, ARRAY_SIZE(buffer));
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); expect_str(ret, buffer, "$2,353.00");
ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
STRINGSA("2353","$2,353.00"); /* Valid number */ /* Valid negative number */
ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, NUO, "-2353", NULL, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "($2,353.00)");
EXPECT_LENA; EXPECT_EQA;
STRINGSA("-2353","($2,353.00)"); /* Valid negative number */ /* Valid real number */
ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, NUO, "2353.1", NULL, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$2,353.10");
EXPECT_LENA; EXPECT_EQA;
STRINGSA("2353.1","$2,353.10"); /* Valid real number */ /* Too many DP --> Truncated */
ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, NUO, "2353.111", NULL, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$2,353.11");
EXPECT_LENA; EXPECT_EQA;
STRINGSA("2353.111","$2,353.11"); /* Too many DP --> Truncated */ /* Too many DP --> Rounded */
ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, NUO, "2353.119", NULL, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$2,353.12");
EXPECT_LENA; EXPECT_EQA;
STRINGSA("2353.119","$2,353.12"); /* Too many DP --> Rounded */ /* Format and flags given --> Error */
ret = GetCurrencyFormatA(lcid, NUO, input, NULL, buffer, ARRAY_SIZE(buffer)); memset(&format, 0, sizeof(format));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); strcpy(buffer, "pristine");
EXPECT_LENA; EXPECT_EQA; 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.NumDigits = 0; /* No decimal separator */
format.LeadingZero = 0; format.LeadingZero = 0;
...@@ -1246,154 +1258,57 @@ static void test_GetCurrencyFormatA(void) ...@@ -1246,154 +1258,57 @@ static void test_GetCurrencyFormatA(void)
format.lpThousandSep = szComma; format.lpThousandSep = szComma;
format.lpCurrencySymbol = szDollar; format.lpCurrencySymbol = szDollar;
STRINGSA("2353","$2353"); /* No decimal or grouping chars expected */ /* No decimal or grouping chars expected */
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, 0, "2353", &format, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$2353");
EXPECT_LENA; EXPECT_EQA;
format.NumDigits = 1; /* 1 DP --> Expect decimal separator */ /* 1 DP --> Expect decimal separator */
STRINGSA("2353","$2353.0"); format.NumDigits = 1;
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, 0, "2353", &format, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$2353.0");
EXPECT_LENA; EXPECT_EQA;
format.Grouping = 2; /* Group by 100's */ /* Group by 100's */
STRINGSA("2353","$23,53.0"); format.Grouping = 2;
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, 0, "2353", &format, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$23,53.0");
EXPECT_LENA; EXPECT_EQA;
STRINGSA("235","$235.0"); /* Grouping of a positive number */ /* Grouping of a positive number */
format.Grouping = 3; format.Grouping = 3;
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, 0, "235", &format, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$235.0");
EXPECT_LENA; EXPECT_EQA;
STRINGSA("-235","$-235.0"); /* Grouping of a negative number */ /* Grouping of a negative number */
format.NegativeOrder = 2; format.NegativeOrder = 2;
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, 0, "-235", &format, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$-235.0");
EXPECT_LENA; EXPECT_EQA;
format.LeadingZero = 1; /* Always provide leading zero */ /* Always provide leading zero */
STRINGSA(".5","$0.5"); format.LeadingZero = 1;
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); ret = GetCurrencyFormatA(lcid, 0, ".5", &format, buffer, ARRAY_SIZE(buffer));
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); expect_str(ret, buffer, "$0.5");
EXPECT_LENA; EXPECT_EQA;
format.PositiveOrder = CY_POS_RIGHT; format.PositiveOrder = CY_POS_RIGHT;
STRINGSA("1","1.0$"); ret = GetCurrencyFormatA(lcid, 0, "1", &format, buffer, ARRAY_SIZE(buffer));
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); expect_str(ret, buffer, "1.0$");
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError());
EXPECT_LENA; EXPECT_EQA;
format.PositiveOrder = CY_POS_LEFT_SPACE; format.PositiveOrder = CY_POS_LEFT_SPACE;
STRINGSA("1","$ 1.0"); ret = GetCurrencyFormatA(lcid, 0, "1", &format, buffer, ARRAY_SIZE(buffer));
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); expect_str(ret, buffer, "$ 1.0");
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError());
EXPECT_LENA; EXPECT_EQA;
format.PositiveOrder = CY_POS_RIGHT_SPACE; format.PositiveOrder = CY_POS_RIGHT_SPACE;
STRINGSA("1","1.0 $"); ret = GetCurrencyFormatA(lcid, 0, "1", &format, buffer, ARRAY_SIZE(buffer));
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); expect_str(ret, buffer, "1.0 $");
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;
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; for (o = 0; o <= 15; o++)
STRINGSA("-1","$ 1.0-"); {
ret = GetCurrencyFormatA(lcid, 0, input, &format, buffer, ARRAY_SIZE(buffer)); winetest_push_context("%d", o);
ok(ret, "Expected ret != 0, got %d, error %d\n", ret, GetLastError()); format.NegativeOrder = o;
EXPECT_LENA; EXPECT_EQA; strcpy(buffer, "pristine");
ret = GetCurrencyFormatA(lcid, 0, "-1", &format, buffer, ARRAY_SIZE(buffer));
format.NegativeOrder = 12; expect_str(ret, buffer, negative_order[o]);
STRINGSA("-1","$ -1.0"); winetest_pop_context();
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;
} }
#define NEG_PARENS 0 /* "(1.1)" */ #define NEG_PARENS 0 /* "(1.1)" */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment