2002-04-24 23:16:51 +02:00
|
|
|
/* Unit test suite for the wsprintf functions
|
|
|
|
*
|
|
|
|
* Copyright 2002 Bill Medland
|
|
|
|
*
|
|
|
|
* 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
|
2002-04-24 23:16:51 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-05-23 04:40:07 +02:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-04-24 23:16:51 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2011-07-25 12:40:46 +02:00
|
|
|
#include "winnls.h"
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *fmt;
|
|
|
|
ULONGLONG value;
|
|
|
|
const char *res;
|
|
|
|
} i64_formats[] =
|
|
|
|
{
|
|
|
|
{ "%I64X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "123450067890A" },
|
|
|
|
{ "%I32X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890A" },
|
|
|
|
{ "%I64d", (ULONGLONG)543210 * 1000000, "543210000000" },
|
|
|
|
{ "%I64X", (LONGLONG)-0x12345, "FFFFFFFFFFFEDCBB" },
|
|
|
|
{ "%I32x", (LONGLONG)-0x12345, "fffedcbb" },
|
|
|
|
{ "%I64u", (LONGLONG)-123, "18446744073709551493" },
|
|
|
|
{ "%Id", (LONGLONG)-12345, "-12345" },
|
|
|
|
#ifdef _WIN64
|
|
|
|
{ "%Ix", ((ULONGLONG)0x12345 << 32) | 0x67890a, "123450067890a" },
|
|
|
|
{ "%Ix", (LONGLONG)-0x12345, "fffffffffffedcbb" },
|
|
|
|
{ "%p", (LONGLONG)-0x12345, "FFFFFFFFFFFEDCBB" },
|
|
|
|
#else
|
|
|
|
{ "%Ix", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890a" },
|
|
|
|
{ "%Ix", (LONGLONG)-0x12345, "fffedcbb" },
|
|
|
|
{ "%p", (LONGLONG)-0x12345, "FFFEDCBB" },
|
|
|
|
#endif
|
|
|
|
};
|
2002-04-24 23:16:51 +02:00
|
|
|
|
2002-12-18 21:51:14 +01:00
|
|
|
static void wsprintfATest(void)
|
2002-04-24 23:16:51 +02:00
|
|
|
{
|
2020-02-09 12:51:29 +01:00
|
|
|
char buf[25], star[4], partial[4];
|
2020-02-19 15:21:31 +01:00
|
|
|
static const WCHAR starW[] = L"\x2606";
|
|
|
|
static const WCHAR fffeW[] = L"\xfffe";
|
|
|
|
static const WCHAR wineW[] = L"\xd83c\xdf77"; /* U+1F377: wine glass */
|
2020-02-09 12:51:29 +01:00
|
|
|
const struct {
|
|
|
|
const void *input;
|
|
|
|
const char *fmt;
|
|
|
|
const char *str;
|
|
|
|
int rc;
|
|
|
|
}
|
|
|
|
testcase[] = {
|
2020-02-09 12:51:31 +01:00
|
|
|
{ starW, "%.1S", partial, 1 },
|
|
|
|
{ starW, "%.2S", star, 2 },
|
|
|
|
{ starW, "%.3S", star, 2 },
|
|
|
|
{ fffeW, "%.1S", "?", 1 },
|
|
|
|
{ fffeW, "%.2S", "?", 1 },
|
|
|
|
{ wineW, "%.2S", "??", 2 },
|
2020-02-09 12:51:29 +01:00
|
|
|
{ star, "%.1s", partial, 1 },
|
2020-02-19 15:21:33 +01:00
|
|
|
{ (void *)0x2606, "%2C", star, 2 },
|
|
|
|
{ (void *)0xfffd, "%C", "?", 1 },
|
|
|
|
{ (void *)0xe199, "%2c", " \x99", 2 },
|
2020-02-09 12:51:29 +01:00
|
|
|
};
|
|
|
|
CPINFO cpinfo;
|
2011-07-25 12:40:46 +02:00
|
|
|
unsigned int i;
|
2002-12-18 21:51:14 +01:00
|
|
|
int rc;
|
2002-04-24 23:16:51 +02:00
|
|
|
|
2002-12-18 21:51:14 +01:00
|
|
|
rc=wsprintfA(buf, "%010ld", -1);
|
2011-07-25 12:40:46 +02:00
|
|
|
ok(rc == 10, "wsprintfA length failure: rc=%d error=%d\n",rc,GetLastError());
|
2002-12-18 21:51:14 +01:00
|
|
|
ok((lstrcmpA(buf, "-000000001") == 0),
|
2004-01-23 21:50:35 +01:00
|
|
|
"wsprintfA zero padded negative value failure: buf=[%s]\n",buf);
|
2011-07-25 12:40:46 +02:00
|
|
|
rc = wsprintfA(buf, "%I64X", (ULONGLONG)0);
|
|
|
|
if (rc == 4 && !lstrcmpA(buf, "I64X"))
|
|
|
|
{
|
|
|
|
win_skip( "I64 formats not supported\n" );
|
|
|
|
return;
|
|
|
|
}
|
2018-06-28 18:17:01 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(i64_formats); i++)
|
2011-07-25 12:40:46 +02:00
|
|
|
{
|
|
|
|
rc = wsprintfA(buf, i64_formats[i].fmt, i64_formats[i].value);
|
|
|
|
ok(rc == strlen(i64_formats[i].res), "%u: wsprintfA length failure: rc=%d\n", i, rc);
|
|
|
|
ok(!strcmp(buf, i64_formats[i].res), "%u: wrong result [%s]\n", i, buf);
|
|
|
|
}
|
2020-02-09 12:51:29 +01:00
|
|
|
|
|
|
|
if (!GetCPInfo(CP_ACP, &cpinfo) || cpinfo.MaxCharSize <= 1)
|
|
|
|
{
|
|
|
|
skip("Multi-byte wsprintfA test isn't available for the current codepage\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = WideCharToMultiByte(CP_ACP, 0, starW, -1, star, sizeof(star), NULL, NULL);
|
|
|
|
ok(rc == 3, "unexpected rc, got %d\n", rc);
|
|
|
|
partial[0] = star[0];
|
|
|
|
partial[1] = '\0';
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(testcase); i++)
|
|
|
|
{
|
|
|
|
memset(buf, 0x11, sizeof(buf));
|
|
|
|
rc = wsprintfA(buf, testcase[i].fmt, testcase[i].input);
|
|
|
|
|
|
|
|
ok(rc == testcase[i].rc,
|
|
|
|
"%u: expected %d, got %d\n",
|
|
|
|
i, testcase[i].rc, rc);
|
|
|
|
|
|
|
|
ok(!strcmp(buf, testcase[i].str),
|
|
|
|
"%u: expected %s, got %s\n",
|
|
|
|
i, wine_dbgstr_a(testcase[i].str), wine_dbgstr_an(buf, rc));
|
|
|
|
}
|
2002-04-24 23:16:51 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 15:21:39 +01:00
|
|
|
static WCHAR my_btowc(BYTE c)
|
|
|
|
{
|
|
|
|
WCHAR wc;
|
|
|
|
if (!IsDBCSLeadByte(c) &&
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (const char *)&c, 1, &wc, 1) > 0)
|
|
|
|
return wc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-18 21:51:14 +01:00
|
|
|
static void wsprintfWTest(void)
|
2002-04-24 23:16:51 +02:00
|
|
|
{
|
2020-02-19 15:21:31 +01:00
|
|
|
static const WCHAR stars[] = L"*\x2606\x2605";
|
|
|
|
WCHAR def_spc[] = L"*?\x2605 ";
|
2020-02-19 15:21:39 +01:00
|
|
|
WCHAR buf[25], fmt[25], res[25], wcA1, wc99;
|
2020-02-09 12:51:35 +01:00
|
|
|
char stars_mb[8], partial00[8], partialFF[8];
|
|
|
|
const struct {
|
|
|
|
const char *input;
|
|
|
|
const WCHAR *fmt;
|
|
|
|
const WCHAR *str;
|
|
|
|
int rc;
|
|
|
|
}
|
|
|
|
testcase[] = {
|
2020-02-19 15:21:31 +01:00
|
|
|
{ stars_mb, L"%.3S", stars, 3 },
|
|
|
|
{ partial00, L"%-4S", L"*\0 ", 4 },
|
|
|
|
{ partialFF, L"%-4S", def_spc, 4 },
|
2020-02-09 12:51:35 +01:00
|
|
|
};
|
|
|
|
CPINFOEXW cpinfoex;
|
2011-07-25 12:40:46 +02:00
|
|
|
unsigned int i;
|
2002-12-18 21:51:14 +01:00
|
|
|
int rc;
|
|
|
|
|
2020-02-19 15:21:31 +01:00
|
|
|
rc=wsprintfW(buf, L"%010ld", -1);
|
2002-12-18 21:51:14 +01:00
|
|
|
if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
2007-07-03 14:50:06 +02:00
|
|
|
{
|
2009-02-23 10:41:03 +01:00
|
|
|
win_skip("wsprintfW is not implemented\n");
|
2002-12-18 21:51:14 +01:00
|
|
|
return;
|
2007-07-03 14:50:06 +02:00
|
|
|
}
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(rc == 10, "wsPrintfW length failure: rc=%d error=%d\n",rc,GetLastError());
|
2020-02-19 15:21:31 +01:00
|
|
|
ok((lstrcmpW(buf, L"-000000001") == 0),
|
2004-01-23 21:50:35 +01:00
|
|
|
"wsprintfW zero padded negative value failure\n");
|
2020-02-19 15:21:31 +01:00
|
|
|
rc = wsprintfW(buf, L"%I64x", (ULONGLONG)0 );
|
|
|
|
if (rc == 4 && !lstrcmpW(buf, L"I64x"))
|
2011-07-25 12:40:46 +02:00
|
|
|
{
|
|
|
|
win_skip( "I64 formats not supported\n" );
|
|
|
|
return;
|
|
|
|
}
|
2018-06-28 18:17:01 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(i64_formats); i++)
|
2011-07-25 12:40:46 +02:00
|
|
|
{
|
2018-06-28 18:17:01 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, i64_formats[i].fmt, -1, fmt, ARRAY_SIZE(fmt));
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, i64_formats[i].res, -1, res, ARRAY_SIZE(res));
|
2011-07-25 12:40:46 +02:00
|
|
|
rc = wsprintfW(buf, fmt, i64_formats[i].value);
|
|
|
|
ok(rc == lstrlenW(res), "%u: wsprintfW length failure: rc=%d\n", i, rc);
|
|
|
|
ok(!lstrcmpW(buf, res), "%u: wrong result [%s]\n", i, wine_dbgstr_w(buf));
|
|
|
|
}
|
2020-02-09 12:51:35 +01:00
|
|
|
|
2020-02-19 15:21:39 +01:00
|
|
|
rc = wsprintfW(buf, L"%2c", L'*');
|
|
|
|
ok(rc == 2, "expected 2, got %d\n", rc);
|
|
|
|
ok(buf[0] == L' ', "expected \\x0020, got \\x%04x\n", buf[0]);
|
|
|
|
ok(buf[1] == L'*', "expected \\x%04x, got \\x%04x\n", L'*', buf[1]);
|
|
|
|
|
|
|
|
rc = wsprintfW(buf, L"%c", L'\x2605');
|
|
|
|
ok(rc == 1, "expected 1, got %d\n", rc);
|
|
|
|
ok(buf[0] == L'\x2605', "expected \\x%04x, got \\x%04x\n", L'\x2605', buf[0]);
|
|
|
|
|
|
|
|
wcA1 = my_btowc(0xA1);
|
|
|
|
rc = wsprintfW(buf, L"%C", 0xA1);
|
|
|
|
ok(rc == 1, "expected 1, got %d\n", rc);
|
2020-02-19 15:21:41 +01:00
|
|
|
ok(buf[0] == wcA1, "expected \\x%04x, got \\x%04x\n", wcA1, buf[0]);
|
2020-02-19 15:21:39 +01:00
|
|
|
|
|
|
|
rc = wsprintfW(buf, L"%C", 0x81A1);
|
|
|
|
ok(rc == 1, "expected 1, got %d\n", rc);
|
2020-02-19 15:21:41 +01:00
|
|
|
ok(buf[0] == wcA1, "expected \\x%04x, got \\x%04x\n", wcA1, buf[0]);
|
2020-02-19 15:21:39 +01:00
|
|
|
|
|
|
|
wc99 = my_btowc(0x99);
|
|
|
|
rc = wsprintfW(buf, L"%2C", 0xe199);
|
|
|
|
ok(rc == 2, "expected 1, got %d\n", rc);
|
|
|
|
ok(buf[0] == L' ', "expected \\x0020, got \\x%04x\n", buf[0]);
|
2020-02-19 15:21:41 +01:00
|
|
|
ok(buf[1] == wc99, "expected \\x%04x, got \\x%04x\n", wc99, buf[1]);
|
2020-02-19 15:21:39 +01:00
|
|
|
|
2020-02-09 12:51:35 +01:00
|
|
|
if (!GetCPInfoExW(CP_ACP, 0, &cpinfoex) || cpinfoex.MaxCharSize <= 1)
|
|
|
|
{
|
|
|
|
skip("Multi-byte wsprintfW test isn't available for the current codepage\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
def_spc[1] = cpinfoex.UnicodeDefaultChar;
|
|
|
|
|
|
|
|
rc = WideCharToMultiByte(CP_ACP, 0, stars, -1, stars_mb, sizeof(stars_mb), NULL, NULL);
|
|
|
|
ok(rc == 6, "expected 6, got %d\n", rc);
|
|
|
|
strcpy(partial00, stars_mb);
|
|
|
|
partial00[2] = '\0';
|
|
|
|
strcpy(partialFF, stars_mb);
|
|
|
|
partialFF[2] = 0xff;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(testcase); i++)
|
|
|
|
{
|
|
|
|
memset(buf, 0x11, sizeof(buf));
|
|
|
|
rc = wsprintfW(buf, testcase[i].fmt, testcase[i].input);
|
|
|
|
|
|
|
|
ok(rc == testcase[i].rc,
|
|
|
|
"%u: expected %d, got %d\n",
|
|
|
|
i, testcase[i].rc, rc);
|
|
|
|
|
2020-02-09 12:51:37 +01:00
|
|
|
ok(!memcmp(buf, testcase[i].str, (testcase[i].rc + 1) * sizeof(WCHAR)),
|
2020-02-09 12:51:35 +01:00
|
|
|
"%u: expected %s, got %s\n", i,
|
|
|
|
wine_dbgstr_wn(testcase[i].str, testcase[i].rc + 1),
|
|
|
|
wine_dbgstr_wn(buf, rc + 1));
|
|
|
|
}
|
2002-04-24 23:16:51 +02:00
|
|
|
}
|
|
|
|
|
2006-05-06 15:18:54 +02:00
|
|
|
/* Test if the CharUpper / CharLower functions return true 16 bit results,
|
2011-07-25 12:40:46 +02:00
|
|
|
if the input is a 16 bit input value. */
|
2006-05-06 15:18:54 +02:00
|
|
|
|
|
|
|
static void CharUpperTest(void)
|
|
|
|
{
|
2013-11-05 22:59:08 +01:00
|
|
|
INT_PTR i, out;
|
|
|
|
BOOL failed = FALSE;
|
2006-05-06 15:18:54 +02:00
|
|
|
|
|
|
|
for (i=0;i<256;i++)
|
|
|
|
{
|
2013-10-23 07:54:32 +02:00
|
|
|
out = (INT_PTR)CharUpperA((LPSTR)i);
|
2006-05-06 15:18:54 +02:00
|
|
|
if ((out >> 16) != 0)
|
|
|
|
{
|
2013-11-05 22:59:08 +01:00
|
|
|
failed = TRUE;
|
2006-05-06 15:18:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-08 13:11:49 +01:00
|
|
|
ok(!failed,"CharUpper failed - 16bit input (0x%0lx) returned 32bit result (0x%0lx)\n",i,out);
|
2006-05-06 15:18:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CharLowerTest(void)
|
|
|
|
{
|
2013-11-05 22:59:08 +01:00
|
|
|
INT_PTR i, out;
|
|
|
|
BOOL failed = FALSE;
|
2006-05-06 15:18:54 +02:00
|
|
|
|
|
|
|
for (i=0;i<256;i++)
|
|
|
|
{
|
2013-10-23 07:54:32 +02:00
|
|
|
out = (INT_PTR)CharLowerA((LPSTR)i);
|
2006-05-06 15:18:54 +02:00
|
|
|
if ((out >> 16) != 0)
|
|
|
|
{
|
2013-11-05 22:59:08 +01:00
|
|
|
failed = TRUE;
|
2006-05-06 15:18:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-08 13:11:49 +01:00
|
|
|
ok(!failed,"CharLower failed - 16bit input (0x%0lx) returned 32bit result (0x%0lx)\n",i,out);
|
2006-05-06 15:18:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-24 23:16:51 +02:00
|
|
|
START_TEST(wsprintf)
|
|
|
|
{
|
2002-12-18 21:51:14 +01:00
|
|
|
wsprintfATest();
|
|
|
|
wsprintfWTest();
|
2006-05-06 15:18:54 +02:00
|
|
|
CharUpperTest();
|
|
|
|
CharLowerTest();
|
2002-04-24 23:16:51 +02:00
|
|
|
}
|