From a03392cf343b9f6654503c8331d8560bedd168e0 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Tue, 26 May 2015 17:15:48 +0000 Subject: [PATCH] [MSVCRT_WINETEST] Sync with Wine Staging 1.7.43. svn path=/trunk/; revision=67923 --- rostests/winetests/msvcrt/misc.c | 63 +++++++++++++++ rostests/winetests/msvcrt/printf.c | 55 ++++++++++--- rostests/winetests/msvcrt/string.c | 124 +++++++++++++++++++++++++++++ 3 files changed, 229 insertions(+), 13 deletions(-) diff --git a/rostests/winetests/msvcrt/misc.c b/rostests/winetests/msvcrt/misc.c index a4c5c8c3665..9939629e152 100644 --- a/rostests/winetests/msvcrt/misc.c +++ b/rostests/winetests/msvcrt/misc.c @@ -23,6 +23,26 @@ #include #include "msvcrt.h" +static inline float __port_infinity(void) +{ + static const unsigned __inf_bytes = 0x7f800000; + return *(const float *)&__inf_bytes; +} +#define INFINITY __port_infinity() + +static inline float __port_nan(void) +{ + static const unsigned __nan_bytes = 0x7fc00000; + return *(const float *)&__nan_bytes; +} +#define NAN __port_nan() + +static inline BOOL almost_equal(double d1, double d2) { + if(d1-d2>-1e-30 && d1-d2<1e-30) + return TRUE; + return FALSE; +} + static int (__cdecl *prand_s)(unsigned int *); static int (__cdecl *pI10_OUTPUT)(long double, int, int, void*); static int (__cdecl *pstrerror_s)(char *, MSVCRT_size_t, int); @@ -34,6 +54,9 @@ static void (__cdecl *p__invalid_parameter)(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t); static void (__cdecl *p_qsort_s)(void*, MSVCRT_size_t, MSVCRT_size_t, int (__cdecl*)(void*, const void*, const void*), void*); +static double (__cdecl *p_atan)(double); +static double (__cdecl *p_exp)(double); +static double (__cdecl *p_tanh)(double); static void init(void) { @@ -48,6 +71,9 @@ static void init(void) p_set_errno = (void *)GetProcAddress(hmod, "_set_errno"); p__invalid_parameter = (void *)GetProcAddress(hmod, "_invalid_parameter"); p_qsort_s = (void *)GetProcAddress(hmod, "qsort_s"); + p_atan = (void *)GetProcAddress(hmod, "atan"); + p_exp = (void *)GetProcAddress(hmod, "exp"); + p_tanh = (void *)GetProcAddress(hmod, "tanh"); } static void test_rand_s(void) @@ -477,6 +503,42 @@ static void test_qsort_s(void) ok(tab[i] == i, "data sorted incorrectly on position %d: %d\n", i, tab[i]); } +static void test_math_functions(void) +{ + double ret; + + errno = 0xdeadbeef; + p_atan(NAN); + ok(errno == EDOM, "errno = %d\n", errno); + + errno = 0xdeadbeef; + ret = p_atan(INFINITY); + ok(almost_equal(ret, 1.57079632679489661923), "ret = %lf\n", ret); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); + + errno = 0xdeadbeef; + ret = p_atan(-INFINITY); + ok(almost_equal(ret, -1.57079632679489661923), "ret = %lf\n", ret); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); + + errno = 0xdeadbeef; + p_tanh(NAN); + ok(errno == EDOM, "errno = %d\n", errno); + + errno = 0xdeadbeef; + ret = p_tanh(INFINITY); + ok(almost_equal(ret, 1.0), "ret = %lf\n", ret); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); + + errno = 0xdeadbeef; + p_exp(NAN); + ok(errno == EDOM, "errno = %d\n", errno); + + errno = 0xdeadbeef; + p_exp(INFINITY); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); +} + START_TEST(misc) { int arg_c; @@ -504,4 +566,5 @@ START_TEST(misc) test__popen(arg_v[0]); test__invalid_parameter(); test_qsort_s(); + test_math_functions(); } diff --git a/rostests/winetests/msvcrt/printf.c b/rostests/winetests/msvcrt/printf.c index 0606c257c71..7f734eaad15 100644 --- a/rostests/winetests/msvcrt/printf.c +++ b/rostests/winetests/msvcrt/printf.c @@ -27,7 +27,6 @@ #include #include -#include #include "windef.h" #include "winbase.h" @@ -35,6 +34,27 @@ #include "wine/test.h" +static inline float __port_infinity(void) +{ + static const unsigned __inf_bytes = 0x7f800000; + return *(const float *)&__inf_bytes; +} +#define INFINITY __port_infinity() + +static inline float __port_nan(void) +{ + static const unsigned __nan_bytes = 0x7fc00000; + return *(const float *)&__nan_bytes; +} +#define NAN __port_nan() + +static inline float __port_ind(void) +{ + static const unsigned __ind_bytes = 0xffc00000; + return *(const float *)&__ind_bytes; +} +#define IND __port_ind() + static int (__cdecl *p__vscprintf)(const char *format, __ms_va_list valist); static int (__cdecl *p__vscwprintf)(const wchar_t *format, __ms_va_list valist); static int (__cdecl *p__vsnwprintf_s)(wchar_t *str, size_t sizeOfBuffer, @@ -82,7 +102,7 @@ static void test_sprintf( void ) { char buffer[100]; const char *format; - double pnumber=789456123, inf, nan; + double pnumber=789456123; int x, r; WCHAR wide[] = { 'w','i','d','e',0}; @@ -675,38 +695,47 @@ static void test_sprintf( void ) r = sprintf(buffer, format, 0x12345); ok(!strcmp(buffer,"2345"), "failed \"%s\"\n", buffer); - nan = 0.0; - inf = 1.0/nan; - nan = sqrt(-1); format = "%lf"; - r = sprintf(buffer, format, nan); + r = sprintf(buffer, format, IND); ok(r==9, "r = %d\n", r); ok(!strcmp(buffer, "-1.#IND00"), "failed: \"%s\"\n", buffer); - r = sprintf(buffer, format, inf); + r = sprintf(buffer, format, NAN); + ok(r==8, "r = %d\n", r); + ok(!strcmp(buffer, "1.#QNAN0"), "failed: \"%s\"\n", buffer); + r = sprintf(buffer, format, INFINITY); ok(r==8, "r = %d\n", r); ok(!strcmp(buffer, "1.#INF00"), "failed: \"%s\"\n", buffer); format = "%le"; - r = sprintf(buffer, format, nan); + r = sprintf(buffer, format, IND); ok(r==14, "r = %d\n", r); ok(!strcmp(buffer, "-1.#IND00e+000"), "failed: \"%s\"\n", buffer); - r = sprintf(buffer, format, inf); + r = sprintf(buffer, format, NAN); + ok(r==13, "r = %d\n", r); + ok(!strcmp(buffer, "1.#QNAN0e+000"), "failed: \"%s\"\n", buffer); + r = sprintf(buffer, format, INFINITY); ok(r==13, "r = %d\n", r); ok(!strcmp(buffer, "1.#INF00e+000"), "failed: \"%s\"\n", buffer); format = "%lg"; - r = sprintf(buffer, format, nan); + r = sprintf(buffer, format, IND); ok(r==7, "r = %d\n", r); ok(!strcmp(buffer, "-1.#IND"), "failed: \"%s\"\n", buffer); - r = sprintf(buffer, format, inf); + r = sprintf(buffer, format, NAN); + ok(r==7, "r = %d\n", r); + ok(!strcmp(buffer, "1.#QNAN"), "failed: \"%s\"\n", buffer); + r = sprintf(buffer, format, INFINITY); ok(r==6, "r = %d\n", r); ok(!strcmp(buffer, "1.#INF"), "failed: \"%s\"\n", buffer); format = "%010.2lf"; - r = sprintf(buffer, format, nan); + r = sprintf(buffer, format, IND); ok(r==10, "r = %d\n", r); ok(!strcmp(buffer, "-000001.#J"), "failed: \"%s\"\n", buffer); - r = sprintf(buffer, format, inf); + r = sprintf(buffer, format, NAN); + ok(r==10, "r = %d\n", r); + ok(!strcmp(buffer, "0000001.#R"), "failed: \"%s\"\n", buffer); + r = sprintf(buffer, format, INFINITY); ok(r==10, "r = %d\n", r); ok(!strcmp(buffer, "0000001.#J"), "failed: \"%s\"\n", buffer); } diff --git a/rostests/winetests/msvcrt/string.c b/rostests/winetests/msvcrt/string.c index 187d2b9aa0b..a10b2415c1c 100644 --- a/rostests/winetests/msvcrt/string.c +++ b/rostests/winetests/msvcrt/string.c @@ -1144,6 +1144,65 @@ static void test_mbcjmsjis(void) _setmbcp(prev_cp); } +static void test_mbctohira(void) +{ + static const unsigned int mbchira_932[][2] = { + {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155}, + {0x82a0, 0x82a0}, {0x833f, 0x833f}, {0x8340, 0x829f}, {0x837e, 0x82dd}, + {0x837f, 0x837f}, {0x8380, 0x82de}, {0x8393, 0x82f1}, {0x8394, 0x8394}, + {0x8396, 0x8396}, {0x8397, 0x8397}, + {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} }; + unsigned int i; + unsigned int prev_cp = _getmbcp(); + + _setmbcp(_MB_CP_SBCS); + for (i = 0; i < sizeof(mbchira_932)/sizeof(mbchira_932[0]); i++) + { + int ret, exp = mbchira_932[i][0]; + ret = _mbctohira(mbchira_932[i][0]); + ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret); + } + + _setmbcp(932); + for (i = 0; i < sizeof(mbchira_932)/sizeof(mbchira_932[0]); i++) + { + unsigned int ret, exp; + ret = _mbctohira(mbchira_932[i][0]); + exp = mbchira_932[i][1]; + ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret); + } + _setmbcp(prev_cp); +} + +static void test_mbctokata(void) +{ + static const unsigned int mbckata_932[][2] = { + {0x8152, 0x8152}, {0x8153, 0x8153}, {0x8154, 0x8154}, {0x8155, 0x8155}, + {0x833f, 0x833f}, {0x829f, 0x8340}, {0x82dd, 0x837e}, {0x837f, 0x837f}, + {0x82de, 0x8380}, {0x8394, 0x8394}, {0x8397, 0x8397}, + {0xa5, 0xa5}, {0xb0, 0xb0}, {0xdd, 0xdd} }; + unsigned int i; + unsigned int prev_cp = _getmbcp(); + + _setmbcp(_MB_CP_SBCS); + for (i = 0; i < sizeof(mbckata_932)/sizeof(mbckata_932[0]); i++) + { + int ret, exp = mbckata_932[i][0]; + ret = _mbctokata(mbckata_932[i][0]); + ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret); + } + + _setmbcp(932); + for (i = 0; i < sizeof(mbckata_932)/sizeof(mbckata_932[0]); i++) + { + unsigned int ret, exp; + ret = _mbctokata(mbckata_932[i][0]); + exp = mbckata_932[i][1]; + ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret); + } + _setmbcp(prev_cp); +} + static void test_mbbtombc(void) { static const unsigned int mbbmbc[][2] = { @@ -1192,6 +1251,37 @@ static void test_mbctombb(void) _setmbcp(prev_cp); } +static void test_ismbckata(void) { + struct katakana_pair { + UINT c; + BOOL exp; + }; + static const struct katakana_pair tests[] = { + {0x8152, FALSE}, {0x8153, FALSE}, {0x8154, FALSE}, {0x8155, FALSE}, + {0x82a0, FALSE}, {0x833f, FALSE}, {0x8340, TRUE }, {0x837e, TRUE }, + {0x837f, FALSE}, {0x8380, TRUE }, {0x8396, TRUE }, {0x8397, FALSE}, + {0xa5, FALSE}, {0xb0, FALSE}, {0xdd, FALSE} + }; + unsigned int prev_cp = _getmbcp(); + int ret; + unsigned int i; + + _setmbcp(_MB_CP_SBCS); + for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { + ret = _ismbckata(tests[i].c); + ok(!ret, "expected 0, got %d for %04x\n", ret, tests[i].c); + } + + _setmbcp(932); + for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { + ret = _ismbckata(tests[i].c); + ok(!!ret == tests[i].exp, "expected %d, got %d for %04x\n", + tests[i].exp, !!ret, tests[i].c); + } + + _setmbcp(prev_cp); +} + static void test_ismbclegal(void) { unsigned int prev_cp = _getmbcp(); int ret, exp, err; @@ -2838,6 +2928,36 @@ static void test__wcsset_s(void) ok(str[2] == 'b', "str[2] = %d\n", str[2]); } +static void test__mbscmp(void) +{ + static const unsigned char a[] = {'a',0}, b[] = {'b',0}; + int ret; + + if (!p_mbrlen) + { + win_skip("_mbscmp tests\n"); + return; + } + + ret = _mbscmp(NULL, NULL); + ok(ret == INT_MAX, "got %d\n", ret); + + ret = _mbscmp(a, NULL); + ok(ret == INT_MAX, "got %d\n", ret); + + ret = _mbscmp(NULL, a); + ok(ret == INT_MAX, "got %d\n", ret); + + ret = _mbscmp(a, a); + ok(!ret, "got %d\n", ret); + + ret = _mbscmp(a, b); + ok(ret == -1, "got %d\n", ret); + + ret = _mbscmp(b, a); + ok(ret == 1, "got %d\n", ret); +} + START_TEST(string) { char mem[100]; @@ -2913,8 +3033,11 @@ START_TEST(string) test__mbscpy_s(); test_mbcjisjms(); test_mbcjmsjis(); + test_mbctohira(); + test_mbctokata(); test_mbbtombc(); test_mbctombb(); + test_ismbckata(); test_ismbclegal(); test_strtok(); test__mbstok(); @@ -2945,4 +3068,5 @@ START_TEST(string) test_strxfrm(); test__strnset_s(); test__wcsset_s(); + test__mbscmp(); }