msvcrt/tests: Add tests for _strncoll/_wcsncoll.

Signed-off-by: Daniel Lehman <dlehman@esri.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Daniel Lehman 2018-08-17 18:51:17 +02:00 committed by Alexandre Julliard
parent 368e9f39b4
commit 9aa7a42a9f
1 changed files with 86 additions and 0 deletions

View File

@ -3387,6 +3387,91 @@ static void test__strupr(void)
VirtualFree(mem, sizeof(str), MEM_RELEASE);
}
static void test__tcsncoll(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 },
{ "English", "abcd", "ABCD", 10, -1 },
{ "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 },
{ "C", "abcd", "ABCD", 10, 1 },
};
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 _tcsncoll 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 = _strncoll(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 = _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);
}
}
START_TEST(string)
{
char mem[100];
@ -3510,4 +3595,5 @@ START_TEST(string)
test__memicmp();
test__memicmp_l();
test__strupr();
test__tcsncoll();
}