os/ossrv/genericopenlibs/cstdlib/TSTLIB/TMISC.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// This test has been converted from it original TMISC.C .
sl@0
    15
// The original was a manaul test and didn't work!
sl@0
    16
// Test code for bsearch, qsort etc. These are all functions which work directly
sl@0
    17
// without using the MSystemInterface - as such none of them use errno to indicate
sl@0
    18
// errors.
sl@0
    19
// 
sl@0
    20
//
sl@0
    21
sl@0
    22
#include <e32test.h>
sl@0
    23
#include <e32svr.h>
sl@0
    24
sl@0
    25
#include <stdarg.h>
sl@0
    26
#include <stdlib.h>
sl@0
    27
#include <stdio.h>
sl@0
    28
#include <math.h>  /* HUGE_VAL */
sl@0
    29
#include <errno.h> /* ERANGE */
sl@0
    30
#include "ESTLIB.H"
sl@0
    31
sl@0
    32
// Defined in ctest.h but contains lots of other declarations we don't want
sl@0
    33
#define test_Data		struct __testdata __td	/* declares global variable __td */
sl@0
    34
sl@0
    35
//
sl@0
    36
// Globals
sl@0
    37
sl@0
    38
static RTest TheTest(_L("TMisc"));
sl@0
    39
sl@0
    40
//
sl@0
    41
//
sl@0
    42
//Test macroses and functions
sl@0
    43
sl@0
    44
static void Check(TInt aValue, TInt aLine)
sl@0
    45
	{
sl@0
    46
	if(!aValue)
sl@0
    47
		{
sl@0
    48
		TheTest(EFalse, aLine);
sl@0
    49
		}
sl@0
    50
	}
sl@0
    51
static  void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    52
	{
sl@0
    53
	if(aValue != aExpected)
sl@0
    54
		{
sl@0
    55
		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
    56
		TheTest(EFalse, aLine);
sl@0
    57
		}
sl@0
    58
	}
sl@0
    59
sl@0
    60
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
    61
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
    62
sl@0
    63
//
sl@0
    64
// Tests
sl@0
    65
sl@0
    66
sl@0
    67
/* random numbers */
sl@0
    68
sl@0
    69
void random_numbers()
sl@0
    70
	{
sl@0
    71
	int i,r;
sl@0
    72
	int rs[20];
sl@0
    73
sl@0
    74
	TheTest.Next(_L("Random numbers"));
sl@0
    75
sl@0
    76
	for (i=0; i<20; i++)
sl@0
    77
		{
sl@0
    78
		r = rand();
sl@0
    79
		printf("%d ", r);
sl@0
    80
		}
sl@0
    81
	printf("\n");
sl@0
    82
	TheTest.Next(_L("Using srand()"));
sl@0
    83
	srand(12345678);
sl@0
    84
	for (i=0; i<20; i++)
sl@0
    85
		{
sl@0
    86
		rs[i]=rand();
sl@0
    87
		printf("%d ",rs[i]);
sl@0
    88
		}
sl@0
    89
	printf("\n");
sl@0
    90
	srand(12345678);
sl@0
    91
	for (i=0; i<20; i++)
sl@0
    92
		TEST(rand()==rs[i]);
sl@0
    93
	}
sl@0
    94
sl@0
    95
/* Sorting */
sl@0
    96
sl@0
    97
typedef struct {
sl@0
    98
	int a;
sl@0
    99
	int b;
sl@0
   100
	int c;
sl@0
   101
	} sort_item;
sl@0
   102
sl@0
   103
int compare_a (const void *left, const void *right)
sl@0
   104
	{
sl@0
   105
	sort_item *lp = (sort_item *)left;
sl@0
   106
	sort_item *rp = (sort_item *)right;
sl@0
   107
sl@0
   108
	if (lp->a < rp->a) return -1;
sl@0
   109
	if (lp->a > rp->a) return  1;
sl@0
   110
	return 0;
sl@0
   111
	}
sl@0
   112
sl@0
   113
int compare_ba (const void *left, const void *right)
sl@0
   114
	{
sl@0
   115
	sort_item *lp = (sort_item *)left;
sl@0
   116
	sort_item *rp = (sort_item *)right;
sl@0
   117
sl@0
   118
	if (lp->b < rp->b) return -1;
sl@0
   119
	if (lp->b > rp->b) return  1;
sl@0
   120
	/* b's are equal, sort on a's */
sl@0
   121
	if (lp->a < rp->a) return -1;
sl@0
   122
	if (lp->a > rp->a) return  1;
sl@0
   123
	return 0;
sl@0
   124
	}
sl@0
   125
sl@0
   126
#define NITEMS 200
sl@0
   127
sort_item list[NITEMS];
sl@0
   128
sl@0
   129
void validate(sort_item *p)
sl@0
   130
	{
sl@0
   131
	int i;
sl@0
   132
	for (i=0; i<NITEMS; i++,p++)
sl@0
   133
		{
sl@0
   134
		if (p->a==9)
sl@0
   135
			continue;
sl@0
   136
		TEST((p->a/4)+p->b == 5000);
sl@0
   137
		TEST((p->a*p->a)/4 == p->c);
sl@0
   138
		}
sl@0
   139
	}
sl@0
   140
sl@0
   141
void sorting()
sl@0
   142
	{
sl@0
   143
	int i;
sl@0
   144
	TheTest.Next(_L("Quicksort"));
sl@0
   145
	for (i=1; i<NITEMS; i++)
sl@0
   146
		{
sl@0
   147
		list[i].a = 2*i;
sl@0
   148
		list[i].b = 5000-(i/2);
sl@0
   149
		list[i].c = i*i;
sl@0
   150
		}
sl@0
   151
sl@0
   152
	/* Sort into increasing order of a. Want item 0 to sort to position 4 */
sl@0
   153
	list[0].a = 9;
sl@0
   154
	list[0].b = 10;
sl@0
   155
	list[0].c = 11;
sl@0
   156
sl@0
   157
	qsort(list, NITEMS, sizeof(list[0]), compare_a);
sl@0
   158
	TEST(list[4].c==11);
sl@0
   159
	validate(list);
sl@0
   160
sl@0
   161
	/* Resort into increasing order of b followed by a. Want item 0 to sort to position 5 */
sl@0
   162
	list[0].a = 9;
sl@0
   163
	list[0].b = 5000-((199-4)/2);
sl@0
   164
	list[0].c = 13;
sl@0
   165
sl@0
   166
	qsort(list, NITEMS, sizeof(list[0]), compare_ba);
sl@0
   167
	TEST(list[5].c==13);
sl@0
   168
	validate(list);
sl@0
   169
	}
sl@0
   170
sl@0
   171
void searching()
sl@0
   172
	{
sl@0
   173
	int i;
sl@0
   174
	sort_item *answer;
sl@0
   175
	sort_item not_there;
sl@0
   176
	TheTest.Next(_L("Binary search for existing items"));
sl@0
   177
	for (i=0; i<NITEMS; i++)
sl@0
   178
		{
sl@0
   179
		answer = (sort_item*)bsearch(&list[i],list,NITEMS,sizeof(list[0]),compare_ba);
sl@0
   180
		TEST(answer==&list[i]);
sl@0
   181
		}
sl@0
   182
	TheTest.Next(_L("Binary search for missing items"));
sl@0
   183
	for (i=0; i<NITEMS; i++)
sl@0
   184
		{
sl@0
   185
		not_there = list[i];
sl@0
   186
		not_there.a++;
sl@0
   187
		answer = (sort_item*)bsearch(&not_there,list,NITEMS,sizeof(list[0]),compare_ba);
sl@0
   188
		if (answer!=NULL)
sl@0
   189
			TEST(!compare_ba(answer,&not_there));
sl@0
   190
		}
sl@0
   191
	for (i=0; i<NITEMS; i++)
sl@0
   192
		{
sl@0
   193
		not_there = list[i];
sl@0
   194
		not_there.a--;
sl@0
   195
		answer = (sort_item*)bsearch(&not_there,list,NITEMS,sizeof(list[0]),compare_ba);
sl@0
   196
		if (answer!=NULL)
sl@0
   197
			TEST(!compare_ba(answer,&not_there));
sl@0
   198
		}
sl@0
   199
	}
sl@0
   200
sl@0
   201
void sscanf_test()
sl@0
   202
	{
sl@0
   203
	int in[4], i;
sl@0
   204
	TheTest.Next(_L("Simple SSCANF tests"));
sl@0
   205
sl@0
   206
	in[0] = in[1] = in[2] = in[3] = 6789;
sl@0
   207
	i = sscanf("1.2.3.4", "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
sl@0
   208
	TEST (in[0]==1);
sl@0
   209
	TEST (in[1]==2);
sl@0
   210
	TEST (in[2]==3);
sl@0
   211
	TEST (in[3]==4);
sl@0
   212
	TEST (i==4);
sl@0
   213
sl@0
   214
	i = sscanf("194.223.254.9", "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
sl@0
   215
	TEST (in[0]==194);
sl@0
   216
	TEST (in[1]==223);
sl@0
   217
	TEST (in[2]==254);
sl@0
   218
	TEST (in[3]==9);
sl@0
   219
	TEST (i==4);
sl@0
   220
sl@0
   221
	i = sscanf("17.183.hello.11", "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
sl@0
   222
	TEST (in[0]==17);
sl@0
   223
	TEST (in[1]==183);
sl@0
   224
	TEST (in[2]==254);
sl@0
   225
	TEST (in[3]==9);
sl@0
   226
	TEST (i==2);
sl@0
   227
	}
sl@0
   228
sl@0
   229
/* setjmp, longjmp */
sl@0
   230
sl@0
   231
#include <setjmp.h>
sl@0
   232
#include <string.h>
sl@0
   233
sl@0
   234
jmp_buf jbufs[4];
sl@0
   235
int count=0;
sl@0
   236
sl@0
   237
static int getStackPointer(void)
sl@0
   238
	{
sl@0
   239
	static char there;
sl@0
   240
	char here;
sl@0
   241
	return &here-&there;
sl@0
   242
	}
sl@0
   243
sl@0
   244
static int getgetStackPointer(void)
sl@0
   245
	{
sl@0
   246
	int n=4;	// local variable to cause change to stack pointer
sl@0
   247
	n+=getStackPointer();
sl@0
   248
	if (n==0)
sl@0
   249
		n=getStackPointer()+37;	// this never happens - it's just to defeat the optimiser
sl@0
   250
	return (n-4);
sl@0
   251
	}
sl@0
   252
sl@0
   253
void jmp_nest(int n)
sl@0
   254
	{
sl@0
   255
	int m=n+100;	// local variable to induce a stack frame
sl@0
   256
	if (n>0)
sl@0
   257
		jmp_nest(n-1);
sl@0
   258
	longjmp(jbufs[3],m);
sl@0
   259
	}
sl@0
   260
sl@0
   261
#ifdef __VC32__
sl@0
   262
#pragma optimize( "", off )		//stop the compiler breaking this TEST
sl@0
   263
#endif
sl@0
   264
sl@0
   265
void setjmp_longjmp()
sl@0
   266
	{
sl@0
   267
	volatile int i,r,j,k,l,m; // volatile to rid us of warnings
sl@0
   268
	volatile int sp1,sp2;
sl@0
   269
	TheTest.Next(_L("Setjmp"));
sl@0
   270
sl@0
   271
	sp1=getStackPointer();
sl@0
   272
	sp2=getgetStackPointer();
sl@0
   273
	TEST(sp1!=sp2);	// call from deeper function nesting should give a different answer
sl@0
   274
sl@0
   275
	memset(jbufs[0],0,sizeof(jmp_buf));
sl@0
   276
	memset(jbufs[1],0,sizeof(jmp_buf));
sl@0
   277
	memset(jbufs[2],0,sizeof(jmp_buf));
sl@0
   278
sl@0
   279
	r=setjmp(jbufs[0]);
sl@0
   280
	TEST(r==0);
sl@0
   281
sl@0
   282
	for (i=0,j=1,k=2,l=3,m=4; i<3; i++,j*=3,k+=j,l*=m,m-=2)
sl@0
   283
		{
sl@0
   284
		r=setjmp(jbufs[i]);
sl@0
   285
		TEST(r==0);
sl@0
   286
		TEST(j>i);
sl@0
   287
		}
sl@0
   288
	r=memcmp(jbufs[0],jbufs[2], sizeof(jmp_buf));
sl@0
   289
sl@0
   290
	if (r!=0)
sl@0
   291
		{
sl@0
   292
		RDebug::Print(_L("  Test code appears to be using preserved registers (a good thing)\n"));
sl@0
   293
		RDebug::Print(_L("  buf @   %08x %08x\n"), jbufs[0], jbufs[2]);
sl@0
   294
		for (i=0;i<16;i++)
sl@0
   295
			{
sl@0
   296
			if (jbufs[0][i] != jbufs[2][i])
sl@0
   297
				RDebug::Print(_L("  buf+%02d: %08x %08x\n"), i*4, jbufs[0][i], jbufs[2][i]);
sl@0
   298
			}
sl@0
   299
		}
sl@0
   300
	else
sl@0
   301
		RDebug::Print(_L("  Test code appears not to exercise preserved registers\n"));
sl@0
   302
sl@0
   303
	r=setjmp(jbufs[0]);
sl@0
   304
	TEST(r==0);
sl@0
   305
	r=setjmp(jbufs[2]);
sl@0
   306
	TEST(r==0);
sl@0
   307
	r=memcmp(jbufs[0],jbufs[2], sizeof(jmp_buf));
sl@0
   308
	TEST(r!=0);	/* must change the return address! */
sl@0
   309
sl@0
   310
	TheTest.Next(_L("Setjmp and longjmp"));
sl@0
   311
sl@0
   312
	r=setjmp(jbufs[0]);
sl@0
   313
	if (r==0)
sl@0
   314
		{
sl@0
   315
		TEST(count==0);
sl@0
   316
		count++;
sl@0
   317
		longjmp(jbufs[0],7);
sl@0
   318
		}
sl@0
   319
	else if (r==7)
sl@0
   320
		{
sl@0
   321
		TEST(count==1);
sl@0
   322
		count++;
sl@0
   323
		longjmp(jbufs[0],3);
sl@0
   324
		}
sl@0
   325
	else if (r==3)
sl@0
   326
		{
sl@0
   327
		TEST(count==2);
sl@0
   328
		count++;
sl@0
   329
		longjmp(jbufs[0],0);	/* 0 must be turned into 1 */
sl@0
   330
		}
sl@0
   331
	else
sl@0
   332
		{
sl@0
   333
		TEST(r==1);
sl@0
   334
		TEST(count==3);
sl@0
   335
		count++;
sl@0
   336
		}
sl@0
   337
sl@0
   338
	sp1=getStackPointer();
sl@0
   339
	r=setjmp(jbufs[3]);
sl@0
   340
	if (r==0)
sl@0
   341
		{
sl@0
   342
		sp2=getStackPointer();
sl@0
   343
		TEST(sp1==sp2);
sl@0
   344
		longjmp(jbufs[3],1);		// simple setjmp/longjmp
sl@0
   345
		}
sl@0
   346
	else if (r==1)
sl@0
   347
		{
sl@0
   348
		sp2=getStackPointer();
sl@0
   349
		TEST(sp1==sp2);
sl@0
   350
		jmp_nest(20);			// more complex example
sl@0
   351
		}
sl@0
   352
	else
sl@0
   353
		{
sl@0
   354
		TEST(r==100);
sl@0
   355
		sp2=getStackPointer();
sl@0
   356
		TEST(sp1==sp2);
sl@0
   357
		}
sl@0
   358
	}
sl@0
   359
sl@0
   360
#ifdef __VC32__
sl@0
   361
#pragma optimize( "", on )	//stop the compiler breaking this TEST
sl@0
   362
#endif
sl@0
   363
sl@0
   364
/* case-insensitive comparison */
sl@0
   365
sl@0
   366
#include <string.h>
sl@0
   367
char agrave[2]= {191,0};
sl@0
   368
sl@0
   369
void casecmp()
sl@0
   370
	{
sl@0
   371
	int r;
sl@0
   372
	char *s1,*s2;
sl@0
   373
	TheTest.Next(_L("Case-insensitive string comparison"));
sl@0
   374
sl@0
   375
	s1="abcd";
sl@0
   376
	r=strcasecmp(s1,s1);
sl@0
   377
	TEST(r==0);
sl@0
   378
sl@0
   379
	s2="abcde";
sl@0
   380
	r=strcasecmp(s1,s2);
sl@0
   381
	TEST(r<0);
sl@0
   382
sl@0
   383
	r=strcasecmp(s2,s1);
sl@0
   384
	TEST(r>0);
sl@0
   385
sl@0
   386
	r=strncasecmp(s1,s2,10);
sl@0
   387
	TEST(r<0);
sl@0
   388
sl@0
   389
	r=strncasecmp(s1,s2,4);
sl@0
   390
	TEST(r==0);
sl@0
   391
sl@0
   392
	s2="ABcD";
sl@0
   393
	r=strcmp(s1,s2);
sl@0
   394
	TEST(r!=0);
sl@0
   395
	r=strcasecmp(s1,s2);
sl@0
   396
	TEST(r==0);
sl@0
   397
sl@0
   398
#if 0
sl@0
   399
	/* Need some way to set up a proper folding example */
sl@0
   400
	r=strncasecmp(s2,agrave,1);
sl@0
   401
	TEST(r==0);
sl@0
   402
#endif
sl@0
   403
	}
sl@0
   404
sl@0
   405
void arguments(int argc, char *argv[])
sl@0
   406
	{
sl@0
   407
	int i;
sl@0
   408
sl@0
   409
	TheTest.Next(_L("Command line arguments"));
sl@0
   410
	TEST(argc>0);
sl@0
   411
	TEST(argv!=0);
sl@0
   412
	printf("  argc=%d\r\n", argc);
sl@0
   413
	for (i=0; i<argc; i++)
sl@0
   414
		{
sl@0
   415
		int j;
sl@0
   416
		int length=strlen(argv[i]);
sl@0
   417
		TEST(argv[i]!=0);
sl@0
   418
		printf("  argv[%d]= ", i);
sl@0
   419
		for (j=0;j<4;j++)
sl@0
   420
			{
sl@0
   421
			printf("%02x ", ((unsigned char *)argv[i])[j]);
sl@0
   422
			if (argv[i][j]=='\0')
sl@0
   423
				break;
sl@0
   424
			}
sl@0
   425
		for (;j<3;j++)
sl@0
   426
			printf("   ");
sl@0
   427
		printf(" \"%s\" length %d\r\n", argv[i], length);
sl@0
   428
		}
sl@0
   429
	}
sl@0
   430
sl@0
   431
struct double_conv {
sl@0
   432
	char* source;
sl@0
   433
	double answer;
sl@0
   434
	int tail_offset;
sl@0
   435
	};
sl@0
   436
sl@0
   437
struct double_conv strtods[] = {
sl@0
   438
	{ "1",		1.0,	1 },
sl@0
   439
	{ "0.1",	0.1,	3 },
sl@0
   440
	{ ".1",		0.1,	2 },
sl@0
   441
	{ " 0.1",	0.1,	4 },
sl@0
   442
	{ " 1 ",	1.0,	2 },
sl@0
   443
	{ "1x",		1.0,	1 },
sl@0
   444
	{ "x",		0.0,	0 },
sl@0
   445
	{ "1.5.3",	1.5,	3 },
sl@0
   446
	{ "1.0e-1m solid red;}...",	0.1,	6 },
sl@0
   447
	{ "1.0e2blah",	100.0,	5 },
sl@0
   448
	{ "3.1415e2blah",	314.15,	8 },
sl@0
   449
	{ "0.2em solid red;}...",	0.2,	3 },
sl@0
   450
	{ "0.2e5m solid red;}...",	20000.0,	5 },
sl@0
   451
	{ 0 }
sl@0
   452
	};
sl@0
   453
sl@0
   454
void strtod_test()
sl@0
   455
	{
sl@0
   456
	double d;
sl@0
   457
	char* p;
sl@0
   458
	struct double_conv *dc;
sl@0
   459
sl@0
   460
	TheTest.Next(_L("text to double conversion"));
sl@0
   461
	for (dc=strtods; dc->source; dc++)
sl@0
   462
		{
sl@0
   463
		d=strtod(dc->source,NULL);
sl@0
   464
		TEST(d==dc->answer);
sl@0
   465
		}
sl@0
   466
	for (dc=strtods; dc->source; dc++)
sl@0
   467
		{
sl@0
   468
		p=(char*)1;
sl@0
   469
		d=strtod(dc->source,&p);
sl@0
   470
		TEST(d==dc->answer);
sl@0
   471
		TEST(p==dc->source+dc->tail_offset);
sl@0
   472
		}
sl@0
   473
sl@0
   474
	/* overflow positive number */
sl@0
   475
	d=strtod("9e9999", NULL);
sl@0
   476
	TEST(d==HUGE_VAL && errno==ERANGE);
sl@0
   477
sl@0
   478
	/* overflow negative number */
sl@0
   479
	d=strtod("-9e9999", NULL);
sl@0
   480
	TEST(d==-HUGE_VAL && errno==ERANGE);
sl@0
   481
sl@0
   482
	/* underflow number */
sl@0
   483
	d=strtod("9e-9999", NULL);
sl@0
   484
	TEST(d==0 && errno==ERANGE);
sl@0
   485
	d=strtod("-9e-9999", NULL);
sl@0
   486
	TEST(d==0 && errno==ERANGE);
sl@0
   487
}
sl@0
   488
sl@0
   489
#define TEST_8	0x88
sl@0
   490
#define TEST_16	0x1617
sl@0
   491
#define TEST_32	0x32333435
sl@0
   492
sl@0
   493
#define TEST_LIST \
sl@0
   494
	TEST_8,  TEST_16, TEST_32, \
sl@0
   495
	TEST_8,  TEST_32, TEST_16, \
sl@0
   496
	TEST_16, TEST_8,  TEST_32, \
sl@0
   497
	TEST_16, TEST_32, TEST_8,  \
sl@0
   498
	TEST_32, TEST_8,  TEST_16, \
sl@0
   499
	TEST_32, TEST_16, TEST_8
sl@0
   500
sl@0
   501
/*
sl@0
   502
   Suppressing RVCT compiler warning (for char/short/long types):
sl@0
   503
   Warning:  #1256-D: "unsigned char" would have been promoted to "int" when passed through the ellipsis parameter;
sl@0
   504
   use the latter type instead.
sl@0
   505
          b = va_arg(ap, unsigned char);
sl@0
   506
              ^
sl@0
   507
*/
sl@0
   508
sl@0
   509
#pragma diag_suppress 1256
sl@0
   510
sl@0
   511
// The above RCVT warning is a compiler error in GCC. Below is the GGC friendly version of the function.
sl@0
   512
#ifdef __GCC32__
sl@0
   513
sl@0
   514
void va_va_bwlblwwblwlblbwlwb(va_list ap)
sl@0
   515
	{
sl@0
   516
	unsigned long l;
sl@0
   517
	unsigned short w;
sl@0
   518
	unsigned char b;
sl@0
   519
sl@0
   520
	l=0; w=0; b=0;
sl@0
   521
	b = va_arg(ap, int);
sl@0
   522
	TEST(b==TEST_8);
sl@0
   523
	w = va_arg(ap, int);
sl@0
   524
	TEST(w==TEST_16);
sl@0
   525
	l = va_arg(ap, unsigned long);
sl@0
   526
	TEST(l==TEST_32);
sl@0
   527
sl@0
   528
	l=0; w=0; b=0;
sl@0
   529
	b = va_arg(ap, int);
sl@0
   530
	TEST(b==TEST_8);
sl@0
   531
	l = va_arg(ap, unsigned long);
sl@0
   532
	TEST(l==TEST_32);
sl@0
   533
	w = va_arg(ap, int);
sl@0
   534
	TEST(w==TEST_16);
sl@0
   535
sl@0
   536
	l=0; w=0; b=0;
sl@0
   537
	w = va_arg(ap, int);
sl@0
   538
	TEST(w==TEST_16);
sl@0
   539
	b = va_arg(ap, int);
sl@0
   540
	TEST(b==TEST_8);
sl@0
   541
	l = va_arg(ap, unsigned long);
sl@0
   542
	TEST(l==TEST_32);
sl@0
   543
sl@0
   544
	l=0; w=0; b=0;
sl@0
   545
	w = va_arg(ap,int);
sl@0
   546
	TEST(w==TEST_16);
sl@0
   547
	l = va_arg(ap, unsigned long);
sl@0
   548
	TEST(l==TEST_32);
sl@0
   549
	b = va_arg(ap, int);
sl@0
   550
	TEST(b==TEST_8);
sl@0
   551
sl@0
   552
	l=0; w=0; b=0;
sl@0
   553
	l = va_arg(ap, unsigned long);
sl@0
   554
	TEST(l==TEST_32);
sl@0
   555
	b = va_arg(ap, int);
sl@0
   556
	TEST(b==TEST_8);
sl@0
   557
	w = va_arg(ap, int);
sl@0
   558
	TEST(w==TEST_16);
sl@0
   559
sl@0
   560
	l=0; w=0; b=0;
sl@0
   561
	l = va_arg(ap, unsigned long);
sl@0
   562
	TEST(l==TEST_32);
sl@0
   563
	w = va_arg(ap, int);
sl@0
   564
	TEST(w==TEST_16);
sl@0
   565
	b = va_arg(ap, int);
sl@0
   566
	TEST(b==TEST_8);
sl@0
   567
	}
sl@0
   568
sl@0
   569
sl@0
   570
#else
sl@0
   571
sl@0
   572
void va_va_bwlblwwblwlblbwlwb(va_list ap)
sl@0
   573
	{
sl@0
   574
	unsigned long l;
sl@0
   575
	unsigned short w;
sl@0
   576
	unsigned char b;
sl@0
   577
sl@0
   578
	l=0; w=0; b=0;
sl@0
   579
	b = va_arg(ap, unsigned char);
sl@0
   580
	TEST(b==TEST_8);
sl@0
   581
	w = va_arg(ap, unsigned short);
sl@0
   582
	TEST(w==TEST_16);
sl@0
   583
	l = va_arg(ap, unsigned long);
sl@0
   584
	TEST(l==TEST_32);
sl@0
   585
sl@0
   586
	l=0; w=0; b=0;
sl@0
   587
	b = va_arg(ap, unsigned char);
sl@0
   588
	TEST(b==TEST_8);
sl@0
   589
	l = va_arg(ap, unsigned long);
sl@0
   590
	TEST(l==TEST_32);
sl@0
   591
	w = va_arg(ap, unsigned short);
sl@0
   592
	TEST(w==TEST_16);
sl@0
   593
sl@0
   594
	l=0; w=0; b=0;
sl@0
   595
	w = va_arg(ap, unsigned short);
sl@0
   596
	TEST(w==TEST_16);
sl@0
   597
	b = va_arg(ap, unsigned char);
sl@0
   598
	TEST(b==TEST_8);
sl@0
   599
	l = va_arg(ap, unsigned long);
sl@0
   600
	TEST(l==TEST_32);
sl@0
   601
sl@0
   602
	l=0; w=0; b=0;
sl@0
   603
	w = va_arg(ap, unsigned short);
sl@0
   604
	TEST(w==TEST_16);
sl@0
   605
	l = va_arg(ap, unsigned long);
sl@0
   606
	TEST(l==TEST_32);
sl@0
   607
	b = va_arg(ap, unsigned char);
sl@0
   608
	TEST(b==TEST_8);
sl@0
   609
sl@0
   610
	l=0; w=0; b=0;
sl@0
   611
	l = va_arg(ap, unsigned long);
sl@0
   612
	TEST(l==TEST_32);
sl@0
   613
	b = va_arg(ap, unsigned char);
sl@0
   614
	TEST(b==TEST_8);
sl@0
   615
	w = va_arg(ap, unsigned short);
sl@0
   616
	TEST(w==TEST_16);
sl@0
   617
sl@0
   618
	l=0; w=0; b=0;
sl@0
   619
	l = va_arg(ap, unsigned long);
sl@0
   620
	TEST(l==TEST_32);
sl@0
   621
	w = va_arg(ap, unsigned short);
sl@0
   622
	TEST(w==TEST_16);
sl@0
   623
	b = va_arg(ap, unsigned char);
sl@0
   624
	TEST(b==TEST_8);
sl@0
   625
	}
sl@0
   626
sl@0
   627
#endif
sl@0
   628
sl@0
   629
sl@0
   630
#pragma diag_default 1256
sl@0
   631
sl@0
   632
void va_lbwlblwwblwlblbwlwb(unsigned long x, ...)
sl@0
   633
	{
sl@0
   634
	va_list ap;
sl@0
   635
	TEST(x==TEST_32);
sl@0
   636
	va_start(ap, x);
sl@0
   637
sl@0
   638
	va_va_bwlblwwblwlblbwlwb(ap);
sl@0
   639
	}
sl@0
   640
sl@0
   641
void va_args_test()
sl@0
   642
	{
sl@0
   643
	TheTest.Next(_L("variadic functions"));
sl@0
   644
sl@0
   645
	va_lbwlblwwblwlblbwlwb( TEST_32, TEST_LIST);
sl@0
   646
	}
sl@0
   647
sl@0
   648
void sprintf_test()
sl@0
   649
	{
sl@0
   650
	char buf[256];
sl@0
   651
	char* hw = "hello, world";
sl@0
   652
sl@0
   653
	TheTest.Next(_L("sprintf function"));
sl@0
   654
sl@0
   655
	/* WAP TOG Defect */
sl@0
   656
    sprintf(buf, "%.*f", 0, 10.1234);
sl@0
   657
	TEST(strcmp(buf, "10")==0);
sl@0
   658
	sprintf(buf, "%.0f", 10.1234);
sl@0
   659
	TEST(strcmp(buf, "10")==0);
sl@0
   660
sl@0
   661
	/* From K&R */
sl@0
   662
	sprintf(buf, ":%s:", hw);
sl@0
   663
	TEST(strcmp(buf, ":hello, world:")==0);
sl@0
   664
sl@0
   665
	sprintf(buf, ":%10s:", hw);
sl@0
   666
	TEST(strcmp(buf, ":hello, world:")==0);
sl@0
   667
sl@0
   668
	sprintf(buf, ":%.10s:", hw);
sl@0
   669
	TEST(strcmp(buf, ":hello, wor:")==0);
sl@0
   670
sl@0
   671
	sprintf(buf, ":%-10s:", hw);
sl@0
   672
	TEST(strcmp(buf, ":hello, world:")==0);
sl@0
   673
sl@0
   674
	sprintf(buf, ":%.15s:", hw);
sl@0
   675
	TEST(strcmp(buf, ":hello, world:")==0);
sl@0
   676
sl@0
   677
	sprintf(buf, ":%-15s:", hw);
sl@0
   678
	TEST(strcmp(buf, ":hello, world   :")==0);
sl@0
   679
sl@0
   680
	sprintf(buf, ":%15.10s:", hw);
sl@0
   681
	TEST(strcmp(buf, ":     hello, wor:")==0);
sl@0
   682
sl@0
   683
	sprintf(buf, ":%-15.10s:", hw);
sl@0
   684
	TEST(strcmp(buf, ":hello, wor     :")==0);
sl@0
   685
	}
sl@0
   686
sl@0
   687
sl@0
   688
static void MainL()
sl@0
   689
	{
sl@0
   690
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STDLIB-LEGACY-TMISC-0001 TMISC tests "));
sl@0
   691
sl@0
   692
	random_numbers();
sl@0
   693
	sorting();
sl@0
   694
	searching();
sl@0
   695
	setjmp_longjmp();
sl@0
   696
	casecmp();
sl@0
   697
	sscanf_test();
sl@0
   698
sl@0
   699
	int argsc = 5;
sl@0
   700
	char *argsv[]=
sl@0
   701
		{
sl@0
   702
		"tmisc", "This", "is", "a", "test.",
sl@0
   703
		};
sl@0
   704
	arguments(argsc, argsv);
sl@0
   705
sl@0
   706
	strtod_test();
sl@0
   707
	va_args_test();
sl@0
   708
	sprintf_test();
sl@0
   709
	}
sl@0
   710
sl@0
   711
sl@0
   712
TInt E32Main()
sl@0
   713
	{
sl@0
   714
	__UHEAP_MARK;
sl@0
   715
sl@0
   716
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   717
    TEST(tc != NULL);
sl@0
   718
sl@0
   719
	TheTest.Title();
sl@0
   720
    TRAPD(err, ::MainL());
sl@0
   721
	TEST2(err, KErrNone);
sl@0
   722
sl@0
   723
	TheTest.End();
sl@0
   724
	TheTest.Close();
sl@0
   725
sl@0
   726
	delete tc;
sl@0
   727
	CloseSTDLIB();
sl@0
   728
sl@0
   729
	__UHEAP_MARKEND;
sl@0
   730
sl@0
   731
	User::Heap().Check();
sl@0
   732
	return KErrNone;
sl@0
   733
	}