2004-03-19 02:53:11 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for string functions.
|
|
|
|
*
|
|
|
|
* Copyright 2004 Uwe Bonnes
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-03-19 02:53:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include <string.h>
|
2005-11-21 13:03:18 +01:00
|
|
|
#include <mbstring.h>
|
2012-11-29 10:22:46 +01:00
|
|
|
#include <wchar.h>
|
2004-03-19 02:53:11 +01:00
|
|
|
#include <stdlib.h>
|
2007-08-22 19:47:01 +02:00
|
|
|
#include <stdio.h>
|
2005-09-06 13:41:48 +02:00
|
|
|
#include <mbctype.h>
|
2007-08-22 19:47:01 +02:00
|
|
|
#include <locale.h>
|
2007-11-15 16:11:26 +01:00
|
|
|
#include <errno.h>
|
2010-03-29 00:04:03 +02:00
|
|
|
#include <limits.h>
|
2019-12-18 23:48:11 +01:00
|
|
|
#include <float.h>
|
2012-12-17 15:19:19 +01:00
|
|
|
#include <math.h>
|
2007-08-22 19:47:01 +02:00
|
|
|
|
2013-11-05 05:30:56 +01:00
|
|
|
/* make it use a definition from string.h */
|
|
|
|
#undef strncpy
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
|
2007-08-22 19:47:01 +02:00
|
|
|
static char *buf_to_string(const unsigned char *bin, int len, int nr)
|
|
|
|
{
|
|
|
|
static char buf[2][1024];
|
|
|
|
char *w = buf[nr];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
sprintf(w, "%02x ", (unsigned char)bin[i]);
|
|
|
|
w += strlen(w);
|
|
|
|
}
|
|
|
|
return buf[nr];
|
|
|
|
}
|
2004-03-19 02:53:11 +01:00
|
|
|
|
2007-08-20 07:34:12 +02:00
|
|
|
#define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
|
2007-08-22 19:47:01 +02:00
|
|
|
#define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); }
|
2007-08-20 07:34:12 +02:00
|
|
|
|
2009-05-23 11:21:28 +02:00
|
|
|
static void* (__cdecl *pmemcpy)(void *, const void *, size_t n);
|
2012-07-28 18:43:43 +02:00
|
|
|
static int (__cdecl *p_memcpy_s)(void *, size_t, const void *, size_t);
|
|
|
|
static int (__cdecl *p_memmove_s)(void *, size_t, const void *, size_t);
|
2009-05-23 11:21:28 +02:00
|
|
|
static int* (__cdecl *pmemcmp)(void *, const void *, size_t n);
|
2020-01-16 11:37:03 +01:00
|
|
|
static int (__cdecl *p_strcmp)(const char *, const char *);
|
|
|
|
static int (__cdecl *p_strncmp)(const char *, const char *, size_t);
|
2017-08-05 18:23:13 +02:00
|
|
|
static int (__cdecl *p_strcpy)(char *dst, const char *src);
|
2009-05-23 11:21:28 +02:00
|
|
|
static int (__cdecl *pstrcpy_s)(char *dst, size_t len, const char *src);
|
|
|
|
static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src);
|
2015-07-06 19:40:10 +02:00
|
|
|
static int (__cdecl *p_mbscat_s)(unsigned char *dst, size_t size, const unsigned char *src);
|
2010-10-21 09:55:43 +02:00
|
|
|
static int (__cdecl *p_mbsnbcat_s)(unsigned char *dst, size_t size, const unsigned char *src, size_t count);
|
2009-05-23 11:21:28 +02:00
|
|
|
static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
|
2014-05-19 11:43:05 +02:00
|
|
|
static int (__cdecl *p__mbscpy_s)(unsigned char*, size_t, const unsigned char*);
|
2009-05-23 11:21:28 +02:00
|
|
|
static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
|
2011-10-04 23:03:03 +02:00
|
|
|
static int (__cdecl *p_wcsncpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc, size_t count);
|
2010-10-18 14:06:16 +02:00
|
|
|
static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
|
2009-11-16 02:09:17 +01:00
|
|
|
static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
|
2010-03-24 22:39:28 +01:00
|
|
|
static size_t (__cdecl *p_strnlen)(const char *, size_t);
|
2010-03-29 00:04:03 +02:00
|
|
|
static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
|
2010-03-29 00:04:32 +02:00
|
|
|
static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
|
2013-03-09 08:56:38 +01:00
|
|
|
static __int64 (__cdecl *p_wcstoi64)(const wchar_t *, wchar_t **, int);
|
|
|
|
static unsigned __int64 (__cdecl *p_wcstoui64)(const wchar_t *, wchar_t **, int);
|
2010-05-06 14:28:08 +02:00
|
|
|
static int (__cdecl *pwcstombs_s)(size_t*,char*,size_t,const wchar_t*,size_t);
|
2020-02-03 20:15:54 +01:00
|
|
|
static int (__cdecl *p_wcstombs_s_l)(size_t*,char*,size_t,const wchar_t*,size_t,_locale_t);
|
2010-05-06 14:28:08 +02:00
|
|
|
static int (__cdecl *pmbstowcs_s)(size_t*,wchar_t*,size_t,const char*,size_t);
|
2012-11-29 10:23:57 +01:00
|
|
|
static size_t (__cdecl *p_mbsrtowcs)(wchar_t*, const char**, size_t, mbstate_t*);
|
2016-05-16 13:29:45 +02:00
|
|
|
static int (__cdecl *p_mbsrtowcs_s)(size_t*,wchar_t*,size_t,const char**,size_t,mbstate_t*);
|
2011-04-27 20:08:41 +02:00
|
|
|
static size_t (__cdecl *pwcsrtombs)(char*, const wchar_t**, size_t, int*);
|
2010-08-27 01:46:35 +02:00
|
|
|
static errno_t (__cdecl *p_gcvt_s)(char*,size_t,double,int);
|
2010-10-11 12:25:15 +02:00
|
|
|
static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
|
2010-10-11 12:25:23 +02:00
|
|
|
static errno_t (__cdecl *p_strlwr_s)(char*,size_t);
|
2010-10-21 09:57:44 +02:00
|
|
|
static errno_t (__cdecl *p_ultoa_s)(__msvcrt_ulong,char*,size_t,int);
|
2008-12-11 22:53:36 +01:00
|
|
|
static int *p__mb_cur_max;
|
|
|
|
static unsigned char *p_mbctype;
|
2011-03-04 23:59:08 +01:00
|
|
|
static int (__cdecl *p_wcslwr_s)(wchar_t*,size_t);
|
2011-03-20 02:17:12 +01:00
|
|
|
static errno_t (__cdecl *p_mbsupr_s)(unsigned char *str, size_t numberOfElements);
|
2011-03-20 02:19:02 +01:00
|
|
|
static errno_t (__cdecl *p_mbslwr_s)(unsigned char *str, size_t numberOfElements);
|
2011-04-05 23:47:22 +02:00
|
|
|
static int (__cdecl *p_wctob)(wint_t);
|
2020-01-28 23:08:13 +01:00
|
|
|
static wint_t (__cdecl *p_btowc)(int);
|
2012-11-29 22:49:58 +01:00
|
|
|
static size_t (__cdecl *p_wcrtomb)(char*, wchar_t, mbstate_t*);
|
2019-09-30 19:09:14 +02:00
|
|
|
static int (__cdecl *p_wcrtomb_s)(size_t*, char*, size_t, wchar_t, mbstate_t*);
|
2011-06-03 15:28:56 +02:00
|
|
|
static int (__cdecl *p_tolower)(int);
|
2018-11-27 05:18:11 +01:00
|
|
|
static int (__cdecl *p_towlower)(wint_t);
|
|
|
|
static int (__cdecl *p__towlower_l)(wint_t, _locale_t);
|
|
|
|
static int (__cdecl *p_towupper)(wint_t);
|
|
|
|
static int (__cdecl *p__towupper_l)(wint_t, _locale_t);
|
|
|
|
static _locale_t(__cdecl *p__create_locale)(int, const char*);
|
|
|
|
static void(__cdecl *p__free_locale)(_locale_t);
|
2012-11-29 10:22:46 +01:00
|
|
|
static size_t (__cdecl *p_mbrlen)(const char*, size_t, mbstate_t*);
|
2012-11-29 10:23:20 +01:00
|
|
|
static size_t (__cdecl *p_mbrtowc)(wchar_t*, const char*, size_t, mbstate_t*);
|
2012-12-17 15:19:19 +01:00
|
|
|
static int (__cdecl *p__atodbl_l)(_CRT_DOUBLE*,char*,_locale_t);
|
2015-06-29 03:42:21 +02:00
|
|
|
static double (__cdecl *p__atof_l)(const char*,_locale_t);
|
|
|
|
static double (__cdecl *p__strtod_l)(const char *,char**,_locale_t);
|
2014-09-02 13:50:44 +02:00
|
|
|
static int (__cdecl *p__strnset_s)(char*,size_t,int,size_t);
|
2019-04-01 19:57:07 +02:00
|
|
|
static int (__cdecl *p__wcsnset_s)(wchar_t*,size_t,wchar_t,size_t);
|
2014-12-23 17:44:28 +01:00
|
|
|
static int (__cdecl *p__wcsset_s)(wchar_t*,size_t,wchar_t);
|
2017-10-05 19:39:29 +02:00
|
|
|
static size_t (__cdecl *p__mbsnlen)(const unsigned char*, size_t);
|
2017-10-06 12:07:23 +02:00
|
|
|
static int (__cdecl *p__mbccpy_s)(unsigned char*, size_t, int*, const unsigned char*);
|
2017-11-08 10:26:16 +01:00
|
|
|
static int (__cdecl *p__memicmp)(const char*, const char*, size_t);
|
|
|
|
static int (__cdecl *p__memicmp_l)(const char*, const char*, size_t, _locale_t);
|
2018-10-30 14:01:09 +01:00
|
|
|
static size_t (__cdecl *p___strncnt)(const char*, size_t);
|
2004-03-19 02:53:11 +01:00
|
|
|
|
|
|
|
#define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
|
|
|
|
#define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
|
|
|
|
|
2010-10-01 13:41:42 +02:00
|
|
|
static HMODULE hMsvcrt;
|
2007-08-22 19:47:01 +02:00
|
|
|
|
2005-08-19 12:01:42 +02:00
|
|
|
static void test_swab( void ) {
|
|
|
|
char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
|
|
|
|
char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
|
|
|
|
char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
|
|
|
|
char expected3[] = "$";
|
|
|
|
|
|
|
|
char from[30];
|
|
|
|
char to[30];
|
|
|
|
|
|
|
|
int testsize;
|
|
|
|
|
|
|
|
/* Test 1 - normal even case */
|
|
|
|
memset(to,'$', sizeof(to));
|
|
|
|
memset(from,'@', sizeof(from));
|
|
|
|
testsize = 26;
|
|
|
|
memcpy(from, original, testsize);
|
|
|
|
_swab( from, to, testsize );
|
|
|
|
ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
|
|
|
|
|
|
|
/* Test 2 - uneven case */
|
|
|
|
memset(to,'$', sizeof(to));
|
|
|
|
memset(from,'@', sizeof(from));
|
|
|
|
testsize = 25;
|
|
|
|
memcpy(from, original, testsize);
|
|
|
|
_swab( from, to, testsize );
|
|
|
|
ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
|
|
|
|
|
|
|
/* Test 3 - from = to */
|
|
|
|
memset(to,'$', sizeof(to));
|
|
|
|
memset(from,'@', sizeof(from));
|
|
|
|
testsize = 26;
|
|
|
|
memcpy(to, original, testsize);
|
|
|
|
_swab( to, to, testsize );
|
|
|
|
ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
|
|
|
|
|
|
|
/* Test 4 - 1 bytes */
|
|
|
|
memset(to,'$', sizeof(to));
|
|
|
|
memset(from,'@', sizeof(from));
|
|
|
|
testsize = 1;
|
|
|
|
memcpy(from, original, testsize);
|
|
|
|
_swab( from, to, testsize );
|
|
|
|
ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
|
|
|
|
}
|
|
|
|
|
2019-10-28 13:29:01 +01:00
|
|
|
static void test_strcspn(void)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
const char *str;
|
|
|
|
const char *rej;
|
|
|
|
int ret;
|
|
|
|
} tests[] = {
|
|
|
|
{ "test", "a", 4 },
|
|
|
|
{ "test", "e", 1 },
|
|
|
|
{ "test", "", 4 },
|
|
|
|
{ "", "a", 0 },
|
|
|
|
{ "a\xf1", "\xf1", 1 }
|
|
|
|
};
|
|
|
|
int r, i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++)
|
|
|
|
{
|
|
|
|
r = strcspn(tests[i].str, tests[i].rej);
|
|
|
|
ok(r == tests[i].ret, "strcspn(\"%s\", \"%s\") = %d, expected %d\n",
|
|
|
|
tests[i].str, tests[i].rej, r, tests[i].ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
#if 0 /* use this to generate more tests */
|
|
|
|
|
|
|
|
static void test_codepage(int cp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int prev;
|
|
|
|
int count = 1;
|
|
|
|
|
|
|
|
ok(_setmbcp(cp) == 0, "Couldn't set mbcp\n");
|
|
|
|
|
2008-12-11 22:53:36 +01:00
|
|
|
prev = p_mbctype[0];
|
2007-08-20 05:19:37 +02:00
|
|
|
printf("static int result_cp_%d_mbctype[] = { ", cp);
|
|
|
|
for (i = 1; i < 257; i++)
|
|
|
|
{
|
2008-12-11 22:53:36 +01:00
|
|
|
if (p_mbctype[i] != prev)
|
2007-08-20 05:19:37 +02:00
|
|
|
{
|
|
|
|
printf("0x%x,%d, ", prev, count);
|
2008-12-11 22:53:36 +01:00
|
|
|
prev = p_mbctype[i];
|
2007-08-20 05:19:37 +02:00
|
|
|
count = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
printf("0x%x,%d };\n", prev, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* RLE-encoded mbctype tables for given codepages */
|
|
|
|
static int result_cp_932_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
|
|
|
|
0x0,1, 0x8,1, 0xc,31, 0x8,1, 0xa,5, 0x9,58, 0xc,29, 0,3 };
|
|
|
|
static int result_cp_936_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,6,
|
|
|
|
0xc,126, 0,1 };
|
|
|
|
static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0xc,126,
|
|
|
|
0,1 };
|
|
|
|
static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4,
|
|
|
|
0x0,2, 0x4,32, 0xc,94, 0,1 };
|
|
|
|
|
2009-01-19 19:57:59 +01:00
|
|
|
static void test_cp_table(int cp, int *result)
|
2007-08-20 05:19:37 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count = 0;
|
|
|
|
int curr = 0;
|
|
|
|
_setmbcp(cp);
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
curr = result[0];
|
|
|
|
count = result[1];
|
|
|
|
result += 2;
|
|
|
|
}
|
2009-01-19 19:57:59 +01:00
|
|
|
ok(p_mbctype[i] == curr, "CP%d: Mismatch in ctype for character %d - %d instead of %d\n", cp, i-1, p_mbctype[i], curr);
|
2007-08-20 05:19:37 +02:00
|
|
|
count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-19 19:57:59 +01:00
|
|
|
#define test_codepage(num) test_cp_table(num, result_cp_##num##_mbctype);
|
2007-08-20 05:19:37 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void test_mbcp(void)
|
2005-09-06 13:41:48 +02:00
|
|
|
{
|
2008-12-11 22:53:36 +01:00
|
|
|
int mb_orig_max = *p__mb_cur_max;
|
2007-08-20 05:19:37 +02:00
|
|
|
int curr_mbcp = _getmbcp();
|
2007-08-20 07:34:12 +02:00
|
|
|
unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
|
2007-08-20 07:46:56 +02:00
|
|
|
unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
|
2007-08-24 02:26:14 +02:00
|
|
|
unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
|
2007-08-22 19:47:01 +02:00
|
|
|
unsigned char buf[16];
|
2007-08-23 04:14:30 +02:00
|
|
|
int step;
|
2011-01-16 22:16:06 +01:00
|
|
|
CPINFO cp_info;
|
2007-08-20 05:19:37 +02:00
|
|
|
|
2007-10-26 22:50:37 +02:00
|
|
|
/* _mbtype tests */
|
|
|
|
|
|
|
|
/* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly
|
|
|
|
* between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses
|
|
|
|
* CP1252 (or the ACP?) so we test only a few ASCII characters */
|
|
|
|
_setmbcp(1252);
|
2008-12-11 22:53:36 +01:00
|
|
|
expect_eq(p_mbctype[10], 0, char, "%x");
|
|
|
|
expect_eq(p_mbctype[50], 0, char, "%x");
|
|
|
|
expect_eq(p_mbctype[66], _SBUP, char, "%x");
|
|
|
|
expect_eq(p_mbctype[100], _SBLOW, char, "%x");
|
|
|
|
expect_eq(p_mbctype[128], 0, char, "%x");
|
2007-10-26 22:50:37 +02:00
|
|
|
_setmbcp(1250);
|
2008-12-11 22:53:36 +01:00
|
|
|
expect_eq(p_mbctype[10], 0, char, "%x");
|
|
|
|
expect_eq(p_mbctype[50], 0, char, "%x");
|
|
|
|
expect_eq(p_mbctype[66], _SBUP, char, "%x");
|
|
|
|
expect_eq(p_mbctype[100], _SBLOW, char, "%x");
|
|
|
|
expect_eq(p_mbctype[128], 0, char, "%x");
|
2007-10-26 22:50:37 +02:00
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
/* double byte code pages */
|
2009-01-19 19:57:59 +01:00
|
|
|
test_codepage(932);
|
2007-08-20 05:19:37 +02:00
|
|
|
test_codepage(936);
|
|
|
|
test_codepage(949);
|
|
|
|
test_codepage(950);
|
2005-09-06 13:41:48 +02:00
|
|
|
|
|
|
|
_setmbcp(936);
|
2008-12-11 22:53:36 +01:00
|
|
|
ok(*p__mb_cur_max == mb_orig_max, "__mb_cur_max shouldn't be updated (is %d != %d)\n", *p__mb_cur_max, mb_orig_max);
|
2007-08-20 07:30:45 +02:00
|
|
|
ok(_ismbblead('\354'), "\354 should be a lead byte\n");
|
|
|
|
ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
|
|
|
|
ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
|
|
|
|
ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
|
|
|
|
ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
|
|
|
|
ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
|
2007-08-20 07:34:12 +02:00
|
|
|
|
2007-08-24 02:26:14 +02:00
|
|
|
/* _ismbslead */
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d");
|
|
|
|
|
|
|
|
expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
|
|
|
|
|
|
|
|
/* _ismbstrail */
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d");
|
|
|
|
|
|
|
|
expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d");
|
|
|
|
expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
|
|
|
|
|
2007-08-24 03:11:43 +02:00
|
|
|
/* _mbsbtype */
|
|
|
|
expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d");
|
|
|
|
|
|
|
|
expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d");
|
|
|
|
expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d");
|
|
|
|
|
2007-08-20 07:34:12 +02:00
|
|
|
/* _mbsnextc */
|
|
|
|
expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
|
|
|
|
expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
|
|
|
|
expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
|
|
|
|
|
2007-08-20 07:46:56 +02:00
|
|
|
/* _mbclen/_mbslen */
|
|
|
|
expect_eq(_mbclen(mbstring), 2, int, "%d");
|
|
|
|
expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
|
|
|
|
expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
|
|
|
|
expect_eq(_mbslen(mbstring2), 4, int, "%d");
|
|
|
|
expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
|
|
|
|
expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
|
|
|
|
|
2017-10-05 19:39:29 +02:00
|
|
|
if(!p__mbsnlen) {
|
|
|
|
win_skip("_mbsnlen tests\n");
|
|
|
|
}else {
|
|
|
|
expect_eq(p__mbsnlen(mbstring, 8), 8, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbstring, 9), 4, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbstring, 10), 4, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbsonlylead, 0), 0, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbsonlylead, 1), 1, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbsonlylead, 2), 0, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbstring2, 7), 7, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbstring2, 8), 4, int, "%d");
|
|
|
|
expect_eq(p__mbsnlen(mbstring2, 9), 4, int, "%d");
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:22:46 +01:00
|
|
|
/* mbrlen */
|
|
|
|
if(!setlocale(LC_ALL, ".936") || !p_mbrlen) {
|
|
|
|
win_skip("mbrlen tests\n");
|
|
|
|
}else {
|
|
|
|
mbstate_t state = 0;
|
|
|
|
expect_eq(p_mbrlen((const char*)mbstring, 2, NULL), 2, int, "%d");
|
|
|
|
expect_eq(p_mbrlen((const char*)&mbstring[2], 2, NULL), 2, int, "%d");
|
|
|
|
expect_eq(p_mbrlen((const char*)&mbstring[3], 2, NULL), 1, int, "%d");
|
|
|
|
expect_eq(p_mbrlen((const char*)mbstring, 1, NULL), -2, int, "%d");
|
|
|
|
expect_eq(p_mbrlen((const char*)mbstring, 1, &state), -2, int, "%d");
|
|
|
|
ok(state == mbstring[0], "incorrect state value (%x)\n", state);
|
|
|
|
expect_eq(p_mbrlen((const char*)&mbstring[1], 1, &state), 2, int, "%d");
|
|
|
|
}
|
2012-11-29 10:23:20 +01:00
|
|
|
|
|
|
|
/* mbrtowc */
|
|
|
|
if(!setlocale(LC_ALL, ".936") || !p_mbrtowc) {
|
|
|
|
win_skip("mbrtowc tests\n");
|
|
|
|
}else {
|
|
|
|
mbstate_t state = 0;
|
|
|
|
wchar_t dst;
|
|
|
|
expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 2, NULL), 2, int, "%d");
|
|
|
|
ok(dst == 0x6c28, "dst = %x, expected 0x6c28\n", dst);
|
|
|
|
expect_eq(p_mbrtowc(&dst, (const char*)mbstring+2, 2, NULL), 2, int, "%d");
|
|
|
|
ok(dst == 0x3f, "dst = %x, expected 0x3f\n", dst);
|
|
|
|
expect_eq(p_mbrtowc(&dst, (const char*)mbstring+3, 2, NULL), 1, int, "%d");
|
|
|
|
ok(dst == 0x20, "dst = %x, expected 0x20\n", dst);
|
|
|
|
expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 1, NULL), -2, int, "%d");
|
|
|
|
ok(dst == 0, "dst = %x, expected 0\n", dst);
|
|
|
|
expect_eq(p_mbrtowc(&dst, (const char*)mbstring, 1, &state), -2, int, "%d");
|
|
|
|
ok(dst == 0, "dst = %x, expected 0\n", dst);
|
|
|
|
ok(state == mbstring[0], "incorrect state value (%x)\n", state);
|
|
|
|
expect_eq(p_mbrtowc(&dst, (const char*)mbstring+1, 1, &state), 2, int, "%d");
|
|
|
|
ok(dst == 0x6c28, "dst = %x, expected 0x6c28\n", dst);
|
|
|
|
ok(state == 0, "incorrect state value (%x)\n", state);
|
|
|
|
}
|
2012-11-29 10:22:46 +01:00
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
|
2007-08-22 19:47:01 +02:00
|
|
|
/* _mbccpy/_mbsncpy */
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbccpy(buf, mbstring);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xff", 3);
|
|
|
|
|
2017-10-06 12:07:23 +02:00
|
|
|
if(!p__mbccpy_s) {
|
|
|
|
win_skip("_mbccpy_s tests\n");
|
|
|
|
}else {
|
|
|
|
int err, copied;
|
|
|
|
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
copied = -1;
|
|
|
|
err = p__mbccpy_s(buf, 0, &copied, mbstring);
|
|
|
|
ok(err == EINVAL, "_mbccpy_s returned %d\n", err);
|
|
|
|
ok(!copied, "copied = %d\n", copied);
|
|
|
|
ok(buf[0] == 0xff, "buf[0] = %x\n", buf[0]);
|
|
|
|
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
copied = -1;
|
|
|
|
err = p__mbccpy_s(buf, 1, &copied, mbstring);
|
|
|
|
ok(err == ERANGE, "_mbccpy_s returned %d\n", err);
|
|
|
|
ok(!copied, "copied = %d\n", copied);
|
|
|
|
ok(!buf[0], "buf[0] = %x\n", buf[0]);
|
|
|
|
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
copied = -1;
|
|
|
|
err = p__mbccpy_s(buf, 2, &copied, mbstring);
|
|
|
|
ok(!err, "_mbccpy_s returned %d\n", err);
|
|
|
|
ok(copied == 2, "copied = %d\n", copied);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xff", 3);
|
|
|
|
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
copied = -1;
|
|
|
|
err = p__mbccpy_s(buf, 2, &copied, (unsigned char *)"\xb0");
|
|
|
|
ok(err == EILSEQ, "_mbccpy_s returned %d\n", err);
|
|
|
|
ok(copied == 1, "copied = %d\n", copied);
|
|
|
|
expect_bin(buf, "\x00\xff", 2);
|
|
|
|
}
|
|
|
|
|
2007-08-22 19:47:01 +02:00
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsncpy(buf, mbstring, 1);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xff", 3);
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsncpy(buf, mbstring, 2);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xb2 \xff", 5);
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsncpy(buf, mbstring, 3);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7);
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsncpy(buf, mbstring, 4);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8);
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsncpy(buf, mbstring, 5);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10);
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsncpy(buf, mbsonlylead, 6);
|
|
|
|
expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8);
|
|
|
|
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsnbcpy(buf, mbstring2, 2);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xff", 3);
|
|
|
|
_mbsnbcpy(buf, mbstring2, 3);
|
|
|
|
expect_bin(buf, "\xb0\xb1\0\xff", 4);
|
|
|
|
_mbsnbcpy(buf, mbstring2, 4);
|
|
|
|
expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5);
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
_mbsnbcpy(buf, mbsonlylead, 5);
|
|
|
|
expect_bin(buf, "\0\0\0\0\0\xff", 6);
|
2007-08-20 07:59:52 +02:00
|
|
|
|
2007-08-23 04:14:30 +02:00
|
|
|
/* _mbsinc/mbsdec */
|
|
|
|
step = _mbsinc(mbstring) - mbstring;
|
|
|
|
ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
|
|
|
|
step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
|
|
|
|
ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
|
|
|
|
|
|
|
|
step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
|
|
|
|
ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
|
|
|
|
step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
|
|
|
|
ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
|
|
|
|
step = _mbsninc(mbstring2, 0) - mbstring2;
|
|
|
|
ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
|
|
|
|
step = _mbsninc(mbstring2, 1) - mbstring2;
|
|
|
|
ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
|
|
|
|
step = _mbsninc(mbstring2, 2) - mbstring2;
|
|
|
|
ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
|
|
|
|
step = _mbsninc(mbstring2, 3) - mbstring2;
|
|
|
|
ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
|
|
|
|
step = _mbsninc(mbstring2, 4) - mbstring2;
|
|
|
|
ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
|
|
|
|
step = _mbsninc(mbstring2, 5) - mbstring2;
|
|
|
|
ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
|
|
|
|
step = _mbsninc(mbstring2, 17) - mbstring2;
|
|
|
|
ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
|
|
|
|
|
2007-08-20 07:59:52 +02:00
|
|
|
/* functions that depend on locale codepage, not mbcp.
|
|
|
|
* we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
|
|
|
|
* (as of Wine 0.9.43)
|
|
|
|
*/
|
2011-01-16 22:16:06 +01:00
|
|
|
GetCPInfo(GetACP(), &cp_info);
|
|
|
|
if (cp_info.MaxCharSize == 1)
|
2007-08-20 07:59:52 +02:00
|
|
|
{
|
|
|
|
expect_eq(mblen((char *)mbstring, 3), 1, int, "%x");
|
|
|
|
expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d");
|
|
|
|
}
|
|
|
|
else
|
2011-01-16 22:16:06 +01:00
|
|
|
skip("Current locale has double-byte charset - could lead to false positives\n");
|
2007-08-20 07:59:52 +02:00
|
|
|
|
2010-02-23 06:43:12 +01:00
|
|
|
_setmbcp(1361);
|
|
|
|
expect_eq(_ismbblead(0x80), 0, int, "%d");
|
|
|
|
todo_wine {
|
|
|
|
expect_eq(_ismbblead(0x81), 1, int, "%d");
|
|
|
|
expect_eq(_ismbblead(0x83), 1, int, "%d");
|
|
|
|
}
|
|
|
|
expect_eq(_ismbblead(0x84), 1, int, "%d");
|
|
|
|
expect_eq(_ismbblead(0xd3), 1, int, "%d");
|
|
|
|
expect_eq(_ismbblead(0xd7), 0, int, "%d");
|
2013-07-22 10:02:27 +02:00
|
|
|
expect_eq(_ismbblead(0xd8), 1, int, "%d");
|
2010-02-23 06:43:12 +01:00
|
|
|
expect_eq(_ismbblead(0xd9), 1, int, "%d");
|
|
|
|
|
|
|
|
expect_eq(_ismbbtrail(0x30), 0, int, "%d");
|
|
|
|
expect_eq(_ismbbtrail(0x31), 1, int, "%d");
|
|
|
|
expect_eq(_ismbbtrail(0x7e), 1, int, "%d");
|
|
|
|
expect_eq(_ismbbtrail(0x7f), 0, int, "%d");
|
|
|
|
expect_eq(_ismbbtrail(0x80), 0, int, "%d");
|
|
|
|
expect_eq(_ismbbtrail(0x81), 1, int, "%d");
|
|
|
|
expect_eq(_ismbbtrail(0xfe), 1, int, "%d");
|
|
|
|
expect_eq(_ismbbtrail(0xff), 0, int, "%d");
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
_setmbcp(curr_mbcp);
|
2005-09-06 13:41:48 +02:00
|
|
|
}
|
2004-03-19 02:53:11 +01:00
|
|
|
|
2005-11-21 13:03:18 +01:00
|
|
|
static void test_mbsspn( void)
|
|
|
|
{
|
|
|
|
unsigned char str1[]="cabernet";
|
|
|
|
unsigned char str2[]="shiraz";
|
|
|
|
unsigned char set[]="abc";
|
|
|
|
unsigned char empty[]="";
|
2019-09-02 19:50:19 +02:00
|
|
|
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";
|
2019-09-02 19:50:37 +02:00
|
|
|
unsigned char mbset3[]="\x8e";
|
2019-09-02 19:50:19 +02:00
|
|
|
int ret, cp = _getmbcp();
|
|
|
|
|
2005-11-21 13:03:18 +01:00
|
|
|
ret=_mbsspn( str1, set);
|
|
|
|
ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
|
|
|
|
ret=_mbsspn( str2, set);
|
|
|
|
ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
|
|
|
|
ret=_mbsspn( str1, empty);
|
|
|
|
ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
|
2019-09-02 19:50:19 +02:00
|
|
|
|
2019-10-28 13:29:09 +01:00
|
|
|
ret=_mbscspn( str1, set);
|
|
|
|
ok( ret==0, "_mbscspn returns %d should be 0\n", ret);
|
|
|
|
ret=_mbscspn( str2, set);
|
|
|
|
ok( ret==4, "_mbscspn returns %d should be 4\n", ret);
|
|
|
|
ret=_mbscspn( str1, empty);
|
|
|
|
ok( ret==8, "_mbscspn returns %d should be 8\n", ret);
|
|
|
|
|
2019-09-02 19:50:19 +02:00
|
|
|
_setmbcp( 932);
|
|
|
|
ret=_mbsspn( mbstr, mbset1);
|
2019-09-02 19:50:24 +02:00
|
|
|
ok( ret==8, "_mbsspn returns %d should be 8\n", ret);
|
2019-09-02 19:50:19 +02:00
|
|
|
ret=_mbsspn( mbstr, mbset2);
|
|
|
|
ok( ret==1, "_mbsspn returns %d should be 1\n", ret);
|
|
|
|
ret=_mbsspn( mbstr+8, mbset1);
|
|
|
|
ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
|
|
|
|
ret=_mbsspn( mbstr+8, mbset2);
|
2019-09-02 19:50:24 +02:00
|
|
|
ok( ret==2, "_mbsspn returns %d should be 2\n", ret);
|
2019-09-02 19:50:37 +02:00
|
|
|
ret=_mbsspn( mbstr, mbset3);
|
|
|
|
ok( ret==14, "_mbsspn returns %d should be 14\n", ret);
|
2019-09-02 19:50:19 +02:00
|
|
|
|
2019-10-28 13:29:09 +01:00
|
|
|
ret=_mbscspn( mbstr, mbset1);
|
|
|
|
ok( ret==0, "_mbscspn returns %d should be 0\n", ret);
|
|
|
|
ret=_mbscspn( mbstr, mbset2);
|
|
|
|
ok( ret==0, "_mbscspn returns %d should be 0\n", ret);
|
|
|
|
ret=_mbscspn( mbstr+8, mbset1);
|
|
|
|
ok( ret==2, "_mbscspn returns %d should be 2\n", ret);
|
|
|
|
ret=_mbscspn( mbstr+8, mbset2);
|
|
|
|
ok( ret==0, "_mbscspn returns %d should be 0\n", ret);
|
|
|
|
ret=_mbscspn( mbstr, mbset3);
|
|
|
|
ok( ret==0, "_mbscspn returns %d should be 0\n", ret);
|
|
|
|
|
2019-09-02 19:50:19 +02:00
|
|
|
_setmbcp( cp);
|
2005-11-21 13:03:18 +01:00
|
|
|
}
|
|
|
|
|
2006-12-23 00:24:30 +01:00
|
|
|
static void test_mbsspnp( void)
|
|
|
|
{
|
|
|
|
unsigned char str1[]="cabernet";
|
|
|
|
unsigned char str2[]="shiraz";
|
|
|
|
unsigned char set[]="abc";
|
|
|
|
unsigned char empty[]="";
|
|
|
|
unsigned char full[]="abcenrt";
|
2019-09-02 19:50:19 +02:00
|
|
|
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";
|
2006-12-23 00:24:30 +01:00
|
|
|
unsigned char* ret;
|
2019-09-02 19:50:19 +02:00
|
|
|
int cp = _getmbcp();
|
|
|
|
|
2006-12-23 00:24:30 +01:00
|
|
|
ret=_mbsspnp( str1, set);
|
|
|
|
ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
|
|
|
|
ret=_mbsspnp( str2, set);
|
|
|
|
ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
|
|
|
|
ret=_mbsspnp( str1, empty);
|
|
|
|
ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
|
|
|
|
ret=_mbsspnp( str1, full);
|
|
|
|
ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
|
2019-09-02 19:50:19 +02:00
|
|
|
|
|
|
|
_setmbcp( 932);
|
|
|
|
ret=_mbsspnp( mbstr, mbset1);
|
2019-09-02 19:50:29 +02:00
|
|
|
ok( ret==mbstr+8, "_mbsspnp returns %p should be %p\n", ret, mbstr+8);
|
2019-09-02 19:50:19 +02:00
|
|
|
ret=_mbsspnp( mbstr, mbset2);
|
|
|
|
ok( ret==mbstr+1, "_mbsspnp returns %p should be %p\n", ret, mbstr+1);
|
|
|
|
ret=_mbsspnp( mbstr+8, mbset1);
|
|
|
|
ok( ret==mbstr+8, "_mbsspnp returns %p should be %p\n", ret, mbstr+8);
|
|
|
|
ret=_mbsspnp( mbstr+8, mbset2);
|
2019-09-02 19:50:29 +02:00
|
|
|
ok( ret==mbstr+10, "_mbsspnp returns %p should be %p\n", ret, mbstr+10);
|
2019-09-02 19:50:19 +02:00
|
|
|
|
|
|
|
_setmbcp( cp);
|
2006-12-23 00:24:30 +01:00
|
|
|
}
|
|
|
|
|
2006-06-21 11:03:26 +02:00
|
|
|
static void test_strdup(void)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
str = _strdup( 0 );
|
|
|
|
ok( str == 0, "strdup returns %s should be 0\n", str);
|
|
|
|
free( str );
|
|
|
|
}
|
|
|
|
|
2020-01-16 11:37:03 +01:00
|
|
|
static void test_strcmp(void)
|
|
|
|
{
|
|
|
|
int ret = p_strcmp( "abc", "abcd" );
|
|
|
|
ok( ret == -1, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strcmp( "", "abc" );
|
|
|
|
ok( ret == -1, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strcmp( "abc", "ab\xa0" );
|
|
|
|
ok( ret == -1, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strcmp( "ab\xb0", "ab\xa0" );
|
|
|
|
ok( ret == 1, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strcmp( "ab\xc2", "ab\xc2" );
|
|
|
|
ok( ret == 0, "wrong ret %d\n", ret );
|
|
|
|
|
|
|
|
ret = p_strncmp( "abc", "abcd", 3 );
|
|
|
|
ok( ret == 0, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strncmp( "", "abc", 3 );
|
2020-01-20 15:59:05 +01:00
|
|
|
ok( ret == 0 - 'a' || ret == -1, "wrong ret %d\n", ret );
|
2020-01-16 11:37:03 +01:00
|
|
|
ret = p_strncmp( "abc", "ab\xa0", 4 );
|
2020-01-20 15:59:05 +01:00
|
|
|
ok( ret == 'c' - 0xa0 || ret == -1, "wrong ret %d\n", ret );
|
2020-01-16 11:37:03 +01:00
|
|
|
ret = p_strncmp( "ab\xb0", "ab\xa0", 3 );
|
2020-01-20 15:59:05 +01:00
|
|
|
ok( ret == 0xb0 - 0xa0 || ret == 1, "wrong ret %d\n", ret );
|
2020-01-16 11:37:03 +01:00
|
|
|
ret = p_strncmp( "ab\xb0", "ab\xa0", 2 );
|
|
|
|
ok( ret == 0, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strncmp( "ab\xc2", "ab\xc2", 3 );
|
|
|
|
ok( ret == 0, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strncmp( "abc", "abd", 0 );
|
|
|
|
ok( ret == 0, "wrong ret %d\n", ret );
|
|
|
|
ret = p_strncmp( "abc", "abc", 12 );
|
|
|
|
ok( ret == 0, "wrong ret %d\n", ret );
|
|
|
|
}
|
|
|
|
|
2007-11-15 16:11:26 +01:00
|
|
|
static void test_strcpy_s(void)
|
|
|
|
{
|
|
|
|
char dest[8];
|
2017-08-05 18:23:13 +02:00
|
|
|
const char small[] = "small";
|
|
|
|
const char big[] = "atoolongstringforthislittledestination";
|
2007-11-15 16:11:26 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!pstrcpy_s)
|
|
|
|
{
|
2014-04-21 13:08:31 +02:00
|
|
|
win_skip("strcpy_s not found\n");
|
2007-11-15 16:11:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = pstrcpy_s(dest, sizeof(dest), small);
|
|
|
|
ok(ret == 0, "Copying a string into a big enough destination returned %d, expected 0\n", ret);
|
|
|
|
ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
|
|
|
|
dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = pstrcpy_s(dest, 0, big);
|
|
|
|
ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
|
|
|
|
dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
ret = pstrcpy_s(dest, 0, NULL);
|
|
|
|
ok(ret == EINVAL, "Copying into a destination of size 0 returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(dest[0] == 'X' && dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
|
|
|
|
dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = pstrcpy_s(dest, sizeof(dest), big);
|
|
|
|
ok(ret == ERANGE, "Copying a big string in a small location returned %d, expected ERANGE\n", ret);
|
|
|
|
ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
|
|
|
|
dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'n' && dest[7] == 'g',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = pstrcpy_s(dest, sizeof(dest), NULL);
|
|
|
|
ok(ret == EINVAL, "Copying from a NULL source string returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(dest[0] == '\0'&& dest[1] == 'X' && dest[2] == 'X' && dest[3] == 'X' &&
|
|
|
|
dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
ret = pstrcpy_s(NULL, sizeof(dest), small);
|
|
|
|
ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret);
|
2017-08-05 18:23:13 +02:00
|
|
|
|
|
|
|
/* strcpy overlapping buffers test */
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest+1, small, sizeof(small));
|
|
|
|
p_strcpy(dest, dest+1);
|
|
|
|
ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
|
|
|
|
dest[4] == 'l' && dest[5] == '\0' && dest[6] == '\0' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
2007-11-15 16:11:26 +01:00
|
|
|
}
|
|
|
|
|
2012-07-28 18:43:43 +02:00
|
|
|
#define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
|
|
|
|
ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
|
|
|
|
dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
|
|
|
|
"Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\
|
|
|
|
dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
|
|
|
|
|
|
|
|
static void test_memcpy_s(void)
|
|
|
|
{
|
2018-10-05 16:38:54 +02:00
|
|
|
static char dest[8], buf[32];
|
2012-07-28 18:43:43 +02:00
|
|
|
static const char tiny[] = {'T',0,'I','N','Y',0};
|
|
|
|
static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
|
|
|
|
int ret;
|
|
|
|
if (!p_memcpy_s) {
|
2014-04-21 13:08:31 +02:00
|
|
|
win_skip("memcpy_s not found\n");
|
2012-07-28 18:43:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal */
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memcpy_s(dest, ARRAY_SIZE(dest), tiny, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret);
|
|
|
|
okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
|
|
|
|
|
|
|
|
/* Vary source size */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memcpy_s(dest, ARRAY_SIZE(dest), big, ARRAY_SIZE(big));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == ERANGE, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret);
|
|
|
|
ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
|
|
|
|
okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
/* Replace source with NULL */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memcpy_s(dest, ARRAY_SIZE(dest), NULL, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == EINVAL, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
/* Vary dest size */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memcpy_s(dest, 0, tiny, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == ERANGE, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret);
|
|
|
|
ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
|
|
|
|
okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
|
|
|
|
|
|
|
|
/* Replace dest with NULL */
|
|
|
|
errno = 0xdeadbeef;
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memcpy_s(NULL, ARRAY_SIZE(dest), tiny, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == EINVAL, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
|
|
|
|
/* Combinations */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memcpy_s(dest, 0, NULL, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
|
2018-10-05 16:38:54 +02:00
|
|
|
|
|
|
|
ret = p_memcpy_s(buf, ARRAY_SIZE(buf), big, ARRAY_SIZE(big));
|
|
|
|
ok(!ret, "memcpy_s returned %d\n", ret);
|
|
|
|
ok(!memcmp(buf, big, sizeof(big)), "unexpected buf\n");
|
|
|
|
|
|
|
|
ret = p_memcpy_s(buf + 1, ARRAY_SIZE(buf) - 1, buf, ARRAY_SIZE(big));
|
|
|
|
ok(!ret, "memcpy_s returned %d\n", ret);
|
|
|
|
ok(!memcmp(buf + 1, big, sizeof(big)), "unexpected buf\n");
|
|
|
|
|
|
|
|
ret = p_memcpy_s(buf, ARRAY_SIZE(buf), buf + 1, ARRAY_SIZE(big));
|
|
|
|
ok(!ret, "memcpy_s returned %d\n", ret);
|
|
|
|
ok(!memcmp(buf, big, sizeof(big)), "unexpected buf\n");
|
2012-07-28 18:43:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_memmove_s(void)
|
|
|
|
{
|
|
|
|
static char dest[8];
|
|
|
|
static const char tiny[] = {'T',0,'I','N','Y',0};
|
|
|
|
static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
|
|
|
|
int ret;
|
|
|
|
if (!p_memmove_s) {
|
2014-04-21 13:08:31 +02:00
|
|
|
win_skip("memmove_s not found\n");
|
2012-07-28 18:43:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal */
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memmove_s(dest, ARRAY_SIZE(dest), tiny, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret);
|
|
|
|
okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X');
|
|
|
|
|
|
|
|
/* Overlapping */
|
|
|
|
memcpy(dest, big, sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memmove_s(dest+1, ARRAY_SIZE(dest)-1, dest, ARRAY_SIZE(dest)-1);
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == 0, "Moving a buffer up one char returned %d, expected 0\n", ret);
|
|
|
|
okchars(dest, big[0], big[0], big[1], big[2], big[3], big[4], big[5], big[6]);
|
|
|
|
|
|
|
|
/* Vary source size */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memmove_s(dest, ARRAY_SIZE(dest), big, ARRAY_SIZE(big));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == ERANGE, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret);
|
|
|
|
ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
|
|
|
|
okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
|
|
|
|
|
|
|
|
/* Replace source with NULL */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memmove_s(dest, ARRAY_SIZE(dest), NULL, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == EINVAL, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
|
|
|
|
|
|
|
|
/* Vary dest size */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memmove_s(dest, 0, tiny, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == ERANGE, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret);
|
|
|
|
ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno);
|
|
|
|
okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
|
|
|
|
|
|
|
|
/* Replace dest with NULL */
|
|
|
|
errno = 0xdeadbeef;
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memmove_s(NULL, ARRAY_SIZE(dest), tiny, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == EINVAL, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
|
|
|
|
/* Combinations */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
2018-06-20 23:35:08 +02:00
|
|
|
ret = p_memmove_s(dest, 0, NULL, ARRAY_SIZE(tiny));
|
2012-07-28 18:43:43 +02:00
|
|
|
ok(ret == EINVAL, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
|
|
|
|
}
|
|
|
|
|
2007-11-16 11:36:03 +01:00
|
|
|
static void test_strcat_s(void)
|
|
|
|
{
|
|
|
|
char dest[8];
|
|
|
|
const char *small = "sma";
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!pstrcat_s)
|
|
|
|
{
|
2014-04-21 13:08:31 +02:00
|
|
|
win_skip("strcat_s not found\n");
|
2007-11-16 11:36:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
dest[0] = '\0';
|
|
|
|
ret = pstrcat_s(dest, sizeof(dest), small);
|
|
|
|
ok(ret == 0, "strcat_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
|
|
|
|
ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == '\0'&&
|
|
|
|
dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
ret = pstrcat_s(dest, sizeof(dest), small);
|
|
|
|
ok(ret == 0, "strcat_s: Attaching a string to a big enough destination returned %d, expected 0\n", ret);
|
|
|
|
ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
|
|
|
|
dest[4] == 'm' && dest[5] == 'a' && dest[6] == '\0'&& dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
ret = pstrcat_s(dest, sizeof(dest), small);
|
|
|
|
ok(ret == ERANGE, "strcat_s: Attaching a string to a filled up destination returned %d, expected ERANGE\n", ret);
|
|
|
|
ok(dest[0] == '\0'&& dest[1] == 'm' && dest[2] == 'a' && dest[3] == 's' &&
|
|
|
|
dest[4] == 'm' && dest[5] == 'a' && dest[6] == 's' && dest[7] == 'm',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
dest[0] = 'a';
|
|
|
|
dest[1] = '\0';
|
|
|
|
|
|
|
|
ret = pstrcat_s(dest, 0, small);
|
|
|
|
ok(ret == EINVAL, "strcat_s: Source len = 0 returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
|
|
|
|
dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
ret = pstrcat_s(dest, 0, NULL);
|
|
|
|
ok(ret == EINVAL, "strcat_s: len = 0 and src = NULL returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(dest[0] == 'a' && dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
|
|
|
|
dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
ret = pstrcat_s(dest, sizeof(dest), NULL);
|
|
|
|
ok(ret == EINVAL, "strcat_s: Sourcing from NULL returned %d, expected EINVAL\n", ret);
|
|
|
|
ok(dest[0] == '\0'&& dest[1] == '\0'&& dest[2] == 'X' && dest[3] == 'X' &&
|
|
|
|
dest[4] == 'X' && dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from strcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
ret = pstrcat_s(NULL, sizeof(dest), small);
|
|
|
|
ok(ret == EINVAL, "strcat_s: Writing to a NULL string returned %d, expected EINVAL\n", ret);
|
|
|
|
}
|
|
|
|
|
2015-07-06 19:40:10 +02:00
|
|
|
static void test__mbscat_s(void)
|
|
|
|
{
|
|
|
|
unsigned char dst[8], src[4];
|
|
|
|
int err;
|
|
|
|
int prev_cp = _getmbcp();
|
|
|
|
|
|
|
|
if(!p_mbscat_s)
|
|
|
|
{
|
|
|
|
win_skip("_mbscat_s not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
src[0] = dst[0] = 0;
|
|
|
|
err = p_mbscat_s(NULL, sizeof(dst), src);
|
|
|
|
ok(err == EINVAL, "_mbscat_s returned %d\n", err);
|
|
|
|
|
|
|
|
err = p_mbscat_s(dst, sizeof(dst), NULL);
|
|
|
|
ok(err == EINVAL, "_mbscat_s returned %d\n", err);
|
|
|
|
|
|
|
|
dst[0] = 'a';
|
|
|
|
err = p_mbscat_s(dst, 1, src);
|
|
|
|
ok(err == EINVAL, "_mbscat_s returned %d\n", err);
|
|
|
|
|
|
|
|
memset(dst, 'a', sizeof(dst));
|
|
|
|
dst[6] = 0;
|
|
|
|
src[0] = 'b';
|
|
|
|
src[1] = 0;
|
|
|
|
|
|
|
|
err = p_mbscat_s(dst, sizeof(dst), src);
|
|
|
|
ok(err == 0, "_mbscat_s returned %d\n", err);
|
|
|
|
ok(!memcmp(dst, "aaaaaab", 8), "dst = %s\n", dst);
|
|
|
|
|
|
|
|
err = p_mbscat_s(dst, sizeof(dst), src);
|
|
|
|
ok(err == ERANGE, "_mbscat_s returned %d\n", err);
|
|
|
|
ok(!dst[0], "dst[0] = %c\n", dst[0]);
|
|
|
|
ok(dst[1] == 'a', "dst[1] = %c\n", dst[1]);
|
|
|
|
|
|
|
|
_setmbcp(932);
|
|
|
|
/* test invalid str in dst */
|
|
|
|
dst[0] = 0x81;
|
|
|
|
dst[1] = 0x81;
|
|
|
|
dst[2] = 0x52;
|
|
|
|
dst[3] = 0;
|
|
|
|
src[0] = 'a';
|
|
|
|
src[1] = 0;
|
|
|
|
err = p_mbscat_s(dst, sizeof(dst), src);
|
|
|
|
ok(err == 0, "_mbscat_s returned %d\n", err);
|
|
|
|
|
|
|
|
/* test invalid str in src */
|
|
|
|
dst[0] = 0;
|
|
|
|
src[0] = 0x81;
|
|
|
|
src[1] = 0x81;
|
|
|
|
src[2] = 0x52;
|
|
|
|
src[3] = 0;
|
|
|
|
err = p_mbscat_s(dst, sizeof(dst), src);
|
|
|
|
ok(err == 0, "_mbscat_s returned %d\n", err);
|
|
|
|
|
|
|
|
/* test dst with leading byte on the end of buffer */
|
|
|
|
dst[0] = 'a';
|
|
|
|
dst[1] = 0x81;
|
|
|
|
dst[2] = 0;
|
|
|
|
src[0] = 'R';
|
|
|
|
src[1] = 0;
|
|
|
|
err = p_mbscat_s(dst, sizeof(dst), src);
|
|
|
|
ok(err == EILSEQ, "_mbscat_s returned %d\n", err);
|
|
|
|
ok(!memcmp(dst, "aR", 3), "dst = %s\n", dst);
|
|
|
|
|
|
|
|
/* test src with leading byte on the end of buffer */
|
|
|
|
dst[0] = 'a';
|
|
|
|
dst[1] = 0;
|
|
|
|
src[0] = 'b';
|
|
|
|
src[1] = 0x81;
|
|
|
|
src[2] = 0;
|
|
|
|
err = p_mbscat_s(dst, sizeof(dst), src);
|
|
|
|
ok(err == EILSEQ, "_mbscat_s returned %d\n", err);
|
|
|
|
ok(!memcmp(dst, "ab", 3), "dst = %s\n", dst);
|
|
|
|
_setmbcp(prev_cp);
|
|
|
|
}
|
|
|
|
|
2007-11-15 16:32:33 +01:00
|
|
|
static void test__mbsnbcpy_s(void)
|
|
|
|
{
|
|
|
|
unsigned char dest[8];
|
|
|
|
const unsigned char big[] = "atoolongstringforthislittledestination";
|
|
|
|
const unsigned char small[] = "small";
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!p_mbsnbcpy_s)
|
|
|
|
{
|
2014-04-21 13:08:31 +02:00
|
|
|
win_skip("_mbsnbcpy_s not found\n");
|
2007-11-15 16:32:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = p_mbsnbcpy_s(dest, sizeof(dest), small, sizeof(small));
|
|
|
|
ok(ret == 0, "_mbsnbcpy_s: Copying a string into a big enough destination returned %d, expected 0\n", ret);
|
|
|
|
ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
|
|
|
|
dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
/* WTF? */
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, sizeof(small));
|
|
|
|
ok(ret == ERANGE, "_mbsnbcpy_s: Copying a too long string returned %d, expected ERANGE\n", ret);
|
|
|
|
ok(dest[0] == '\0'&& dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
|
|
|
|
dest[4] == 'l' && dest[5] == 'o' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, big, 4);
|
|
|
|
ok(ret == 0, "_mbsnbcpy_s: Copying a too long string with a count cap returned %d, expected 0\n", ret);
|
|
|
|
ok(dest[0] == 'a' && dest[1] == 't' && dest[2] == 'o' && dest[3] == 'o' &&
|
|
|
|
dest[4] == '\0'&& dest[5] == 'X' && dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = p_mbsnbcpy_s(dest, sizeof(dest) - 2, small, sizeof(small) + 10);
|
|
|
|
ok(ret == 0, "_mbsnbcpy_s: Copying more data than the source string len returned %d, expected 0\n", ret);
|
|
|
|
ok(dest[0] == 's' && dest[1] == 'm' && dest[2] == 'a' && dest[3] == 'l' &&
|
|
|
|
dest[4] == 'l' && dest[5] == '\0'&& dest[6] == 'X' && dest[7] == 'X',
|
|
|
|
"Unexpected return data from _mbsnbcpy_s: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
|
|
|
|
}
|
|
|
|
|
2014-05-19 11:43:05 +02:00
|
|
|
static void test__mbscpy_s(void)
|
|
|
|
{
|
|
|
|
const unsigned char src[] = "source string";
|
|
|
|
unsigned char dest[16];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!p__mbscpy_s)
|
|
|
|
{
|
|
|
|
win_skip("_mbscpy_s not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = p__mbscpy_s(NULL, 0, src);
|
|
|
|
ok(ret == EINVAL, "got %d\n", ret);
|
|
|
|
ret = p__mbscpy_s(NULL, sizeof(dest), src);
|
|
|
|
ok(ret == EINVAL, "got %d\n", ret);
|
|
|
|
ret = p__mbscpy_s(dest, 0, src);
|
|
|
|
ok(ret == EINVAL, "got %d\n", ret);
|
|
|
|
dest[0] = 'x';
|
|
|
|
ret = p__mbscpy_s(dest, sizeof(dest), NULL);
|
|
|
|
ok(ret == EINVAL, "got %d\n", ret);
|
|
|
|
ok(!dest[0], "dest buffer was not modified on invalid argument\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = p__mbscpy_s(dest, sizeof(dest), src);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
ok(!memcmp(dest, src, sizeof(src)), "dest = %s\n", dest);
|
|
|
|
ok(dest[sizeof(src)] == 'X', "unused part of buffer was modified\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
ret = p__mbscpy_s(dest, 4, src);
|
|
|
|
ok(ret == ERANGE, "got %d\n", ret);
|
|
|
|
ok(!dest[0], "incorrect dest buffer (%d)\n", dest[0]);
|
|
|
|
ok(dest[1] == src[1], "incorrect dest buffer (%d)\n", dest[1]);
|
|
|
|
}
|
|
|
|
|
2008-02-27 09:58:04 +01:00
|
|
|
static void test_wcscpy_s(void)
|
|
|
|
{
|
|
|
|
static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
|
|
|
|
static WCHAR szDest[18];
|
|
|
|
static WCHAR szDestShort[8];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!p_wcscpy_s)
|
|
|
|
{
|
2011-10-04 23:03:03 +02:00
|
|
|
win_skip("wcscpy_s not found\n");
|
2008-02-27 09:58:04 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-08 23:22:43 +02:00
|
|
|
/* Test NULL Dest */
|
2013-08-02 19:58:57 +02:00
|
|
|
errno = EBADF;
|
2008-02-27 09:58:04 +01:00
|
|
|
ret = p_wcscpy_s(NULL, 18, szLongText);
|
|
|
|
ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
|
2013-08-02 19:58:57 +02:00
|
|
|
ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
|
2008-02-27 09:58:04 +01:00
|
|
|
|
2008-04-08 23:22:43 +02:00
|
|
|
/* Test NULL Source */
|
2013-08-02 19:58:57 +02:00
|
|
|
errno = EBADF;
|
2008-02-27 09:58:04 +01:00
|
|
|
szDest[0] = 'A';
|
|
|
|
ret = p_wcscpy_s(szDest, 18, NULL);
|
|
|
|
ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
|
2013-08-02 19:58:57 +02:00
|
|
|
ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
|
|
|
|
ok(szDest[0] == 0, "szDest[0] not 0, got %c\n", szDest[0]);
|
2008-02-27 09:58:04 +01:00
|
|
|
|
|
|
|
/* Test invalid size */
|
2013-08-02 19:58:57 +02:00
|
|
|
errno = EBADF;
|
2008-02-27 09:58:04 +01:00
|
|
|
szDest[0] = 'A';
|
|
|
|
ret = p_wcscpy_s(szDest, 0, szLongText);
|
2008-05-26 17:13:49 +02:00
|
|
|
/* Later versions changed the return value for this case to EINVAL,
|
|
|
|
* and don't modify the result if the dest size is 0.
|
|
|
|
*/
|
|
|
|
ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
|
2013-08-02 19:58:57 +02:00
|
|
|
ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
|
2008-05-26 17:13:49 +02:00
|
|
|
ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
|
2008-02-27 09:58:04 +01:00
|
|
|
|
|
|
|
/* Copy same buffer size */
|
|
|
|
ret = p_wcscpy_s(szDest, 18, szLongText);
|
|
|
|
ok(ret == 0, "expected 0 got %d\n", ret);
|
|
|
|
ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
|
|
|
|
|
2019-06-24 05:49:34 +02:00
|
|
|
/* dest == source */
|
|
|
|
ret = p_wcscpy_s(szDest, 18, szDest);
|
|
|
|
ok(ret == 0, "expected 0 got %d\n", ret);
|
|
|
|
ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
|
|
|
|
|
2008-02-27 09:58:04 +01:00
|
|
|
/* Copy smaller buffer size */
|
2013-08-02 19:58:57 +02:00
|
|
|
errno = EBADF;
|
2008-02-27 09:58:04 +01:00
|
|
|
szDest[0] = 'A';
|
|
|
|
ret = p_wcscpy_s(szDestShort, 8, szLongText);
|
2008-05-26 17:13:49 +02:00
|
|
|
ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
|
2013-08-02 19:58:57 +02:00
|
|
|
ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
|
2008-02-27 09:58:04 +01:00
|
|
|
ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
|
2011-10-04 23:03:03 +02:00
|
|
|
|
|
|
|
if(!p_wcsncpy_s)
|
|
|
|
{
|
|
|
|
win_skip("wcsncpy_s not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsncpy_s(NULL, 18, szLongText, ARRAY_SIZE(szLongText));
|
2011-10-04 23:03:03 +02:00
|
|
|
ok(ret == EINVAL, "p_wcsncpy_s expect EINVAL got %d\n", ret);
|
|
|
|
|
|
|
|
szDest[0] = 'A';
|
|
|
|
ret = p_wcsncpy_s(szDest, 18, NULL, 1);
|
|
|
|
ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
|
|
|
|
ok(szDest[0] == 0, "szDest[0] not 0\n");
|
|
|
|
|
|
|
|
szDest[0] = 'A';
|
|
|
|
ret = p_wcsncpy_s(szDest, 18, NULL, 0);
|
|
|
|
ok(ret == 0, "expected ERROR_SUCCESS got %d\n", ret);
|
|
|
|
ok(szDest[0] == 0, "szDest[0] not 0\n");
|
|
|
|
|
|
|
|
szDest[0] = 'A';
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsncpy_s(szDest, 0, szLongText, ARRAY_SIZE(szLongText));
|
2011-10-04 23:03:03 +02:00
|
|
|
ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
|
|
|
|
ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
|
|
|
|
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsncpy_s(szDest, 18, szLongText, ARRAY_SIZE(szLongText));
|
2011-10-04 23:03:03 +02:00
|
|
|
ok(ret == 0, "expected 0 got %d\n", ret);
|
|
|
|
ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
|
|
|
|
|
|
|
|
szDest[0] = 'A';
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsncpy_s(szDestShort, 8, szLongText, ARRAY_SIZE(szLongText));
|
2011-10-04 23:03:03 +02:00
|
|
|
ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
|
|
|
|
ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
|
2012-04-12 16:19:31 +02:00
|
|
|
|
|
|
|
szDest[0] = 'A';
|
|
|
|
ret = p_wcsncpy_s(szDest, 5, szLongText, -1);
|
|
|
|
ok(ret == STRUNCATE, "expected STRUNCATE got %d\n", ret);
|
|
|
|
ok(szDest[4] == 0, "szDest[4] not 0\n");
|
|
|
|
ok(!memcmp(szDest, szLongText, 4*sizeof(WCHAR)), "szDest = %s\n", wine_dbgstr_w(szDest));
|
2012-04-24 18:44:07 +02:00
|
|
|
|
|
|
|
ret = p_wcsncpy_s(NULL, 0, (void*)0xdeadbeef, 0);
|
|
|
|
ok(ret == 0, "ret = %d\n", ret);
|
|
|
|
|
|
|
|
szDestShort[0] = '1';
|
|
|
|
szDestShort[1] = 0;
|
|
|
|
ret = p_wcsncpy_s(szDestShort+1, 4, szDestShort, -1);
|
|
|
|
ok(ret == STRUNCATE, "expected ERROR_SUCCESS got %d\n", ret);
|
|
|
|
ok(szDestShort[0]=='1' && szDestShort[1]=='1' && szDestShort[2]=='1' && szDestShort[3]=='1',
|
|
|
|
"szDestShort = %s\n", wine_dbgstr_w(szDestShort));
|
2008-02-27 09:58:04 +01:00
|
|
|
}
|
|
|
|
|
2009-11-16 02:09:17 +01:00
|
|
|
static void test__wcsupr_s(void)
|
|
|
|
{
|
|
|
|
static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
|
|
|
|
'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
|
|
|
|
static const WCHAR expectedString[] = {'M', 'I', 'X', 'E', 'D', 'L', 'O',
|
|
|
|
'W', 'E', 'R', 'U', 'P', 'P', 'E',
|
|
|
|
'R', 0};
|
2018-06-20 23:35:09 +02:00
|
|
|
WCHAR testBuffer[2*ARRAY_SIZE(mixedString)];
|
2009-11-16 02:09:17 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!p_wcsupr_s)
|
|
|
|
{
|
|
|
|
win_skip("_wcsupr_s not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test NULL input string and invalid size. */
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_wcsupr_s(NULL, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
/* Test NULL input string and valid size. */
|
|
|
|
errno = EBADF;
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsupr_s(NULL, ARRAY_SIZE(testBuffer));
|
2009-11-16 02:09:17 +01:00
|
|
|
ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
/* Test empty string with zero size. */
|
|
|
|
errno = EBADF;
|
|
|
|
testBuffer[0] = '\0';
|
|
|
|
ret = p_wcsupr_s(testBuffer, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
|
|
|
|
|
|
|
|
/* Test empty string with size of one. */
|
|
|
|
testBuffer[0] = '\0';
|
|
|
|
ret = p_wcsupr_s(testBuffer, 1);
|
|
|
|
ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
|
|
|
|
ok(testBuffer[0] == '\0', "Expected the buffer to be unchanged\n");
|
|
|
|
|
|
|
|
/* Test one-byte buffer with zero size. */
|
|
|
|
errno = EBADF;
|
|
|
|
testBuffer[0] = 'x';
|
|
|
|
ret = p_wcsupr_s(testBuffer, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
|
|
|
|
|
|
|
|
/* Test one-byte buffer with size of one. */
|
|
|
|
errno = EBADF;
|
|
|
|
testBuffer[0] = 'x';
|
|
|
|
ret = p_wcsupr_s(testBuffer, 1);
|
|
|
|
ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
|
|
|
|
|
|
|
|
/* Test invalid size. */
|
|
|
|
wcscpy(testBuffer, mixedString);
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_wcsupr_s(testBuffer, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
|
|
|
|
|
|
|
|
/* Test normal string uppercasing. */
|
|
|
|
wcscpy(testBuffer, mixedString);
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsupr_s(testBuffer, ARRAY_SIZE(mixedString));
|
2009-11-16 02:09:17 +01:00
|
|
|
ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
|
|
|
|
ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
|
|
|
|
|
|
|
|
/* Test uppercasing with a shorter buffer size count. */
|
|
|
|
wcscpy(testBuffer, mixedString);
|
|
|
|
errno = EBADF;
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsupr_s(testBuffer, ARRAY_SIZE(mixedString) - 1);
|
2009-11-16 02:09:17 +01:00
|
|
|
ok(ret == EINVAL, "Expected _wcsupr_s to fail with EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(testBuffer[0] == '\0', "Expected the first buffer character to be null\n");
|
|
|
|
|
|
|
|
/* Test uppercasing with a longer buffer size count. */
|
|
|
|
wcscpy(testBuffer, mixedString);
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcsupr_s(testBuffer, ARRAY_SIZE(testBuffer));
|
2009-11-16 02:09:17 +01:00
|
|
|
ok(ret == 0, "Expected _wcsupr_s to succeed, got %d\n", ret);
|
|
|
|
ok(!wcscmp(testBuffer, expectedString), "Expected the string to be fully upper-case\n");
|
|
|
|
}
|
|
|
|
|
2011-03-04 23:59:08 +01:00
|
|
|
static void test__wcslwr_s(void)
|
|
|
|
{
|
|
|
|
static const WCHAR mixedString[] = {'M', 'i', 'X', 'e', 'D', 'l', 'o', 'w',
|
|
|
|
'e', 'r', 'U', 'P', 'P', 'E', 'R', 0};
|
|
|
|
static const WCHAR expectedString[] = {'m', 'i', 'x', 'e', 'd', 'l', 'o',
|
|
|
|
'w', 'e', 'r', 'u', 'p', 'p', 'e',
|
|
|
|
'r', 0};
|
2018-06-20 23:35:09 +02:00
|
|
|
WCHAR buffer[2*ARRAY_SIZE(mixedString)];
|
2011-03-04 23:59:08 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!p_wcslwr_s)
|
|
|
|
{
|
|
|
|
win_skip("_wcslwr_s not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test NULL input string and invalid size. */
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_wcslwr_s(NULL, 0);
|
|
|
|
ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
/* Test NULL input string and valid size. */
|
|
|
|
errno = EBADF;
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcslwr_s(NULL, ARRAY_SIZE(buffer));
|
2011-03-04 23:59:08 +01:00
|
|
|
ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
/* Test empty string with zero size. */
|
|
|
|
errno = EBADF;
|
|
|
|
buffer[0] = 'a';
|
|
|
|
ret = p_wcslwr_s(buffer, 0);
|
|
|
|
ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "expected errno EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == 0, "expected empty string\n");
|
|
|
|
|
|
|
|
/* Test empty string with size of one. */
|
|
|
|
buffer[0] = 0;
|
|
|
|
ret = p_wcslwr_s(buffer, 1);
|
|
|
|
ok(ret == 0, "got %d\n", ret);
|
|
|
|
ok(buffer[0] == 0, "expected buffer to be unchanged\n");
|
|
|
|
|
|
|
|
/* Test one-byte buffer with zero size. */
|
|
|
|
errno = EBADF;
|
|
|
|
buffer[0] = 'x';
|
|
|
|
ret = p_wcslwr_s(buffer, 0);
|
|
|
|
ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "expected empty string\n");
|
|
|
|
|
|
|
|
/* Test one-byte buffer with size of one. */
|
|
|
|
errno = EBADF;
|
|
|
|
buffer[0] = 'x';
|
|
|
|
ret = p_wcslwr_s(buffer, 1);
|
|
|
|
ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "expected empty string\n");
|
|
|
|
|
|
|
|
/* Test invalid size. */
|
|
|
|
wcscpy(buffer, mixedString);
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_wcslwr_s(buffer, 0);
|
|
|
|
ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "expected empty string\n");
|
|
|
|
|
|
|
|
/* Test normal string uppercasing. */
|
|
|
|
wcscpy(buffer, mixedString);
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcslwr_s(buffer, ARRAY_SIZE(mixedString));
|
2011-03-04 23:59:08 +01:00
|
|
|
ok(ret == 0, "expected 0, got %d\n", ret);
|
|
|
|
ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
|
|
|
|
|
|
|
|
/* Test uppercasing with a shorter buffer size count. */
|
|
|
|
wcscpy(buffer, mixedString);
|
|
|
|
errno = EBADF;
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcslwr_s(buffer, ARRAY_SIZE(mixedString) - 1);
|
2011-03-04 23:59:08 +01:00
|
|
|
ok(ret == EINVAL, "expected EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "expected empty string\n");
|
|
|
|
|
|
|
|
/* Test uppercasing with a longer buffer size count. */
|
|
|
|
wcscpy(buffer, mixedString);
|
2018-06-20 23:35:09 +02:00
|
|
|
ret = p_wcslwr_s(buffer, ARRAY_SIZE(buffer));
|
2011-03-04 23:59:08 +01:00
|
|
|
ok(ret == 0, "expected 0, got %d\n", ret);
|
|
|
|
ok(!wcscmp(buffer, expectedString), "expected lowercase\n");
|
|
|
|
}
|
|
|
|
|
2009-01-24 00:37:57 +01:00
|
|
|
static void test_mbcjisjms(void)
|
|
|
|
{
|
|
|
|
/* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
|
|
|
|
unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140},
|
|
|
|
{0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc},
|
2012-03-21 15:02:14 +01:00
|
|
|
{0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381},
|
2009-01-24 00:37:57 +01:00
|
|
|
{0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}};
|
2012-03-21 15:02:12 +01:00
|
|
|
int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
|
|
|
|
unsigned int i, j;
|
|
|
|
int prev_cp = _getmbcp();
|
2009-01-24 00:37:57 +01:00
|
|
|
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(cp); i++)
|
2009-01-24 00:37:57 +01:00
|
|
|
{
|
2012-03-21 15:02:12 +01:00
|
|
|
_setmbcp(cp[i]);
|
|
|
|
for (j = 0; jisjms[j][0] != 0; j++)
|
|
|
|
{
|
|
|
|
unsigned int ret, exp;
|
|
|
|
ret = _mbcjistojms(jisjms[j][0]);
|
|
|
|
exp = (cp[i] == 932) ? jisjms[j][1] : jisjms[j][0];
|
|
|
|
ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
|
|
|
|
exp, ret, jisjms[j][0], cp[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_setmbcp(prev_cp);
|
2009-01-24 00:37:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-15 15:41:30 +01:00
|
|
|
static void test_mbcjmsjis(void)
|
|
|
|
{
|
|
|
|
/* List of value-pairs to test. The test assumes the last pair to be {0, ..} */
|
|
|
|
unsigned int jmsjis[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121},
|
|
|
|
{0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160},
|
|
|
|
{0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e},
|
|
|
|
{0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0},
|
|
|
|
{0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21},
|
|
|
|
{0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}};
|
|
|
|
int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
|
|
|
|
unsigned int i, j;
|
|
|
|
int prev_cp = _getmbcp();
|
|
|
|
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(cp); i++)
|
2012-03-15 15:41:30 +01:00
|
|
|
{
|
|
|
|
_setmbcp(cp[i]);
|
|
|
|
for (j = 0; jmsjis[j][0] != 0; j++)
|
|
|
|
{
|
|
|
|
unsigned int ret, exp;
|
|
|
|
ret = _mbcjmstojis(jmsjis[j][0]);
|
|
|
|
exp = (cp[i] == 932) ? jmsjis[j][1] : jmsjis[j][0];
|
2012-03-15 15:41:33 +01:00
|
|
|
ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n",
|
|
|
|
exp, ret, jmsjis[j][0], cp[i]);
|
2012-03-15 15:41:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_setmbcp(prev_cp);
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:48:46 +01:00
|
|
|
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);
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(mbchira_932); i++)
|
2015-03-16 13:48:46 +01:00
|
|
|
{
|
|
|
|
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);
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(mbchira_932); i++)
|
2015-03-16 13:48:46 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:48:48 +01:00
|
|
|
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);
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(mbckata_932); i++)
|
2015-03-16 13:48:48 +01:00
|
|
|
{
|
|
|
|
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);
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(mbckata_932); i++)
|
2015-03-16 13:48:48 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:02:08 +01:00
|
|
|
static void test_mbbtombc(void)
|
|
|
|
{
|
|
|
|
static const unsigned int mbbmbc[][2] = {
|
|
|
|
{0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197},
|
|
|
|
{0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f},
|
|
|
|
{0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340},
|
|
|
|
{0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}};
|
|
|
|
int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS };
|
|
|
|
int i, j;
|
|
|
|
int prev_cp = _getmbcp();
|
|
|
|
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(cp); i++)
|
2012-03-21 15:02:08 +01:00
|
|
|
{
|
|
|
|
_setmbcp(cp[i]);
|
|
|
|
for (j = 0; mbbmbc[j][0] != 0; j++)
|
|
|
|
{
|
|
|
|
unsigned int exp, ret;
|
|
|
|
ret = _mbbtombc(mbbmbc[j][0]);
|
|
|
|
exp = (cp[i] == 932) ? mbbmbc[j][1] : mbbmbc[j][0];
|
2012-03-21 15:02:10 +01:00
|
|
|
ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
|
|
|
|
exp, ret, mbbmbc[j][0], cp[i]);
|
2012-03-21 15:02:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_setmbcp(prev_cp);
|
|
|
|
}
|
|
|
|
|
2010-02-24 04:52:52 +01:00
|
|
|
static void test_mbctombb(void)
|
|
|
|
{
|
|
|
|
static const unsigned int mbcmbb_932[][2] = {
|
|
|
|
{0x829e, 0x829e}, {0x829f, 0xa7}, {0x82f1, 0xdd}, {0x82f2, 0x82f2},
|
|
|
|
{0x833f, 0x833f}, {0x8340, 0xa7}, {0x837e, 0xd0}, {0x837f, 0x837f},
|
|
|
|
{0x8380, 0xd1}, {0x8396, 0xb9}, {0x8397, 0x8397}, {0x813f, 0x813f},
|
|
|
|
{0x8140, 0x20}, {0x814c, 0x814c}, {0x814f, 0x5e}, {0x8197, 0x40},
|
|
|
|
{0x8198, 0x8198}, {0x8258, 0x39}, {0x8259, 0x8259}, {0x825f, 0x825f},
|
|
|
|
{0x8260, 0x41}, {0x82f1, 0xdd}, {0x82f2, 0x82f2}, {0,0}};
|
|
|
|
unsigned int exp, ret, i;
|
|
|
|
unsigned int prev_cp = _getmbcp();
|
|
|
|
|
|
|
|
_setmbcp(932);
|
|
|
|
for (i = 0; mbcmbb_932[i][0] != 0; i++)
|
|
|
|
{
|
|
|
|
ret = _mbctombb(mbcmbb_932[i][0]);
|
|
|
|
exp = mbcmbb_932[i][1];
|
|
|
|
ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret);
|
|
|
|
}
|
|
|
|
_setmbcp(prev_cp);
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:48:45 +01:00
|
|
|
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);
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++) {
|
2015-03-16 13:48:45 +01:00
|
|
|
ret = _ismbckata(tests[i].c);
|
|
|
|
ok(!ret, "expected 0, got %d for %04x\n", ret, tests[i].c);
|
|
|
|
}
|
|
|
|
|
|
|
|
_setmbcp(932);
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++) {
|
2015-03-16 13:48:45 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-02-23 07:05:44 +01:00
|
|
|
static void test_ismbclegal(void) {
|
|
|
|
unsigned int prev_cp = _getmbcp();
|
|
|
|
int ret, exp, err;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
_setmbcp(932); /* Japanese */
|
|
|
|
err = 0;
|
|
|
|
for(i = 0; i < 0x10000; i++) {
|
|
|
|
ret = _ismbclegal(i);
|
|
|
|
exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) ||
|
|
|
|
(HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) &&
|
|
|
|
((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
|
|
|
|
(LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC));
|
|
|
|
if(ret != exp) {
|
|
|
|
err = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
|
|
|
|
_setmbcp(936); /* Chinese (GBK) */
|
|
|
|
err = 0;
|
|
|
|
for(i = 0; i < 0x10000; i++) {
|
|
|
|
ret = _ismbclegal(i);
|
|
|
|
exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
|
|
|
|
LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE;
|
|
|
|
if(ret != exp) {
|
|
|
|
err = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
|
|
|
|
_setmbcp(949); /* Korean */
|
|
|
|
err = 0;
|
|
|
|
for(i = 0; i < 0x10000; i++) {
|
|
|
|
ret = _ismbclegal(i);
|
|
|
|
exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
|
|
|
|
LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE;
|
|
|
|
if(ret != exp) {
|
|
|
|
err = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
|
|
|
|
_setmbcp(950); /* Chinese (Big5) */
|
|
|
|
err = 0;
|
|
|
|
for(i = 0; i < 0x10000; i++) {
|
|
|
|
ret = _ismbclegal(i);
|
|
|
|
exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE &&
|
|
|
|
((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) ||
|
|
|
|
(LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE));
|
|
|
|
if(ret != exp) {
|
|
|
|
err = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
|
|
|
|
_setmbcp(1361); /* Korean (Johab) */
|
|
|
|
err = 0;
|
|
|
|
for(i = 0; i < 0x10000; i++) {
|
|
|
|
ret = _ismbclegal(i);
|
|
|
|
exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) ||
|
|
|
|
(HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) &&
|
|
|
|
((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) ||
|
|
|
|
(LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) &&
|
|
|
|
HIBYTE(i) != 0xDF;
|
|
|
|
if(ret != exp) {
|
|
|
|
err = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i);
|
|
|
|
|
|
|
|
_setmbcp(prev_cp);
|
|
|
|
}
|
|
|
|
|
2009-04-22 07:04:20 +02:00
|
|
|
static const struct {
|
|
|
|
const char* string;
|
|
|
|
const char* delimiter;
|
|
|
|
int exp_offsetret1; /* returned offset from string after first call to strtok()
|
|
|
|
-1 means NULL */
|
|
|
|
int exp_offsetret2; /* returned offset from string after second call to strtok()
|
|
|
|
-1 means NULL */
|
|
|
|
int exp_offsetret3; /* returned offset from string after third call to strtok()
|
|
|
|
-1 means NULL */
|
|
|
|
} testcases_strtok[] = {
|
|
|
|
{ "red cabernet", " ", 0, 4, -1 },
|
|
|
|
{ "sparkling white riesling", " ", 0, 10, 16 },
|
|
|
|
{ " pale cream sherry", "e ", 1, 6, 9 },
|
|
|
|
/* end mark */
|
|
|
|
{ 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_strtok(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *strret;
|
|
|
|
char teststr[100];
|
|
|
|
for( i = 0; testcases_strtok[i].string; i++){
|
|
|
|
strcpy( teststr, testcases_strtok[i].string);
|
|
|
|
strret = strtok( teststr, testcases_strtok[i].delimiter);
|
|
|
|
ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
|
|
|
|
(!strret && testcases_strtok[i].exp_offsetret1 == -1),
|
|
|
|
"string (%p) \'%s\' return %p\n",
|
|
|
|
teststr, testcases_strtok[i].string, strret);
|
|
|
|
if( !strret) continue;
|
|
|
|
strret = strtok( NULL, testcases_strtok[i].delimiter);
|
|
|
|
ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
|
|
|
|
(!strret && testcases_strtok[i].exp_offsetret2 == -1),
|
|
|
|
"second call string (%p) \'%s\' return %p\n",
|
|
|
|
teststr, testcases_strtok[i].string, strret);
|
|
|
|
if( !strret) continue;
|
|
|
|
strret = strtok( NULL, testcases_strtok[i].delimiter);
|
|
|
|
ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
|
|
|
|
(!strret && testcases_strtok[i].exp_offsetret3 == -1),
|
|
|
|
"third call string (%p) \'%s\' return %p\n",
|
|
|
|
teststr, testcases_strtok[i].string, strret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-31 21:36:45 +02:00
|
|
|
static void test_strtol(void)
|
|
|
|
{
|
2015-06-08 12:00:55 +02:00
|
|
|
static char neg[] = "-0x";
|
|
|
|
|
2009-08-31 21:36:45 +02:00
|
|
|
char* e;
|
2009-10-08 01:20:22 +02:00
|
|
|
LONG l;
|
|
|
|
ULONG ul;
|
2009-08-31 21:36:45 +02:00
|
|
|
|
|
|
|
/* errno is only set in case of error, so reset errno to EBADF to check for errno modification */
|
2009-09-02 12:16:29 +02:00
|
|
|
/* errno is modified on W2K8+ */
|
2009-08-31 21:36:45 +02:00
|
|
|
errno = EBADF;
|
|
|
|
l = strtol("-1234", &e, 0);
|
2009-10-08 01:20:22 +02:00
|
|
|
ok(l==-1234, "wrong value %d\n", l);
|
2009-09-02 12:16:29 +02:00
|
|
|
ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
|
2009-08-31 21:36:45 +02:00
|
|
|
errno = EBADF;
|
|
|
|
ul = strtoul("1234", &e, 0);
|
2009-10-08 01:20:22 +02:00
|
|
|
ok(ul==1234, "wrong value %u\n", ul);
|
2009-09-02 12:16:29 +02:00
|
|
|
ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
|
2009-08-31 21:36:45 +02:00
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
l = strtol("2147483647L", &e, 0);
|
2009-10-08 01:20:22 +02:00
|
|
|
ok(l==2147483647, "wrong value %d\n", l);
|
2009-09-02 12:16:29 +02:00
|
|
|
ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
|
2009-08-31 21:36:45 +02:00
|
|
|
errno = EBADF;
|
|
|
|
l = strtol("-2147483648L", &e, 0);
|
2009-10-08 01:20:22 +02:00
|
|
|
ok(l==-2147483647L - 1, "wrong value %d\n", l);
|
2009-09-02 12:16:29 +02:00
|
|
|
ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
|
2009-08-31 21:36:45 +02:00
|
|
|
errno = EBADF;
|
|
|
|
ul = strtoul("4294967295UL", &e, 0);
|
2009-10-08 01:20:22 +02:00
|
|
|
ok(ul==4294967295ul, "wrong value %u\n", ul);
|
2009-09-02 12:16:29 +02:00
|
|
|
ok(errno == EBADF || broken(errno == 0), "wrong errno %d\n", errno);
|
2009-08-31 21:36:45 +02:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
l = strtol("9223372036854775807L", &e, 0);
|
2009-10-08 01:20:22 +02:00
|
|
|
ok(l==2147483647, "wrong value %d\n", l);
|
2009-08-31 21:36:45 +02:00
|
|
|
ok(errno == ERANGE, "wrong errno %d\n", errno);
|
|
|
|
errno = 0;
|
|
|
|
ul = strtoul("9223372036854775807L", &e, 0);
|
2009-10-08 01:20:22 +02:00
|
|
|
ok(ul==4294967295ul, "wrong value %u\n", ul);
|
2009-08-31 21:36:45 +02:00
|
|
|
ok(errno == ERANGE, "wrong errno %d\n", errno);
|
2013-09-25 14:41:52 +02:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ul = strtoul("-2", NULL, 0);
|
|
|
|
ok(ul == -2, "wrong value %u\n", ul);
|
|
|
|
ok(errno == 0, "wrong errno %d\n", errno);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ul = strtoul("-4294967294", NULL, 0);
|
|
|
|
ok(ul == 2, "wrong value %u\n", ul);
|
|
|
|
ok(errno == 0, "wrong errno %d\n", errno);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ul = strtoul("-4294967295", NULL, 0);
|
|
|
|
ok(ul==1, "wrong value %u\n", ul);
|
|
|
|
ok(errno == 0, "wrong errno %d\n", errno);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ul = strtoul("-4294967296", NULL, 0);
|
|
|
|
ok(ul == 1, "wrong value %u\n", ul);
|
|
|
|
ok(errno == ERANGE, "wrong errno %d\n", errno);
|
2015-06-08 12:00:55 +02:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
l = strtol(neg, &e, 0);
|
|
|
|
ok(l == 0, "wrong value %d\n", l);
|
|
|
|
ok(errno == 0, "wrong errno %d\n", errno);
|
|
|
|
ok(e == neg, "e = %p, neg = %p\n", e, neg);
|
2009-08-31 21:36:45 +02:00
|
|
|
}
|
|
|
|
|
2010-03-24 22:39:28 +01:00
|
|
|
static void test_strnlen(void)
|
|
|
|
{
|
|
|
|
static const char str[] = "string";
|
|
|
|
size_t res;
|
|
|
|
|
|
|
|
if(!p_strnlen) {
|
|
|
|
win_skip("strnlen not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = p_strnlen(str, 20);
|
|
|
|
ok(res == 6, "Returned length = %d\n", (int)res);
|
|
|
|
|
|
|
|
res = p_strnlen(str, 3);
|
|
|
|
ok(res == 3, "Returned length = %d\n", (int)res);
|
|
|
|
|
|
|
|
res = p_strnlen(NULL, 0);
|
|
|
|
ok(res == 0, "Returned length = %d\n", (int)res);
|
|
|
|
}
|
|
|
|
|
2010-03-29 00:04:03 +02:00
|
|
|
static void test__strtoi64(void)
|
|
|
|
{
|
|
|
|
static const char no1[] = "31923";
|
|
|
|
static const char no2[] = "-213312";
|
|
|
|
static const char no3[] = "12aa";
|
|
|
|
static const char no4[] = "abc12";
|
|
|
|
static const char overflow[] = "99999999999999999999";
|
|
|
|
static const char neg_overflow[] = "-99999999999999999999";
|
|
|
|
static const char hex[] = "0x123";
|
|
|
|
static const char oct[] = "000123";
|
|
|
|
static const char blanks[] = " 12 212.31";
|
|
|
|
|
|
|
|
__int64 res;
|
2010-03-29 00:04:32 +02:00
|
|
|
unsigned __int64 ures;
|
2010-03-29 00:04:03 +02:00
|
|
|
char *endpos;
|
|
|
|
|
2010-03-29 00:04:32 +02:00
|
|
|
if(!p_strtoi64 || !p_strtoui64) {
|
|
|
|
win_skip("_strtoi64 or _strtoui64 not found\n");
|
2010-03-29 00:04:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
res = p_strtoi64(no1, NULL, 10);
|
|
|
|
ok(res == 31923, "res != 31923\n");
|
|
|
|
res = p_strtoi64(no2, NULL, 10);
|
|
|
|
ok(res == -213312, "res != -213312\n");
|
|
|
|
res = p_strtoi64(no3, NULL, 10);
|
|
|
|
ok(res == 12, "res != 12\n");
|
|
|
|
res = p_strtoi64(no4, &endpos, 10);
|
|
|
|
ok(res == 0, "res != 0\n");
|
|
|
|
ok(endpos == no4, "Scanning was not stopped on first character\n");
|
|
|
|
res = p_strtoi64(hex, &endpos, 10);
|
|
|
|
ok(res == 0, "res != 0\n");
|
|
|
|
ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
|
|
|
|
res = p_strtoi64(oct, &endpos, 10);
|
|
|
|
ok(res == 123, "res != 123\n");
|
|
|
|
ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
|
|
|
|
res = p_strtoi64(blanks, &endpos, 10);
|
2010-06-22 17:49:41 +02:00
|
|
|
ok(res == 12, "res != 12\n");
|
2010-03-29 00:04:03 +02:00
|
|
|
ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
res = p_strtoi64(overflow, &endpos, 10);
|
|
|
|
ok(res == _I64_MAX, "res != _I64_MAX\n");
|
|
|
|
ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
|
|
|
|
ok(errno == ERANGE, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
res = p_strtoi64(neg_overflow, &endpos, 10);
|
|
|
|
ok(res == _I64_MIN, "res != _I64_MIN\n");
|
|
|
|
ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
|
|
|
|
ok(errno == ERANGE, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
res = p_strtoi64(no1, &endpos, 16);
|
|
|
|
ok(res == 203043, "res != 203043\n");
|
|
|
|
ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
|
|
|
|
res = p_strtoi64(no2, &endpos, 16);
|
|
|
|
ok(res == -2175762, "res != -2175762\n");
|
|
|
|
ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
|
|
|
|
res = p_strtoi64(no3, &endpos, 16);
|
|
|
|
ok(res == 4778, "res != 4778\n");
|
|
|
|
ok(endpos == no3+strlen(no3), "Incorrect endpos (%p-%p)\n", no3, endpos);
|
|
|
|
res = p_strtoi64(no4, &endpos, 16);
|
|
|
|
ok(res == 703506, "res != 703506\n");
|
|
|
|
ok(endpos == no4+strlen(no4), "Incorrect endpos (%p-%p)\n", no4, endpos);
|
|
|
|
res = p_strtoi64(hex, &endpos, 16);
|
|
|
|
ok(res == 291, "res != 291\n");
|
|
|
|
ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
|
|
|
|
res = p_strtoi64(oct, &endpos, 16);
|
|
|
|
ok(res == 291, "res != 291\n");
|
|
|
|
ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
|
|
|
|
res = p_strtoi64(blanks, &endpos, 16);
|
|
|
|
ok(res == 18, "res != 18\n");
|
|
|
|
ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
res = p_strtoi64(hex, &endpos, 36);
|
|
|
|
ok(res == 1541019, "res != 1541019\n");
|
|
|
|
ok(endpos == hex+strlen(hex), "Incorrect endpos (%p-%p)\n", hex, endpos);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
res = p_strtoi64(no1, &endpos, 0);
|
|
|
|
ok(res == 31923, "res != 31923\n");
|
|
|
|
ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
|
|
|
|
res = p_strtoi64(no2, &endpos, 0);
|
|
|
|
ok(res == -213312, "res != -213312\n");
|
|
|
|
ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
|
|
|
|
res = p_strtoi64(no3, &endpos, 10);
|
|
|
|
ok(res == 12, "res != 12\n");
|
|
|
|
ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
|
|
|
|
res = p_strtoi64(no4, &endpos, 10);
|
|
|
|
ok(res == 0, "res != 0\n");
|
|
|
|
ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
|
|
|
|
res = p_strtoi64(hex, &endpos, 10);
|
|
|
|
ok(res == 0, "res != 0\n");
|
|
|
|
ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
|
|
|
|
res = p_strtoi64(oct, &endpos, 10);
|
|
|
|
ok(res == 123, "res != 123\n");
|
|
|
|
ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
|
|
|
|
res = p_strtoi64(blanks, &endpos, 10);
|
|
|
|
ok(res == 12, "res != 12\n");
|
|
|
|
ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %x\n", errno);
|
2010-03-29 00:04:32 +02:00
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ures = p_strtoui64(no1, &endpos, 0);
|
|
|
|
ok(ures == 31923, "ures != 31923\n");
|
|
|
|
ok(endpos == no1+strlen(no1), "Incorrect endpos (%p-%p)\n", no1, endpos);
|
|
|
|
ures = p_strtoui64(no2, &endpos, 0);
|
|
|
|
ok(ures == -213312, "ures != -213312\n");
|
|
|
|
ok(endpos == no2+strlen(no2), "Incorrect endpos (%p-%p)\n", no2, endpos);
|
|
|
|
ures = p_strtoui64(no3, &endpos, 10);
|
|
|
|
ok(ures == 12, "ures != 12\n");
|
|
|
|
ok(endpos == no3+2, "Incorrect endpos (%p-%p)\n", no3, endpos);
|
|
|
|
ures = p_strtoui64(no4, &endpos, 10);
|
|
|
|
ok(ures == 0, "ures != 0\n");
|
|
|
|
ok(endpos == no4, "Incorrect endpos (%p-%p)\n", no4, endpos);
|
|
|
|
ures = p_strtoui64(hex, &endpos, 10);
|
|
|
|
ok(ures == 0, "ures != 0\n");
|
|
|
|
ok(endpos == hex+1, "Incorrect endpos (%p-%p)\n", hex, endpos);
|
|
|
|
ures = p_strtoui64(oct, &endpos, 10);
|
|
|
|
ok(ures == 123, "ures != 123\n");
|
|
|
|
ok(endpos == oct+strlen(oct), "Incorrect endpos (%p-%p)\n", oct, endpos);
|
|
|
|
ures = p_strtoui64(blanks, &endpos, 10);
|
|
|
|
ok(ures == 12, "ures != 12\n");
|
|
|
|
ok(endpos == blanks+10, "Incorrect endpos (%p-%p)\n", blanks, endpos);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ures = p_strtoui64(overflow, &endpos, 10);
|
|
|
|
ok(ures == _UI64_MAX, "ures != _UI64_MAX\n");
|
|
|
|
ok(endpos == overflow+strlen(overflow), "Incorrect endpos (%p-%p)\n", overflow, endpos);
|
|
|
|
ok(errno == ERANGE, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ures = p_strtoui64(neg_overflow, &endpos, 10);
|
|
|
|
ok(ures == 1, "ures != 1\n");
|
|
|
|
ok(endpos == neg_overflow+strlen(neg_overflow), "Incorrect endpos (%p-%p)\n", neg_overflow, endpos);
|
|
|
|
ok(errno == ERANGE, "errno = %x\n", errno);
|
2010-03-29 00:04:03 +02:00
|
|
|
}
|
|
|
|
|
2019-12-26 18:30:48 +01:00
|
|
|
static inline BOOL compare_double(double f, double g, unsigned int ulps)
|
|
|
|
{
|
|
|
|
ULONGLONG x = *(ULONGLONG *)&f;
|
|
|
|
ULONGLONG y = *(ULONGLONG *)&g;
|
|
|
|
|
|
|
|
if (f < 0)
|
|
|
|
x = ~x + 1;
|
|
|
|
else
|
|
|
|
x |= ((ULONGLONG)1)<<63;
|
|
|
|
if (g < 0)
|
|
|
|
y = ~y + 1;
|
|
|
|
else
|
|
|
|
y |= ((ULONGLONG)1)<<63;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2019-12-26 18:30:48 +01:00
|
|
|
return (x>y ? x-y : y-x) <= ulps;
|
2019-12-18 23:48:11 +01:00
|
|
|
}
|
|
|
|
|
2010-04-21 11:26:22 +02:00
|
|
|
static void test__strtod(void)
|
|
|
|
{
|
2020-05-04 11:30:18 +02:00
|
|
|
static const struct {
|
|
|
|
const char *str;
|
|
|
|
int len;
|
|
|
|
double ret;
|
|
|
|
} tests[] = {
|
|
|
|
{ "12.1", 4, 12.1 },
|
|
|
|
{ "-13.721", 7, -13.721 },
|
|
|
|
{ "INF", 0, 0 },
|
|
|
|
{ ".21e12", 6, 210000000000.0 },
|
|
|
|
{ "214353e-3", 9, 214.353 },
|
|
|
|
{ "NAN", 0, 0 },
|
|
|
|
{ "12.1d2", 6, 12.1e2 },
|
|
|
|
{ " d10", 0, 0 },
|
|
|
|
{ "0.1", 3, 0.1 },
|
|
|
|
{ "-0.1", 4, -0.1 },
|
|
|
|
{ "0.1281832188491894198128921", 27, 0.1281832188491894198128921 },
|
|
|
|
{ "0.82181281288121", 16, 0.82181281288121 },
|
|
|
|
{ "21921922352523587651128218821", 29, 21921922352523587651128218821.0 },
|
|
|
|
{ "0.1d238", 7, 0.1e238 },
|
|
|
|
{ "0.1D-4736", 9, 0 },
|
|
|
|
{ "3.4028234663852887e38", 21, FLT_MAX },
|
|
|
|
{ "1.7976931348623158e+308", 23, DBL_MAX },
|
2020-05-04 11:30:24 +02:00
|
|
|
{ "00", 2, 0 },
|
|
|
|
{ "00.", 3, 0 },
|
|
|
|
{ ".00", 3, 0 },
|
|
|
|
{ "-0.", 3, 0 },
|
|
|
|
{ "0e13", 4, 0 },
|
2020-05-04 11:30:18 +02:00
|
|
|
};
|
2010-04-26 12:33:28 +02:00
|
|
|
const char overflow[] = "1d9999999999999999999";
|
2010-04-21 11:26:22 +02:00
|
|
|
|
|
|
|
char *end;
|
|
|
|
double d;
|
2020-05-04 11:30:18 +02:00
|
|
|
int i;
|
2010-04-21 11:26:22 +02:00
|
|
|
|
2020-05-04 11:30:18 +02:00
|
|
|
for (i=0; i<ARRAY_SIZE(tests); i++)
|
|
|
|
{
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
d = strtod(tests[i].str, &end);
|
|
|
|
ok(d == tests[i].ret, "%d) d = %.16e\n", i, d);
|
|
|
|
ok(end == tests[i].str + tests[i].len, "%d) len = %d\n",
|
|
|
|
i, (int)(end - tests[i].str));
|
|
|
|
ok(errno = 0xdeadbeef, "%d) errno = %d\n", i, errno);
|
|
|
|
}
|
2010-07-22 12:35:08 +02:00
|
|
|
|
2015-06-29 03:42:21 +02:00
|
|
|
if (!p__strtod_l)
|
|
|
|
win_skip("_strtod_l not found\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errno = EBADF;
|
|
|
|
d = strtod(NULL, NULL);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 0.0, "d = %.16e\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
ok(errno == EINVAL, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
end = (char *)0xdeadbeef;
|
|
|
|
d = strtod(NULL, &end);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 0.0, "d = %.16e\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
ok(errno == EINVAL, "errno = %x\n", errno);
|
2015-06-29 03:42:34 +02:00
|
|
|
ok(!end, "incorrect end ptr %p\n", end);
|
2015-06-29 03:42:21 +02:00
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
d = p__strtod_l(NULL, NULL, NULL);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 0.0, "d = %.16e\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
ok(errno == EINVAL, "errno = %x\n", errno);
|
|
|
|
}
|
|
|
|
|
2010-04-21 11:26:22 +02:00
|
|
|
/* Set locale with non '.' decimal point (',') */
|
|
|
|
if(!setlocale(LC_ALL, "Polish")) {
|
|
|
|
win_skip("system with limited locales\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = strtod("12.1", NULL);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 12.0, "d = %.16e\n", d);
|
2010-04-21 11:26:22 +02:00
|
|
|
|
|
|
|
d = strtod("12,1", NULL);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 12.1, "d = %.16e\n", d);
|
2010-04-21 11:26:22 +02:00
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
2010-04-26 12:33:28 +02:00
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
2011-02-09 22:43:34 +01:00
|
|
|
strtod(overflow, &end);
|
2010-04-26 12:33:28 +02:00
|
|
|
ok(errno == ERANGE, "errno = %x\n", errno);
|
2010-07-21 11:09:15 +02:00
|
|
|
ok(end == overflow+21, "incorrect end (%d)\n", (int)(end-overflow));
|
2010-04-26 12:33:28 +02:00
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
strtod("-1d309", NULL);
|
|
|
|
ok(errno == ERANGE, "errno = %x\n", errno);
|
2010-04-21 11:26:22 +02:00
|
|
|
}
|
|
|
|
|
2010-05-06 14:28:08 +02:00
|
|
|
static void test_mbstowcs(void)
|
|
|
|
{
|
|
|
|
static const wchar_t wSimple[] = { 't','e','x','t',0 };
|
|
|
|
static const wchar_t wHiragana[] = { 0x3042,0x3043,0 };
|
2017-08-04 16:06:37 +02:00
|
|
|
static const wchar_t wEmpty[] = { 0 };
|
2010-05-06 14:28:08 +02:00
|
|
|
static const char mSimple[] = "text";
|
|
|
|
static const char mHiragana[] = { 0x82,0xa0,0x82,0xa1,0 };
|
2017-08-04 16:06:37 +02:00
|
|
|
static const char mEmpty[] = { 0 };
|
2010-05-06 14:28:08 +02:00
|
|
|
|
2011-04-27 20:08:41 +02:00
|
|
|
const wchar_t *pwstr;
|
2010-05-06 14:28:08 +02:00
|
|
|
wchar_t wOut[6];
|
|
|
|
char mOut[6];
|
|
|
|
size_t ret;
|
|
|
|
int err;
|
2012-11-29 10:23:57 +01:00
|
|
|
const char *pmbstr;
|
|
|
|
mbstate_t state;
|
2010-05-06 14:28:08 +02:00
|
|
|
|
|
|
|
wOut[4] = '!'; wOut[5] = '\0';
|
|
|
|
mOut[4] = '!'; mOut[5] = '\0';
|
|
|
|
|
2014-01-09 17:34:05 +01:00
|
|
|
if(pmbstowcs_s) {
|
|
|
|
/* crashes on some systems */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = mbstowcs(wOut, NULL, 4);
|
|
|
|
ok(ret == -1, "mbstowcs did not return -1\n");
|
|
|
|
ok(errno == EINVAL, "errno = %d\n", errno);
|
|
|
|
}
|
2014-01-08 12:13:22 +01:00
|
|
|
|
2010-05-06 14:28:08 +02:00
|
|
|
ret = mbstowcs(NULL, mSimple, 0);
|
2010-08-29 10:44:26 +02:00
|
|
|
ok(ret == 4, "mbstowcs did not return 4\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
|
|
|
|
ret = mbstowcs(wOut, mSimple, 4);
|
2010-08-29 10:44:26 +02:00
|
|
|
ok(ret == 4, "mbstowcs did not return 4\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(wOut, wSimple, 4*sizeof(wchar_t)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
ok(wOut[4] == '!', "wOut[4] != \'!\'\n");
|
|
|
|
|
2017-08-04 16:06:37 +02:00
|
|
|
ret = mbstowcs(NULL, mEmpty, 1);
|
|
|
|
ok(ret == 0, "mbstowcs did not return 0, got %d\n", (int)ret);
|
|
|
|
|
|
|
|
ret = mbstowcs(wOut, mEmpty, 1);
|
|
|
|
ok(ret == 0, "mbstowcs did not return 0, got %d\n", (int)ret);
|
|
|
|
ok(!memcmp(wOut, wEmpty, sizeof(wEmpty)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
|
2010-05-06 14:28:08 +02:00
|
|
|
ret = wcstombs(NULL, wSimple, 0);
|
2010-08-29 10:44:26 +02:00
|
|
|
ok(ret == 4, "wcstombs did not return 4\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
|
|
|
|
ret = wcstombs(mOut, wSimple, 6);
|
2010-08-29 10:44:26 +02:00
|
|
|
ok(ret == 4, "wcstombs did not return 4\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
|
|
|
|
|
|
|
|
ret = wcstombs(mOut, wSimple, 2);
|
2010-08-29 10:44:26 +02:00
|
|
|
ok(ret == 2, "wcstombs did not return 2\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(mOut, mSimple, 5*sizeof(char)), "mOut = %s\n", mOut);
|
|
|
|
|
2017-08-04 16:06:37 +02:00
|
|
|
ret = wcstombs(NULL, wEmpty, 1);
|
|
|
|
ok(ret == 0, "wcstombs did not return 0, got %d\n", (int)ret);
|
|
|
|
|
|
|
|
ret = wcstombs(mOut, wEmpty, 1);
|
|
|
|
ok(ret == 0, "wcstombs did not return 0, got %d\n", (int)ret);
|
|
|
|
ok(!memcmp(mOut, mEmpty, sizeof(mEmpty)), "mOut = %s\n", mOut);
|
|
|
|
|
2010-05-06 14:28:08 +02:00
|
|
|
if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
|
|
|
|
win_skip("Japanese_Japan.932 locale not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = mbstowcs(wOut, mHiragana, 6);
|
2010-08-29 10:44:26 +02:00
|
|
|
ok(ret == 2, "mbstowcs did not return 2\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
|
2017-08-04 16:06:37 +02:00
|
|
|
ret = mbstowcs(wOut, mEmpty, 6);
|
2017-08-04 16:06:39 +02:00
|
|
|
ok(ret == 0, "mbstowcs did not return 0, got %d\n", (int)ret);
|
2017-08-04 16:06:37 +02:00
|
|
|
ok(!memcmp(wOut, wEmpty, sizeof(wEmpty)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
|
2010-05-06 14:28:08 +02:00
|
|
|
ret = wcstombs(mOut, wHiragana, 6);
|
2010-08-29 10:44:26 +02:00
|
|
|
ok(ret == 4, "wcstombs did not return 4\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
|
|
|
|
|
2017-08-04 16:06:37 +02:00
|
|
|
ret = wcstombs(mOut, wEmpty, 6);
|
|
|
|
ok(ret == 0, "wcstombs did not return 0, got %d\n", (int)ret);
|
|
|
|
ok(!memcmp(mOut, mEmpty, sizeof(mEmpty)), "mOut = %s\n", mOut);
|
|
|
|
|
2010-05-06 14:28:08 +02:00
|
|
|
if(!pmbstowcs_s || !pwcstombs_s) {
|
2011-06-03 15:28:56 +02:00
|
|
|
setlocale(LC_ALL, "C");
|
2010-05-06 14:28:08 +02:00
|
|
|
win_skip("mbstowcs_s or wcstombs_s not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:06:29 +01:00
|
|
|
err = pmbstowcs_s(&ret, wOut, 1, mSimple, _TRUNCATE);
|
|
|
|
ok(err == STRUNCATE, "err = %d\n", err);
|
|
|
|
ok(ret == 1, "mbstowcs_s did not return 0\n");
|
|
|
|
ok(!wOut[0], "wOut[0] = %d\n", wOut[0]);
|
|
|
|
|
2010-06-06 17:24:09 +02:00
|
|
|
err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(err == 0, "err = %d\n", err);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 5, "mbstowcs_s did not return 5\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(wOut, wSimple, sizeof(wSimple)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
|
2010-06-06 17:24:09 +02:00
|
|
|
err = pmbstowcs_s(&ret, wOut, 6, mHiragana, _TRUNCATE);
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(err == 0, "err = %d\n", err);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 3, "mbstowcs_s did not return 3\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
|
2017-08-04 16:06:37 +02:00
|
|
|
err = pmbstowcs_s(&ret, wOut, 6, mEmpty, _TRUNCATE);
|
2017-08-04 16:06:39 +02:00
|
|
|
ok(err == 0, "err = %d\n", err);
|
|
|
|
ok(ret == 1, "mbstowcs_s did not return 1, got %d\n", (int)ret);
|
2017-08-04 16:06:37 +02:00
|
|
|
ok(!memcmp(wOut, wEmpty, sizeof(wEmpty)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
|
2011-03-30 15:45:04 +02:00
|
|
|
err = pmbstowcs_s(&ret, NULL, 0, mHiragana, 1);
|
|
|
|
ok(err == 0, "err = %d\n", err);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 3, "mbstowcs_s did not return 3\n");
|
2011-03-30 15:45:04 +02:00
|
|
|
|
2010-06-06 17:24:09 +02:00
|
|
|
err = pwcstombs_s(&ret, mOut, 6, wSimple, _TRUNCATE);
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(err == 0, "err = %d\n", err);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 5, "wcstombs_s did not return 5\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
|
|
|
|
|
2010-06-06 17:24:09 +02:00
|
|
|
err = pwcstombs_s(&ret, mOut, 6, wHiragana, _TRUNCATE);
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(err == 0, "err = %d\n", err);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 5, "wcstombs_s did not return 5\n");
|
2010-05-06 14:28:08 +02:00
|
|
|
ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);
|
2011-03-30 15:45:04 +02:00
|
|
|
|
2017-08-04 16:06:37 +02:00
|
|
|
err = pwcstombs_s(&ret, mOut, 6, wEmpty, _TRUNCATE);
|
|
|
|
ok(err == 0, "err = %d\n", err);
|
|
|
|
ok(ret == 1, "wcstombs_s did not return 1, got %d\n", (int)ret);
|
|
|
|
ok(!memcmp(mOut, mEmpty, sizeof(mEmpty)), "mOut = %s\n", mOut);
|
|
|
|
|
2011-03-30 15:45:04 +02:00
|
|
|
err = pwcstombs_s(&ret, NULL, 0, wHiragana, 1);
|
|
|
|
ok(err == 0, "err = %d\n", err);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 5, "wcstombs_s did not return 5\n");
|
2011-04-27 20:08:41 +02:00
|
|
|
|
|
|
|
if(!pwcsrtombs) {
|
2011-06-03 15:28:56 +02:00
|
|
|
setlocale(LC_ALL, "C");
|
2011-04-27 20:08:41 +02:00
|
|
|
win_skip("wcsrtombs not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pwstr = wSimple;
|
|
|
|
err = -3;
|
|
|
|
ret = pwcsrtombs(mOut, &pwstr, 4, &err);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 4, "wcsrtombs did not return 4\n");
|
2011-04-27 20:08:41 +02:00
|
|
|
ok(err == 0, "err = %d\n", err);
|
|
|
|
ok(pwstr == wSimple+4, "pwstr = %p (wszSimple = %p)\n", pwstr, wSimple);
|
|
|
|
ok(!memcmp(mOut, mSimple, ret), "mOut = %s\n", mOut);
|
|
|
|
|
|
|
|
pwstr = wSimple;
|
|
|
|
ret = pwcsrtombs(mOut, &pwstr, 5, NULL);
|
2011-04-30 02:45:06 +02:00
|
|
|
ok(ret == 4, "wcsrtombs did not return 4\n");
|
2011-04-27 20:08:41 +02:00
|
|
|
ok(pwstr == NULL, "pwstr != NULL\n");
|
|
|
|
ok(!memcmp(mOut, mSimple, sizeof(mSimple)), "mOut = %s\n", mOut);
|
2011-06-03 15:28:56 +02:00
|
|
|
|
2012-11-29 10:23:57 +01:00
|
|
|
if(!p_mbsrtowcs) {
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
win_skip("mbsrtowcs not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-16 13:29:45 +02:00
|
|
|
pmbstr = mHiragana;
|
|
|
|
ret = p_mbsrtowcs(NULL, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == 2, "mbsrtowcs did not return 2\n");
|
|
|
|
ok(pmbstr == mHiragana, "pmbstr = %p, expected %p\n", pmbstr, mHiragana);
|
|
|
|
|
2012-11-29 10:23:57 +01:00
|
|
|
pmbstr = mHiragana;
|
|
|
|
ret = p_mbsrtowcs(wOut, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == 2, "mbsrtowcs did not return 2\n");
|
|
|
|
ok(!memcmp(wOut, wHiragana, sizeof(wHiragana)), "wOut = %s\n", wine_dbgstr_w(wOut));
|
|
|
|
ok(!pmbstr, "pmbstr != NULL\n");
|
|
|
|
|
|
|
|
state = mHiragana[0];
|
|
|
|
pmbstr = mHiragana+1;
|
|
|
|
ret = p_mbsrtowcs(wOut, &pmbstr, 6, &state);
|
|
|
|
ok(ret == 2, "mbsrtowcs did not return 2\n");
|
|
|
|
ok(wOut[0] == 0x3042, "wOut[0] = %x\n", wOut[0]);
|
|
|
|
ok(wOut[1] == 0xff61, "wOut[1] = %x\n", wOut[1]);
|
|
|
|
ok(wOut[2] == 0, "wOut[2] = %x\n", wOut[2]);
|
|
|
|
ok(!pmbstr, "pmbstr != NULL\n");
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsrtowcs(wOut, NULL, 6, &state);
|
|
|
|
ok(ret == -1, "mbsrtowcs did not return -1\n");
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
2016-05-16 13:29:45 +02:00
|
|
|
if(!p_mbsrtowcs_s) {
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
win_skip("mbsrtowcs_s not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmbstr = mHiragana;
|
|
|
|
err = p_mbsrtowcs_s(&ret, NULL, 0, NULL, 6, NULL);
|
|
|
|
ok(ret == -1, "mbsrtowcs_s did not return -1\n");
|
|
|
|
ok(err == EINVAL, "err = %d\n", err);
|
|
|
|
err = p_mbsrtowcs_s(&ret, NULL, 1, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == -1, "mbsrtowcs_s did not return -1\n");
|
|
|
|
ok(err == EINVAL, "err = %d\n", err);
|
|
|
|
err = p_mbsrtowcs_s(&ret, wOut, 0, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == -1, "mbsrtowcs_s did not return -1\n");
|
|
|
|
ok(err == EINVAL, "err = %d\n", err);
|
|
|
|
|
|
|
|
pmbstr = mHiragana;
|
|
|
|
errno = 0;
|
|
|
|
err = p_mbsrtowcs_s(&ret, NULL, 0, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == 3, "mbsrtowcs_s did not return 3\n");
|
|
|
|
ok(err == 0, "err = %d\n", err);
|
|
|
|
ok(pmbstr == mHiragana, "pmbstr = %p, expected %p\n", pmbstr, mHiragana);
|
|
|
|
ok(errno == 0, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
pmbstr = mHiragana;
|
|
|
|
err = p_mbsrtowcs_s(&ret, wOut, 1, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == 2, "mbsrtowcs_s did not return 2\n");
|
|
|
|
ok(err == 0, "err = %d\n", err);
|
|
|
|
ok(!wOut[0], "wOut[0] = '%c'\n", wOut[0]);
|
|
|
|
ok(pmbstr == mHiragana+2, "pmbstr = %p, expected %p\n", pmbstr, mHiragana+2);
|
|
|
|
ok(errno == 0, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
pmbstr = mHiragana;
|
|
|
|
err = p_mbsrtowcs_s(&ret, wOut, 2, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == 3, "mbsrtowcs_s did not return 3\n");
|
|
|
|
ok(err == 0, "err = %d\n", err);
|
|
|
|
ok(!wOut[0], "wOut[0] = '%c'\n", wOut[0]);
|
|
|
|
ok(pmbstr == mHiragana+4, "pmbstr = %p, expected %p\n", pmbstr, mHiragana+4);
|
|
|
|
ok(errno == 0, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
pmbstr = mHiragana;
|
|
|
|
err = p_mbsrtowcs_s(&ret, wOut, 3, &pmbstr, 6, NULL);
|
|
|
|
ok(ret == 3, "mbsrtowcs_s did not return 3\n");
|
|
|
|
ok(err == 0, "err = %d\n", err);
|
|
|
|
ok(!pmbstr, "pmbstr != NULL\n");
|
|
|
|
ok(errno == 0, "errno = %d\n", errno);
|
|
|
|
|
2011-06-03 15:28:56 +02:00
|
|
|
setlocale(LC_ALL, "C");
|
2010-05-06 14:28:08 +02:00
|
|
|
}
|
|
|
|
|
2020-02-03 20:15:54 +01:00
|
|
|
static void test__wcstombs_s_l(void)
|
|
|
|
{
|
|
|
|
struct test {
|
|
|
|
const wchar_t *wstr;
|
|
|
|
size_t wlen;
|
|
|
|
const char *str;
|
|
|
|
size_t len;
|
|
|
|
size_t ret;
|
|
|
|
int err;
|
|
|
|
const char *locale;
|
|
|
|
} tests[] = {
|
|
|
|
/* wstr str ret err locale */
|
|
|
|
{ L"", 0, NULL, 0, 1, 0, NULL },
|
|
|
|
{ L"\xfffd", 1, NULL, 0, 2, 0, NULL },
|
2020-02-03 21:14:11 +01:00
|
|
|
{ L"\xfffd", 1, "", 1, 0, EILSEQ, NULL },
|
|
|
|
{ L"\xfffd", 1, "", 6, 0, EILSEQ, NULL },
|
2020-02-03 20:15:54 +01:00
|
|
|
{ L"text", _TRUNCATE, "text", 5, 5, 0, NULL },
|
2020-02-03 21:14:11 +01:00
|
|
|
{ L"text", _TRUNCATE, "", 1, 1, STRUNCATE, NULL },
|
|
|
|
{ L"text", 5, "", 3, 0, ERANGE, NULL },
|
2020-02-03 20:15:54 +01:00
|
|
|
|
2020-02-03 21:06:10 +01:00
|
|
|
{ L"", 0, NULL, 0, 1, 0, "English_United States.1252" },
|
2020-02-03 21:14:11 +01:00
|
|
|
{ L"\xfffd", 1, NULL, 0, 0, EILSEQ, "English_United States.1252" },
|
|
|
|
{ L"\xfffd", 1, "", 1, 0, EILSEQ, "English_United States.1252" },
|
|
|
|
{ L"\xfffd", 1, "", 6, 0, EILSEQ, "English_United States.1252" },
|
2020-02-03 20:15:54 +01:00
|
|
|
{ L"text", _TRUNCATE, "text", 5, 5, 0, "English_United States.1252" },
|
2020-02-03 21:14:11 +01:00
|
|
|
{ L"text", _TRUNCATE, "", 1, 1, STRUNCATE, "English_United States.1252" },
|
|
|
|
{ L"text", 5, "", 3, 0, ERANGE, "English_United States.1252" },
|
2020-02-03 20:15:54 +01:00
|
|
|
};
|
|
|
|
_locale_t locale;
|
|
|
|
char out[6];
|
|
|
|
size_t ret;
|
|
|
|
int err;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!p__create_locale) {
|
|
|
|
win_skip("_create_locale not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++)
|
|
|
|
{
|
|
|
|
if(tests[i].locale)
|
|
|
|
{
|
|
|
|
locale = p__create_locale(LC_ALL, tests[i].locale);
|
|
|
|
ok(locale != NULL, "_create_locale failed for %s\n", tests[i].locale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
locale = NULL;
|
|
|
|
|
|
|
|
ret = ~0;
|
|
|
|
memset(out, 0xcc, sizeof(out));
|
|
|
|
err = p_wcstombs_s_l(&ret, tests[i].str ? out : NULL, tests[i].len,
|
|
|
|
tests[i].wstr, tests[i].wlen, locale);
|
|
|
|
ok(ret == tests[i].ret, "%d: expected ret %d, got %d for '%s' in locale %s\n", i, tests[i].ret, ret,
|
|
|
|
wine_dbgstr_w(tests[i].wstr), tests[i].locale);
|
|
|
|
ok(err == tests[i].err, "%d: expected err %d, got %d for '%s' in locale %s\n", i, tests[i].err, err,
|
|
|
|
wine_dbgstr_w(tests[i].wstr), tests[i].locale);
|
|
|
|
if(tests[i].str)
|
|
|
|
ok(!memcmp(out, tests[i].str, strlen(tests[i].str)+1),
|
|
|
|
"%d: expected out %s, got %s for '%s' in locale %s\n", i, tests[i].str, out,
|
|
|
|
wine_dbgstr_w(tests[i].wstr), tests[i].locale);
|
|
|
|
|
|
|
|
p__free_locale(locale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 01:46:35 +02:00
|
|
|
static void test_gcvt(void)
|
|
|
|
{
|
|
|
|
char buf[1024], *res;
|
|
|
|
errno_t err;
|
|
|
|
|
|
|
|
if(!p_gcvt_s) {
|
|
|
|
win_skip("Skipping _gcvt tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
res = _gcvt(1.2, -1, buf);
|
|
|
|
ok(res == NULL, "res != NULL\n");
|
|
|
|
ok(errno == ERANGE, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
res = _gcvt(1.2, 5, NULL);
|
|
|
|
ok(res == NULL, "res != NULL\n");
|
|
|
|
ok(errno == EINVAL, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
res = gcvt(1.2, 5, buf);
|
|
|
|
ok(res == buf, "res != buf\n");
|
|
|
|
ok(!strcmp(buf, "1.2"), "buf = %s\n", buf);
|
|
|
|
|
|
|
|
buf[0] = 'x';
|
|
|
|
err = p_gcvt_s(buf, 5, 1.2, 10);
|
|
|
|
ok(err == ERANGE, "err = %d\n", err);
|
|
|
|
ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
|
|
|
|
|
|
|
|
buf[0] = 'x';
|
|
|
|
err = p_gcvt_s(buf, 4, 123456, 2);
|
|
|
|
ok(err == ERANGE, "err = %d\n", err);
|
|
|
|
ok(buf[0] == '\0', "buf[0] = %c\n", buf[0]);
|
|
|
|
}
|
|
|
|
|
2010-10-11 12:25:15 +02:00
|
|
|
static void test__itoa_s(void)
|
|
|
|
{
|
|
|
|
errno_t ret;
|
|
|
|
char buffer[33];
|
|
|
|
|
|
|
|
if (!p_itoa_s)
|
|
|
|
{
|
|
|
|
win_skip("Skipping _itoa_s tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_itoa_s(0, NULL, 0, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_itoa_s(0, buffer, 0, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
|
|
|
|
ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
|
|
|
|
ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_itoa_s(12345678, buffer, 4, 10);
|
|
|
|
ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
|
|
|
|
ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
|
|
|
|
ok(!memcmp(buffer, "\000765", 4),
|
|
|
|
"Expected the output buffer to be null terminated with truncated output\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_itoa_s(12345678, buffer, 8, 10);
|
|
|
|
ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
|
|
|
|
ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
|
|
|
|
ok(!memcmp(buffer, "\0007654321", 8),
|
|
|
|
"Expected the output buffer to be null terminated with truncated output\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_itoa_s(-12345678, buffer, 9, 10);
|
|
|
|
ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
|
|
|
|
ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
|
|
|
|
ok(!memcmp(buffer, "\00087654321", 9),
|
|
|
|
"Expected the output buffer to be null terminated with truncated output\n");
|
|
|
|
|
|
|
|
ret = p_itoa_s(12345678, buffer, 9, 10);
|
|
|
|
ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "12345678"),
|
|
|
|
"Expected output buffer string to be \"12345678\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
|
|
|
|
ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "1010101010101010"),
|
|
|
|
"Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
|
|
|
|
ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "nell"),
|
|
|
|
"Expected output buffer string to be \"nell\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
|
|
|
|
ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "hag"),
|
|
|
|
"Expected output buffer string to be \"hag\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
|
|
|
|
ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "-12345678"),
|
|
|
|
"Expected output buffer string to be \"-12345678\", got \"%s\"\n",
|
|
|
|
buffer);
|
2013-10-15 16:29:00 +02:00
|
|
|
|
|
|
|
itoa(100, buffer, 100);
|
|
|
|
ok(!strcmp(buffer, "10"),
|
|
|
|
"Expected output buffer string to be \"10\", got \"%s\"\n", buffer);
|
2010-10-11 12:25:15 +02:00
|
|
|
}
|
|
|
|
|
2010-10-11 12:25:23 +02:00
|
|
|
static void test__strlwr_s(void)
|
|
|
|
{
|
|
|
|
errno_t ret;
|
|
|
|
char buffer[20];
|
|
|
|
|
|
|
|
if (!p_strlwr_s)
|
|
|
|
{
|
|
|
|
win_skip("Skipping _strlwr_s tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_strlwr_s(NULL, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_strlwr_s(NULL, sizeof(buffer));
|
|
|
|
ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_strlwr_s(buffer, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
strcpy(buffer, "GoRrIsTeR");
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_strlwr_s(buffer, 5);
|
|
|
|
ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
|
2011-12-23 20:02:54 +01:00
|
|
|
"Expected the output buffer to be \"\\0oRrIsTeR\"\n");
|
2010-10-11 12:25:23 +02:00
|
|
|
|
|
|
|
strcpy(buffer, "GoRrIsTeR");
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR") - 1);
|
|
|
|
ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")),
|
2011-12-23 20:02:54 +01:00
|
|
|
"Expected the output buffer to be \"\\0oRrIsTeR\"\n");
|
2010-10-11 12:25:23 +02:00
|
|
|
|
|
|
|
strcpy(buffer, "GoRrIsTeR");
|
|
|
|
ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR"));
|
|
|
|
ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "gorrister"),
|
|
|
|
"Expected the output buffer to be \"gorrister\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
memcpy(buffer, "GoRrIsTeR\0ELLEN", sizeof("GoRrIsTeR\0ELLEN"));
|
|
|
|
ret = p_strlwr_s(buffer, sizeof(buffer));
|
|
|
|
ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(buffer, "gorrister\0ELLEN", sizeof("gorrister\0ELLEN")),
|
|
|
|
"Expected the output buffer to be \"gorrister\\0ELLEN\", got \"%s\"\n",
|
|
|
|
buffer);
|
2019-12-04 10:04:46 +01:00
|
|
|
|
|
|
|
ret = p_strlwr_s((char *)"already_lowercase", sizeof("already_lowercase"));
|
|
|
|
ok(ret == 0, "Expected _strlwr_s to return 0, got %d\n", ret);
|
2010-10-11 12:25:23 +02:00
|
|
|
}
|
|
|
|
|
2010-10-18 14:06:16 +02:00
|
|
|
static void test_wcsncat_s(void)
|
|
|
|
{
|
|
|
|
static wchar_t abcW[] = {'a','b','c',0};
|
|
|
|
int ret;
|
|
|
|
wchar_t dst[4];
|
|
|
|
wchar_t src[4];
|
|
|
|
|
|
|
|
if (!p_wcsncat_s)
|
|
|
|
{
|
|
|
|
win_skip("skipping wcsncat_s tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(src, abcW, sizeof(abcW));
|
|
|
|
dst[0] = 0;
|
|
|
|
ret = p_wcsncat_s(NULL, 4, src, 4);
|
|
|
|
ok(ret == EINVAL, "err = %d\n", ret);
|
|
|
|
ret = p_wcsncat_s(dst, 0, src, 4);
|
|
|
|
ok(ret == EINVAL, "err = %d\n", ret);
|
|
|
|
ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
|
|
|
|
ok(ret == EINVAL, "err = %d\n", ret);
|
|
|
|
ret = p_wcsncat_s(dst, 4, NULL, 0);
|
|
|
|
ok(ret == 0, "err = %d\n", ret);
|
|
|
|
|
|
|
|
dst[0] = 0;
|
|
|
|
ret = p_wcsncat_s(dst, 2, src, 4);
|
|
|
|
ok(ret == ERANGE, "err = %d\n", ret);
|
|
|
|
|
|
|
|
dst[0] = 0;
|
|
|
|
ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
|
2010-10-19 07:24:52 +02:00
|
|
|
ok(ret == STRUNCATE, "err = %d\n", ret);
|
2010-10-18 14:06:16 +02:00
|
|
|
ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
|
2010-10-19 07:24:52 +02:00
|
|
|
|
|
|
|
memcpy(dst, abcW, sizeof(abcW));
|
|
|
|
dst[3] = 'd';
|
|
|
|
ret = p_wcsncat_s(dst, 4, src, 4);
|
|
|
|
ok(ret == EINVAL, "err = %d\n", ret);
|
2010-10-18 14:06:16 +02:00
|
|
|
}
|
|
|
|
|
2010-10-21 09:55:43 +02:00
|
|
|
static void test__mbsnbcat_s(void)
|
|
|
|
{
|
|
|
|
unsigned char dest[16];
|
|
|
|
const unsigned char first[] = "dinosaur";
|
|
|
|
const unsigned char second[] = "duck";
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!p_mbsnbcat_s)
|
|
|
|
{
|
|
|
|
win_skip("Skipping _mbsnbcat_s tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test invalid arguments. */
|
|
|
|
ret = p_mbsnbcat_s(NULL, 0, NULL, 0);
|
|
|
|
ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(NULL, 10, NULL, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(NULL, 0, NULL, 10);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(dest, 0, NULL, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(dest, 0, second, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(dest[0] == 'X', "Expected the output buffer to be untouched\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), NULL, 10);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(dest[0] == '\0', "Expected the output buffer to be null terminated\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
dest[0] = '\0';
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
|
|
|
|
ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(dest, second, sizeof(second)),
|
|
|
|
"Expected the output buffer string to be \"duck\"\n");
|
|
|
|
|
|
|
|
/* Test source truncation behavior. */
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), second, 0);
|
|
|
|
ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(dest, first, sizeof(first)),
|
|
|
|
"Expected the output buffer string to be \"dinosaur\"\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second));
|
|
|
|
ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
|
|
|
|
"Expected the output buffer string to be \"dinosaurduck\"\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) + 1);
|
|
|
|
ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
|
|
|
|
"Expected the output buffer string to be \"dinosaurduck\"\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 1);
|
|
|
|
ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(dest, "dinosaurduck", sizeof("dinosaurduck")),
|
|
|
|
"Expected the output buffer string to be \"dinosaurduck\"\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(dest), second, sizeof(second) - 2);
|
|
|
|
ok(ret == 0, "Expected _mbsnbcat_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(dest, "dinosaurduc", sizeof("dinosaurduc")),
|
|
|
|
"Expected the output buffer string to be \"dinosaurduc\"\n");
|
|
|
|
|
|
|
|
/* Test destination truncation behavior. */
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(first) - 1, second, sizeof(second));
|
|
|
|
ok(ret == EINVAL, "Expected _mbsnbcat_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(!memcmp(dest, "\0inosaur", sizeof("\0inosaur") - 1),
|
|
|
|
"Expected the output buffer string to be \"\\0inosaur\" without ending null terminator\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(first), second, sizeof(second));
|
|
|
|
ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
|
|
|
|
ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
|
|
|
|
ok(!memcmp(dest, "\0inosaurd", sizeof("\0inosaurd") - 1),
|
|
|
|
"Expected the output buffer string to be \"\\0inosaurd\" without ending null terminator\n");
|
|
|
|
|
|
|
|
memset(dest, 'X', sizeof(dest));
|
|
|
|
memcpy(dest, first, sizeof(first));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsnbcat_s(dest, sizeof(first) + 1, second, sizeof(second));
|
|
|
|
ok(ret == ERANGE, "Expected _mbsnbcat_s to return ERANGE, got %d\n", ret);
|
|
|
|
ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
|
|
|
|
ok(!memcmp(dest, "\0inosaurdu", sizeof("\0inosaurdu") - 1),
|
|
|
|
"Expected the output buffer string to be \"\\0inosaurdu\" without ending null terminator\n");
|
|
|
|
}
|
|
|
|
|
2011-03-20 02:17:12 +01:00
|
|
|
static void test__mbsupr_s(void)
|
|
|
|
{
|
|
|
|
errno_t ret;
|
|
|
|
unsigned char buffer[20];
|
|
|
|
|
|
|
|
if (!p_mbsupr_s)
|
|
|
|
{
|
|
|
|
win_skip("Skipping _mbsupr_s tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsupr_s(NULL, 0);
|
|
|
|
ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsupr_s(NULL, sizeof(buffer));
|
|
|
|
ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsupr_s(buffer, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsupr_s(buffer, sizeof("abcdefgh"));
|
|
|
|
ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
|
|
|
|
"Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsupr_s(buffer, sizeof(buffer));
|
|
|
|
ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(buffer, "ABCDEFGH", sizeof("ABCDEFGH")),
|
|
|
|
"Expected the output buffer to be \"ABCDEFGH\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
memcpy(buffer, "abcdefgh", sizeof("abcdefgh"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsupr_s(buffer, 4);
|
|
|
|
ok(ret == EINVAL, "Expected _mbsupr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
memcpy(buffer, "abcdefgh\0ijklmnop", sizeof("abcdefgh\0ijklmnop"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbsupr_s(buffer, sizeof(buffer));
|
|
|
|
ok(ret == 0, "Expected _mbsupr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(buffer, "ABCDEFGH\0ijklmnop", sizeof("ABCDEFGH\0ijklmnop")),
|
|
|
|
"Expected the output buffer to be \"ABCDEFGH\\0ijklmnop\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-20 02:19:02 +01:00
|
|
|
static void test__mbslwr_s(void)
|
|
|
|
{
|
|
|
|
errno_t ret;
|
|
|
|
unsigned char buffer[20];
|
|
|
|
|
|
|
|
if (!p_mbslwr_s)
|
|
|
|
{
|
|
|
|
win_skip("Skipping _mbslwr_s tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbslwr_s(NULL, 0);
|
|
|
|
ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbslwr_s(NULL, sizeof(buffer));
|
|
|
|
ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbslwr_s(buffer, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbslwr_s(buffer, sizeof("ABCDEFGH"));
|
|
|
|
ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
|
|
|
|
"Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbslwr_s(buffer, sizeof(buffer));
|
|
|
|
ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(buffer, "abcdefgh", sizeof("abcdefgh")),
|
|
|
|
"Expected the output buffer to be \"abcdefgh\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
memcpy(buffer, "ABCDEFGH", sizeof("ABCDEFGH"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbslwr_s(buffer, 4);
|
|
|
|
ok(ret == EINVAL, "Expected _mbslwr_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
memcpy(buffer, "ABCDEFGH\0IJKLMNOP", sizeof("ABCDEFGH\0IJKLMNOP"));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_mbslwr_s(buffer, sizeof(buffer));
|
|
|
|
ok(ret == 0, "Expected _mbslwr_s to return 0, got %d\n", ret);
|
|
|
|
ok(!memcmp(buffer, "abcdefgh\0IJKLMNOP", sizeof("abcdefgh\0IJKLMNOP")),
|
|
|
|
"Expected the output buffer to be \"abcdefgh\\0IJKLMNOP\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
}
|
|
|
|
|
2013-06-21 12:17:43 +02:00
|
|
|
static void test__mbstok(void)
|
|
|
|
{
|
|
|
|
const unsigned char delim[] = "t";
|
|
|
|
|
|
|
|
char str[] = "!.!test";
|
|
|
|
unsigned char *ret;
|
|
|
|
|
|
|
|
strtok(str, "!");
|
|
|
|
|
|
|
|
ret = _mbstok(NULL, delim);
|
|
|
|
/* most versions of msvcrt use the same buffer for strtok and _mbstok */
|
|
|
|
ok(!ret || broken((char*)ret==str+4),
|
|
|
|
"_mbstok(NULL, \"t\") = %p, expected NULL (%p)\n", ret, str);
|
|
|
|
|
|
|
|
ret = _mbstok(NULL, delim);
|
|
|
|
ok(!ret, "_mbstok(NULL, \"t\") = %p, expected NULL\n", ret);
|
|
|
|
}
|
|
|
|
|
2010-10-21 09:57:44 +02:00
|
|
|
static void test__ultoa_s(void)
|
|
|
|
{
|
|
|
|
errno_t ret;
|
|
|
|
char buffer[33];
|
|
|
|
|
|
|
|
if (!p_ultoa_s)
|
|
|
|
{
|
|
|
|
win_skip("Skipping _ultoa_s tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_ultoa_s(0, NULL, 0, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_ultoa_s(0, buffer, 0, 0);
|
|
|
|
ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_ultoa_s(0, buffer, sizeof(buffer), 0);
|
|
|
|
ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_ultoa_s(0, buffer, sizeof(buffer), 64);
|
|
|
|
ok(ret == EINVAL, "Expected _ultoa_s to return EINVAL, got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
|
|
|
|
ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_ultoa_s(12345678, buffer, 4, 10);
|
|
|
|
ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
|
|
|
|
ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
|
|
|
|
ok(!memcmp(buffer, "\000765", 4),
|
|
|
|
"Expected the output buffer to be null terminated with truncated output\n");
|
|
|
|
|
|
|
|
memset(buffer, 'X', sizeof(buffer));
|
|
|
|
errno = EBADF;
|
|
|
|
ret = p_ultoa_s(12345678, buffer, 8, 10);
|
|
|
|
ok(ret == ERANGE, "Expected _ultoa_s to return ERANGE, got %d\n", ret);
|
|
|
|
ok(errno == ERANGE, "Expected errno to be ERANGE, got %d\n", errno);
|
|
|
|
ok(!memcmp(buffer, "\0007654321", 8),
|
|
|
|
"Expected the output buffer to be null terminated with truncated output\n");
|
|
|
|
|
|
|
|
ret = p_ultoa_s(12345678, buffer, 9, 10);
|
|
|
|
ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "12345678"),
|
|
|
|
"Expected output buffer string to be \"12345678\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
ret = p_ultoa_s(43690, buffer, sizeof(buffer), 2);
|
|
|
|
ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "1010101010101010"),
|
|
|
|
"Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
ret = p_ultoa_s(1092009, buffer, sizeof(buffer), 36);
|
|
|
|
ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "nell"),
|
|
|
|
"Expected output buffer string to be \"nell\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
ret = p_ultoa_s(5704, buffer, sizeof(buffer), 18);
|
|
|
|
ok(ret == 0, "Expected _ultoa_s to return 0, got %d\n", ret);
|
|
|
|
ok(!strcmp(buffer, "hag"),
|
|
|
|
"Expected output buffer string to be \"hag\", got \"%s\"\n",
|
|
|
|
buffer);
|
|
|
|
}
|
|
|
|
|
2011-04-05 23:47:22 +02:00
|
|
|
static void test_wctob(void)
|
|
|
|
{
|
2019-09-02 19:50:12 +02:00
|
|
|
int ret, cp = _getmbcp();
|
2011-04-05 23:47:22 +02:00
|
|
|
|
|
|
|
if(!p_wctob || !setlocale(LC_ALL, "chinese-traditional")) {
|
|
|
|
win_skip("Skipping wctob tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = p_wctob(0x8141);
|
|
|
|
ok(ret == EOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_wctob(0x81);
|
|
|
|
ok(ret == EOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_wctob(0xe0);
|
|
|
|
ok(ret == 0x61, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
_setmbcp(1250);
|
|
|
|
ret = p_wctob(0x81);
|
2011-10-12 11:55:35 +02:00
|
|
|
ok(ret == EOF, "ret = %x\n", ret);
|
2011-04-05 23:47:22 +02:00
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
ret = p_wctob(0x8141);
|
|
|
|
ok(ret == EOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_wctob(0x81);
|
2019-10-29 17:41:41 +01:00
|
|
|
ok(ret == (signed char)0x81, "ret = %x\n", ret);
|
2011-04-05 23:47:22 +02:00
|
|
|
|
2011-11-30 14:34:13 +01:00
|
|
|
ret = p_wctob(0x9f);
|
2019-10-29 17:41:41 +01:00
|
|
|
ok(ret == (signed char)0x9f, "ret = %x\n", ret);
|
2011-11-30 14:34:13 +01:00
|
|
|
|
2011-04-05 23:47:22 +02:00
|
|
|
ret = p_wctob(0xe0);
|
2019-10-29 17:41:41 +01:00
|
|
|
ok(ret == (signed char)0xe0, "ret = %x\n", ret);
|
2019-09-02 19:50:12 +02:00
|
|
|
|
|
|
|
_setmbcp(cp);
|
2011-04-05 23:47:22 +02:00
|
|
|
}
|
2019-09-02 19:50:12 +02:00
|
|
|
|
2020-01-28 23:08:13 +01:00
|
|
|
static void test_btowc(void)
|
|
|
|
{
|
|
|
|
wint_t ret;
|
|
|
|
int cp = _getmbcp();
|
|
|
|
|
|
|
|
if(!p_btowc || !setlocale(LC_ALL, "chinese-traditional")) {
|
|
|
|
win_skip("Skipping btowc tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = p_btowc(EOF);
|
|
|
|
ok(ret == WEOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x61);
|
|
|
|
ok(ret == 0x61, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x81);
|
|
|
|
ok(ret == WEOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0xe0);
|
|
|
|
ok(ret == WEOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
_setmbcp(1250);
|
|
|
|
ret = p_btowc(0x61);
|
|
|
|
ok(ret == 0x61, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x81);
|
|
|
|
ok(ret == WEOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0xe0);
|
|
|
|
ok(ret == WEOF, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
if(!setlocale(LC_CTYPE, ".1250")) {
|
|
|
|
win_skip("No codepage 1250 support\n");
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
_setmbcp(cp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = p_btowc(0x61);
|
|
|
|
ok(ret == 0x61, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x81);
|
|
|
|
ok(ret == 0x81, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0xe0);
|
|
|
|
ok(ret == 0x155, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x100);
|
|
|
|
ok(ret == 0x00, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x1e0);
|
|
|
|
ok(ret == 0x155, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
ret = p_btowc(0x61);
|
|
|
|
ok(ret == 0x61, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x81);
|
|
|
|
ok(ret == 0x81, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x9f);
|
|
|
|
ok(ret == 0x9f, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0xe0);
|
|
|
|
ok(ret == 0xe0, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x100);
|
|
|
|
ok(ret == 0x00, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_btowc(0x1e0);
|
|
|
|
ok(ret == 0xe0, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
_setmbcp(cp);
|
|
|
|
}
|
|
|
|
|
2012-11-29 22:49:58 +01:00
|
|
|
static void test_wctomb(void)
|
|
|
|
{
|
|
|
|
mbstate_t state;
|
|
|
|
unsigned char dst[10];
|
|
|
|
size_t ret;
|
2019-09-30 19:09:14 +02:00
|
|
|
int err;
|
2012-11-29 22:49:58 +01:00
|
|
|
|
|
|
|
if(!p_wcrtomb || !setlocale(LC_ALL, "Japanese_Japan.932")) {
|
|
|
|
win_skip("wcrtomb tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = p_wcrtomb(NULL, 0x3042, NULL);
|
|
|
|
ok(ret == 2, "wcrtomb did not return 2\n");
|
|
|
|
|
|
|
|
state = 1;
|
|
|
|
dst[2] = 'a';
|
|
|
|
ret = p_wcrtomb((char*)dst, 0x3042, &state);
|
|
|
|
ok(ret == 2, "wcrtomb did not return 2\n");
|
|
|
|
ok(state == 0, "state != 0\n");
|
|
|
|
ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
|
|
|
|
ok(dst[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst[1]);
|
|
|
|
ok(dst[2] == 'a', "dst[2] != 'a'\n");
|
|
|
|
|
|
|
|
ret = p_wcrtomb((char*)dst, 0x3043, NULL);
|
|
|
|
ok(ret == 2, "wcrtomb did not return 2\n");
|
|
|
|
ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
|
|
|
|
ok(dst[1] == 0xa1, "dst[1] = %x, expected 0xa1\n", dst[1]);
|
|
|
|
|
|
|
|
ret = p_wcrtomb((char*)dst, 0x20, NULL);
|
|
|
|
ok(ret == 1, "wcrtomb did not return 1\n");
|
|
|
|
ok(dst[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst[0]);
|
|
|
|
|
|
|
|
ret = p_wcrtomb((char*)dst, 0xffff, NULL);
|
|
|
|
ok(ret == -1, "wcrtomb did not return -1\n");
|
2013-07-25 10:14:33 +02:00
|
|
|
ok(dst[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst[0]);
|
2012-11-29 22:49:58 +01:00
|
|
|
|
2019-09-30 19:09:14 +02:00
|
|
|
if(!p_wcrtomb_s) {
|
|
|
|
win_skip("wcrtomb_s tests\n");
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = 1;
|
|
|
|
dst[2] = 'a';
|
|
|
|
err = p_wcrtomb_s(&ret, (char*)dst, sizeof(dst), 0x3042, &state);
|
|
|
|
ok(!err, "err = %d\n", err);
|
|
|
|
ok(ret == 2, "ret != 2\n");
|
|
|
|
ok(!state, "state != 0\n");
|
|
|
|
ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
|
|
|
|
ok(dst[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst[1]);
|
|
|
|
ok(dst[2] == 'a', "dst[2] != 'a'\n");
|
|
|
|
|
|
|
|
err = p_wcrtomb_s(&ret, (char*)dst, sizeof(dst), 0x3042, NULL);
|
|
|
|
ok(!err, "err = %d\n", err);
|
|
|
|
ok(ret == 2, "ret != 2\n");
|
|
|
|
ok(!state, "state != 0\n");
|
|
|
|
ok(dst[0] == 0x82, "dst[0] = %x, expected 0x82\n", dst[0]);
|
|
|
|
ok(dst[1] == 0xa0, "dst[1] = %x, expected 0xa0\n", dst[1]);
|
|
|
|
|
|
|
|
err = p_wcrtomb_s(&ret, (char*)dst, sizeof(dst), 0x20, NULL);
|
|
|
|
ok(!err, "err = %d\n", err);
|
|
|
|
ok(ret == 1, "ret != 1\n");
|
|
|
|
ok(dst[0] == 0x20, "dst[0] = %x, expected 0x20\n", dst[0]);
|
|
|
|
|
|
|
|
err = p_wcrtomb_s(&ret, NULL, 0, 0x20, NULL);
|
|
|
|
ok(!err, "err = %d\n", err);
|
|
|
|
ok(ret == 1, "ret != 1\n");
|
|
|
|
|
|
|
|
err = p_wcrtomb_s(&ret, (char*)dst, sizeof(dst), 0xffff, NULL);
|
|
|
|
ok(err == EILSEQ, "err = %d\n", err);
|
|
|
|
ok(ret == -1, "wcrtomb did not return -1\n");
|
|
|
|
ok(dst[0] == 0x3f, "dst[0] = %x, expected 0x3f\n", dst[0]);
|
|
|
|
|
2012-11-29 22:49:58 +01:00
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
}
|
2011-04-05 23:47:22 +02:00
|
|
|
|
2011-06-03 15:28:56 +02:00
|
|
|
static void test_tolower(void)
|
|
|
|
{
|
2015-09-12 13:15:27 +02:00
|
|
|
WCHAR chw, lower;
|
2014-03-13 14:12:53 +01:00
|
|
|
char ch, lch;
|
|
|
|
int ret, len;
|
2011-06-03 15:28:56 +02:00
|
|
|
|
2014-03-13 14:12:53 +01:00
|
|
|
/* test C locale when locale was never changed */
|
2011-06-03 15:28:56 +02:00
|
|
|
ret = p_tolower(0x41);
|
|
|
|
ok(ret == 0x61, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ret = p_tolower(0xF4);
|
|
|
|
ok(ret == 0xF4, "ret = %x\n", ret);
|
|
|
|
|
2014-03-13 14:12:53 +01:00
|
|
|
errno = 0xdeadbeef;
|
2011-06-03 15:28:56 +02:00
|
|
|
ret = p_tolower((char)0xF4);
|
2019-01-23 11:59:05 +01:00
|
|
|
ok(ret == (char)0xF4, "ret = %x\n", ret);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
|
2011-06-03 15:28:56 +02:00
|
|
|
|
2014-03-13 14:12:53 +01:00
|
|
|
errno = 0xdeadbeef;
|
2011-06-03 15:28:56 +02:00
|
|
|
ret = p_tolower((char)0xD0);
|
2019-01-23 11:59:05 +01:00
|
|
|
ok(ret == (char)0xD0, "ret = %x\n", ret);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p_tolower((char)0xF4);
|
|
|
|
ok(ret == (char)0xF4, "ret = %x\n", ret);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
|
2011-06-03 15:28:56 +02:00
|
|
|
|
2014-03-13 14:12:53 +01:00
|
|
|
/* test C locale after setting locale */
|
2011-06-03 15:28:56 +02:00
|
|
|
if(!setlocale(LC_ALL, "us")) {
|
|
|
|
win_skip("skipping tolower tests that depends on locale\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-03-13 14:12:53 +01:00
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
|
|
|
|
ch = 0xF4;
|
|
|
|
errno = 0xdeadbeef;
|
2019-10-31 09:14:17 +01:00
|
|
|
ret = p_tolower((signed char)ch);
|
2015-09-12 13:15:27 +02:00
|
|
|
if(!MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, &ch, 1, &chw, 1) ||
|
|
|
|
LCMapStringW(CP_ACP, LCMAP_LOWERCASE, &chw, 1, &lower, 1) != 1 ||
|
|
|
|
(len = WideCharToMultiByte(CP_ACP, 0, &lower, 1, &lch, 1, NULL, NULL)) != 1)
|
|
|
|
len = 0;
|
2014-03-13 14:12:53 +01:00
|
|
|
if(len)
|
|
|
|
ok(ret==(unsigned char)lch || broken(ret==ch)/*WinXP-*/, "ret = %x\n", ret);
|
|
|
|
else
|
|
|
|
ok(ret == ch, "ret = %x\n", ret);
|
|
|
|
if(!len || ret==(unsigned char)lch)
|
|
|
|
ok(errno == EILSEQ, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
ch = 0xD0;
|
|
|
|
errno = 0xdeadbeef;
|
2019-10-31 09:14:17 +01:00
|
|
|
ret = p_tolower((signed char)ch);
|
2015-09-12 13:15:27 +02:00
|
|
|
if(!MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, &ch, 1, &chw, 1) ||
|
|
|
|
LCMapStringW(CP_ACP, LCMAP_LOWERCASE, &chw, 1, &lower, 1) != 1 ||
|
|
|
|
(len = WideCharToMultiByte(CP_ACP, 0, &lower, 1, &lch, 1, NULL, NULL)) != 1)
|
|
|
|
len = 0;
|
2014-03-13 14:12:53 +01:00
|
|
|
if(len)
|
|
|
|
ok(ret==(unsigned char)lch || broken(ret==ch)/*WinXP-*/, "ret = %x\n", ret);
|
|
|
|
else
|
|
|
|
ok(ret == ch, "ret = %x\n", ret);
|
|
|
|
if(!len || ret==(unsigned char)lch)
|
|
|
|
ok(errno == EILSEQ, "errno = %d\n", errno);
|
|
|
|
|
2019-10-31 09:14:17 +01:00
|
|
|
ret = p_tolower((unsigned char)0xD0);
|
2014-03-13 14:12:53 +01:00
|
|
|
ok(ret == 0xD0, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
ok(setlocale(LC_ALL, "us") != NULL, "setlocale failed\n");
|
2011-06-03 15:28:56 +02:00
|
|
|
|
2019-10-31 09:14:17 +01:00
|
|
|
ret = p_tolower((signed char)0xD0);
|
2011-06-03 15:28:56 +02:00
|
|
|
ok(ret == 0xF0, "ret = %x\n", ret);
|
|
|
|
|
2019-10-31 09:14:17 +01:00
|
|
|
ret = p_tolower((unsigned char)0xD0);
|
2011-06-03 15:28:56 +02:00
|
|
|
ok(ret == 0xF0, "ret = %x\n", ret);
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
}
|
|
|
|
|
2019-12-18 23:48:11 +01:00
|
|
|
static double mul_pow10(double x, double exp)
|
|
|
|
{
|
|
|
|
int fpexcept = _EM_DENORMAL|_EM_INVALID|_EM_ZERODIVIDE|_EM_OVERFLOW|_EM_UNDERFLOW|_EM_INEXACT;
|
|
|
|
BOOL negexp = (exp < 0);
|
|
|
|
int fpcontrol;
|
|
|
|
double ret;
|
|
|
|
|
|
|
|
if(negexp)
|
|
|
|
exp = -exp;
|
|
|
|
fpcontrol = _control87(0, 0);
|
|
|
|
_control87(fpexcept, 0xffffffff);
|
|
|
|
ret = pow(10.0, exp);
|
|
|
|
ret = (negexp ? x/ret : x*ret);
|
|
|
|
_control87(fpcontrol, 0xffffffff);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:19:19 +01:00
|
|
|
static void test__atodbl(void)
|
|
|
|
{
|
|
|
|
_CRT_DOUBLE d;
|
|
|
|
char num[32];
|
2019-12-18 23:48:11 +01:00
|
|
|
int i, j, ret;
|
2012-12-17 15:19:19 +01:00
|
|
|
|
|
|
|
if(!p__atodbl_l) {
|
|
|
|
/* Old versions of msvcrt use different values for _OVERFLOW and _UNDERFLOW
|
|
|
|
* Because of this lets skip _atodbl tests when _atodbl_l is not available */
|
|
|
|
win_skip("_atodbl_l is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
num[0] = 0;
|
|
|
|
ret = p__atodbl_l(&d, num, NULL);
|
|
|
|
ok(ret == 0, "_atodbl_l(&d, \"\", NULL) returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
|
|
|
|
ret = _atodbl(&d, num);
|
|
|
|
ok(ret == 0, "_atodbl(&d, \"\") returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
|
|
|
|
|
|
|
|
strcpy(num, "t");
|
|
|
|
ret = p__atodbl_l(&d, num, NULL);
|
|
|
|
ok(ret == 0, "_atodbl_l(&d, \"t\", NULL) returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
|
|
|
|
ret = _atodbl(&d, num);
|
|
|
|
ok(ret == 0, "_atodbl(&d, \"t\") returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
|
|
|
|
|
|
|
|
strcpy(num, "0");
|
|
|
|
ret = p__atodbl_l(&d, num, NULL);
|
|
|
|
ok(ret == 0, "_atodbl_l(&d, \"0\", NULL) returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
|
|
|
|
ret = _atodbl(&d, num);
|
|
|
|
ok(ret == 0, "_atodbl(&d, \"0\") returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 0, "d.x = %lf, expected 0\n", d.x);
|
|
|
|
|
|
|
|
strcpy(num, "123");
|
|
|
|
ret = p__atodbl_l(&d, num, NULL);
|
|
|
|
ok(ret == 0, "_atodbl_l(&d, \"123\", NULL) returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 123, "d.x = %lf, expected 123\n", d.x);
|
|
|
|
ret = _atodbl(&d, num);
|
|
|
|
ok(ret == 0, "_atodbl(&d, \"123\") returned %d, expected 0\n", ret);
|
|
|
|
ok(d.x == 123, "d.x = %lf, expected 123\n", d.x);
|
|
|
|
|
2019-12-18 23:48:11 +01:00
|
|
|
/* check over the whole range of (simple) normal doubles */
|
|
|
|
for (j = DBL_MIN_10_EXP; j <= DBL_MAX_10_EXP; j++) {
|
|
|
|
for (i = 1; i <= 9; i++) {
|
|
|
|
double expected = mul_pow10(i, j);
|
|
|
|
if (expected < DBL_MIN || expected > DBL_MAX) continue;
|
|
|
|
snprintf(num, sizeof(num), "%de%d", i, j);
|
|
|
|
ret = _atodbl(&d, num);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(compare_double(d.x, expected, 2), "d.x = %.16e, expected %.16e\n", d.x, expected);
|
2019-12-18 23:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check with denormal doubles */
|
2012-12-17 15:19:19 +01:00
|
|
|
strcpy(num, "1e-309");
|
|
|
|
ret = p__atodbl_l(&d, num, NULL);
|
|
|
|
ok(ret == _UNDERFLOW, "_atodbl_l(&d, \"1e-309\", NULL) returned %d, expected _UNDERFLOW\n", ret);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(compare_double(d.x, 1e-309, 1), "d.x = %.16e, expected 0\n", d.x);
|
2012-12-17 15:19:19 +01:00
|
|
|
ret = _atodbl(&d, num);
|
|
|
|
ok(ret == _UNDERFLOW, "_atodbl(&d, \"1e-309\") returned %d, expected _UNDERFLOW\n", ret);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(compare_double(d.x, 1e-309, 1), "d.x = %.16e, expected 0\n", d.x);
|
2012-12-17 15:19:19 +01:00
|
|
|
|
|
|
|
strcpy(num, "1e309");
|
|
|
|
ret = p__atodbl_l(&d, num, NULL);
|
|
|
|
ok(ret == _OVERFLOW, "_atodbl_l(&d, \"1e309\", NULL) returned %d, expected _OVERFLOW\n", ret);
|
|
|
|
ret = _atodbl(&d, num);
|
|
|
|
ok(ret == _OVERFLOW, "_atodbl(&d, \"1e309\") returned %d, expected _OVERFLOW\n", ret);
|
|
|
|
}
|
|
|
|
|
2012-12-24 12:10:21 +01:00
|
|
|
static void test__stricmp(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = _stricmp("test", "test");
|
|
|
|
ok(ret == 0, "_stricmp returned %d\n", ret);
|
|
|
|
ret = _stricmp("a", "z");
|
|
|
|
ok(ret < 0, "_stricmp returned %d\n", ret);
|
|
|
|
ret = _stricmp("z", "a");
|
|
|
|
ok(ret > 0, "_stricmp returned %d\n", ret);
|
|
|
|
ret = _stricmp("\xa5", "\xb9");
|
|
|
|
ok(ret < 0, "_stricmp returned %d\n", ret);
|
|
|
|
|
|
|
|
if(!setlocale(LC_ALL, "polish")) {
|
2013-01-05 16:17:42 +01:00
|
|
|
win_skip("stricmp tests\n");
|
2012-12-24 12:10:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = _stricmp("test", "test");
|
|
|
|
ok(ret == 0, "_stricmp returned %d\n", ret);
|
|
|
|
ret = _stricmp("a", "z");
|
|
|
|
ok(ret < 0, "_stricmp returned %d\n", ret);
|
|
|
|
ret = _stricmp("z", "a");
|
|
|
|
ok(ret > 0, "_stricmp returned %d\n", ret);
|
|
|
|
ret = _stricmp("\xa5", "\xb9");
|
|
|
|
ok(ret == 0, "_stricmp returned %d\n", ret);
|
2014-09-03 14:43:02 +02:00
|
|
|
ret = _stricmp("a", "\xb9");
|
|
|
|
ok(ret < 0, "_stricmp returned %d\n", ret);
|
2012-12-24 12:10:21 +01:00
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
}
|
|
|
|
|
2013-03-09 08:56:38 +01:00
|
|
|
static void test__wcstoi64(void)
|
|
|
|
{
|
2019-12-17 14:16:48 +01:00
|
|
|
static const struct { WCHAR str[24]; __int64 res; unsigned __int64 ures; int base; } tests[] =
|
|
|
|
{
|
|
|
|
{ L"9", 9, 9, 10 },
|
|
|
|
{ L" ", 0, 0 },
|
|
|
|
{ L"-1234", -1234, -1234 },
|
2020-03-11 09:28:59 +01:00
|
|
|
{ L"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
|
|
|
|
{ L"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
|
2019-12-17 14:16:48 +01:00
|
|
|
{ { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
|
|
|
|
{ { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
|
|
|
|
{ { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
|
|
|
|
{ { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
|
|
|
|
{ { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
|
|
|
|
{ { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
|
|
|
|
{ { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
|
|
|
|
{ { '+',0x0e50,0xff17,'1' }, 071, 071 },
|
|
|
|
{ { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
|
|
|
|
{ L"4294967295", 4294967295, 4294967295 },
|
|
|
|
{ L"4294967296", 4294967296, 4294967296 },
|
|
|
|
{ L"9223372036854775807", 9223372036854775807, 9223372036854775807 },
|
|
|
|
{ L"9223372036854775808", _I64_MAX, 9223372036854775808u },
|
|
|
|
{ L"18446744073709551615", _I64_MAX, _UI64_MAX },
|
|
|
|
{ L"18446744073709551616", _I64_MAX, _UI64_MAX },
|
|
|
|
{ L"-4294967295", -4294967295, -4294967295 },
|
|
|
|
{ L"-4294967296", -4294967296, -4294967296 },
|
|
|
|
{ L"-9223372036854775807", -9223372036854775807, -9223372036854775807 },
|
|
|
|
{ L"-9223372036854775808", _I64_MIN, 9223372036854775808u },
|
|
|
|
{ L"-18446744073709551615", _I64_MIN, 1 },
|
|
|
|
{ L"-18446744073709551616", _I64_MIN, 1 },
|
|
|
|
};
|
2017-01-25 16:02:23 +01:00
|
|
|
static const WCHAR zeros[] = {
|
|
|
|
0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
|
|
|
|
0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
|
|
|
|
};
|
|
|
|
int i;
|
2013-03-09 08:56:38 +01:00
|
|
|
|
|
|
|
__int64 res;
|
|
|
|
unsigned __int64 ures;
|
|
|
|
WCHAR *endpos;
|
|
|
|
|
|
|
|
if (!p_wcstoi64 || !p_wcstoui64) {
|
|
|
|
win_skip("_wcstoi64 or _wcstoui64 not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-17 14:16:48 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++)
|
|
|
|
{
|
|
|
|
res = p_wcstoi64( tests[i].str, &endpos, tests[i].base );
|
|
|
|
ok( res == tests[i].res, "%u: %s res %s\n",
|
|
|
|
i, wine_dbgstr_w(tests[i].str), wine_dbgstr_longlong(res) );
|
|
|
|
if (!res) ok( endpos == tests[i].str, "%u: wrong endpos %p/%p\n", i, endpos, tests[i].str );
|
|
|
|
ures = p_wcstoui64( tests[i].str, &endpos, tests[i].base );
|
|
|
|
ok( ures == tests[i].ures, "%u: %s res %s\n",
|
|
|
|
i, wine_dbgstr_w(tests[i].str), wine_dbgstr_longlong(ures) );
|
|
|
|
}
|
2017-01-25 16:02:23 +01:00
|
|
|
|
|
|
|
/* Test various unicode digits */
|
2018-06-20 23:35:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(zeros); ++i) {
|
2017-01-25 16:02:23 +01:00
|
|
|
WCHAR tmp[] = {zeros[i] + 4, zeros[i], zeros[i] + 5, 0};
|
|
|
|
res = p_wcstoi64(tmp, NULL, 0);
|
2017-01-25 16:02:25 +01:00
|
|
|
ok(res == 405, "with zero = U+%04X: got %d, expected 405\n", zeros[i], (int)res);
|
2017-01-25 16:02:23 +01:00
|
|
|
tmp[1] = zeros[i] + 10;
|
|
|
|
res = p_wcstoi64(tmp, NULL, 16);
|
2017-01-25 16:02:25 +01:00
|
|
|
ok(res == 4, "with zero = U+%04X: got %d, expected 4\n", zeros[i], (int)res);
|
2017-01-25 16:02:23 +01:00
|
|
|
}
|
2013-03-09 08:56:38 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 15:27:31 +01:00
|
|
|
static void test__wcstol(void)
|
|
|
|
{
|
|
|
|
static const struct { WCHAR str[24]; long res; unsigned long ures; int base; } tests[] =
|
|
|
|
{
|
|
|
|
{ L"9", 9, 9, 10 },
|
|
|
|
{ L" ", 0, 0 },
|
|
|
|
{ L"-1234", -1234, -1234 },
|
2020-03-11 09:28:59 +01:00
|
|
|
{ L"\x09\x0a\x0b\x0c\x0d -123", -123, -123 },
|
|
|
|
{ L"\xa0\x2002\x2003\x2028\x3000 +44", 44, 44 },
|
2019-12-17 15:27:31 +01:00
|
|
|
{ { 0x3231 }, 0, 0 }, /* PARENTHESIZED IDEOGRAPH STOCK */
|
|
|
|
{ { 0x4e00 }, 0, 0 }, /* CJK Ideograph, First */
|
|
|
|
{ { 0x0bef }, 0, 0 }, /* TAMIL DIGIT NINE */
|
|
|
|
{ { 0x0e59 }, 9, 9 }, /* THAI DIGIT NINE */
|
|
|
|
{ { 0xff19 }, 9, 9 }, /* FULLWIDTH DIGIT NINE */
|
|
|
|
{ { 0x00b9 }, 0, 0 }, /* SUPERSCRIPT ONE */
|
|
|
|
{ { '-',0x0e50,'x',0xff19,'1' }, -0x91, -0x91 },
|
|
|
|
{ { '+',0x0e50,0xff17,'1' }, 071, 071 },
|
|
|
|
{ { 0xff19,'f',0x0e59,0xff46 }, 0x9f9, 0x9f9, 16 },
|
|
|
|
{ L"2147483647", 2147483647, 2147483647 },
|
|
|
|
{ L"2147483648", LONG_MAX, 2147483648 },
|
|
|
|
{ L"4294967295", LONG_MAX, 4294967295 },
|
|
|
|
{ L"4294967296", LONG_MAX, ULONG_MAX },
|
|
|
|
{ L"9223372036854775807", LONG_MAX, ULONG_MAX },
|
|
|
|
{ L"-2147483647", -2147483647, -2147483647 },
|
|
|
|
{ L"-2147483648", LONG_MIN, LONG_MIN },
|
|
|
|
{ L"-4294967295", LONG_MIN, 1 },
|
|
|
|
{ L"-4294967296", LONG_MIN, 1 },
|
|
|
|
{ L"-9223372036854775807", LONG_MIN, 1 },
|
|
|
|
};
|
|
|
|
static const WCHAR zeros[] = {
|
|
|
|
0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
|
|
|
|
0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
long res;
|
|
|
|
unsigned long ures;
|
|
|
|
WCHAR *endpos;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++)
|
|
|
|
{
|
|
|
|
res = wcstol( tests[i].str, &endpos, tests[i].base );
|
|
|
|
ok( res == tests[i].res, "%u: %s res %08lx\n",
|
|
|
|
i, wine_dbgstr_w(tests[i].str), res );
|
|
|
|
if (!res) ok( endpos == tests[i].str, "%u: wrong endpos %p/%p\n", i, endpos, tests[i].str );
|
|
|
|
ures = wcstoul( tests[i].str, &endpos, tests[i].base );
|
|
|
|
ok( ures == tests[i].ures, "%u: %s res %08lx\n",
|
|
|
|
i, wine_dbgstr_w(tests[i].str), ures );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test various unicode digits */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(zeros); ++i) {
|
|
|
|
WCHAR tmp[] = {zeros[i] + 4, zeros[i], zeros[i] + 5, 0};
|
|
|
|
res = wcstol(tmp, NULL, 0);
|
|
|
|
ok(res == 405, "with zero = U+%04X: got %d, expected 405\n", zeros[i], (int)res);
|
|
|
|
tmp[1] = zeros[i] + 10;
|
|
|
|
res = wcstol(tmp, NULL, 16);
|
|
|
|
ok(res == 4, "with zero = U+%04X: got %d, expected 4\n", zeros[i], (int)res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 15:52:10 +02:00
|
|
|
static void test_atoi(void)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = atoi("0");
|
|
|
|
ok(r == 0, "atoi(0) = %d\n", r);
|
|
|
|
|
|
|
|
r = atoi("-1");
|
|
|
|
ok(r == -1, "atoi(-1) = %d\n", r);
|
|
|
|
|
|
|
|
r = atoi("1");
|
|
|
|
ok(r == 1, "atoi(1) = %d\n", r);
|
|
|
|
|
|
|
|
r = atoi("4294967296");
|
|
|
|
ok(r == 0, "atoi(4294967296) = %d\n", r);
|
|
|
|
}
|
|
|
|
|
2019-03-16 14:49:08 +01:00
|
|
|
static void test_atol(void)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = atol("0");
|
|
|
|
ok(r == 0, "atol(0) = %d\n", r);
|
|
|
|
|
|
|
|
r = atol("-1");
|
|
|
|
ok(r == -1, "atol(-1) = %d\n", r);
|
|
|
|
|
|
|
|
r = atol("1");
|
|
|
|
ok(r == 1, "atol(1) = %d\n", r);
|
|
|
|
|
|
|
|
r = atol("4294967296");
|
|
|
|
ok(r == 0, "atol(4294967296) = %d\n", r);
|
|
|
|
}
|
|
|
|
|
2015-06-29 03:42:21 +02:00
|
|
|
static void test_atof(void)
|
|
|
|
{
|
|
|
|
double d;
|
|
|
|
|
|
|
|
d = atof("0.0");
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 0.0, "d = %lf\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
|
|
|
|
d = atof("1.0");
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 1.0, "d = %lf\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
|
|
|
|
d = atof("-1.0");
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == -1.0, "d = %lf\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
|
|
|
|
if (!p__atof_l)
|
|
|
|
{
|
|
|
|
win_skip("_atof_l not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
d = atof(NULL);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 0.0, "d = %lf\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
ok(errno == EINVAL, "errno = %x\n", errno);
|
|
|
|
|
|
|
|
errno = EBADF;
|
|
|
|
d = p__atof_l(NULL, NULL);
|
2019-12-26 18:30:48 +01:00
|
|
|
ok(d == 0.0, "d = %lf\n", d);
|
2015-06-29 03:42:21 +02:00
|
|
|
ok(errno == EINVAL, "errno = %x\n", errno);
|
|
|
|
}
|
|
|
|
|
2013-08-13 21:47:20 +02:00
|
|
|
static void test_strncpy(void)
|
|
|
|
{
|
|
|
|
#define TEST_STRNCPY_LEN 10
|
2019-04-10 19:11:18 +02:00
|
|
|
/* use function pointer to bypass gcc builtin */
|
|
|
|
char *(__cdecl *p_strncpy)(char*,const char*,size_t);
|
2013-08-13 21:47:20 +02:00
|
|
|
char *ret;
|
|
|
|
char dst[TEST_STRNCPY_LEN + 1];
|
|
|
|
char not_null_terminated[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
|
|
|
|
|
2019-04-10 19:11:18 +02:00
|
|
|
p_strncpy = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "strncpy");
|
|
|
|
|
2013-08-13 21:47:20 +02:00
|
|
|
/* strlen(src) > TEST_STRNCPY_LEN */
|
2019-04-10 19:11:18 +02:00
|
|
|
ret = p_strncpy(dst, "01234567890123456789", TEST_STRNCPY_LEN);
|
2013-08-13 21:47:20 +02:00
|
|
|
ok(ret == dst, "ret != dst\n");
|
|
|
|
ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
|
|
|
|
|
|
|
|
/* without null-terminated */
|
2019-04-10 19:11:18 +02:00
|
|
|
ret = p_strncpy(dst, not_null_terminated, TEST_STRNCPY_LEN);
|
2013-08-13 21:47:20 +02:00
|
|
|
ok(ret == dst, "ret != dst\n");
|
|
|
|
ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
|
|
|
|
|
|
|
|
/* strlen(src) < TEST_STRNCPY_LEN */
|
|
|
|
strcpy(dst, "0123456789");
|
2019-04-10 19:11:18 +02:00
|
|
|
ret = p_strncpy(dst, "012345", TEST_STRNCPY_LEN);
|
2013-08-13 21:47:20 +02:00
|
|
|
ok(ret == dst, "ret != dst\n");
|
|
|
|
ok(!strcmp(dst, "012345"), "dst != 012345\n");
|
|
|
|
ok(dst[TEST_STRNCPY_LEN - 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n");
|
|
|
|
|
|
|
|
/* strlen(src) == TEST_STRNCPY_LEN */
|
2019-04-10 19:11:18 +02:00
|
|
|
ret = p_strncpy(dst, "0123456789", TEST_STRNCPY_LEN);
|
2013-08-13 21:47:20 +02:00
|
|
|
ok(ret == dst, "ret != dst\n");
|
|
|
|
ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:52:40 +02:00
|
|
|
static void test_strxfrm(void)
|
|
|
|
{
|
|
|
|
char dest[256];
|
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
/* crashes on old version of msvcrt */
|
|
|
|
if(p__atodbl_l) {
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = strxfrm(NULL, "src", 1);
|
|
|
|
ok(ret == INT_MAX, "ret = %d\n", (int)ret);
|
|
|
|
ok(errno == EINVAL, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = strxfrm(dest, NULL, 100);
|
|
|
|
ok(ret == INT_MAX, "ret = %d\n", (int)ret);
|
|
|
|
ok(errno == EINVAL, "errno = %d\n", errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = strxfrm(NULL, "src", 0);
|
|
|
|
ok(ret == 3, "ret = %d\n", (int)ret);
|
|
|
|
dest[0] = 'a';
|
|
|
|
ret = strxfrm(dest, "src", 0);
|
|
|
|
ok(ret == 3, "ret = %d\n", (int)ret);
|
|
|
|
ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
|
|
|
|
|
|
|
|
dest[3] = 'a';
|
|
|
|
ret = strxfrm(dest, "src", 5);
|
|
|
|
ok(ret == 3, "ret = %d\n", (int)ret);
|
|
|
|
ok(!strcmp(dest, "src"), "dest = %s\n", dest);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
dest[1] = 'a';
|
|
|
|
ret = strxfrm(dest, "src", 1);
|
|
|
|
ok(ret == 3, "ret = %d\n", (int)ret);
|
|
|
|
ok(dest[0] == 's', "dest[0] = %d\n", dest[0]);
|
|
|
|
ok(dest[1] == 'a', "dest[1] = %d\n", dest[1]);
|
|
|
|
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
|
|
|
|
|
|
|
|
ret = strxfrm(dest, "", 5);
|
|
|
|
ok(ret == 0, "ret = %d\n", (int)ret);
|
|
|
|
ok(!dest[0], "dest[0] = %d\n", dest[0]);
|
|
|
|
|
|
|
|
if(!setlocale(LC_ALL, "polish")) {
|
|
|
|
win_skip("stxfrm tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = strxfrm(NULL, "src", 0);
|
|
|
|
ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
|
|
|
|
dest[0] = 'a';
|
|
|
|
ret = strxfrm(dest, "src", 0);
|
|
|
|
ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
|
|
|
|
ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
|
|
|
|
|
|
|
|
ret = strxfrm(dest, "src", ret+1);
|
|
|
|
ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
|
|
|
|
ok(dest[0], "dest[0] = 0\n");
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
dest[0] = 'a';
|
|
|
|
ret = strxfrm(dest, "src", 5);
|
|
|
|
ok(ret>5 && ret<sizeof(dest)-1, "ret = %d\n", (int)ret);
|
|
|
|
ok(!dest[0] || broken(!p__atodbl_l && dest[0]=='a'), "dest[0] = %d\n", dest[0]);
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
}
|
|
|
|
|
2014-09-02 13:50:44 +02:00
|
|
|
static void test__strnset_s(void)
|
|
|
|
{
|
|
|
|
char buf[5] = {0};
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if(!p__strnset_s) {
|
|
|
|
win_skip("_strnset_s not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = p__strnset_s(NULL, 0, 'a', 0);
|
|
|
|
ok(r == 0, "r = %d\n", r);
|
|
|
|
|
|
|
|
buf[0] = buf[1] = buf[2] = 'b';
|
|
|
|
r = p__strnset_s(buf, sizeof(buf), 'a', 2);
|
|
|
|
ok(r == 0, "r = %d\n", r);
|
|
|
|
ok(!strcmp(buf, "aab"), "buf = %s\n", buf);
|
|
|
|
|
|
|
|
r = p__strnset_s(buf, 0, 'a', 0);
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
|
|
|
|
r = p__strnset_s(NULL, 0, 'a', 1);
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
|
|
|
|
buf[3] = 'b';
|
|
|
|
r = p__strnset_s(buf, sizeof(buf)-1, 'c', 2);
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
ok(!buf[0] && buf[1]=='c' && buf[2]=='b', "buf = %s\n", buf);
|
|
|
|
}
|
|
|
|
|
2019-04-01 19:57:07 +02:00
|
|
|
static void test__wcsnset_s(void)
|
|
|
|
{
|
|
|
|
wchar_t text[] = { 't','e','x','t',0 };
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if(!p__wcsnset_s) {
|
|
|
|
win_skip("_wcsnset_s not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = p__wcsnset_s(NULL, 0, 'a', 0);
|
|
|
|
ok(r == 0, "r = %d\n", r);
|
|
|
|
|
|
|
|
r = p__wcsnset_s(text, 0, 'a', 1);
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
ok(text[0] == 't', "text[0] = %d\n", text[0]);
|
|
|
|
|
|
|
|
r = p__wcsnset_s(NULL, 2, 'a', 1);
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
|
|
|
|
r = p__wcsnset_s(text, 2, 'a', 3);
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
ok(text[0] == 0, "text[0] = %d\n", text[0]);
|
|
|
|
ok(text[1] == 'e', "text[1] = %d\n", text[1]);
|
|
|
|
|
|
|
|
text[0] = 't';
|
|
|
|
r = p__wcsnset_s(text, 5, 'a', 1);
|
|
|
|
ok(r == 0, "r = %d\n", r);
|
|
|
|
ok(text[0] == 'a', "text[0] = %d\n", text[0]);
|
|
|
|
ok(text[1] == 'e', "text[1] = %d\n", text[1]);
|
|
|
|
|
|
|
|
text[1] = 0;
|
|
|
|
r = p__wcsnset_s(text, 5, 'b', 3);
|
|
|
|
ok(r == 0, "r = %d\n", r);
|
|
|
|
ok(text[0] == 'b', "text[0] = %d\n", text[0]);
|
|
|
|
ok(text[1] == 0, "text[1] = %d\n", text[1]);
|
|
|
|
ok(text[2] == 'x', "text[2] = %d\n", text[2]);
|
|
|
|
}
|
|
|
|
|
2014-12-23 17:44:28 +01:00
|
|
|
static void test__wcsset_s(void)
|
|
|
|
{
|
|
|
|
wchar_t str[10];
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if(!p__wcsset_s) {
|
|
|
|
win_skip("_wcsset_s not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = p__wcsset_s(NULL, 0, 'a');
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
|
|
|
|
str[0] = 'a';
|
|
|
|
r = p__wcsset_s(str, 0, 'a');
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
ok(str[0] == 'a', "str[0] = %d\n", str[0]);
|
|
|
|
|
|
|
|
str[0] = 'a';
|
|
|
|
str[1] = 'b';
|
|
|
|
r = p__wcsset_s(str, 2, 'c');
|
|
|
|
ok(r == EINVAL, "r = %d\n", r);
|
|
|
|
ok(!str[0], "str[0] = %d\n", str[0]);
|
|
|
|
ok(str[1] == 'b', "str[1] = %d\n", str[1]);
|
|
|
|
|
|
|
|
str[0] = 'a';
|
|
|
|
str[1] = 0;
|
|
|
|
str[2] = 'b';
|
|
|
|
r = p__wcsset_s(str, 3, 'c');
|
2019-04-01 18:00:16 +02:00
|
|
|
ok(r == 0, "r = %d\n", r);
|
2014-12-23 17:44:28 +01:00
|
|
|
ok(str[0] == 'c', "str[0] = %d\n", str[0]);
|
|
|
|
ok(str[1] == 0, "str[1] = %d\n", str[1]);
|
|
|
|
ok(str[2] == 'b', "str[2] = %d\n", str[2]);
|
|
|
|
}
|
|
|
|
|
2015-04-24 14:48:04 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-08-08 15:44:41 +02:00
|
|
|
static void test__ismbclx(void)
|
|
|
|
{
|
2019-09-02 19:50:12 +02:00
|
|
|
int ret, cp = _getmbcp();
|
2017-08-08 15:44:41 +02:00
|
|
|
|
|
|
|
ret = _ismbcl0(0);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2019-02-14 14:35:45 +01:00
|
|
|
ret = _ismbcl1(0);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2019-02-15 12:24:57 +01:00
|
|
|
ret = _ismbcl2(0);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2019-09-02 19:50:12 +02:00
|
|
|
_setmbcp(1252);
|
2017-08-08 15:44:41 +02:00
|
|
|
|
|
|
|
ret = _ismbcl0(0x8140);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2019-02-14 14:35:45 +01:00
|
|
|
ret = _ismbcl1(0x889f);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2019-02-15 12:24:57 +01:00
|
|
|
ret = _ismbcl2(0x989f);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2017-08-08 15:44:41 +02:00
|
|
|
_setmbcp(932);
|
|
|
|
|
|
|
|
ret = _ismbcl0(0);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
ret = _ismbcl0(0x8140);
|
|
|
|
ok(ret, "got %d\n", ret);
|
|
|
|
|
2019-02-14 14:35:19 +01:00
|
|
|
ret = _ismbcl0(0x817f);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2019-02-14 14:35:45 +01:00
|
|
|
ret = _ismbcl1(0);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
ret = _ismbcl1(0x889f);
|
|
|
|
ok(ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
ret = _ismbcl1(0x88fd);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2019-02-15 12:24:57 +01:00
|
|
|
ret = _ismbcl2(0);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
ret = _ismbcl2(0x989f);
|
|
|
|
ok(ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
ret = _ismbcl2(0x993f);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
2017-08-08 15:44:41 +02:00
|
|
|
_setmbcp(cp);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
ret = p__memicmp(NULL, NULL, 0);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
ret = p__memicmp(s1, s2, 2);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
|
|
|
|
ret = p__memicmp(s1, s2, 3);
|
|
|
|
ok(ret == -1, "got %d\n", ret);
|
|
|
|
|
|
|
|
if (!p__memicmp_l)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Following calls crash on WinXP/W2k3. */
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp(NULL, NULL, 1);
|
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp(s1, NULL, 1);
|
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp(NULL, s2, 1);
|
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test__memicmp_l(void)
|
|
|
|
{
|
|
|
|
static const char *s1 = "abc";
|
|
|
|
static const char *s2 = "aBd";
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!p__memicmp_l)
|
|
|
|
{
|
|
|
|
win_skip("_memicmp_l not found.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp_l(NULL, NULL, 0, NULL);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
ok(errno == 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp_l(NULL, NULL, 1, NULL);
|
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp_l(s1, NULL, 1, NULL);
|
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp_l(NULL, s2, 1, NULL);
|
|
|
|
ok(ret == _NLSCMPERROR, "got %d\n", ret);
|
|
|
|
ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp_l(s1, s2, 2, NULL);
|
|
|
|
ok(!ret, "got %d\n", ret);
|
|
|
|
ok(errno == 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno);
|
|
|
|
|
|
|
|
errno = 0xdeadbeef;
|
|
|
|
ret = p__memicmp_l(s1, s2, 3, NULL);
|
|
|
|
ok(ret == -1, "got %d\n", ret);
|
|
|
|
ok(errno == 0xdeadbeef, "errno is %d, expected 0xdeadbeef\n", errno);
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:51:56 +01:00
|
|
|
static void test__strupr(void)
|
|
|
|
{
|
|
|
|
const char str[] = "123";
|
2019-12-04 10:04:46 +01:00
|
|
|
const char *const_p;
|
2018-03-22 18:51:56 +01:00
|
|
|
char str2[4];
|
|
|
|
char *mem, *p;
|
|
|
|
DWORD prot;
|
|
|
|
|
|
|
|
mem = VirtualAlloc(NULL, sizeof(str), MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
ok(mem != NULL, "VirtualAlloc failed\n");
|
|
|
|
memcpy(mem, str, sizeof(str));
|
|
|
|
ok(VirtualProtect(mem, sizeof(str), PAGE_READONLY, &prot), "VirtualProtect failed\n");
|
|
|
|
|
|
|
|
strcpy(str2, "aBc");
|
|
|
|
p = _strupr(str2);
|
|
|
|
ok(p == str2, "_strupr returned %p\n", p);
|
|
|
|
ok(!strcmp(str2, "ABC"), "str2 = %s\n", str2);
|
|
|
|
|
|
|
|
p = _strupr(mem);
|
|
|
|
ok(p == mem, "_strupr returned %p\n", p);
|
|
|
|
ok(!strcmp(mem, "123"), "mem = %s\n", mem);
|
|
|
|
|
2019-12-04 10:04:46 +01:00
|
|
|
const_p = "ALREADY_UPPERCASE";
|
|
|
|
p = _strupr((char *)const_p);
|
|
|
|
ok(p == const_p, "_strupr returned %p\n", p);
|
|
|
|
|
2018-03-22 18:51:56 +01:00
|
|
|
if(!setlocale(LC_ALL, "english")) {
|
|
|
|
VirtualFree(mem, sizeof(str), MEM_RELEASE);
|
|
|
|
win_skip("English locale _strupr tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(str2, "aBc");
|
|
|
|
p = _strupr(str2);
|
|
|
|
ok(p == str2, "_strupr returned %p\n", p);
|
|
|
|
ok(!strcmp(str2, "ABC"), "str2 = %s\n", str2);
|
|
|
|
|
|
|
|
if (0) /* crashes on Windows */
|
|
|
|
{
|
|
|
|
p = _strupr(mem);
|
|
|
|
ok(p == mem, "_strupr returned %p\n", p);
|
|
|
|
ok(!strcmp(mem, "123"), "mem = %s\n", mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
VirtualFree(mem, sizeof(str), MEM_RELEASE);
|
|
|
|
}
|
|
|
|
|
2018-08-17 18:51:17 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 18:51:42 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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[] =
|
|
|
|
{
|
|
|
|
{ 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 05:18:11 +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] */
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
ok(ret == j, "expected self %x, got %x for C locale\n", j, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
p__free_locale(locale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-28 13:29:15 +01:00
|
|
|
static void test_strstr(void)
|
|
|
|
{
|
|
|
|
static char long_str[1024];
|
|
|
|
const struct {
|
|
|
|
const char *haystack;
|
|
|
|
const char *needle;
|
|
|
|
int off;
|
|
|
|
} tests[] = {
|
|
|
|
{ "", "", 0 },
|
|
|
|
{ "", "a", -1 },
|
|
|
|
{ "a", "", 0 },
|
|
|
|
{ "aabc", "abc", 1 },
|
|
|
|
{ "aaaa", "aaaa", 0 },
|
|
|
|
{ "simple", "simple", 0 },
|
|
|
|
{ "aaaaxaaaaxaaaa", "aaaaa", -1 },
|
|
|
|
{ "aaaaxaaaaxaaaaa", "aaaaa", 10 },
|
|
|
|
{ "abcabcdababcdabcdabde", "abcdabd", 13 },
|
|
|
|
{ "abababababcabababcababbba", "abababcaba", 4 },
|
|
|
|
{ long_str, long_str+1, 0 }
|
|
|
|
};
|
|
|
|
const char *r, *exp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(long_str, 'a', sizeof(long_str)-1);
|
|
|
|
|
|
|
|
for (i=0; i<ARRAY_SIZE(tests); i++)
|
|
|
|
{
|
|
|
|
r = strstr(tests[i].haystack, tests[i].needle);
|
|
|
|
exp = tests[i].off == -1 ? NULL : tests[i].haystack + tests[i].off;
|
|
|
|
ok(r == exp, "%d) strstr returned %p, expected %p\n", i, r, exp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-11 20:04:32 +01:00
|
|
|
static void test_iswdigit(void)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
WCHAR c;
|
|
|
|
int r;
|
|
|
|
} tests[] = {
|
|
|
|
{ '0', C1_DIGIT },
|
|
|
|
{ '9', C1_DIGIT },
|
|
|
|
{ 'a', 0 },
|
|
|
|
{ 0xff16, C1_DIGIT },
|
|
|
|
{ 0x0660, C1_DIGIT },
|
|
|
|
{ 0x0ce6, C1_DIGIT }
|
|
|
|
};
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++)
|
|
|
|
{
|
|
|
|
r = iswdigit(tests[i].c);
|
|
|
|
ok(r == tests[i].r, "iswdigit returned %x for %x\n", r, tests[i].c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-19 02:53:11 +01:00
|
|
|
START_TEST(string)
|
|
|
|
{
|
2007-10-26 11:15:26 +02:00
|
|
|
char mem[100];
|
2004-05-04 06:13:05 +02:00
|
|
|
static const char xilstring[]="c:/xilinx";
|
2006-12-13 17:52:55 +01:00
|
|
|
int nLen;
|
|
|
|
|
|
|
|
hMsvcrt = GetModuleHandleA("msvcrt.dll");
|
|
|
|
if (!hMsvcrt)
|
|
|
|
hMsvcrt = GetModuleHandleA("msvcrtd.dll");
|
2007-08-14 20:46:32 +02:00
|
|
|
ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
|
2004-03-19 02:53:11 +01:00
|
|
|
SET(pmemcpy,"memcpy");
|
2012-07-28 18:43:43 +02:00
|
|
|
p_memcpy_s = (void*)GetProcAddress( hMsvcrt, "memcpy_s" );
|
|
|
|
p_memmove_s = (void*)GetProcAddress( hMsvcrt, "memmove_s" );
|
2004-03-19 02:53:11 +01:00
|
|
|
SET(pmemcmp,"memcmp");
|
2008-12-11 22:53:36 +01:00
|
|
|
SET(p_mbctype,"_mbctype");
|
|
|
|
SET(p__mb_cur_max,"__mb_cur_max");
|
2017-08-05 18:23:13 +02:00
|
|
|
SET(p_strcpy, "strcpy");
|
2020-01-16 11:37:03 +01:00
|
|
|
SET(p_strcmp, "strcmp");
|
|
|
|
SET(p_strncmp, "strncmp");
|
2008-03-10 11:30:45 +01:00
|
|
|
pstrcpy_s = (void *)GetProcAddress( hMsvcrt,"strcpy_s" );
|
|
|
|
pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
|
2015-07-06 19:40:10 +02:00
|
|
|
p_mbscat_s = (void*)GetProcAddress( hMsvcrt, "_mbscat_s" );
|
2010-10-21 09:55:43 +02:00
|
|
|
p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
|
2008-03-10 11:30:45 +01:00
|
|
|
p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
|
2014-05-19 11:43:05 +02:00
|
|
|
p__mbscpy_s = (void *)GetProcAddress( hMsvcrt,"_mbscpy_s" );
|
2008-03-10 11:30:45 +01:00
|
|
|
p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
|
2011-10-04 23:03:03 +02:00
|
|
|
p_wcsncpy_s = (void *)GetProcAddress( hMsvcrt,"wcsncpy_s" );
|
2010-10-18 14:06:16 +02:00
|
|
|
p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
|
2009-11-16 02:09:17 +01:00
|
|
|
p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
|
2010-03-24 22:39:28 +01:00
|
|
|
p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
|
2010-08-27 01:46:35 +02:00
|
|
|
p_strtoi64 = (void *)GetProcAddress(hMsvcrt, "_strtoi64");
|
|
|
|
p_strtoui64 = (void *)GetProcAddress(hMsvcrt, "_strtoui64");
|
2013-03-09 08:56:38 +01:00
|
|
|
p_wcstoi64 = (void *)GetProcAddress(hMsvcrt, "_wcstoi64");
|
|
|
|
p_wcstoui64 = (void *)GetProcAddress(hMsvcrt, "_wcstoui64");
|
2010-08-27 01:46:35 +02:00
|
|
|
pmbstowcs_s = (void *)GetProcAddress(hMsvcrt, "mbstowcs_s");
|
|
|
|
pwcstombs_s = (void *)GetProcAddress(hMsvcrt, "wcstombs_s");
|
2020-02-03 20:15:54 +01:00
|
|
|
p_wcstombs_s_l = (void *)GetProcAddress(hMsvcrt, "_wcstombs_s_l");
|
2011-04-27 20:08:41 +02:00
|
|
|
pwcsrtombs = (void *)GetProcAddress(hMsvcrt, "wcsrtombs");
|
2010-08-27 01:46:35 +02:00
|
|
|
p_gcvt_s = (void *)GetProcAddress(hMsvcrt, "_gcvt_s");
|
2010-10-11 12:25:15 +02:00
|
|
|
p_itoa_s = (void *)GetProcAddress(hMsvcrt, "_itoa_s");
|
2010-10-11 12:25:23 +02:00
|
|
|
p_strlwr_s = (void *)GetProcAddress(hMsvcrt, "_strlwr_s");
|
2010-10-21 09:57:44 +02:00
|
|
|
p_ultoa_s = (void *)GetProcAddress(hMsvcrt, "_ultoa_s");
|
2011-03-04 23:59:08 +01:00
|
|
|
p_wcslwr_s = (void*)GetProcAddress(hMsvcrt, "_wcslwr_s");
|
2011-03-20 02:17:12 +01:00
|
|
|
p_mbsupr_s = (void*)GetProcAddress(hMsvcrt, "_mbsupr_s");
|
2011-03-20 02:19:02 +01:00
|
|
|
p_mbslwr_s = (void*)GetProcAddress(hMsvcrt, "_mbslwr_s");
|
2020-01-28 23:08:13 +01:00
|
|
|
p_btowc = (void*)GetProcAddress(hMsvcrt, "btowc");
|
2011-04-05 23:47:22 +02:00
|
|
|
p_wctob = (void*)GetProcAddress(hMsvcrt, "wctob");
|
2012-11-29 22:49:58 +01:00
|
|
|
p_wcrtomb = (void*)GetProcAddress(hMsvcrt, "wcrtomb");
|
2019-09-30 19:09:14 +02:00
|
|
|
p_wcrtomb_s = (void*)GetProcAddress(hMsvcrt, "wcrtomb_s");
|
2011-06-03 15:28:56 +02:00
|
|
|
p_tolower = (void*)GetProcAddress(hMsvcrt, "tolower");
|
2018-11-27 05:18:11 +01:00
|
|
|
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");
|
2012-11-29 10:22:46 +01:00
|
|
|
p_mbrlen = (void*)GetProcAddress(hMsvcrt, "mbrlen");
|
2012-11-29 10:23:20 +01:00
|
|
|
p_mbrtowc = (void*)GetProcAddress(hMsvcrt, "mbrtowc");
|
2012-11-29 10:23:57 +01:00
|
|
|
p_mbsrtowcs = (void*)GetProcAddress(hMsvcrt, "mbsrtowcs");
|
2016-05-16 13:29:45 +02:00
|
|
|
p_mbsrtowcs_s = (void*)GetProcAddress(hMsvcrt, "mbsrtowcs_s");
|
2012-12-17 15:19:19 +01:00
|
|
|
p__atodbl_l = (void*)GetProcAddress(hMsvcrt, "_atodbl_l");
|
2015-06-29 03:42:21 +02:00
|
|
|
p__atof_l = (void*)GetProcAddress(hMsvcrt, "_atof_l");
|
|
|
|
p__strtod_l = (void*)GetProcAddress(hMsvcrt, "_strtod_l");
|
2014-09-02 13:50:44 +02:00
|
|
|
p__strnset_s = (void*)GetProcAddress(hMsvcrt, "_strnset_s");
|
2019-04-01 19:57:07 +02:00
|
|
|
p__wcsnset_s = (void*)GetProcAddress(hMsvcrt, "_wcsnset_s");
|
2014-12-23 17:44:28 +01:00
|
|
|
p__wcsset_s = (void*)GetProcAddress(hMsvcrt, "_wcsset_s");
|
2017-10-05 19:39:29 +02:00
|
|
|
p__mbsnlen = (void*)GetProcAddress(hMsvcrt, "_mbsnlen");
|
2017-10-06 12:07:23 +02:00
|
|
|
p__mbccpy_s = (void*)GetProcAddress(hMsvcrt, "_mbccpy_s");
|
2017-11-08 10:26:16 +01:00
|
|
|
p__memicmp = (void*)GetProcAddress(hMsvcrt, "_memicmp");
|
|
|
|
p__memicmp_l = (void*)GetProcAddress(hMsvcrt, "_memicmp_l");
|
2018-10-30 14:01:09 +01:00
|
|
|
p___strncnt = (void*)GetProcAddress(hMsvcrt, "__strncnt");
|
2004-03-19 02:53:11 +01:00
|
|
|
|
|
|
|
/* MSVCRT memcpy behaves like memmove for overlapping moves,
|
|
|
|
MFC42 CString::Insert seems to rely on that behaviour */
|
2007-10-26 11:15:26 +02:00
|
|
|
strcpy(mem,xilstring);
|
2006-12-13 17:52:55 +01:00
|
|
|
nLen=strlen(xilstring);
|
2007-10-26 11:15:26 +02:00
|
|
|
pmemcpy(mem+5, mem,nLen+1);
|
|
|
|
ok(pmemcmp(mem+5,xilstring, nLen) == 0,
|
|
|
|
"Got result %s\n",mem+5);
|
2005-08-19 12:01:42 +02:00
|
|
|
|
2014-03-13 14:12:53 +01:00
|
|
|
/* run tolower tests first */
|
|
|
|
test_tolower();
|
2005-08-19 12:01:42 +02:00
|
|
|
test_swab();
|
2019-10-28 13:29:01 +01:00
|
|
|
test_strcspn();
|
2007-08-20 05:19:37 +02:00
|
|
|
test_mbcp();
|
2005-11-21 13:03:18 +01:00
|
|
|
test_mbsspn();
|
2006-12-23 00:24:30 +01:00
|
|
|
test_mbsspnp();
|
2006-06-21 11:03:26 +02:00
|
|
|
test_strdup();
|
2020-01-16 11:37:03 +01:00
|
|
|
test_strcmp();
|
2007-11-15 16:11:26 +01:00
|
|
|
test_strcpy_s();
|
2012-07-28 18:43:43 +02:00
|
|
|
test_memcpy_s();
|
|
|
|
test_memmove_s();
|
2007-11-16 11:36:03 +01:00
|
|
|
test_strcat_s();
|
2015-07-06 19:40:10 +02:00
|
|
|
test__mbscat_s();
|
2007-11-15 16:32:33 +01:00
|
|
|
test__mbsnbcpy_s();
|
2014-05-19 11:43:05 +02:00
|
|
|
test__mbscpy_s();
|
2009-01-24 00:37:57 +01:00
|
|
|
test_mbcjisjms();
|
2012-03-15 15:41:30 +01:00
|
|
|
test_mbcjmsjis();
|
2015-03-16 13:48:46 +01:00
|
|
|
test_mbctohira();
|
2015-03-16 13:48:48 +01:00
|
|
|
test_mbctokata();
|
2012-03-21 15:02:08 +01:00
|
|
|
test_mbbtombc();
|
2010-02-24 04:52:52 +01:00
|
|
|
test_mbctombb();
|
2015-03-16 13:48:45 +01:00
|
|
|
test_ismbckata();
|
2010-02-23 07:05:44 +01:00
|
|
|
test_ismbclegal();
|
2009-04-22 07:04:20 +02:00
|
|
|
test_strtok();
|
2013-06-21 12:17:43 +02:00
|
|
|
test__mbstok();
|
2008-02-27 09:58:04 +01:00
|
|
|
test_wcscpy_s();
|
2009-11-16 02:09:17 +01:00
|
|
|
test__wcsupr_s();
|
2009-08-31 21:36:45 +02:00
|
|
|
test_strtol();
|
2010-03-24 22:39:28 +01:00
|
|
|
test_strnlen();
|
2010-03-29 00:04:03 +02:00
|
|
|
test__strtoi64();
|
2010-04-21 11:26:22 +02:00
|
|
|
test__strtod();
|
2010-05-06 14:28:08 +02:00
|
|
|
test_mbstowcs();
|
2020-02-03 20:15:54 +01:00
|
|
|
test__wcstombs_s_l();
|
2010-08-27 01:46:35 +02:00
|
|
|
test_gcvt();
|
2010-10-11 12:25:15 +02:00
|
|
|
test__itoa_s();
|
2010-10-11 12:25:23 +02:00
|
|
|
test__strlwr_s();
|
2010-10-18 14:06:16 +02:00
|
|
|
test_wcsncat_s();
|
2010-10-21 09:55:43 +02:00
|
|
|
test__mbsnbcat_s();
|
2010-10-21 09:57:44 +02:00
|
|
|
test__ultoa_s();
|
2011-03-04 23:59:08 +01:00
|
|
|
test__wcslwr_s();
|
2011-03-20 02:17:12 +01:00
|
|
|
test__mbsupr_s();
|
2011-03-20 02:19:02 +01:00
|
|
|
test__mbslwr_s();
|
2011-04-05 23:47:22 +02:00
|
|
|
test_wctob();
|
2020-01-28 23:08:13 +01:00
|
|
|
test_btowc();
|
2012-11-29 22:49:58 +01:00
|
|
|
test_wctomb();
|
2012-12-17 15:19:19 +01:00
|
|
|
test__atodbl();
|
2012-12-24 12:10:21 +01:00
|
|
|
test__stricmp();
|
2013-03-09 08:56:38 +01:00
|
|
|
test__wcstoi64();
|
2019-12-17 15:27:31 +01:00
|
|
|
test__wcstol();
|
2013-06-04 15:52:10 +02:00
|
|
|
test_atoi();
|
2019-03-16 14:49:08 +01:00
|
|
|
test_atol();
|
2015-06-29 03:42:21 +02:00
|
|
|
test_atof();
|
2013-08-13 21:47:20 +02:00
|
|
|
test_strncpy();
|
2014-06-12 17:52:40 +02:00
|
|
|
test_strxfrm();
|
2014-09-02 13:50:44 +02:00
|
|
|
test__strnset_s();
|
2019-04-01 19:57:07 +02:00
|
|
|
test__wcsnset_s();
|
2014-12-23 17:44:28 +01:00
|
|
|
test__wcsset_s();
|
2015-04-24 14:48:04 +02:00
|
|
|
test__mbscmp();
|
2017-08-08 15:44:41 +02:00
|
|
|
test__ismbclx();
|
2017-11-08 10:26:16 +01:00
|
|
|
test__memicmp();
|
|
|
|
test__memicmp_l();
|
2018-03-22 18:51:56 +01:00
|
|
|
test__strupr();
|
2018-08-17 18:51:17 +02:00
|
|
|
test__tcsncoll();
|
2018-08-17 18:51:42 +02:00
|
|
|
test__tcsnicoll();
|
2018-10-30 14:01:09 +01:00
|
|
|
test___strncnt();
|
2018-11-27 05:18:11 +01:00
|
|
|
test_C_locale();
|
2019-10-28 13:29:15 +01:00
|
|
|
test_strstr();
|
2019-11-11 20:04:32 +01:00
|
|
|
test_iswdigit();
|
2004-03-19 02:53:11 +01:00
|
|
|
}
|