diff --git a/modules/rostests/winetests/msvcrt/cpp.c b/modules/rostests/winetests/msvcrt/cpp.c index cf5e4c7d60b..07b49ae755d 100644 --- a/modules/rostests/winetests/msvcrt/cpp.c +++ b/modules/rostests/winetests/msvcrt/cpp.c @@ -1108,8 +1108,8 @@ static void test_demangle_datatype(void) { "?AV?$CDB_GEN_BIG_ENUM_FLAG@W4CDB_WYSIWYG_BITS_ENUM@@$01@@@", "?AV?$CDB_GEN_BIG_ENUM_FLAG@W4CDB_WYSIWYG_BITS_ENUM@@$01@@@", FALSE}, /* { "?AV?$CDB_GEN_BIG_ENUM_FLAG@W4CDB_WYSIWYG_BITS_ENUM@@$011@@@", "?AV?$CDB_GEN_BIG_ENUM_FLAG@W4CDB_WYSIWYG_BITS_ENUM@@$011@@@",FALSE}, */ }; - int i, num_test = (sizeof(demangle)/sizeof(struct _demangle)); - + int i, num_test = ARRAY_SIZE(demangle); + for (i = 0; i < num_test; i++) { name = p__unDName(0, demangle[i].mangled, 0, pmalloc, pfree, 0x2800); @@ -1326,7 +1326,7 @@ static void test_demangle(void) /* 130 */ {"??_E?$TStrArray@$$BY0BAA@D$0BA@@@UAEPAXI@Z", "public: virtual void * __thiscall TStrArray::`vector deleting destructor'(unsigned int)"}, }; - int i, num_test = (sizeof(test)/sizeof(test[0])); + int i, num_test = ARRAY_SIZE(test); char* name; for (i = 0; i < num_test; i++) diff --git a/modules/rostests/winetests/msvcrt/dir.c b/modules/rostests/winetests/msvcrt/dir.c index a29d32b9d39..210cf3983cd 100644 --- a/modules/rostests/winetests/msvcrt/dir.c +++ b/modules/rostests/winetests/msvcrt/dir.c @@ -97,7 +97,7 @@ static void test_makepath(void) unsigned int i, n; - for (i = 0; i < sizeof(makepath_cases)/sizeof(makepath_cases[0]); ++i) + for (i = 0; i < ARRAY_SIZE(makepath_cases); ++i) { const makepath_case* p = &makepath_cases[i]; @@ -253,7 +253,7 @@ static void test_makepath_s(void) ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); /* Test with the normal _makepath cases. */ - for (i = 0; i < sizeof(makepath_cases)/sizeof(makepath_cases[0]); i++) + for (i = 0; i < ARRAY_SIZE(makepath_cases); i++) { const makepath_case *p = makepath_cases + i; @@ -296,7 +296,7 @@ static void test_makepath_s(void) } /* Try insufficient length cases. */ - for (i = 0; i < sizeof(makepath_s_cases)/sizeof(makepath_s_cases[0]); i++) + for (i = 0; i < ARRAY_SIZE(makepath_s_cases); i++) { const makepath_s_case *p = makepath_s_cases + i; @@ -457,12 +457,12 @@ static void test_searchenv(void) ok(path_len, "GetTempPath failed\n"); memcpy(path, tmppath, path_len); - for(i=0; i=0; i--) { + for (i=ARRAY_SIZE(dirs)-1; i>=0; i--) { strcpy(path+path_len, dirs[i]); ok(!rmdir(path), "rmdir failed (dir = %s)\n", path); } diff --git a/modules/rostests/winetests/msvcrt/file.c b/modules/rostests/winetests/msvcrt/file.c index 136ee1563e6..fe62d5c385e 100644 --- a/modules/rostests/winetests/msvcrt/file.c +++ b/modules/rostests/winetests/msvcrt/file.c @@ -144,7 +144,7 @@ static void test_fileops( void ) write (fd, outbuffer, sizeof (outbuffer)); close (fd); - for (bufmode=0; bufmode < sizeof(bufmodes)/sizeof(bufmodes[0]); bufmode++) + for (bufmode=0; bufmode < ARRAY_SIZE(bufmodes); bufmode++) { fd = open ("fdopen.tst", O_RDONLY | O_BINARY); file = fdopen (fd, "rb"); @@ -195,13 +195,13 @@ static void test_fileops( void ) } fd = open ("fdopen.tst", O_RDONLY | O_TEXT); file = fdopen (fd, "rt"); /* open in TEXT mode */ - ok(fgetws(wbuffer,sizeof(wbuffer)/sizeof(wbuffer[0]),file) !=0,"fgetws failed unexpected\n"); - ok(fgetws(wbuffer,sizeof(wbuffer)/sizeof(wbuffer[0]),file) ==0,"fgetws didn't signal EOF\n"); + ok(fgetws(wbuffer,ARRAY_SIZE(wbuffer),file) !=0,"fgetws failed unexpected\n"); + ok(fgetws(wbuffer,ARRAY_SIZE(wbuffer),file) ==0,"fgetws didn't signal EOF\n"); ok(feof(file) !=0,"feof doesn't signal EOF\n"); rewind(file); ok(fgetws(wbuffer,strlen(outbuffer),file) !=0,"fgetws failed unexpected\n"); ok(lstrlenW(wbuffer) == (lstrlenA(outbuffer) -1),"fgetws didn't read right size\n"); - ok(fgetws(wbuffer,sizeof(outbuffer)/sizeof(outbuffer[0]),file) !=0,"fgets failed unexpected\n"); + ok(fgetws(wbuffer,ARRAY_SIZE(outbuffer),file) !=0,"fgets failed unexpected\n"); ok(lstrlenW(wbuffer) == 1,"fgets dropped chars\n"); fclose (file); @@ -624,7 +624,7 @@ static void test_flsbuf( void ) static const int bufmodes[] = {_IOFBF,_IONBF}; tempf=_tempnam(".","wne"); - for (bufmode=0; bufmode < sizeof(bufmodes)/sizeof(bufmodes[0]); bufmode++) + for (bufmode=0; bufmode < ARRAY_SIZE(bufmodes); bufmode++) { tempfh = fopen(tempf,"wb"); setvbuf(tempfh,NULL,bufmodes[bufmode],2048); @@ -878,8 +878,7 @@ static void test_fgetwc_locale(const char* text, const char* locale, int codepag { /* mbstowcs rejects invalid multibyte sequence, so we use MultiByteToWideChar here. */ - ret = MultiByteToWideChar(codepage, 0, text, -1, - wtextW, sizeof(wtextW)/sizeof(wtextW[0])); + ret = MultiByteToWideChar(codepage, 0, text, -1, wtextW, ARRAY_SIZE(wtextW)); ok(ret > 0, "MultiByteToWideChar failed\n"); } else @@ -910,7 +909,7 @@ static void test_fgetwc_locale(const char* text, const char* locale, int codepag tempfh = fopen(tempfile, "rb"); ok(tempfh != NULL, "can't open tempfile\n"); - for (i = 0; i < sizeof(wchar_text)/sizeof(wchar_text[0]); i++) + for (i = 0; i < ARRAY_SIZE(wchar_text); i++) { ch = fgetwc(tempfh); ok(ch == wchar_text[i], "got %04hx, expected %04x (cp%d[%d])\n", ch, wchar_text[i], codepage, i); @@ -946,7 +945,7 @@ static void test_fgetwc_unicode(void) tempfh = fopen(tempfile, "rt,ccs=unicode"); ok(tempfh != NULL, "can't open tempfile\n"); - for (i = 1; i < sizeof(wchar_text)/sizeof(wchar_text[0]); i++) + for (i = 1; i < ARRAY_SIZE(wchar_text); i++) { ch = fgetwc(tempfh); ok(ch == wchar_text[i], @@ -958,7 +957,7 @@ static void test_fgetwc_unicode(void) tempfh = fopen(tempfile, "wb"); ok(tempfh != NULL, "can't open tempfile\n"); - ret = WideCharToMultiByte(CP_UTF8, 0, wchar_text, sizeof(wchar_text)/sizeof(wchar_text[0]), + ret = WideCharToMultiByte(CP_UTF8, 0, wchar_text, ARRAY_SIZE(wchar_text), utf8_text, sizeof(utf8_text), NULL, NULL); ok(ret > 0, "utf-8 conversion failed\n"); fwrite(utf8_text, sizeof(char), ret, tempfh); @@ -966,7 +965,7 @@ static void test_fgetwc_unicode(void) tempfh = fopen(tempfile, "rt, ccs=UTF-8"); ok(tempfh != NULL, "can't open tempfile\n"); - for (i = 1; i < sizeof(wchar_text)/sizeof(wchar_text[0]); i++) + for (i = 1; i < ARRAY_SIZE(wchar_text); i++) { ch = fgetwc(tempfh); ok(ch == wchar_text[i], @@ -2659,5 +2658,5 @@ START_TEST(file) /* Wait for the (_P_NOWAIT) spawned processes to finish to make sure the report * file contains lines in the correct order */ - WaitForMultipleObjects(sizeof(proc_handles)/sizeof(proc_handles[0]), proc_handles, TRUE, 5000); + WaitForMultipleObjects(ARRAY_SIZE(proc_handles), proc_handles, TRUE, 5000); } diff --git a/modules/rostests/winetests/msvcrt/locale.c b/modules/rostests/winetests/msvcrt/locale.c index f87a7914d0e..ff777599aa2 100644 --- a/modules/rostests/winetests/msvcrt/locale.c +++ b/modules/rostests/winetests/msvcrt/locale.c @@ -144,12 +144,10 @@ static void test_setlocale(void) || broken(!strcmp(ret, "Chinese_Taiwan.950")), "ret = %s\n", ret); ret = setlocale(LC_ALL, "Chinese_China.936"); -todo_wine ok(ret != NULL || broken (ret == NULL), "ret == NULL\n"); if(ret) { trace("Chinese_China.936=%s\n", ret); -todo_wine ok(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936") /* Vista - Win7 */ || !strcmp(ret, "Chinese (Simplified)_China.936") /* Win8 - Win10 */ || broken(!strcmp(ret, "Chinese_People's Republic of China.936")), "ret = %s\n", ret); @@ -158,12 +156,14 @@ todo_wine ret = setlocale(LC_ALL, "csy"); ok(ret != NULL || broken (ret == NULL), "ret == NULL\n"); if(ret) - ok(!strcmp(ret, "Czech_Czech Republic.1250"), "ret = %s\n", ret); + ok(!strcmp(ret, "Czech_Czech Republic.1250") + || !strcmp(ret, "Czech_Czechia.1250"), "ret = %s\n", ret); ret = setlocale(LC_ALL, "czech"); ok(ret != NULL || broken (ret == NULL), "ret == NULL\n"); if(ret) - ok(!strcmp(ret, "Czech_Czech Republic.1250"), "ret = %s\n", ret); + ok(!strcmp(ret, "Czech_Czech Republic.1250") + || !strcmp(ret, "Czech_Czechia.1250"), "ret = %s\n", ret); ret = setlocale(LC_ALL, "dan"); ok(ret != NULL || broken (ret == NULL), "ret == NULL\n"); @@ -614,6 +614,9 @@ todo_wine ret = setlocale(LC_ALL, "English_United States.UTF8"); ok(ret == NULL, "ret != NULL\n"); + + ret = setlocale(LC_ALL, "en-US"); + ok(ret == NULL || broken (ret != NULL), "ret != NULL\n"); /* XP & 2003 */ } static void test_crtGetStringTypeW(void) @@ -640,7 +643,7 @@ static void test_crtGetStringTypeW(void) return; } - for(i=0; i 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + + memset(str1W, 0xee, sizeof(str1W)); + len = mbstowcs(str1W, str1, ARRAY_SIZE(str1W)); + str1W[len] = 0; + + memset(str2W, 0xff, sizeof(str2W)); + len = mbstowcs(str2W, str2, ARRAY_SIZE(str2W)); + str2W[len] = 0; + + ret = _wcsncoll(str1W, str2W, tests[i].count); + if (!tests[i].exp) + ok(!ret, "expected 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else if (tests[i].exp < 0) + ok(ret < 0, "expected < 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else + ok(ret > 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + } +} + +static void test__tcsnicoll(void) +{ + struct test { + const char *locale; + const char *str1; + const char *str2; + size_t count; + int exp; + }; + static const struct test tests[] = { + { "English", "abcd", "ABCD", 4, 0 }, + { "English", "abcd", "ABCD", 10, 0 }, + + { "English", "abc", "ABCD", 3, 0 }, + { "English", "abc", "ABCD", 4, -1 }, + { "English", "abc", "ABCD", 10, -1 }, + + { "English", "abcd", "ABC", 3, 0 }, + { "English", "abcd", "ABC", 4, 1 }, + { "English", "abcd", "ABC", 10, 1 }, + + { "English", "abcE", "ABCF", 3, 0 }, + + { "C", "abcd", "ABCD", 4, 0 }, + { "C", "abcd", "ABCD", 10, 0 }, + + { "C", "abc", "ABCD", 3, 0 }, + { "C", "abc", "ABCD", 10, -1 }, + + { "C", "abcd", "ABC", 3, 0 }, + { "C", "abcd", "ABC", 10, 1 }, + + { "C", "abce", "ABCf", 3, 0 }, + }; + WCHAR str1W[16]; + WCHAR str2W[16]; + char str1[16]; + char str2[16]; + size_t len; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(tests); i++) + { + if (!setlocale(LC_ALL, tests[i].locale)) + { + win_skip("%s locale _tcsnicoll tests\n", tests[i].locale); + for (; i+1 < ARRAY_SIZE(tests); i++) + if (strcmp(tests[i].locale, tests[i+1].locale)) break; + continue; + } + + memset(str1, 0xee, sizeof(str1)); + strcpy(str1, tests[i].str1); + + memset(str2, 0xff, sizeof(str2)); + strcpy(str2, tests[i].str2); + + ret = _strnicoll(str1, str2, tests[i].count); + if (!tests[i].exp) + ok(!ret, "expected 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else if (tests[i].exp < 0) + ok(ret < 0, "expected < 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else + ok(ret > 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + + memset(str1W, 0xee, sizeof(str1W)); + len = mbstowcs(str1W, str1, ARRAY_SIZE(str1W)); + str1W[len] = 0; + + memset(str2W, 0xff, sizeof(str2W)); + len = mbstowcs(str2W, str2, ARRAY_SIZE(str2W)); + str2W[len] = 0; + + ret = _wcsnicoll(str1W, str2W, tests[i].count); + if (!tests[i].exp) + ok(!ret, "expected 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else if (tests[i].exp < 0) + ok(ret < 0, "expected < 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else + ok(ret > 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + } +} + +static void test___strncnt(void) +{ + static const struct + { + const char *str; + size_t size; + size_t ret; + } + strncnt_tests[] = + { + { NULL, 0, 0 }, + { "a", 0, 0 }, + { "a", 1, 1 }, + { "a", 10, 1 }, + { "abc", 1, 1 }, + }; + unsigned int i; + size_t ret; + + if (!p___strncnt) + { + win_skip("__strncnt() is not available.\n"); + return; + } + + if (0) /* crashes */ + ret = p___strncnt(NULL, 1); + + for (i = 0; i < ARRAY_SIZE(strncnt_tests); ++i) + { + ret = p___strncnt(strncnt_tests[i].str, strncnt_tests[i].size); + ok(ret == strncnt_tests[i].ret, "%u: unexpected return value %u.\n", i, (int)ret); + } +} + +static void test_C_locale(void) +{ + int i, j; + wint_t ret, exp; + _locale_t locale; + static const char *locales[] = { NULL, "C" }; + + /* C locale only converts case for [a-zA-Z] */ + setlocale(LC_ALL, "C"); + for (i = 0; i <= 0xffff; i++) + { + ret = p_towlower(i); + if (i >= 'A' && i <= 'Z') + { + exp = i + 'a' - 'A'; + ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret); + } + else + todo_wine_if(ret != i) + ok(ret == i, "expected self %x, got %x for C locale\n", i, ret); + + ret = p_towupper(i); + if (i >= 'a' && i <= 'z') + { + exp = i + 'A' - 'a'; + ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret); + } + else + todo_wine_if(ret != i) + ok(ret == i, "expected self %x, got %x for C locale\n", i, ret); + } + + if (!p__towlower_l || !p__towupper_l || !p__create_locale) + { + win_skip("_towlower_l/_towupper_l/_create_locale not available\n"); + return; + } + + for (i = 0; i < ARRAY_SIZE(locales); i++) { + locale = locales[i] ? p__create_locale(LC_ALL, locales[i]) : NULL; + + for (j = 0; j <= 0xffff; j++) { + ret = p__towlower_l(j, locale); + if (j >= 'A' && j <= 'Z') + { + exp = j + 'a' - 'A'; + ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret); + } + else + todo_wine_if(ret != j) + ok(ret == j, "expected self %x, got %x for C locale\n", j, ret); + + ret = p__towupper_l(j, locale); + if (j >= 'a' && j <= 'z') + { + exp = j + 'A' - 'a'; + ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret); + } + else + todo_wine_if(ret != j) + ok(ret == j, "expected self %x, got %x for C locale\n", j, ret); + } + + p__free_locale(locale); + } +} + START_TEST(string) { char mem[100]; @@ -3391,6 +3721,12 @@ START_TEST(string) p_wctob = (void*)GetProcAddress(hMsvcrt, "wctob"); p_wcrtomb = (void*)GetProcAddress(hMsvcrt, "wcrtomb"); p_tolower = (void*)GetProcAddress(hMsvcrt, "tolower"); + p_towlower = (void*)GetProcAddress(hMsvcrt, "towlower"); + p__towlower_l = (void*)GetProcAddress(hMsvcrt, "_towlower_l"); + p_towupper = (void*)GetProcAddress(hMsvcrt, "towupper"); + p__towupper_l = (void*)GetProcAddress(hMsvcrt, "_towupper_l"); + p__create_locale = (void*)GetProcAddress(hMsvcrt, "_create_locale"); + p__free_locale = (void*)GetProcAddress(hMsvcrt, "_free_locale"); p_mbrlen = (void*)GetProcAddress(hMsvcrt, "mbrlen"); p_mbrtowc = (void*)GetProcAddress(hMsvcrt, "mbrtowc"); p_mbsrtowcs = (void*)GetProcAddress(hMsvcrt, "mbsrtowcs"); @@ -3404,6 +3740,7 @@ START_TEST(string) p__mbccpy_s = (void*)GetProcAddress(hMsvcrt, "_mbccpy_s"); p__memicmp = (void*)GetProcAddress(hMsvcrt, "_memicmp"); p__memicmp_l = (void*)GetProcAddress(hMsvcrt, "_memicmp_l"); + p___strncnt = (void*)GetProcAddress(hMsvcrt, "__strncnt"); /* MSVCRT memcpy behaves like memmove for overlapping moves, MFC42 CString::Insert seems to rely on that behaviour */ @@ -3468,4 +3805,9 @@ START_TEST(string) test__ismbclx(); test__memicmp(); test__memicmp_l(); + test__strupr(); + test__tcsncoll(); + test__tcsnicoll(); + test___strncnt(); + test_C_locale(); }