wsprintf.c 2.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
 /* 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
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 19
 */

20 21
#include <stdarg.h>

22
#include "wine/test.h"
23
#include "windef.h"
24 25 26
#include "winbase.h"
#include "winuser.h"

27
static void wsprintfATest(void)
28 29
{
    char buf[25];
30
    int rc;
31

32
    rc=wsprintfA(buf, "%010ld", -1);
33
    ok(rc == 10, "wsPrintfA length failure: rc=%d error=%d\n",rc,GetLastError());
34
    ok((lstrcmpA(buf, "-000000001") == 0),
35
       "wsprintfA zero padded negative value failure: buf=[%s]\n",buf);
36 37
}

38
static void wsprintfWTest(void)
39
{
40 41
    static const WCHAR fmt[] = {'%','0','1','0','l','d','\0'};
    static const WCHAR target[] = {'-','0','0','0','0','0','0','0','0','1', '\0'};
42
    WCHAR buf[25];
43 44 45 46 47
    int rc;

    rc=wsprintfW(buf, fmt, -1);
    if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
        return;
48
    ok(rc == 10, "wsPrintfW length failure: rc=%d error=%d\n",rc,GetLastError());
49
    ok((lstrcmpW(buf, target) == 0),
50
       "wsprintfW zero padded negative value failure\n");
51 52
}

53
/* Test if the CharUpper / CharLower functions return true 16 bit results,
54
   if the input is a 16 bit input value. Up to Wine 11-2003 the input value
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
   0xff returns 0xffffffff. */

static void CharUpperTest(void)
{
    int i,out,failed;

    failed = 0;
    for (i=0;i<256;i++)
    	{
	out = (int) CharUpper((LPTSTR)i);
	/* printf("%0x ",out); */
	if ((out >> 16) != 0)
	   {
	   failed = 1;
	   break;
	   }
	}
72
    ok(!failed,"CharUpper failed - 16bit input (0x%0x) returned 32bit result (0x%0x)\n",i,out);
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

static void CharLowerTest(void)
{
    int i,out,failed;

    failed = 0;
    for (i=0;i<256;i++)
    	{
	out = (int) CharLower((LPTSTR)i);
	/* printf("%0x ",out); */
	if ((out >> 16) != 0)
	   {
	   failed = 1;
	   break;
	   }
	}
90
    ok(!failed,"CharLower failed - 16bit input (0x%0x) returned 32bit result (0x%0x)\n",i,out);
91 92 93
}


94 95
START_TEST(wsprintf)
{
96 97
    wsprintfATest();
    wsprintfWTest();
98 99
    CharUpperTest();
    CharLowerTest();
100
}