os/ossrv/genericopenlibs/cstdlib/TSTLIB/TMISC.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/TMISC.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,733 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// This test has been converted from it original TMISC.C .
    1.18 +// The original was a manaul test and didn't work!
    1.19 +// Test code for bsearch, qsort etc. These are all functions which work directly
    1.20 +// without using the MSystemInterface - as such none of them use errno to indicate
    1.21 +// errors.
    1.22 +// 
    1.23 +//
    1.24 +
    1.25 +#include <e32test.h>
    1.26 +#include <e32svr.h>
    1.27 +
    1.28 +#include <stdarg.h>
    1.29 +#include <stdlib.h>
    1.30 +#include <stdio.h>
    1.31 +#include <math.h>  /* HUGE_VAL */
    1.32 +#include <errno.h> /* ERANGE */
    1.33 +#include "ESTLIB.H"
    1.34 +
    1.35 +// Defined in ctest.h but contains lots of other declarations we don't want
    1.36 +#define test_Data		struct __testdata __td	/* declares global variable __td */
    1.37 +
    1.38 +//
    1.39 +// Globals
    1.40 +
    1.41 +static RTest TheTest(_L("TMisc"));
    1.42 +
    1.43 +//
    1.44 +//
    1.45 +//Test macroses and functions
    1.46 +
    1.47 +static void Check(TInt aValue, TInt aLine)
    1.48 +	{
    1.49 +	if(!aValue)
    1.50 +		{
    1.51 +		TheTest(EFalse, aLine);
    1.52 +		}
    1.53 +	}
    1.54 +static  void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.55 +	{
    1.56 +	if(aValue != aExpected)
    1.57 +		{
    1.58 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.59 +		TheTest(EFalse, aLine);
    1.60 +		}
    1.61 +	}
    1.62 +
    1.63 +#define TEST(arg) ::Check((arg), __LINE__)
    1.64 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.65 +
    1.66 +//
    1.67 +// Tests
    1.68 +
    1.69 +
    1.70 +/* random numbers */
    1.71 +
    1.72 +void random_numbers()
    1.73 +	{
    1.74 +	int i,r;
    1.75 +	int rs[20];
    1.76 +
    1.77 +	TheTest.Next(_L("Random numbers"));
    1.78 +
    1.79 +	for (i=0; i<20; i++)
    1.80 +		{
    1.81 +		r = rand();
    1.82 +		printf("%d ", r);
    1.83 +		}
    1.84 +	printf("\n");
    1.85 +	TheTest.Next(_L("Using srand()"));
    1.86 +	srand(12345678);
    1.87 +	for (i=0; i<20; i++)
    1.88 +		{
    1.89 +		rs[i]=rand();
    1.90 +		printf("%d ",rs[i]);
    1.91 +		}
    1.92 +	printf("\n");
    1.93 +	srand(12345678);
    1.94 +	for (i=0; i<20; i++)
    1.95 +		TEST(rand()==rs[i]);
    1.96 +	}
    1.97 +
    1.98 +/* Sorting */
    1.99 +
   1.100 +typedef struct {
   1.101 +	int a;
   1.102 +	int b;
   1.103 +	int c;
   1.104 +	} sort_item;
   1.105 +
   1.106 +int compare_a (const void *left, const void *right)
   1.107 +	{
   1.108 +	sort_item *lp = (sort_item *)left;
   1.109 +	sort_item *rp = (sort_item *)right;
   1.110 +
   1.111 +	if (lp->a < rp->a) return -1;
   1.112 +	if (lp->a > rp->a) return  1;
   1.113 +	return 0;
   1.114 +	}
   1.115 +
   1.116 +int compare_ba (const void *left, const void *right)
   1.117 +	{
   1.118 +	sort_item *lp = (sort_item *)left;
   1.119 +	sort_item *rp = (sort_item *)right;
   1.120 +
   1.121 +	if (lp->b < rp->b) return -1;
   1.122 +	if (lp->b > rp->b) return  1;
   1.123 +	/* b's are equal, sort on a's */
   1.124 +	if (lp->a < rp->a) return -1;
   1.125 +	if (lp->a > rp->a) return  1;
   1.126 +	return 0;
   1.127 +	}
   1.128 +
   1.129 +#define NITEMS 200
   1.130 +sort_item list[NITEMS];
   1.131 +
   1.132 +void validate(sort_item *p)
   1.133 +	{
   1.134 +	int i;
   1.135 +	for (i=0; i<NITEMS; i++,p++)
   1.136 +		{
   1.137 +		if (p->a==9)
   1.138 +			continue;
   1.139 +		TEST((p->a/4)+p->b == 5000);
   1.140 +		TEST((p->a*p->a)/4 == p->c);
   1.141 +		}
   1.142 +	}
   1.143 +
   1.144 +void sorting()
   1.145 +	{
   1.146 +	int i;
   1.147 +	TheTest.Next(_L("Quicksort"));
   1.148 +	for (i=1; i<NITEMS; i++)
   1.149 +		{
   1.150 +		list[i].a = 2*i;
   1.151 +		list[i].b = 5000-(i/2);
   1.152 +		list[i].c = i*i;
   1.153 +		}
   1.154 +
   1.155 +	/* Sort into increasing order of a. Want item 0 to sort to position 4 */
   1.156 +	list[0].a = 9;
   1.157 +	list[0].b = 10;
   1.158 +	list[0].c = 11;
   1.159 +
   1.160 +	qsort(list, NITEMS, sizeof(list[0]), compare_a);
   1.161 +	TEST(list[4].c==11);
   1.162 +	validate(list);
   1.163 +
   1.164 +	/* Resort into increasing order of b followed by a. Want item 0 to sort to position 5 */
   1.165 +	list[0].a = 9;
   1.166 +	list[0].b = 5000-((199-4)/2);
   1.167 +	list[0].c = 13;
   1.168 +
   1.169 +	qsort(list, NITEMS, sizeof(list[0]), compare_ba);
   1.170 +	TEST(list[5].c==13);
   1.171 +	validate(list);
   1.172 +	}
   1.173 +
   1.174 +void searching()
   1.175 +	{
   1.176 +	int i;
   1.177 +	sort_item *answer;
   1.178 +	sort_item not_there;
   1.179 +	TheTest.Next(_L("Binary search for existing items"));
   1.180 +	for (i=0; i<NITEMS; i++)
   1.181 +		{
   1.182 +		answer = (sort_item*)bsearch(&list[i],list,NITEMS,sizeof(list[0]),compare_ba);
   1.183 +		TEST(answer==&list[i]);
   1.184 +		}
   1.185 +	TheTest.Next(_L("Binary search for missing items"));
   1.186 +	for (i=0; i<NITEMS; i++)
   1.187 +		{
   1.188 +		not_there = list[i];
   1.189 +		not_there.a++;
   1.190 +		answer = (sort_item*)bsearch(&not_there,list,NITEMS,sizeof(list[0]),compare_ba);
   1.191 +		if (answer!=NULL)
   1.192 +			TEST(!compare_ba(answer,&not_there));
   1.193 +		}
   1.194 +	for (i=0; i<NITEMS; i++)
   1.195 +		{
   1.196 +		not_there = list[i];
   1.197 +		not_there.a--;
   1.198 +		answer = (sort_item*)bsearch(&not_there,list,NITEMS,sizeof(list[0]),compare_ba);
   1.199 +		if (answer!=NULL)
   1.200 +			TEST(!compare_ba(answer,&not_there));
   1.201 +		}
   1.202 +	}
   1.203 +
   1.204 +void sscanf_test()
   1.205 +	{
   1.206 +	int in[4], i;
   1.207 +	TheTest.Next(_L("Simple SSCANF tests"));
   1.208 +
   1.209 +	in[0] = in[1] = in[2] = in[3] = 6789;
   1.210 +	i = sscanf("1.2.3.4", "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
   1.211 +	TEST (in[0]==1);
   1.212 +	TEST (in[1]==2);
   1.213 +	TEST (in[2]==3);
   1.214 +	TEST (in[3]==4);
   1.215 +	TEST (i==4);
   1.216 +
   1.217 +	i = sscanf("194.223.254.9", "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
   1.218 +	TEST (in[0]==194);
   1.219 +	TEST (in[1]==223);
   1.220 +	TEST (in[2]==254);
   1.221 +	TEST (in[3]==9);
   1.222 +	TEST (i==4);
   1.223 +
   1.224 +	i = sscanf("17.183.hello.11", "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
   1.225 +	TEST (in[0]==17);
   1.226 +	TEST (in[1]==183);
   1.227 +	TEST (in[2]==254);
   1.228 +	TEST (in[3]==9);
   1.229 +	TEST (i==2);
   1.230 +	}
   1.231 +
   1.232 +/* setjmp, longjmp */
   1.233 +
   1.234 +#include <setjmp.h>
   1.235 +#include <string.h>
   1.236 +
   1.237 +jmp_buf jbufs[4];
   1.238 +int count=0;
   1.239 +
   1.240 +static int getStackPointer(void)
   1.241 +	{
   1.242 +	static char there;
   1.243 +	char here;
   1.244 +	return &here-&there;
   1.245 +	}
   1.246 +
   1.247 +static int getgetStackPointer(void)
   1.248 +	{
   1.249 +	int n=4;	// local variable to cause change to stack pointer
   1.250 +	n+=getStackPointer();
   1.251 +	if (n==0)
   1.252 +		n=getStackPointer()+37;	// this never happens - it's just to defeat the optimiser
   1.253 +	return (n-4);
   1.254 +	}
   1.255 +
   1.256 +void jmp_nest(int n)
   1.257 +	{
   1.258 +	int m=n+100;	// local variable to induce a stack frame
   1.259 +	if (n>0)
   1.260 +		jmp_nest(n-1);
   1.261 +	longjmp(jbufs[3],m);
   1.262 +	}
   1.263 +
   1.264 +#ifdef __VC32__
   1.265 +#pragma optimize( "", off )		//stop the compiler breaking this TEST
   1.266 +#endif
   1.267 +
   1.268 +void setjmp_longjmp()
   1.269 +	{
   1.270 +	volatile int i,r,j,k,l,m; // volatile to rid us of warnings
   1.271 +	volatile int sp1,sp2;
   1.272 +	TheTest.Next(_L("Setjmp"));
   1.273 +
   1.274 +	sp1=getStackPointer();
   1.275 +	sp2=getgetStackPointer();
   1.276 +	TEST(sp1!=sp2);	// call from deeper function nesting should give a different answer
   1.277 +
   1.278 +	memset(jbufs[0],0,sizeof(jmp_buf));
   1.279 +	memset(jbufs[1],0,sizeof(jmp_buf));
   1.280 +	memset(jbufs[2],0,sizeof(jmp_buf));
   1.281 +
   1.282 +	r=setjmp(jbufs[0]);
   1.283 +	TEST(r==0);
   1.284 +
   1.285 +	for (i=0,j=1,k=2,l=3,m=4; i<3; i++,j*=3,k+=j,l*=m,m-=2)
   1.286 +		{
   1.287 +		r=setjmp(jbufs[i]);
   1.288 +		TEST(r==0);
   1.289 +		TEST(j>i);
   1.290 +		}
   1.291 +	r=memcmp(jbufs[0],jbufs[2], sizeof(jmp_buf));
   1.292 +
   1.293 +	if (r!=0)
   1.294 +		{
   1.295 +		RDebug::Print(_L("  Test code appears to be using preserved registers (a good thing)\n"));
   1.296 +		RDebug::Print(_L("  buf @   %08x %08x\n"), jbufs[0], jbufs[2]);
   1.297 +		for (i=0;i<16;i++)
   1.298 +			{
   1.299 +			if (jbufs[0][i] != jbufs[2][i])
   1.300 +				RDebug::Print(_L("  buf+%02d: %08x %08x\n"), i*4, jbufs[0][i], jbufs[2][i]);
   1.301 +			}
   1.302 +		}
   1.303 +	else
   1.304 +		RDebug::Print(_L("  Test code appears not to exercise preserved registers\n"));
   1.305 +
   1.306 +	r=setjmp(jbufs[0]);
   1.307 +	TEST(r==0);
   1.308 +	r=setjmp(jbufs[2]);
   1.309 +	TEST(r==0);
   1.310 +	r=memcmp(jbufs[0],jbufs[2], sizeof(jmp_buf));
   1.311 +	TEST(r!=0);	/* must change the return address! */
   1.312 +
   1.313 +	TheTest.Next(_L("Setjmp and longjmp"));
   1.314 +
   1.315 +	r=setjmp(jbufs[0]);
   1.316 +	if (r==0)
   1.317 +		{
   1.318 +		TEST(count==0);
   1.319 +		count++;
   1.320 +		longjmp(jbufs[0],7);
   1.321 +		}
   1.322 +	else if (r==7)
   1.323 +		{
   1.324 +		TEST(count==1);
   1.325 +		count++;
   1.326 +		longjmp(jbufs[0],3);
   1.327 +		}
   1.328 +	else if (r==3)
   1.329 +		{
   1.330 +		TEST(count==2);
   1.331 +		count++;
   1.332 +		longjmp(jbufs[0],0);	/* 0 must be turned into 1 */
   1.333 +		}
   1.334 +	else
   1.335 +		{
   1.336 +		TEST(r==1);
   1.337 +		TEST(count==3);
   1.338 +		count++;
   1.339 +		}
   1.340 +
   1.341 +	sp1=getStackPointer();
   1.342 +	r=setjmp(jbufs[3]);
   1.343 +	if (r==0)
   1.344 +		{
   1.345 +		sp2=getStackPointer();
   1.346 +		TEST(sp1==sp2);
   1.347 +		longjmp(jbufs[3],1);		// simple setjmp/longjmp
   1.348 +		}
   1.349 +	else if (r==1)
   1.350 +		{
   1.351 +		sp2=getStackPointer();
   1.352 +		TEST(sp1==sp2);
   1.353 +		jmp_nest(20);			// more complex example
   1.354 +		}
   1.355 +	else
   1.356 +		{
   1.357 +		TEST(r==100);
   1.358 +		sp2=getStackPointer();
   1.359 +		TEST(sp1==sp2);
   1.360 +		}
   1.361 +	}
   1.362 +
   1.363 +#ifdef __VC32__
   1.364 +#pragma optimize( "", on )	//stop the compiler breaking this TEST
   1.365 +#endif
   1.366 +
   1.367 +/* case-insensitive comparison */
   1.368 +
   1.369 +#include <string.h>
   1.370 +char agrave[2]= {191,0};
   1.371 +
   1.372 +void casecmp()
   1.373 +	{
   1.374 +	int r;
   1.375 +	char *s1,*s2;
   1.376 +	TheTest.Next(_L("Case-insensitive string comparison"));
   1.377 +
   1.378 +	s1="abcd";
   1.379 +	r=strcasecmp(s1,s1);
   1.380 +	TEST(r==0);
   1.381 +
   1.382 +	s2="abcde";
   1.383 +	r=strcasecmp(s1,s2);
   1.384 +	TEST(r<0);
   1.385 +
   1.386 +	r=strcasecmp(s2,s1);
   1.387 +	TEST(r>0);
   1.388 +
   1.389 +	r=strncasecmp(s1,s2,10);
   1.390 +	TEST(r<0);
   1.391 +
   1.392 +	r=strncasecmp(s1,s2,4);
   1.393 +	TEST(r==0);
   1.394 +
   1.395 +	s2="ABcD";
   1.396 +	r=strcmp(s1,s2);
   1.397 +	TEST(r!=0);
   1.398 +	r=strcasecmp(s1,s2);
   1.399 +	TEST(r==0);
   1.400 +
   1.401 +#if 0
   1.402 +	/* Need some way to set up a proper folding example */
   1.403 +	r=strncasecmp(s2,agrave,1);
   1.404 +	TEST(r==0);
   1.405 +#endif
   1.406 +	}
   1.407 +
   1.408 +void arguments(int argc, char *argv[])
   1.409 +	{
   1.410 +	int i;
   1.411 +
   1.412 +	TheTest.Next(_L("Command line arguments"));
   1.413 +	TEST(argc>0);
   1.414 +	TEST(argv!=0);
   1.415 +	printf("  argc=%d\r\n", argc);
   1.416 +	for (i=0; i<argc; i++)
   1.417 +		{
   1.418 +		int j;
   1.419 +		int length=strlen(argv[i]);
   1.420 +		TEST(argv[i]!=0);
   1.421 +		printf("  argv[%d]= ", i);
   1.422 +		for (j=0;j<4;j++)
   1.423 +			{
   1.424 +			printf("%02x ", ((unsigned char *)argv[i])[j]);
   1.425 +			if (argv[i][j]=='\0')
   1.426 +				break;
   1.427 +			}
   1.428 +		for (;j<3;j++)
   1.429 +			printf("   ");
   1.430 +		printf(" \"%s\" length %d\r\n", argv[i], length);
   1.431 +		}
   1.432 +	}
   1.433 +
   1.434 +struct double_conv {
   1.435 +	char* source;
   1.436 +	double answer;
   1.437 +	int tail_offset;
   1.438 +	};
   1.439 +
   1.440 +struct double_conv strtods[] = {
   1.441 +	{ "1",		1.0,	1 },
   1.442 +	{ "0.1",	0.1,	3 },
   1.443 +	{ ".1",		0.1,	2 },
   1.444 +	{ " 0.1",	0.1,	4 },
   1.445 +	{ " 1 ",	1.0,	2 },
   1.446 +	{ "1x",		1.0,	1 },
   1.447 +	{ "x",		0.0,	0 },
   1.448 +	{ "1.5.3",	1.5,	3 },
   1.449 +	{ "1.0e-1m solid red;}...",	0.1,	6 },
   1.450 +	{ "1.0e2blah",	100.0,	5 },
   1.451 +	{ "3.1415e2blah",	314.15,	8 },
   1.452 +	{ "0.2em solid red;}...",	0.2,	3 },
   1.453 +	{ "0.2e5m solid red;}...",	20000.0,	5 },
   1.454 +	{ 0 }
   1.455 +	};
   1.456 +
   1.457 +void strtod_test()
   1.458 +	{
   1.459 +	double d;
   1.460 +	char* p;
   1.461 +	struct double_conv *dc;
   1.462 +
   1.463 +	TheTest.Next(_L("text to double conversion"));
   1.464 +	for (dc=strtods; dc->source; dc++)
   1.465 +		{
   1.466 +		d=strtod(dc->source,NULL);
   1.467 +		TEST(d==dc->answer);
   1.468 +		}
   1.469 +	for (dc=strtods; dc->source; dc++)
   1.470 +		{
   1.471 +		p=(char*)1;
   1.472 +		d=strtod(dc->source,&p);
   1.473 +		TEST(d==dc->answer);
   1.474 +		TEST(p==dc->source+dc->tail_offset);
   1.475 +		}
   1.476 +
   1.477 +	/* overflow positive number */
   1.478 +	d=strtod("9e9999", NULL);
   1.479 +	TEST(d==HUGE_VAL && errno==ERANGE);
   1.480 +
   1.481 +	/* overflow negative number */
   1.482 +	d=strtod("-9e9999", NULL);
   1.483 +	TEST(d==-HUGE_VAL && errno==ERANGE);
   1.484 +
   1.485 +	/* underflow number */
   1.486 +	d=strtod("9e-9999", NULL);
   1.487 +	TEST(d==0 && errno==ERANGE);
   1.488 +	d=strtod("-9e-9999", NULL);
   1.489 +	TEST(d==0 && errno==ERANGE);
   1.490 +}
   1.491 +
   1.492 +#define TEST_8	0x88
   1.493 +#define TEST_16	0x1617
   1.494 +#define TEST_32	0x32333435
   1.495 +
   1.496 +#define TEST_LIST \
   1.497 +	TEST_8,  TEST_16, TEST_32, \
   1.498 +	TEST_8,  TEST_32, TEST_16, \
   1.499 +	TEST_16, TEST_8,  TEST_32, \
   1.500 +	TEST_16, TEST_32, TEST_8,  \
   1.501 +	TEST_32, TEST_8,  TEST_16, \
   1.502 +	TEST_32, TEST_16, TEST_8
   1.503 +
   1.504 +/*
   1.505 +   Suppressing RVCT compiler warning (for char/short/long types):
   1.506 +   Warning:  #1256-D: "unsigned char" would have been promoted to "int" when passed through the ellipsis parameter;
   1.507 +   use the latter type instead.
   1.508 +          b = va_arg(ap, unsigned char);
   1.509 +              ^
   1.510 +*/
   1.511 +
   1.512 +#pragma diag_suppress 1256
   1.513 +
   1.514 +// The above RCVT warning is a compiler error in GCC. Below is the GGC friendly version of the function.
   1.515 +#ifdef __GCC32__
   1.516 +
   1.517 +void va_va_bwlblwwblwlblbwlwb(va_list ap)
   1.518 +	{
   1.519 +	unsigned long l;
   1.520 +	unsigned short w;
   1.521 +	unsigned char b;
   1.522 +
   1.523 +	l=0; w=0; b=0;
   1.524 +	b = va_arg(ap, int);
   1.525 +	TEST(b==TEST_8);
   1.526 +	w = va_arg(ap, int);
   1.527 +	TEST(w==TEST_16);
   1.528 +	l = va_arg(ap, unsigned long);
   1.529 +	TEST(l==TEST_32);
   1.530 +
   1.531 +	l=0; w=0; b=0;
   1.532 +	b = va_arg(ap, int);
   1.533 +	TEST(b==TEST_8);
   1.534 +	l = va_arg(ap, unsigned long);
   1.535 +	TEST(l==TEST_32);
   1.536 +	w = va_arg(ap, int);
   1.537 +	TEST(w==TEST_16);
   1.538 +
   1.539 +	l=0; w=0; b=0;
   1.540 +	w = va_arg(ap, int);
   1.541 +	TEST(w==TEST_16);
   1.542 +	b = va_arg(ap, int);
   1.543 +	TEST(b==TEST_8);
   1.544 +	l = va_arg(ap, unsigned long);
   1.545 +	TEST(l==TEST_32);
   1.546 +
   1.547 +	l=0; w=0; b=0;
   1.548 +	w = va_arg(ap,int);
   1.549 +	TEST(w==TEST_16);
   1.550 +	l = va_arg(ap, unsigned long);
   1.551 +	TEST(l==TEST_32);
   1.552 +	b = va_arg(ap, int);
   1.553 +	TEST(b==TEST_8);
   1.554 +
   1.555 +	l=0; w=0; b=0;
   1.556 +	l = va_arg(ap, unsigned long);
   1.557 +	TEST(l==TEST_32);
   1.558 +	b = va_arg(ap, int);
   1.559 +	TEST(b==TEST_8);
   1.560 +	w = va_arg(ap, int);
   1.561 +	TEST(w==TEST_16);
   1.562 +
   1.563 +	l=0; w=0; b=0;
   1.564 +	l = va_arg(ap, unsigned long);
   1.565 +	TEST(l==TEST_32);
   1.566 +	w = va_arg(ap, int);
   1.567 +	TEST(w==TEST_16);
   1.568 +	b = va_arg(ap, int);
   1.569 +	TEST(b==TEST_8);
   1.570 +	}
   1.571 +
   1.572 +
   1.573 +#else
   1.574 +
   1.575 +void va_va_bwlblwwblwlblbwlwb(va_list ap)
   1.576 +	{
   1.577 +	unsigned long l;
   1.578 +	unsigned short w;
   1.579 +	unsigned char b;
   1.580 +
   1.581 +	l=0; w=0; b=0;
   1.582 +	b = va_arg(ap, unsigned char);
   1.583 +	TEST(b==TEST_8);
   1.584 +	w = va_arg(ap, unsigned short);
   1.585 +	TEST(w==TEST_16);
   1.586 +	l = va_arg(ap, unsigned long);
   1.587 +	TEST(l==TEST_32);
   1.588 +
   1.589 +	l=0; w=0; b=0;
   1.590 +	b = va_arg(ap, unsigned char);
   1.591 +	TEST(b==TEST_8);
   1.592 +	l = va_arg(ap, unsigned long);
   1.593 +	TEST(l==TEST_32);
   1.594 +	w = va_arg(ap, unsigned short);
   1.595 +	TEST(w==TEST_16);
   1.596 +
   1.597 +	l=0; w=0; b=0;
   1.598 +	w = va_arg(ap, unsigned short);
   1.599 +	TEST(w==TEST_16);
   1.600 +	b = va_arg(ap, unsigned char);
   1.601 +	TEST(b==TEST_8);
   1.602 +	l = va_arg(ap, unsigned long);
   1.603 +	TEST(l==TEST_32);
   1.604 +
   1.605 +	l=0; w=0; b=0;
   1.606 +	w = va_arg(ap, unsigned short);
   1.607 +	TEST(w==TEST_16);
   1.608 +	l = va_arg(ap, unsigned long);
   1.609 +	TEST(l==TEST_32);
   1.610 +	b = va_arg(ap, unsigned char);
   1.611 +	TEST(b==TEST_8);
   1.612 +
   1.613 +	l=0; w=0; b=0;
   1.614 +	l = va_arg(ap, unsigned long);
   1.615 +	TEST(l==TEST_32);
   1.616 +	b = va_arg(ap, unsigned char);
   1.617 +	TEST(b==TEST_8);
   1.618 +	w = va_arg(ap, unsigned short);
   1.619 +	TEST(w==TEST_16);
   1.620 +
   1.621 +	l=0; w=0; b=0;
   1.622 +	l = va_arg(ap, unsigned long);
   1.623 +	TEST(l==TEST_32);
   1.624 +	w = va_arg(ap, unsigned short);
   1.625 +	TEST(w==TEST_16);
   1.626 +	b = va_arg(ap, unsigned char);
   1.627 +	TEST(b==TEST_8);
   1.628 +	}
   1.629 +
   1.630 +#endif
   1.631 +
   1.632 +
   1.633 +#pragma diag_default 1256
   1.634 +
   1.635 +void va_lbwlblwwblwlblbwlwb(unsigned long x, ...)
   1.636 +	{
   1.637 +	va_list ap;
   1.638 +	TEST(x==TEST_32);
   1.639 +	va_start(ap, x);
   1.640 +
   1.641 +	va_va_bwlblwwblwlblbwlwb(ap);
   1.642 +	}
   1.643 +
   1.644 +void va_args_test()
   1.645 +	{
   1.646 +	TheTest.Next(_L("variadic functions"));
   1.647 +
   1.648 +	va_lbwlblwwblwlblbwlwb( TEST_32, TEST_LIST);
   1.649 +	}
   1.650 +
   1.651 +void sprintf_test()
   1.652 +	{
   1.653 +	char buf[256];
   1.654 +	char* hw = "hello, world";
   1.655 +
   1.656 +	TheTest.Next(_L("sprintf function"));
   1.657 +
   1.658 +	/* WAP TOG Defect */
   1.659 +    sprintf(buf, "%.*f", 0, 10.1234);
   1.660 +	TEST(strcmp(buf, "10")==0);
   1.661 +	sprintf(buf, "%.0f", 10.1234);
   1.662 +	TEST(strcmp(buf, "10")==0);
   1.663 +
   1.664 +	/* From K&R */
   1.665 +	sprintf(buf, ":%s:", hw);
   1.666 +	TEST(strcmp(buf, ":hello, world:")==0);
   1.667 +
   1.668 +	sprintf(buf, ":%10s:", hw);
   1.669 +	TEST(strcmp(buf, ":hello, world:")==0);
   1.670 +
   1.671 +	sprintf(buf, ":%.10s:", hw);
   1.672 +	TEST(strcmp(buf, ":hello, wor:")==0);
   1.673 +
   1.674 +	sprintf(buf, ":%-10s:", hw);
   1.675 +	TEST(strcmp(buf, ":hello, world:")==0);
   1.676 +
   1.677 +	sprintf(buf, ":%.15s:", hw);
   1.678 +	TEST(strcmp(buf, ":hello, world:")==0);
   1.679 +
   1.680 +	sprintf(buf, ":%-15s:", hw);
   1.681 +	TEST(strcmp(buf, ":hello, world   :")==0);
   1.682 +
   1.683 +	sprintf(buf, ":%15.10s:", hw);
   1.684 +	TEST(strcmp(buf, ":     hello, wor:")==0);
   1.685 +
   1.686 +	sprintf(buf, ":%-15.10s:", hw);
   1.687 +	TEST(strcmp(buf, ":hello, wor     :")==0);
   1.688 +	}
   1.689 +
   1.690 +
   1.691 +static void MainL()
   1.692 +	{
   1.693 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STDLIB-LEGACY-TMISC-0001 TMISC tests "));
   1.694 +
   1.695 +	random_numbers();
   1.696 +	sorting();
   1.697 +	searching();
   1.698 +	setjmp_longjmp();
   1.699 +	casecmp();
   1.700 +	sscanf_test();
   1.701 +
   1.702 +	int argsc = 5;
   1.703 +	char *argsv[]=
   1.704 +		{
   1.705 +		"tmisc", "This", "is", "a", "test.",
   1.706 +		};
   1.707 +	arguments(argsc, argsv);
   1.708 +
   1.709 +	strtod_test();
   1.710 +	va_args_test();
   1.711 +	sprintf_test();
   1.712 +	}
   1.713 +
   1.714 +
   1.715 +TInt E32Main()
   1.716 +	{
   1.717 +	__UHEAP_MARK;
   1.718 +
   1.719 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.720 +    TEST(tc != NULL);
   1.721 +
   1.722 +	TheTest.Title();
   1.723 +    TRAPD(err, ::MainL());
   1.724 +	TEST2(err, KErrNone);
   1.725 +
   1.726 +	TheTest.End();
   1.727 +	TheTest.Close();
   1.728 +
   1.729 +	delete tc;
   1.730 +	CloseSTDLIB();
   1.731 +
   1.732 +	__UHEAP_MARKEND;
   1.733 +
   1.734 +	User::Heap().Check();
   1.735 +	return KErrNone;
   1.736 +	}