2015-09-29 13:40:12 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Martin Storsjo
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdio.h>
|
2019-01-28 12:08:27 +01:00
|
|
|
#include <locale.h>
|
2020-03-18 18:44:41 +01:00
|
|
|
#include <mbctype.h>
|
|
|
|
#include <mbstring.h>
|
2015-09-29 13:40:12 +02:00
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2017-11-08 10:26:16 +01:00
|
|
|
#define DEFINE_EXPECT(func) \
|
|
|
|
static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
|
|
|
|
|
|
|
|
#define SET_EXPECT(func) \
|
|
|
|
expect_ ## func = TRUE
|
|
|
|
|
|
|
|
#define CHECK_EXPECT2(func) \
|
|
|
|
do { \
|
2017-11-26 12:49:36 +01:00
|
|
|
ok(expect_ ##func, "unexpected call " #func "\n"); \
|
2017-11-08 10:26:16 +01:00
|
|
|
called_ ## func = TRUE; \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
#define CHECK_EXPECT(func) \
|
|
|
|
do { \
|
|
|
|
CHECK_EXPECT2(func); \
|
|
|
|
expect_ ## func = FALSE; \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
#define CHECK_CALLED(func) \
|
|
|
|
do { \
|
2017-11-26 12:49:36 +01:00
|
|
|
ok(called_ ## func, "expected " #func "\n"); \
|
2017-11-08 10:26:16 +01:00
|
|
|
expect_ ## func = called_ ## func = FALSE; \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
DEFINE_EXPECT(invalid_parameter_handler);
|
|
|
|
|
|
|
|
static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
|
|
|
|
const wchar_t *function, const wchar_t *file,
|
|
|
|
unsigned line, uintptr_t arg)
|
|
|
|
{
|
|
|
|
CHECK_EXPECT(invalid_parameter_handler);
|
|
|
|
ok(expression == NULL, "expression is not NULL\n");
|
|
|
|
ok(function == NULL, "function is not NULL\n");
|
|
|
|
ok(file == NULL, "file is not NULL\n");
|
|
|
|
ok(line == 0, "line = %u\n", line);
|
|
|
|
ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
_ACRTIMP int __cdecl _o_tolower(int);
|
|
|
|
_ACRTIMP int __cdecl _o_toupper(int);
|
2015-09-29 13:40:12 +02:00
|
|
|
|
|
|
|
static BOOL local_isnan(double d)
|
|
|
|
{
|
|
|
|
return d != d;
|
|
|
|
}
|
|
|
|
|
2020-07-16 13:10:45 +02:00
|
|
|
#define test_strtod_str_errno(string, value, length, err) _test_strtod_str(__LINE__, string, value, length, err)
|
|
|
|
#define test_strtod_str(string, value, length) _test_strtod_str(__LINE__, string, value, length, 0)
|
|
|
|
static void _test_strtod_str(int line, const char* string, double value, int length, int err)
|
2015-09-29 13:40:12 +02:00
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
double d;
|
2020-07-16 13:10:45 +02:00
|
|
|
errno = 0xdeadbeef;
|
2020-03-18 18:44:41 +01:00
|
|
|
d = strtod(string, &end);
|
2020-07-16 13:10:45 +02:00
|
|
|
if(!err)
|
|
|
|
ok_(__FILE__, line)(errno == 0xdeadbeef, "errno = %d\n", errno);
|
|
|
|
else
|
|
|
|
ok_(__FILE__, line)(errno == err, "errno = %d\n", errno);
|
2020-04-28 19:21:57 +02:00
|
|
|
if (local_isnan(value))
|
|
|
|
ok_(__FILE__, line)(local_isnan(d), "d = %.16le (\"%s\")\n", d, string);
|
|
|
|
else
|
|
|
|
ok_(__FILE__, line)(d == value, "d = %.16le (\"%s\")\n", d, string);
|
2015-09-29 13:40:12 +02:00
|
|
|
ok_(__FILE__, line)(end == string + length, "incorrect end (%d, \"%s\")\n", (int)(end - string), string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_strtod(void)
|
|
|
|
{
|
|
|
|
test_strtod_str("infinity", INFINITY, 8);
|
|
|
|
test_strtod_str("INFINITY", INFINITY, 8);
|
|
|
|
test_strtod_str("InFiNiTy", INFINITY, 8);
|
|
|
|
test_strtod_str("INF", INFINITY, 3);
|
|
|
|
test_strtod_str("-inf", -INFINITY, 4);
|
|
|
|
test_strtod_str("inf42", INFINITY, 3);
|
|
|
|
test_strtod_str("inffoo", INFINITY, 3);
|
|
|
|
test_strtod_str("infini", INFINITY, 3);
|
2020-01-07 15:35:52 +01:00
|
|
|
test_strtod_str("input", 0, 0);
|
|
|
|
test_strtod_str("-input", 0, 0);
|
2020-07-16 13:10:45 +02:00
|
|
|
test_strtod_str_errno("1.7976931348623159e+308", INFINITY, 23, ERANGE);
|
|
|
|
test_strtod_str_errno("-1.7976931348623159e+308", -INFINITY, 24, ERANGE);
|
2015-09-29 13:40:12 +02:00
|
|
|
|
|
|
|
test_strtod_str("NAN", NAN, 3);
|
|
|
|
test_strtod_str("nan", NAN, 3);
|
|
|
|
test_strtod_str("NaN", NAN, 3);
|
|
|
|
|
|
|
|
test_strtod_str("0x42", 66, 4);
|
|
|
|
test_strtod_str("0X42", 66, 4);
|
|
|
|
test_strtod_str("-0x42", -66, 5);
|
|
|
|
test_strtod_str("0x1p1", 2, 5);
|
|
|
|
test_strtod_str("0x1P1", 2, 5);
|
|
|
|
test_strtod_str("0x1p+1", 2, 6);
|
|
|
|
test_strtod_str("0x2p-1", 1, 6);
|
|
|
|
test_strtod_str("0xA", 10, 3);
|
|
|
|
test_strtod_str("0xa", 10, 3);
|
|
|
|
test_strtod_str("0xABCDEF", 11259375, 8);
|
|
|
|
test_strtod_str("0Xabcdef", 11259375, 8);
|
|
|
|
|
|
|
|
test_strtod_str("0x1.1", 1.0625, 5);
|
|
|
|
test_strtod_str("0x1.1p1", 2.125, 7);
|
|
|
|
test_strtod_str("0x1.A", 1.625, 5);
|
|
|
|
test_strtod_str("0x1p1a", 2, 5);
|
2019-11-22 16:41:30 +01:00
|
|
|
test_strtod_str("0xp3", 0, 1);
|
|
|
|
test_strtod_str("0x.", 0, 1);
|
|
|
|
test_strtod_str("0x.8", 0.5, 4);
|
|
|
|
test_strtod_str("0x.8p", 0.5, 4);
|
|
|
|
test_strtod_str("0x0p10000000000000000000000000", 0, 30);
|
|
|
|
test_strtod_str("0x1p-1026", 1.3906711615670009e-309, 9);
|
|
|
|
|
|
|
|
test_strtod_str("0x1ffffffffffffe.80000000000000000000", 9007199254740990.0, 37);
|
|
|
|
test_strtod_str("0x1ffffffffffffe.80000000000000000001", 9007199254740991.0, 37);
|
|
|
|
test_strtod_str("0x1fffffffffffff.80000000000000000000", 9007199254740992.0, 37);
|
|
|
|
test_strtod_str("0x1fffffffffffff.80000000000000000001", 9007199254740992.0, 37);
|
2019-12-30 13:23:47 +01:00
|
|
|
|
|
|
|
test_strtod_str("4.0621786324484881721115322e-53", 4.0621786324484881721115322e-53, 31);
|
2020-04-28 19:21:57 +02:00
|
|
|
test_strtod_str("1.8905590910042396899370942", 1.8905590910042396899370942, 27);
|
2020-07-16 13:10:45 +02:00
|
|
|
test_strtod_str("1.7976931348623158e+308", 1.7976931348623158e+308, 23);
|
2019-12-30 13:23:47 +01:00
|
|
|
test_strtod_str("2.2250738585072014e-308", 2.2250738585072014e-308, 23);
|
|
|
|
test_strtod_str("4.9406564584124654e-324", 4.9406564584124654e-324, 23);
|
2020-07-23 15:38:46 +02:00
|
|
|
test_strtod_str("2.48e-324", 4.9406564584124654e-324, 9);
|
|
|
|
test_strtod_str_errno("2.47e-324", 0, 9, ERANGE);
|
2015-09-29 13:40:12 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 10:26:16 +01:00
|
|
|
static void test__memicmp(void)
|
|
|
|
{
|
|
|
|
static const char *s1 = "abc";
|
|
|
|
static const char *s2 = "aBd";
|
|
|
|
int ret;
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp(NULL, NULL, 0);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
SET_EXPECT(invalid_parameter_handler);
|
|
|
|
errno = 0xdeadbeef;
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp(NULL, NULL, 1);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
2020-03-12 17:21:24 +01:00
|
|
|
ok(errno == EINVAL, "Unexpected errno = %d\n", errno);
|
2017-11-08 10:26:16 +01:00
|
|
|
CHECK_CALLED(invalid_parameter_handler);
|
|
|
|
|
|
|
|
SET_EXPECT(invalid_parameter_handler);
|
|
|
|
errno = 0xdeadbeef;
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp(s1, NULL, 1);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
2020-03-12 17:21:24 +01:00
|
|
|
ok(errno == EINVAL, "Unexpected errno = %d\n", errno);
|
2017-11-08 10:26:16 +01:00
|
|
|
CHECK_CALLED(invalid_parameter_handler);
|
|
|
|
|
|
|
|
SET_EXPECT(invalid_parameter_handler);
|
|
|
|
errno = 0xdeadbeef;
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp(NULL, s2, 1);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
2020-03-12 17:21:24 +01:00
|
|
|
ok(errno == EINVAL, "Unexpected errno = %d\n", errno);
|
2017-11-08 10:26:16 +01:00
|
|
|
CHECK_CALLED(invalid_parameter_handler);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp(s1, s2, 2);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp(s1, s2, 3);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == -1, "got %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test__memicmp_l(void)
|
|
|
|
{
|
|
|
|
static const char *s1 = "abc";
|
|
|
|
static const char *s2 = "aBd";
|
|
|
|
int ret;
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp_l(NULL, NULL, 0, NULL);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
SET_EXPECT(invalid_parameter_handler);
|
|
|
|
errno = 0xdeadbeef;
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp_l(NULL, NULL, 1, NULL);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
2020-03-12 17:21:24 +01:00
|
|
|
ok(errno == EINVAL, "Unexpected errno = %d\n", errno);
|
2017-11-08 10:26:16 +01:00
|
|
|
CHECK_CALLED(invalid_parameter_handler);
|
|
|
|
|
|
|
|
SET_EXPECT(invalid_parameter_handler);
|
|
|
|
errno = 0xdeadbeef;
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp_l(s1, NULL, 1, NULL);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
2020-03-12 17:21:24 +01:00
|
|
|
ok(errno == EINVAL, "Unexpected errno = %d\n", errno);
|
2017-11-08 10:26:16 +01:00
|
|
|
CHECK_CALLED(invalid_parameter_handler);
|
|
|
|
|
|
|
|
SET_EXPECT(invalid_parameter_handler);
|
|
|
|
errno = 0xdeadbeef;
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp_l(NULL, s2, 1, NULL);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
2020-03-12 17:21:24 +01:00
|
|
|
ok(errno == EINVAL, "Unexpected errno = %d\n", errno);
|
2017-11-08 10:26:16 +01:00
|
|
|
CHECK_CALLED(invalid_parameter_handler);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp_l(s1, s2, 2, NULL);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _memicmp_l(s1, s2, 3, NULL);
|
2017-11-08 10:26:16 +01:00
|
|
|
ok(ret == -1, "got %d\n", ret);
|
|
|
|
}
|
2018-10-30 14:01:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void test___strncnt(void)
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
size_t size;
|
|
|
|
size_t ret;
|
|
|
|
}
|
|
|
|
strncnt_tests[] =
|
|
|
|
{
|
|
|
|
{ "a", 0, 0 },
|
|
|
|
{ "a", 1, 1 },
|
|
|
|
{ "a", 10, 1 },
|
|
|
|
{ "abc", 1, 1 },
|
|
|
|
};
|
|
|
|
unsigned int i;
|
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(strncnt_tests); ++i)
|
|
|
|
{
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = __strncnt(strncnt_tests[i].str, strncnt_tests[i].size);
|
2018-10-30 14:01:09 +01:00
|
|
|
ok(ret == strncnt_tests[i].ret, "%u: unexpected return value %u.\n", i, (int)ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0) /* crashes */
|
|
|
|
{
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = __strncnt(NULL, 0);
|
|
|
|
ret = __strncnt(NULL, 1);
|
2018-10-30 14:01:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 12:08:27 +01:00
|
|
|
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] */
|
2020-03-18 18:44:41 +01:00
|
|
|
setlocale(LC_ALL, "C");
|
2019-01-28 12:08:27 +01:00
|
|
|
for (i = 0; i <= 0xffff; i++)
|
|
|
|
{
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = tolower(i);
|
2020-01-09 23:03:17 +01:00
|
|
|
if (i >= 'A' && i <= 'Z')
|
|
|
|
{
|
|
|
|
exp = i + 'a' - 'A';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == i, "expected self %x, got %x for C locale\n", i, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _tolower(i);
|
2020-01-09 23:03:17 +01:00
|
|
|
exp = i + 'a' - 'A';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _o_tolower(i);
|
2020-01-09 23:03:17 +01:00
|
|
|
if (i >= 'A' && i <= 'Z')
|
|
|
|
{
|
|
|
|
exp = i + 'a' - 'A';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == i, "expected self %x, got %x for C locale\n", i, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = towlower(i);
|
2019-01-28 12:08:27 +01:00
|
|
|
if (i >= 'A' && i <= 'Z')
|
|
|
|
{
|
|
|
|
exp = i + 'a' - 'A';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == i, "expected self %x, got %x for C locale\n", i, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = toupper(i);
|
2020-01-09 23:03:17 +01:00
|
|
|
if (i >= 'a' && i <= 'z')
|
|
|
|
{
|
|
|
|
exp = i + 'A' - 'a';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == i, "expected self %x, got %x for C locale\n", i, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _toupper(i);
|
2020-01-09 23:03:17 +01:00
|
|
|
exp = i + 'A' - 'a';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _o_toupper(i);
|
2020-01-09 23:03:17 +01:00
|
|
|
if (i >= 'a' && i <= 'z')
|
|
|
|
{
|
|
|
|
exp = i + 'A' - 'a';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == i, "expected self %x, got %x for C locale\n", i, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = towupper(i);
|
2019-01-28 12:08:27 +01:00
|
|
|
if (i >= 'a' && i <= 'z')
|
|
|
|
{
|
|
|
|
exp = i + 'A' - 'a';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == i, "expected self %x, got %x for C locale\n", i, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(locales); i++) {
|
2020-03-18 18:44:41 +01:00
|
|
|
locale = locales[i] ? _create_locale(LC_ALL, locales[i]) : NULL;
|
2019-01-28 12:08:27 +01:00
|
|
|
|
|
|
|
for (j = 0; j <= 0xffff; j++) {
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _towlower_l(j, locale);
|
2019-01-28 12:08:27 +01:00
|
|
|
if (j >= 'A' && j <= 'Z')
|
|
|
|
{
|
|
|
|
exp = j + 'a' - 'A';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == j, "expected self %x, got %x for C locale\n", j, ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _towupper_l(j, locale);
|
2019-01-28 12:08:27 +01:00
|
|
|
if (j >= 'a' && j <= 'z')
|
|
|
|
{
|
|
|
|
exp = j + 'A' - 'a';
|
|
|
|
ok(ret == exp, "expected %x, got %x for C locale\n", exp, ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret == j, "expected self %x, got %x for C locale\n", j, ret);
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
_free_locale(locale);
|
2019-01-28 12:08:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:50:37 +02:00
|
|
|
static void test_mbsspn( void)
|
|
|
|
{
|
|
|
|
unsigned char str1[] = "cabernet";
|
|
|
|
unsigned char str2[] = "shiraz";
|
|
|
|
unsigned char set[] = "abc";
|
|
|
|
unsigned char empty[] = "";
|
|
|
|
unsigned char mbstr[] = " 2019\x94\x4e" "6\x8c\x8e" "29\x93\xfa";
|
|
|
|
unsigned char mbset1[] = "0123456789 \x94\x4e";
|
|
|
|
unsigned char mbset2[] = " \x94\x4e\x8c\x8e";
|
|
|
|
unsigned char mbset3[] = "\x8e";
|
2020-03-18 18:44:41 +01:00
|
|
|
int ret, cp = _getmbcp();
|
2019-09-02 19:50:37 +02:00
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _mbsspn(str1, set);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 3, "_mbsspn returns %d should be 3\n", ret);
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _mbsspn(str2, set);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 0, "_mbsspn returns %d should be 0\n", ret);
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _mbsspn(str1, empty);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 0, "_mbsspn returns %d should be 0\n", ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
_setmbcp(932);
|
|
|
|
ret = _mbsspn(mbstr, mbset1);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 8, "_mbsspn returns %d should be 8\n", ret);
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _mbsspn(mbstr, mbset2);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 1, "_mbsspn returns %d should be 1\n", ret);
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _mbsspn(mbstr+8, mbset1);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 0, "_mbsspn returns %d should be 0\n", ret);
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _mbsspn(mbstr+8, mbset2);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 2, "_mbsspn returns %d should be 2\n", ret);
|
2020-03-18 18:44:41 +01:00
|
|
|
ret = _mbsspn(mbstr, mbset3);
|
2019-09-02 19:50:37 +02:00
|
|
|
ok(ret == 14, "_mbsspn returns %d should be 14\n", ret);
|
|
|
|
|
2020-03-18 18:44:41 +01:00
|
|
|
_setmbcp(cp);
|
2019-09-02 19:50:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-24 06:51:22 +01:00
|
|
|
static void test_wcstok(void)
|
|
|
|
{
|
|
|
|
static const wchar_t *input = L"two words";
|
|
|
|
wchar_t buffer[16];
|
|
|
|
wchar_t *token;
|
|
|
|
wchar_t *next;
|
|
|
|
|
|
|
|
next = NULL;
|
|
|
|
wcscpy(buffer, input);
|
2020-03-18 18:44:41 +01:00
|
|
|
token = wcstok(buffer, L" ", &next);
|
2020-01-24 06:51:22 +01:00
|
|
|
ok(!wcscmp(L"two", token), "expected \"two\", got \"%ls\"\n", token);
|
|
|
|
ok(next == token + 4, "expected %p, got %p\n", token + 4, next);
|
2020-03-18 18:44:41 +01:00
|
|
|
token = wcstok(NULL, L" ", &next);
|
2020-01-24 06:51:22 +01:00
|
|
|
ok(!wcscmp(L"words", token), "expected \"words\", got \"%ls\"\n", token);
|
|
|
|
ok(next == token + 5, "expected %p, got %p\n", token + 5, next);
|
2020-03-18 18:44:41 +01:00
|
|
|
token = wcstok(NULL, L" ", &next);
|
2020-01-24 06:51:22 +01:00
|
|
|
ok(!token, "expected NULL, got %p\n", token);
|
|
|
|
|
|
|
|
wcscpy(buffer, input);
|
2020-03-18 18:44:41 +01:00
|
|
|
token = wcstok(buffer, L" ", NULL);
|
2020-01-24 06:51:22 +01:00
|
|
|
ok(!wcscmp(L"two", token), "expected \"two\", got \"%ls\"\n", token);
|
2020-03-18 18:44:41 +01:00
|
|
|
token = wcstok(NULL, L" ", NULL);
|
2020-01-24 06:51:22 +01:00
|
|
|
ok(!wcscmp(L"words", token), "expected \"words\", got \"%ls\"\n", token);
|
2020-03-18 18:44:41 +01:00
|
|
|
token = wcstok(NULL, L" ", NULL);
|
2020-01-24 06:51:22 +01:00
|
|
|
ok(!token, "expected NULL, got %p\n", token);
|
2021-05-25 15:59:46 +02:00
|
|
|
|
|
|
|
next = NULL;
|
|
|
|
wcscpy(buffer, input);
|
|
|
|
token = wcstok(buffer, L"=", &next);
|
|
|
|
ok(!wcscmp(token, input), "expected \"%ls\", got \"%ls\"\n", input, token);
|
|
|
|
ok(next == buffer + wcslen(input), "expected %p, got %p\n", buffer + wcslen(input), next);
|
|
|
|
token = wcstok(NULL, L"=", &next);
|
|
|
|
ok(!token, "expected NULL, got \"%ls\"\n", token);
|
|
|
|
ok(next == buffer + wcslen(input), "expected %p, got %p\n", buffer + wcslen(input), next);
|
|
|
|
|
|
|
|
next = NULL;
|
|
|
|
wcscpy(buffer, L"");
|
|
|
|
token = wcstok(buffer, L"=", &next);
|
|
|
|
ok(token == NULL, "expected NULL, got \"%ls\"\n", token);
|
|
|
|
ok(next == buffer, "expected %p, got %p\n", buffer, next);
|
|
|
|
token = wcstok(NULL, L"=", &next);
|
|
|
|
ok(!token, "expected NULL, got \"%ls\"\n", token);
|
|
|
|
ok(next == buffer, "expected %p, got %p\n", buffer, next);
|
2020-01-24 06:51:22 +01:00
|
|
|
}
|
|
|
|
|
2020-03-25 19:15:24 +01:00
|
|
|
static void test__strnicmp(void)
|
|
|
|
{
|
|
|
|
static const char str1[] = "TEST";
|
|
|
|
static const char str2[] = "test";
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
SET_EXPECT(invalid_parameter_handler);
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = _strnicmp(str1, str2, -1);
|
|
|
|
todo_wine CHECK_CALLED(invalid_parameter_handler);
|
|
|
|
todo_wine ok(ret == _NLSCMPERROR, "got %d.\n", ret);
|
|
|
|
todo_wine ok(errno == EINVAL, "Unexpected errno %d.\n", errno);
|
|
|
|
|
|
|
|
ret = _strnicmp(str1, str2, 0x7fffffff);
|
|
|
|
ok(!ret, "got %d.\n", ret);
|
|
|
|
}
|
|
|
|
|
2020-08-07 03:44:59 +02:00
|
|
|
static void test_SpecialCasing(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
wint_t ret, exp;
|
|
|
|
_locale_t locale;
|
|
|
|
struct test {
|
|
|
|
const char *lang;
|
|
|
|
wint_t ch;
|
|
|
|
wint_t exp;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct test ucases[] = {
|
|
|
|
{"English", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
|
|
|
|
{"English", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
|
|
|
|
|
|
|
|
{"Turkish", 'I', 'i'}, /* LATIN CAPITAL LETTER I */
|
|
|
|
{"Turkish", 0x0130}, /* LATIN CAPITAL LETTER I WITH DOT ABOVE */
|
|
|
|
};
|
|
|
|
struct test lcases[] = {
|
|
|
|
{"English", 'i', 'I'}, /* LATIN SMALL LETTER I */
|
|
|
|
{"English", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
|
|
|
|
|
|
|
|
{"Turkish", 'i', 'I'}, /* LATIN SMALL LETTER I */
|
|
|
|
{"Turkish", 0x0131}, /* LATIN SMALL LETTER DOTLESS I */
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ucases); i++) {
|
|
|
|
if (!setlocale(LC_ALL, ucases[i].lang)) {
|
|
|
|
win_skip("skipping special case tests for %s\n", ucases[i].lang);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = towlower(ucases[i].ch);
|
|
|
|
exp = ucases[i].exp ? ucases[i].exp : ucases[i].ch;
|
|
|
|
ok(ret == exp, "expected lowercase %x, got %x for locale %s\n", exp, ret, ucases[i].lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(lcases); i++) {
|
|
|
|
if (!setlocale(LC_ALL, lcases[i].lang)) {
|
|
|
|
win_skip("skipping special case tests for %s\n", lcases[i].lang);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = towupper(lcases[i].ch);
|
|
|
|
exp = lcases[i].exp ? lcases[i].exp : lcases[i].ch;
|
|
|
|
ok(ret == exp, "expected uppercase %x, got %x for locale %s\n", exp, ret, lcases[i].lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
|
|
|
|
/* test _towlower_l creating locale */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ucases); i++) {
|
|
|
|
if (!(locale = _create_locale(LC_ALL, ucases[i].lang))) {
|
|
|
|
win_skip("locale %s not available. skipping\n", ucases[i].lang);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = _towlower_l(ucases[i].ch, locale);
|
|
|
|
exp = ucases[i].exp ? ucases[i].exp : ucases[i].ch;
|
|
|
|
ok(ret == exp, "expected lowercase %x, got %x for locale %s\n", exp, ret, ucases[i].lang);
|
|
|
|
|
|
|
|
_free_locale(locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test _towupper_l creating locale */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(lcases); i++) {
|
|
|
|
if (!(locale = _create_locale(LC_ALL, lcases[i].lang))) {
|
|
|
|
win_skip("locale %s not available. skipping\n", lcases[i].lang);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = _towupper_l(lcases[i].ch, locale);
|
|
|
|
exp = lcases[i].exp ? lcases[i].exp : lcases[i].ch;
|
|
|
|
ok(ret == exp, "expected uppercase %x, got %x for locale %s\n", exp, ret, lcases[i].lang);
|
|
|
|
|
|
|
|
_free_locale(locale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 21:56:25 +02:00
|
|
|
static void test__mbbtype_l(void)
|
|
|
|
{
|
|
|
|
int expected, ret;
|
|
|
|
unsigned int c;
|
|
|
|
|
|
|
|
_setmbcp(_MB_CP_LOCALE);
|
|
|
|
for (c = 0; c < 256; ++c)
|
|
|
|
{
|
|
|
|
expected = _mbbtype(c, 0);
|
|
|
|
ret = _mbbtype_l(c, 0, NULL);
|
|
|
|
ok(ret == expected, "c %#x, got ret %#x, expected %#x.\n", c, ret, expected);
|
|
|
|
|
|
|
|
expected = _mbbtype(c, 1);
|
|
|
|
ret = _mbbtype_l(c, 1, NULL);
|
|
|
|
ok(ret == expected, "c %#x, got ret %#x, expected %#x.\n", c, ret, expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:40:12 +02:00
|
|
|
START_TEST(string)
|
|
|
|
{
|
2020-03-26 11:42:00 +01:00
|
|
|
ok(_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
|
|
|
|
"Invalid parameter handler was already set\n");
|
|
|
|
|
2015-09-29 13:40:12 +02:00
|
|
|
test_strtod();
|
2017-11-08 10:26:16 +01:00
|
|
|
test__memicmp();
|
|
|
|
test__memicmp_l();
|
2018-10-30 14:01:09 +01:00
|
|
|
test___strncnt();
|
2019-01-28 12:08:27 +01:00
|
|
|
test_C_locale();
|
2019-09-02 19:50:37 +02:00
|
|
|
test_mbsspn();
|
2020-01-24 06:51:22 +01:00
|
|
|
test_wcstok();
|
2020-03-25 19:15:24 +01:00
|
|
|
test__strnicmp();
|
2020-08-07 03:44:59 +02:00
|
|
|
test_SpecialCasing();
|
2020-09-23 21:56:25 +02:00
|
|
|
test__mbbtype_l();
|
2015-09-29 13:40:12 +02:00
|
|
|
}
|