os/kernelhwsrv/kerneltest/e32test/buffer/t_buf.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) 1994-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 the License "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
// e32test\buffer\t_buf.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test methods of the TBuf16, TBuf8, TBuf template class.
sl@0
    17
// API Information:
sl@0
    18
// TBuf16, TBuf8, TBuf.
sl@0
    19
// Details :
sl@0
    20
// - Create some 16 bit modifiable descriptors, 8 bit modifiable descriptors
sl@0
    21
// of fixed length, Build-independent modifiable descriptors, initialize 
sl@0
    22
// with different strings and check for
sl@0
    23
// - Comparison operators,
sl@0
    24
// - Property access methods,
sl@0
    25
// - Fill & swap methods,
sl@0
    26
// - Conversion methods,
sl@0
    27
// - Comparison methods,
sl@0
    28
// - Pattern Matching methods,
sl@0
    29
// - Pattern Locating methods,
sl@0
    30
// - Copying methods, 
sl@0
    31
// - Find, FindC, FindF methods,
sl@0
    32
// - Repeat, Trim, TrimLeft, TrimRight, Insert, Delete, Left,
sl@0
    33
// Right, Mid methods,
sl@0
    34
// - Formatting methods,
sl@0
    35
// - Replace methods are as expected.
sl@0
    36
// - Construct some descriptors with buffer length, string and buffer reference and
sl@0
    37
// verify that they are created successfully.
sl@0
    38
// - Test assignment operators and comparison operators for different descriptors.
sl@0
    39
// - Initialize some descriptors and check descriptors' maximum length, length and 
sl@0
    40
// size are as expected. 
sl@0
    41
// - Check Fill and Swap methods are as expected.
sl@0
    42
// - Test Fold, Collate, LowerCase, UpperCase methods are as expected.
sl@0
    43
// - Test Comparison methods are as expected.
sl@0
    44
// - Test pattern matching for simple string, wild cards with collated comparison. Verify that the 
sl@0
    45
// return value is KErrNotFound when pattern doesn't match.
sl@0
    46
// - Check Locating methods by searching character in forward and backward direction and 
sl@0
    47
// verify the return value is KErrNotFound when unavailable character is searched.
sl@0
    48
// - Check copying strings and converting those into lower and upper case strings are
sl@0
    49
// as expected.
sl@0
    50
// - Check Find methods by searching string and verify the return value is KErrNotFound when 
sl@0
    51
// unavailable string is searched.
sl@0
    52
// - Check Repeat, Trim, Insert and Delete methods are as expected.
sl@0
    53
// - Check the formatting operations are as expected.
sl@0
    54
// - Check integer to decimal character representation is as expected.
sl@0
    55
// - Check integer to character representation with different number system is as expected.
sl@0
    56
// - Check string formatting with variable parameter list is as expected
sl@0
    57
// - Check Replace method by replacing string at different places in a string is as expected.
sl@0
    58
// - Check the conversion of real numbers, extended precision real numbers into string
sl@0
    59
// format is as expected.
sl@0
    60
// - Check Format and FormatList methods are as expected.
sl@0
    61
// - Check Format of TReal is as expected.
sl@0
    62
// - Check the non-leaving and leaving descriptors overflow handlers are as expected. 
sl@0
    63
// Platforms/Drives/Compatibility:
sl@0
    64
// All 
sl@0
    65
// Assumptions/Requirement/Pre-requisites:
sl@0
    66
// Failures and causes:
sl@0
    67
// Base Port information:
sl@0
    68
// 
sl@0
    69
//
sl@0
    70
sl@0
    71
#include <e32test.h>
sl@0
    72
#include <e32math.h>
sl@0
    73
#include <hal.h>
sl@0
    74
#include <hal_data.h>
sl@0
    75
#include <hal_data.h>
sl@0
    76
#include <e32svr.h>
sl@0
    77
sl@0
    78
#ifdef __VC32__
sl@0
    79
    // Solve compilation problem caused by non-English locale
sl@0
    80
    #pragma setlocale("english")
sl@0
    81
#endif
sl@0
    82
sl@0
    83
LOCAL_D RTest test(_L("T_BUF"));
sl@0
    84
sl@0
    85
#pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
sl@0
    86
#pragma warning(disable: 4310) // disabling warning "cast truncates constant value"
sl@0
    87
sl@0
    88
#undef _TL
sl@0
    89
#define _TL(a) DESTEMPLATE((S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)) 
sl@0
    90
#undef _TS
sl@0
    91
#define _TS(a) ((const S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)) 
sl@0
    92
sl@0
    93
template<class T,class S,class DESTEMPLATE>	
sl@0
    94
class TestTBuf
sl@0
    95
	{
sl@0
    96
public:
sl@0
    97
	TestTBuf(TInt aLength); // Test class constructor.
sl@0
    98
	void Test1();   // Tests all functions of the class.
sl@0
    99
	void Test2();   // Tests all constructors.
sl@0
   100
	void Test3();	// Tests all assignment operators
sl@0
   101
	void Test4();	// Tests all comparison operators
sl@0
   102
	void Test5();	// Tests all property access
sl@0
   103
	void Test6();	// Tests all fill and swap
sl@0
   104
	void Test7();	// Tests all conversion 
sl@0
   105
	void Test8();	// Tests all comparison
sl@0
   106
	void Test9();	// Tests all matching
sl@0
   107
	void Test10();	// Tests all locating
sl@0
   108
	void Test11();	// Tests all Copying
sl@0
   109
	void Test12();	// Tests all finding
sl@0
   110
	void Test13();	// Tests all basic like ops
sl@0
   111
	void Test14();  // Tests all formating
sl@0
   112
	void Test15();  // Tests all replacing
sl@0
   113
	void test_TBuf(); // Test all classes
sl@0
   114
protected:
sl@0
   115
	void Test1List(T* a,T* b,...);
sl@0
   116
	void Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...);
sl@0
   117
private:
sl@0
   118
	TInt iMaxBufLength;
sl@0
   119
	};
sl@0
   120
sl@0
   121
void TestEq(const TDesC8& a, const TDesC8& b, TInt aLine)
sl@0
   122
	{
sl@0
   123
	if (a!=b)
sl@0
   124
		{
sl@0
   125
		TBuf<256> buf;
sl@0
   126
		test.Printf(_L("LINE %d:\n"),aLine);
sl@0
   127
		buf.Copy(a);
sl@0
   128
		test.Printf(_L("a=%S\n"),&buf);
sl@0
   129
		buf.Copy(b);
sl@0
   130
		test.Printf(_L("b=%S\n"),&buf);
sl@0
   131
		test(0);
sl@0
   132
		}
sl@0
   133
	}
sl@0
   134
sl@0
   135
void TestEq(const TDesC16& a, const TDesC16& b, TInt aLine)
sl@0
   136
	{
sl@0
   137
	if (a!=b)
sl@0
   138
		{
sl@0
   139
		test.Printf(_L("LINE %d:\n"),aLine);
sl@0
   140
		test.Printf(_L("a=%S\n"),&a);
sl@0
   141
		test.Printf(_L("b=%S\n"),&b);
sl@0
   142
		test(0);
sl@0
   143
		}
sl@0
   144
	}
sl@0
   145
sl@0
   146
#define TESTEQ(a,b)	TestEq((a),(b),__LINE__)
sl@0
   147
sl@0
   148
template <class T,class S,class DESTEMPLATE>
sl@0
   149
GLDEF_C TestTBuf<T,S,DESTEMPLATE>::TestTBuf(TInt aLength)
sl@0
   150
// Constructor.
sl@0
   151
	: iMaxBufLength(aLength)
sl@0
   152
	{}
sl@0
   153
sl@0
   154
template <class T,class S,class DESTEMPLATE>
sl@0
   155
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1List(T* a,T* b,...)
sl@0
   156
// Test the format with list functions.
sl@0
   157
	{
sl@0
   158
	VA_LIST list;
sl@0
   159
	VA_START(list,b);
sl@0
   160
	a->Format(*b,list);
sl@0
   161
	VA_START(list,b);
sl@0
   162
	a->AppendFormat(*b,list);
sl@0
   163
	VA_START(list,b);
sl@0
   164
	a->Format(_TL("%d"),list);
sl@0
   165
	VA_START(list,b);
sl@0
   166
	a->AppendFormat(_TL("%d"),list);
sl@0
   167
	}
sl@0
   168
sl@0
   169
template <class T,class S,class DESTEMPLATE>
sl@0
   170
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1()
sl@0
   171
// Tests all functions of the class.
sl@0
   172
	{
sl@0
   173
	test.Start(_L("Constructors"));
sl@0
   174
	T a;
sl@0
   175
	T b;
sl@0
   176
	T c(_TL("AB"));
sl@0
   177
	T d(c);
sl@0
   178
sl@0
   179
// To avoid unused warning
sl@0
   180
    a.Length();
sl@0
   181
    b.Length();
sl@0
   182
    c.Length();
sl@0
   183
    d.Length();
sl@0
   184
sl@0
   185
	test.Next(_L("Copy operators"));
sl@0
   186
	a=_TL("DE");
sl@0
   187
	b=c;
sl@0
   188
	a+=_TL("DE");
sl@0
   189
	b+=c;
sl@0
   190
sl@0
   191
	test.Next(_L("Comparison operators"));
sl@0
   192
	TInt t=(a<b);
sl@0
   193
	t=(a<_TL("AB"));
sl@0
   194
	t=(_TL("AB")<a);
sl@0
   195
	t=(a<=b);
sl@0
   196
	t=(a<=_TL("AB"));
sl@0
   197
	t=(_TL("AB")<=a);
sl@0
   198
	t=(a>b);
sl@0
   199
	t=(a>_TL("AB"));
sl@0
   200
	t=(_TL("AB")>a);
sl@0
   201
	t=(a>=b);
sl@0
   202
	t=(a>=_TL("AB"));
sl@0
   203
	t=(_TL("AB")>=a);
sl@0
   204
	t=(a==b);
sl@0
   205
	t=(a==_TL("AB"));
sl@0
   206
	t=(_TL("AB")==a);
sl@0
   207
	t=(a!=_TL("AB"));
sl@0
   208
	t=(_TL("AB")!=a);
sl@0
   209
sl@0
   210
	test.Next(_L("Property access"));
sl@0
   211
	a[0]='A';
sl@0
   212
	a.Ptr();
sl@0
   213
	TInt i=a.MaxLength()-a.Length();
sl@0
   214
	i=a.Size();
sl@0
   215
	a.Zero();
sl@0
   216
	a.SetLength(2); 
sl@0
   217
sl@0
   218
	test.Next(_L("Fill & swap"));
sl@0
   219
	a.Fill(' ');
sl@0
   220
	a.Fill(' ',iMaxBufLength);
sl@0
   221
	a.FillZ();
sl@0
   222
	a.FillZ(iMaxBufLength);
sl@0
   223
	a.Swap(b);
sl@0
   224
sl@0
   225
	test.Next(_L("Conversion"));
sl@0
   226
	a.Fold();
sl@0
   227
	a.Collate();
sl@0
   228
	a.LowerCase();
sl@0
   229
	a.UpperCase();
sl@0
   230
	a.Capitalize();
sl@0
   231
sl@0
   232
	test.Next(_L("Comparison"));
sl@0
   233
	a.Compare(b);
sl@0
   234
	a.Compare(_TL("AB"));
sl@0
   235
	a.CompareF(b);
sl@0
   236
	a.CompareF(_TL("AB"));
sl@0
   237
	a.CompareC(b);
sl@0
   238
	a.CompareC(_TL("AB"));
sl@0
   239
sl@0
   240
	test.Next(_L("Matching"));
sl@0
   241
	a.Match(b);
sl@0
   242
	a.Match(_TL("AB"));
sl@0
   243
	a.MatchF(b);
sl@0
   244
	a.MatchF(_TL("AB"));
sl@0
   245
sl@0
   246
	T buf(_TL("abcdef"));
sl@0
   247
	TInt res = buf.MatchF(_TL("abc*def"));
sl@0
   248
	test(res == 0);
sl@0
   249
sl@0
   250
	a.MatchC(b);
sl@0
   251
	a.MatchC(_TL("AB"));
sl@0
   252
sl@0
   253
	test.Next(_L("Locating"));
sl@0
   254
	a.Locate('A');
sl@0
   255
	a.LocateF('A');
sl@0
   256
	a.LocateReverse('A');
sl@0
   257
	a.LocateReverseF('A');
sl@0
   258
sl@0
   259
	test.Next(_L("Copying"));
sl@0
   260
	a.Copy(b);
sl@0
   261
	a.Copy(_TL("AB"));
sl@0
   262
//	a.Copy(_TL("AB"),1);
sl@0
   263
	a.CopyF(b);
sl@0
   264
	a.CopyF(_TL("AB"));
sl@0
   265
	a.CopyC(b);
sl@0
   266
	a.CopyC(_TL("AB"));
sl@0
   267
	a.CopyLC(b);
sl@0
   268
	a.CopyLC(_TL("AB"));
sl@0
   269
	a.CopyUC(b);
sl@0
   270
	a.CopyUC(_TL("AB"));
sl@0
   271
	a.CopyCP(b);
sl@0
   272
	a.CopyCP(_TL("AB"));
sl@0
   273
sl@0
   274
	test.Next(_L("Finding"));
sl@0
   275
	a.Find(b);
sl@0
   276
	a.Find(_TL("AB"));
sl@0
   277
	a.FindF(b);
sl@0
   278
	a.FindF(_TL("AB"));
sl@0
   279
	a.FindC(b);
sl@0
   280
	a.FindC(_TL("AB"));
sl@0
   281
sl@0
   282
	test.Next(_L("Basic like ops"));
sl@0
   283
	a.Repeat(b);
sl@0
   284
	a.Repeat(_TL("AB"));
sl@0
   285
	a.TrimLeft();
sl@0
   286
	a.TrimRight();
sl@0
   287
	a.Trim();
sl@0
   288
	b=_TL("AA");
sl@0
   289
	a.Insert(0,b);
sl@0
   290
	a.Delete(0,2);
sl@0
   291
	b = a.Left(1);
sl@0
   292
	b = a.Right(1);
sl@0
   293
	b = a.Mid(0,1);
sl@0
   294
sl@0
   295
	test.Next(_L("Formating"));
sl@0
   296
	a.Justify(_TL("AB"),10,ELeft,' ');
sl@0
   297
	a.Justify(b,10,ELeft,' ');
sl@0
   298
	b.Fill('A',2);
sl@0
   299
	a.Zero();
sl@0
   300
	a.AppendJustify(_TL("AB"),10,ELeft,' ');
sl@0
   301
	a.AppendJustify(b,10,ELeft,' ');
sl@0
   302
	TInt v1=10;
sl@0
   303
	a.Num(v1);
sl@0
   304
	a.AppendNum(v1);
sl@0
   305
	TInt v2=10;
sl@0
   306
	a.Num((TUint)v2,EHex);
sl@0
   307
	a.AppendNum((TUint)v2,EHex);
sl@0
   308
	a.NumUC((TUint)v2,EHex);
sl@0
   309
	a.AppendNumUC((TUint)v2,EHex);
sl@0
   310
	TReal v3=10.0;
sl@0
   311
	TRealFormat ff;
sl@0
   312
	ff.iType=KRealFormatFixed;
sl@0
   313
	ff.iWidth=10;
sl@0
   314
	ff.iPlaces=2;
sl@0
   315
	ff.iPoint='.';
sl@0
   316
	ff.iTriad=',';
sl@0
   317
	ff.iTriLen=3;
sl@0
   318
	a.Num(v3,ff);
sl@0
   319
	a.AppendNum(v3,ff);
sl@0
   320
	a.Format(_TL("%d"),12);
sl@0
   321
	a.AppendFormat(_TL("%d"),12);
sl@0
   322
	b=_TL("%d");
sl@0
   323
	a.Format(b,12);
sl@0
   324
	a.AppendFormat(b,12);
sl@0
   325
	Test1List(&a,&b,12);
sl@0
   326
sl@0
   327
	test.Next(_L("Replacing"));
sl@0
   328
	a=_TL("AAC");
sl@0
   329
	b=_TL("B");
sl@0
   330
	a.Replace(1,1,b);
sl@0
   331
	test.End();
sl@0
   332
	}
sl@0
   333
sl@0
   334
template <class T,class S,class DESTEMPLATE>
sl@0
   335
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test2()
sl@0
   336
// Tests all constructors.
sl@0
   337
	{
sl@0
   338
	test.Start(_L("Default"));
sl@0
   339
	T a;
sl@0
   340
	test(a.MaxLength()==iMaxBufLength);
sl@0
   341
	test(a.Length()==0);
sl@0
   342
sl@0
   343
	test.Next(_L("By length"));
sl@0
   344
	T b(iMaxBufLength>>1);
sl@0
   345
	test(b.MaxLength()==iMaxBufLength);
sl@0
   346
	test(b.Length()==(iMaxBufLength>>1));
sl@0
   347
sl@0
   348
	test.Next(_L("By string"));
sl@0
   349
	T c(_TL("AB"));
sl@0
   350
	test(c.MaxLength()==iMaxBufLength);
sl@0
   351
	test(c.Length()==2);
sl@0
   352
	test(c[0]=='A');
sl@0
   353
	test(c[1]=='B');
sl@0
   354
sl@0
   355
	test.Next(_L("By buffer reference"));
sl@0
   356
	T d(c);
sl@0
   357
	test(d.MaxLength()==iMaxBufLength);
sl@0
   358
	test(d.Length()==2);
sl@0
   359
	test(d[0]=='A');
sl@0
   360
	test(d[1]=='B');
sl@0
   361
	test.End();
sl@0
   362
	}
sl@0
   363
sl@0
   364
template <class T,class S,class DESTEMPLATE>
sl@0
   365
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test3()
sl@0
   366
// Tests all assignment operators
sl@0
   367
	{
sl@0
   368
	test.Start(_L("By String"));
sl@0
   369
	T a;
sl@0
   370
	a=_TL("AB");
sl@0
   371
	a+=_TL("CD");
sl@0
   372
	test(a.Length()==4);
sl@0
   373
	test(a==_TL("ABCD"));
sl@0
   374
sl@0
   375
	test.Next(_L("By buffer"));
sl@0
   376
	T b;
sl@0
   377
	b=a;
sl@0
   378
	b+=a;
sl@0
   379
	test(b.Length()==8);
sl@0
   380
	test(b==_TL("ABCDABCD"));
sl@0
   381
//	
sl@0
   382
	test.End();
sl@0
   383
	}
sl@0
   384
sl@0
   385
template <class T,class S,class DESTEMPLATE>
sl@0
   386
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test4()
sl@0
   387
// Test all comparison operators
sl@0
   388
	{
sl@0
   389
	test.Start(_L("By NULL string"));
sl@0
   390
	T a;
sl@0
   391
	test(a==_TL(""));		// NULL strings
sl@0
   392
	test(!(a!=_TL("")));
sl@0
   393
	test(a<=_TL(""));
sl@0
   394
	test(a>=_TL(""));
sl@0
   395
	test(!(a<_TL("")));
sl@0
   396
	test(!(a>_TL("")));
sl@0
   397
	test(_TL("")==a);
sl@0
   398
	test(!(_TL("")!=a));
sl@0
   399
	test(_TL("")<=a);
sl@0
   400
	test(_TL("")>=a);
sl@0
   401
	test(!(_TL("")<a));
sl@0
   402
	test(!(_TL("")>a));
sl@0
   403
sl@0
   404
	test.Next(_L("By string or buffer"));
sl@0
   405
	a=_TL("abc");
sl@0
   406
	test(a==_TL("abc"));		// ==
sl@0
   407
	test(!(a==_TL("xyz")));
sl@0
   408
	test(!(a==_TL("aa")));
sl@0
   409
	test(_TL("abc")==a);
sl@0
   410
	test(!(_TL("xyz")==a));
sl@0
   411
	test(!(_TL("aa")==a));
sl@0
   412
	test(a!=_TL("xyz"));		// !=
sl@0
   413
	test(!(a!=_TL("abc")));
sl@0
   414
	test(a!=_TL("aa"));
sl@0
   415
	test(_TL("xyz")!=a);
sl@0
   416
	test(!(_TL("abc")!=a));
sl@0
   417
	test(_TL("aa")!=a);
sl@0
   418
	test(a<_TL("x"));			// <
sl@0
   419
	test(!(a<_TL("abc")));
sl@0
   420
	test(!(a<_TL("aa")));
sl@0
   421
	test(_TL("aa")<a);
sl@0
   422
	test(!(_TL("abc")<a));
sl@0
   423
	test(!(_TL("xyz")<a));
sl@0
   424
	test(a>_TL("aa"));			// >
sl@0
   425
	test(!(a>_TL("abc")));
sl@0
   426
	test(!(a>_TL("xyz")));
sl@0
   427
	test(_TL("xyz")>a);
sl@0
   428
	test(!(_TL("abc")>a));
sl@0
   429
	test(!(_TL("aa")>a));
sl@0
   430
	test(a>=_TL("abc"));		// >=
sl@0
   431
	test(!(a>=_TL("xyz")));
sl@0
   432
	test(a>=_TL("aa"));
sl@0
   433
	test(_TL("abc")>=a);
sl@0
   434
	test(!(_TL("aaa")>=a));
sl@0
   435
	test(_TL("xyz")>=a);
sl@0
   436
	test(a<=_TL("abc"));		// <=
sl@0
   437
	test(!(a<=_TL("aa")));
sl@0
   438
	test(a<=_TL("xyz"));
sl@0
   439
	test(_TL("abc")<=a);
sl@0
   440
	test(!(_TL("xyz")<=a));
sl@0
   441
	test(_TL("aa")<=a);
sl@0
   442
sl@0
   443
	test.Next(_L("By special characters"));
sl@0
   444
	a=_TL("!@#$%^&*()");
sl@0
   445
	test(a==_TL("!@#$%^&*()"));
sl@0
   446
	test.End();	
sl@0
   447
	}
sl@0
   448
sl@0
   449
template <class T,class S,class DESTEMPLATE>
sl@0
   450
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test5()
sl@0
   451
// Test all property access
sl@0
   452
	{
sl@0
   453
	test.Start(_L("Length and Size"));
sl@0
   454
	T a;
sl@0
   455
	TInt maxLength=a.MaxLength();
sl@0
   456
    TInt i;
sl@0
   457
	for (i=0;i<maxLength;i++)
sl@0
   458
		{
sl@0
   459
		test(a.Length()==i);	// Length
sl@0
   460
		test(a.Size()==(TInt)(sizeof(S)*i)); // Size
sl@0
   461
		a.AppendNum(i%10);
sl@0
   462
		}
sl@0
   463
	const T b=a;
sl@0
   464
	for (i=0;i<maxLength;i++)
sl@0
   465
		{
sl@0
   466
		test(a[i]=='0'+(i%10));	// At
sl@0
   467
		test(b[i]=='0'+(i%10));	// AtConst
sl@0
   468
		}
sl@0
   469
	test(a[0]==*a.Ptr());	//Ptr
sl@0
   470
	a.SetLength(0);	// SetLength
sl@0
   471
	test(a.Length()==0);
sl@0
   472
	a.SetLength(maxLength-1);
sl@0
   473
	test(a.Length()==maxLength-1);
sl@0
   474
	a.Zero();	// Null
sl@0
   475
	test(a.Length()==0);
sl@0
   476
	test.End();
sl@0
   477
	}
sl@0
   478
sl@0
   479
template <class T,class S,class DESTEMPLATE>
sl@0
   480
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test6()
sl@0
   481
// Fill and Swap
sl@0
   482
	{
sl@0
   483
	test.Start(_L("Fill and Swap"));
sl@0
   484
	T a,b;
sl@0
   485
	TChar chr;
sl@0
   486
	TInt j;
sl@0
   487
	TInt maxLength=a.MaxLength();
sl@0
   488
	for (TInt i=0;i<maxLength;i++)
sl@0
   489
		{
sl@0
   490
		chr=(i%10)+'0';
sl@0
   491
		a.SetLength(i);
sl@0
   492
		a.Fill(chr);	// Fill(TChar)
sl@0
   493
		b.Swap(a);
sl@0
   494
		test(b.Length()==i);	// Swap
sl@0
   495
		j=0;
sl@0
   496
		while (j<i)
sl@0
   497
			test(b[j++]=='0'+(i%10));
sl@0
   498
		b.FillZ();	// FillZ()
sl@0
   499
		a.Swap(b);
sl@0
   500
		j=0;
sl@0
   501
		while (j<i)
sl@0
   502
			test(a[j++]==0);
sl@0
   503
		a.Fill(chr,i);	// Fill(TChar,TUint)
sl@0
   504
		j=0;
sl@0
   505
		while (j<i)
sl@0
   506
			test(a[j++]=='0'+(i%10));
sl@0
   507
		a.FillZ(i);	// FillZ(TUint)
sl@0
   508
		j=0;
sl@0
   509
		while (j<i)
sl@0
   510
			test(a[j++]==0);
sl@0
   511
		}
sl@0
   512
	test.End();
sl@0
   513
	}
sl@0
   514
sl@0
   515
template <class T,class S,class DESTEMPLATE>
sl@0
   516
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test7()
sl@0
   517
// Conversion operators
sl@0
   518
	{
sl@0
   519
	test.Start(_L("Fold, collate ..."));
sl@0
   520
	T a;
sl@0
   521
	T b;
sl@0
   522
	a=_TL("abc AbC");
sl@0
   523
	b=_TL("ABC ABC");
sl@0
   524
	a.Fold();
sl@0
   525
	b.Fold();
sl@0
   526
	test(a==b);
sl@0
   527
	a=_TL("abc AbC");
sl@0
   528
	b=_TL("ABC ABC");
sl@0
   529
	a.Collate();
sl@0
   530
	b.Collate();
sl@0
   531
	test(a==b);
sl@0
   532
	a.LowerCase();
sl@0
   533
	test(a==_TL("abc abc"));
sl@0
   534
	a.Capitalize();
sl@0
   535
	test(a==_TL("Abc abc"));
sl@0
   536
	a.UpperCase();
sl@0
   537
	test(a==_TL("ABC ABC"));
sl@0
   538
	test.End();
sl@0
   539
	}
sl@0
   540
sl@0
   541
template <class T,class S,class DESTEMPLATE>
sl@0
   542
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test8()
sl@0
   543
// Comparison
sl@0
   544
	{
sl@0
   545
	test.Start(_L("By string"));
sl@0
   546
	T a;
sl@0
   547
	a=_TL("abc AbC");
sl@0
   548
	test(a.Compare(_TL("abc AbC"))==0);
sl@0
   549
	test(a.CompareF(_TL("ABC aBc"))==0);
sl@0
   550
	test(a.Compare(_TL("xyz"))!=0);
sl@0
   551
	test(a.CompareC(_TL("xyz"))!=0);
sl@0
   552
	test(a.CompareF(_TL("xyz"))!=0);
sl@0
   553
sl@0
   554
	test.Next(_L("By buffer"));
sl@0
   555
	T b;
sl@0
   556
	T c;
sl@0
   557
	a=_TL("abc AbC");
sl@0
   558
	b=_TL("abc AbC");
sl@0
   559
	c=_TL("xyz");
sl@0
   560
	test(a.Compare(b)==0);
sl@0
   561
	test(a.Compare(c)!=0);
sl@0
   562
	b=_TL("ABC aBc");
sl@0
   563
	test(a.CompareC(c)!=0);
sl@0
   564
	test(a.CompareF(b)==0);
sl@0
   565
	test(a.CompareF(c)!=0);
sl@0
   566
sl@0
   567
	test.End();
sl@0
   568
	}
sl@0
   569
sl@0
   570
template <class T,class S,class DESTEMPLATE>
sl@0
   571
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test9()
sl@0
   572
// Matching (need to test explicit result as error KErrNotFound = KMaxTUint
sl@0
   573
// 			 and so registers as TRUE. (test parameter is TUint) )
sl@0
   574
	{
sl@0
   575
	test.Start(_L("By string"));
sl@0
   576
	T a;
sl@0
   577
	a=_TL("abc AbC");
sl@0
   578
	test(a.Match(_TL("abc AbC"))==0);
sl@0
   579
	test(a.MatchC(_TL("ABC aBc"))==0);
sl@0
   580
	test(a.MatchF(_TL("ABC aBc"))==0);
sl@0
   581
	test(a.Match(_TL("xyz"))==KErrNotFound);
sl@0
   582
	test(a.MatchC(_TL("xyz"))==KErrNotFound);
sl@0
   583
	test(a.MatchF(_TL("xyz"))==KErrNotFound);
sl@0
   584
sl@0
   585
	test.Next(_L("By buffer"));
sl@0
   586
	T b;
sl@0
   587
	T c;
sl@0
   588
	a=_TL("abc AbC");
sl@0
   589
	b=_TL("abc AbC");
sl@0
   590
	c=_TL("xyz");
sl@0
   591
	test(a.Match(b)==0);
sl@0
   592
	test(a.Match(c)==KErrNotFound);
sl@0
   593
	b=_TL("ABC aBc");
sl@0
   594
	test(a.MatchC(b)==0);
sl@0
   595
	test(a.MatchC(c)==KErrNotFound);
sl@0
   596
	test(a.MatchF(b)==0);
sl@0
   597
	test(a.MatchF(c)==KErrNotFound);
sl@0
   598
sl@0
   599
	test.Next(_L("Wildcards"));
sl@0
   600
	a=_TL("abcxyz");
sl@0
   601
	test(a.Match(_TL("abc*"))==0);
sl@0
   602
	test(a.Match(_TL("abw*"))==KErrNotFound);
sl@0
   603
	a=_TL("abcdefg");
sl@0
   604
	test(a.Match(_TL("a*fg"))==0);
sl@0
   605
	test(a.Match(_TL("a*f"))==KErrNotFound);
sl@0
   606
	test(a.Match(_TL("abc*fgh"))==KErrNotFound);
sl@0
   607
	a=_TL("abcdef");
sl@0
   608
	test(a.Match(_TL("abc?ef"))==0);
sl@0
   609
	test(a.Match(_TL("abc?xf"))==KErrNotFound);
sl@0
   610
sl@0
   611
	a=_TL("a(01)");
sl@0
   612
	test(a.Match(_TL("*(01)"))==1);
sl@0
   613
	test(a.Match(_TL("?(01)"))==0);
sl@0
   614
	test(a.Match(_TL("?(*)"))==0);
sl@0
   615
	test(a.Match(_TL("?(**)"))==0);
sl@0
   616
sl@0
   617
	test(a.Match(_TL("?(\?\?)"))==0);
sl@0
   618
	test(a.Match(_TL("*(*)"))>=0);
sl@0
   619
	test(a.Match(_TL("*(0?)"))>=0);
sl@0
   620
	test(a.Match(_TL("a(\?\?)"))==0);
sl@0
   621
	test(a.Match(_TL("*(\?\?)"))>=0);
sl@0
   622
sl@0
   623
	test.Next(_L("wild cards with collated comparison"));
sl@0
   624
	a = _TL("abcdefghijkl");
sl@0
   625
	test(a.MatchC(_TL("abc*")) == 0);
sl@0
   626
	test(a.MatchC(_TL("abc")) == KErrNotFound);
sl@0
   627
	test(a.MatchC(_TL("xyz")) == KErrNotFound);
sl@0
   628
	test(a.MatchC(_TL("*def")) == KErrNotFound);
sl@0
   629
	test(a.MatchC(_TL("*def*")) == 3);
sl@0
   630
	test(a.MatchC(_TL("*d?f*")) == 3);
sl@0
   631
	test(a.MatchC(_TL("a*kl")) == 0);
sl@0
   632
	test(a.MatchC(_TL("*e*?l")) == 4);
sl@0
   633
	test(a.MatchC(_TL("abc*dEf*")) == 0);
sl@0
   634
	
sl@0
   635
	
sl@0
   636
	T candidate;
sl@0
   637
	T search;
sl@0
   638
	
sl@0
   639
	candidate = _TL("");
sl@0
   640
	search = _TL("**");
sl@0
   641
	test(candidate.MatchC(search) == 0);
sl@0
   642
	
sl@0
   643
	candidate = _TL("");
sl@0
   644
	search = _TL("*");
sl@0
   645
	test(candidate.MatchC(search) == 0);
sl@0
   646
	
sl@0
   647
	candidate = _TL("abcd");
sl@0
   648
	search = _TL("*abc*cd");
sl@0
   649
	test(candidate.MatchC(search) == KErrNotFound);
sl@0
   650
   	
sl@0
   651
	if (sizeof(S) == 2)
sl@0
   652
		{
sl@0
   653
		test.Next(_L("Unicode MatchC and FindC treat base+accent as equal to composed character"));
sl@0
   654
		TPtrC p = _L("te\x302te");
sl@0
   655
		test(p.MatchC(_L("t\xeate")) == 0);
sl@0
   656
		test(p.FindC(_L("t\xeate")) == 0);
sl@0
   657
		}
sl@0
   658
sl@0
   659
	test.End();
sl@0
   660
	}
sl@0
   661
sl@0
   662
template <class T,class S,class DESTEMPLATE>
sl@0
   663
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test10()
sl@0
   664
// Locating
sl@0
   665
	{
sl@0
   666
	T a;
sl@0
   667
	TChar b;
sl@0
   668
sl@0
   669
	test.Start(_L("First Char"));
sl@0
   670
	b='a';
sl@0
   671
	a=_TL("axaxa");
sl@0
   672
	test(a.Locate(b)==0);
sl@0
   673
	test(a.LocateF(b)==0);
sl@0
   674
	test(a.LocateReverse(b)==4);
sl@0
   675
	test(a.LocateReverseF(b)==4);
sl@0
   676
sl@0
   677
	test.Next(_L("Middle Char"));
sl@0
   678
	a=_TL("xaxa");
sl@0
   679
	test(a.Locate(b)==1);
sl@0
   680
	test(a.LocateF(b)==1);
sl@0
   681
	a=_TL("axax");
sl@0
   682
	test(a.LocateReverse(b)==2);
sl@0
   683
	test(a.LocateReverseF(b)==2);
sl@0
   684
sl@0
   685
	test.Next(_L("Last Char"));
sl@0
   686
	a=_TL("xxa");
sl@0
   687
	test(a.Locate(b)==2);
sl@0
   688
	test(a.LocateF(b)==2);
sl@0
   689
	a=_TL("axx");
sl@0
   690
	test(a.LocateReverse(b)==0);
sl@0
   691
	test(a.LocateReverseF(b)==0);
sl@0
   692
sl@0
   693
	test.Next(_L("Test for failure of locate"));
sl@0
   694
	a=_TL("xxx");
sl@0
   695
	test(a.Locate(b)==KErrNotFound);
sl@0
   696
	test(a.LocateF(b)==KErrNotFound);
sl@0
   697
	test(a.LocateReverse(b)==KErrNotFound);
sl@0
   698
	test(a.LocateReverseF(b)==KErrNotFound);
sl@0
   699
sl@0
   700
	test.End();
sl@0
   701
	}
sl@0
   702
sl@0
   703
template <class T,class S,class DESTEMPLATE>
sl@0
   704
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test11()
sl@0
   705
// Copying
sl@0
   706
	{
sl@0
   707
	T a, b;
sl@0
   708
		
sl@0
   709
	test.Start(_L("By String"));
sl@0
   710
	a.Copy(_TL("abc"));
sl@0
   711
	test(a.Length()==3);
sl@0
   712
	test(a==_TL("abc"));
sl@0
   713
	a.CopyF(_TL("abc"));
sl@0
   714
	test(a.Length()==3);
sl@0
   715
	b.CopyF(_TL("ABC"));
sl@0
   716
	test(a==b);
sl@0
   717
	a.CopyLC(_TL("AbC"));
sl@0
   718
	test(a==_TL("abc"));
sl@0
   719
	test(a.Length()==3);
sl@0
   720
	a.CopyC(_TL("abc"));
sl@0
   721
	b.CopyC(_TL("ABC"));
sl@0
   722
	test(a==b);
sl@0
   723
	test(a.Length()==3);
sl@0
   724
	a.CopyCP(_TL("abc"));
sl@0
   725
	test(a==_TL("Abc"));
sl@0
   726
	test(a.Length()==3);
sl@0
   727
	a.CopyUC(_TL("aBc"));
sl@0
   728
	test(a==_TL("ABC"));
sl@0
   729
	test(a.Length()==3);
sl@0
   730
//	a.Copy(_TL("abc"),3);
sl@0
   731
//	test(a==_TL("abc"));
sl@0
   732
//	test(a.Length()==3);
sl@0
   733
//	a.Copy(_TL("abcd"),3);
sl@0
   734
//	test(a==_TL("abc"));
sl@0
   735
//	test(a.Length()==3);
sl@0
   736
sl@0
   737
	test.Next(_L("By buffer"));
sl@0
   738
	b=_TL("abc");
sl@0
   739
	a.Copy(b);
sl@0
   740
	test(a==_TL("abc"));
sl@0
   741
	test(a.Length()==3);
sl@0
   742
	a=_TL("");
sl@0
   743
	a.CopyF(b);
sl@0
   744
	b.CopyF(_TL("ABC"));
sl@0
   745
	test(a==b);
sl@0
   746
	test(a.Length()==3);
sl@0
   747
	a=_TL("");
sl@0
   748
	b=_TL("AbC");
sl@0
   749
	a.CopyLC(b);
sl@0
   750
	test(a==_TL("abc"));
sl@0
   751
	test(a.Length()==3);
sl@0
   752
	a=_TL("");
sl@0
   753
	b=_TL("abC");
sl@0
   754
	a.CopyC(b);
sl@0
   755
	b.CopyC(_TL("ABC"));
sl@0
   756
	test(a==b);
sl@0
   757
	test(a.Length()==3);
sl@0
   758
	a=_TL("");
sl@0
   759
	b=_TL("abC");
sl@0
   760
	a.CopyCP(b);
sl@0
   761
	test(a==_TL("Abc"));
sl@0
   762
	test(a.Length()==3);
sl@0
   763
	a=_TL("");
sl@0
   764
	b=_TL("aBc");
sl@0
   765
	a.CopyUC(b);
sl@0
   766
	test(a.Length()==3);
sl@0
   767
	test(a==_TL("ABC"));
sl@0
   768
sl@0
   769
	test.End();
sl@0
   770
	}
sl@0
   771
sl@0
   772
sl@0
   773
template <class T,class S,class DESTEMPLATE>
sl@0
   774
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test12()
sl@0
   775
// Finding
sl@0
   776
	{
sl@0
   777
	test.Start(_L("By String"));
sl@0
   778
	T a,b;
sl@0
   779
	a=_TL("abccef");
sl@0
   780
	test(a.Find(_TL(""))==0);
sl@0
   781
	test(a.Find(_TL("abc"))==0);
sl@0
   782
	test(a.Find(_TL("cce"))==2);
sl@0
   783
	test(a.Find(_TL("cef"))==3);
sl@0
   784
	test(a.Find(_TL("efg"))==KErrNotFound);
sl@0
   785
	test(a.Find(_TL("xxx"))==KErrNotFound);
sl@0
   786
	test(a.FindF(_TL(""))==0);
sl@0
   787
	test(a.FindF(_TL("AbC"))==0);
sl@0
   788
	test(a.FindF(_TL("CcE"))==2);
sl@0
   789
	test(a.FindF(_TL("CeF"))==3);
sl@0
   790
	test(a.FindF(_TL("efg"))==KErrNotFound);
sl@0
   791
	test(a.FindF(_TL("xxx"))==KErrNotFound);
sl@0
   792
	test(a.FindC(_TL(""))==0);
sl@0
   793
	test(a.FindC(_TL("aBc"))==0);
sl@0
   794
	test(a.FindC(_TL("cce"))==2);
sl@0
   795
	test(a.FindC(_TL("cEf"))==3);
sl@0
   796
	test(a.FindC(_TL("efg"))==KErrNotFound);
sl@0
   797
	test(a.FindC(_TL("xxx"))==KErrNotFound);
sl@0
   798
sl@0
   799
	test.Next(_L("By buffer"));
sl@0
   800
	test(a.Find(b)==0);
sl@0
   801
	test(a.FindF(b)==0);
sl@0
   802
	test(a.FindC(b)==0);
sl@0
   803
	b=_TL("xxx");
sl@0
   804
	test(a.Find(b)==KErrNotFound);
sl@0
   805
	test(a.FindF(b)==KErrNotFound);
sl@0
   806
	test(a.FindC(b)==KErrNotFound);
sl@0
   807
	b=_TL("efg");
sl@0
   808
	test(a.Find(b)==KErrNotFound);
sl@0
   809
	test(a.FindF(b)==KErrNotFound);
sl@0
   810
	test(a.FindC(b)==KErrNotFound);
sl@0
   811
	b=_TL("abc");
sl@0
   812
	test(a.Find(b)==0);
sl@0
   813
	b=_TL("cce");
sl@0
   814
	test(a.Find(b)==2);
sl@0
   815
	b=_TL("cef");
sl@0
   816
	test(a.Find(b)==3);
sl@0
   817
	b=_TL("AbC");
sl@0
   818
	test(a.FindF(b)==0);
sl@0
   819
	b=_TL("CcE");
sl@0
   820
	test(a.FindF(b)==2);
sl@0
   821
	b=_TL("CeF");
sl@0
   822
	test(a.FindF(b)==3);
sl@0
   823
	b=_TL("aBc");
sl@0
   824
	test(a.FindC(b)==0);
sl@0
   825
	b=_TL("cCe");
sl@0
   826
	test(a.FindC(b)==2);
sl@0
   827
	b=_TL("cEf");
sl@0
   828
	test(a.FindC(b)==3);
sl@0
   829
sl@0
   830
	test.End();
sl@0
   831
	}
sl@0
   832
sl@0
   833
template <class T,class S,class DESTEMPLATE>
sl@0
   834
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test13()
sl@0
   835
// Basic like ops
sl@0
   836
	{
sl@0
   837
	test.Start(_L("Repeat, trim, insert and delete"));
sl@0
   838
	T a,b;
sl@0
   839
	TInt max=a.MaxLength(); 
sl@0
   840
	b=_TL("abc");
sl@0
   841
	a.Repeat(_TL("abc"));
sl@0
   842
	test(a==_TL(""));
sl@0
   843
	a.Repeat(b);
sl@0
   844
	test(a==_TL(""));
sl@0
   845
	for (TInt j=1;j<max;j++) // ?? Cannot SetLength = MaxLength
sl@0
   846
		{
sl@0
   847
		a.SetLength(j);
sl@0
   848
		a.Repeat(_TL("abc"));
sl@0
   849
        TInt i;
sl@0
   850
		for (i=0;i<j;i++)
sl@0
   851
			test(a[i]==b[i%3]);
sl@0
   852
		a=_TL("");
sl@0
   853
		a.SetLength(j);
sl@0
   854
		a.Repeat(b);
sl@0
   855
		for (i=0;i<j;i++)
sl@0
   856
			test(a[i]==b[i%3]);
sl@0
   857
		a=_TL("");
sl@0
   858
		}
sl@0
   859
	a=_TL("\t\n  ab \t\n ");
sl@0
   860
	a.TrimLeft();
sl@0
   861
	test(a==_TL("ab \t\n "));
sl@0
   862
	test(a.Length()==6);
sl@0
   863
	a=_TL("\t\n  ab \t\n ");
sl@0
   864
	a.TrimRight();
sl@0
   865
	test(a==_TL("\t\n  ab"));
sl@0
   866
	test(a.Length()==6);
sl@0
   867
	a=_TL(" \t\n ab \t \n");
sl@0
   868
	a.Trim();
sl@0
   869
	test(a==_TL("ab"));
sl@0
   870
	a.Trim();
sl@0
   871
	test(a==_TL("ab"));
sl@0
   872
	a=_TL("abc");
sl@0
   873
	b=_TL("123");
sl@0
   874
	a.Insert(1,b);
sl@0
   875
	test(a==_TL("a123bc"));
sl@0
   876
	test(a.Length()==6);
sl@0
   877
	b=_TL("");
sl@0
   878
	a.Insert(4,b);
sl@0
   879
	test(a==_TL("a123bc"));
sl@0
   880
	test(a.Length()==6);
sl@0
   881
	a.Insert(0,b);
sl@0
   882
	test(a==_TL("a123bc"));
sl@0
   883
	test(a.Length()==6);
sl@0
   884
	a.Delete(1,3);
sl@0
   885
	test(a==_TL("abc"));
sl@0
   886
	test(a.Length()==3);
sl@0
   887
	a.Delete(0,3);
sl@0
   888
	test(a==_TL(""));
sl@0
   889
	test(a.Length()==0);
sl@0
   890
sl@0
   891
	test.Next(_L("TrimAll"));
sl@0
   892
	a=_TL("");
sl@0
   893
	a.TrimAll();
sl@0
   894
	test(a==_TL(""));
sl@0
   895
	a=_TL(" ");
sl@0
   896
	a.TrimAll();
sl@0
   897
	test(a==_TL(""));
sl@0
   898
	a=_TL("   ");
sl@0
   899
	a.TrimAll();
sl@0
   900
	test(a==_TL(""));
sl@0
   901
	a=_TL("    ab cd  ef    g");
sl@0
   902
	a.TrimAll();
sl@0
   903
	test(a==_TL("ab cd ef g"));
sl@0
   904
	a=_TL("abcdef");
sl@0
   905
	a.TrimAll();
sl@0
   906
	test(a==_TL("abcdef"));
sl@0
   907
	a=_TL("a  b\t cd\t\tef");
sl@0
   908
	a.TrimAll();
sl@0
   909
	test(a==_TL("a b\tcd\tef"));
sl@0
   910
	a=_TL("abcdef \t ghijk");
sl@0
   911
	a.TrimAll();
sl@0
   912
	test(a==_TL("abcdef ghijk"));
sl@0
   913
	a=_TL("abcdef g");
sl@0
   914
	a.TrimAll();
sl@0
   915
	test(a==_TL("abcdef g"));
sl@0
   916
	a=_TL("ab  cd  ef  gh  ij");
sl@0
   917
	a.TrimAll();
sl@0
   918
	test(a==_TL("ab cd ef gh ij"));
sl@0
   919
	a=_TL("a        b          c     defg h     i  jk l     mno pqr stu  vw   xyz");
sl@0
   920
	a.TrimAll();
sl@0
   921
	test(a==_TL("a b c defg h i jk l mno pqr stu vw xyz"));
sl@0
   922
sl@0
   923
	test.Next(_L("Right, Left and Mid"));
sl@0
   924
	a=_TL("abcdef");
sl@0
   925
	b = a.Left(3);
sl@0
   926
	test(b==_TL("abc"));
sl@0
   927
	test(b.Length()==3);
sl@0
   928
	b = a.Right(3);
sl@0
   929
	test(b==_TL("def"));
sl@0
   930
	b = a.Mid(2);
sl@0
   931
	test(b==_TL("cdef"));
sl@0
   932
	test(b.Length()==4);
sl@0
   933
	b = a.Left(2);
sl@0
   934
	test(b==_TL("ab"));
sl@0
   935
	test(b.Length()==2);
sl@0
   936
	b = a.Right(2);
sl@0
   937
	test(b==_TL("ef"));
sl@0
   938
	b = a.Mid(2,1);
sl@0
   939
	test(b==_TL("c"));
sl@0
   940
	test(b.Length()==1);
sl@0
   941
	b = a.Left(6);
sl@0
   942
	test(b==_TL("abcdef"));
sl@0
   943
	test(b.Length()==6);
sl@0
   944
	b=_TL("");
sl@0
   945
	b.SetLength(4);
sl@0
   946
	b = a.Right(6);
sl@0
   947
	test(b==_TL("abcdef"));
sl@0
   948
	test(b.Length()==6);
sl@0
   949
	a = a.Left(6);
sl@0
   950
	test(a==_TL("abcdef"));
sl@0
   951
	b=_TL("");
sl@0
   952
	b = a.Mid(0,6);
sl@0
   953
	test(b==_TL("abcdef")); 
sl@0
   954
	test.End();
sl@0
   955
	}
sl@0
   956
sl@0
   957
template <class T,class S,class DESTEMPLATE>
sl@0
   958
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14()
sl@0
   959
// Formating operations
sl@0
   960
	{
sl@0
   961
	test.Start(_L("Justify"));
sl@0
   962
	T a,b,d;
sl@0
   963
	TInt aWidth;
sl@0
   964
	TChar c;
sl@0
   965
	a=_TL("wxyz");
sl@0
   966
	b=_TL("abc");
sl@0
   967
	d=_TL("linearisation");
sl@0
   968
	const S* pD=_TS("299792458");
sl@0
   969
	c='x';
sl@0
   970
	aWidth=KDefaultJustifyWidth; // Left justified, Default width
sl@0
   971
	a.Justify(b,aWidth,ELeft,c);
sl@0
   972
	test(a==b);
sl@0
   973
	test(a.Length()==3);
sl@0
   974
	a.AppendJustify(b,aWidth,ELeft,c);
sl@0
   975
	test(a==_TL("abcabc"));
sl@0
   976
	test(a.Length()==6);
sl@0
   977
	aWidth=1;	// Width < String length
sl@0
   978
	a.Justify(b,aWidth,ELeft,c);
sl@0
   979
	test(a==_TL("a"));
sl@0
   980
	test(a.Length()==1);
sl@0
   981
	a.AppendJustify(b,aWidth,ELeft,c);
sl@0
   982
	test(a==_TL("aa"));
sl@0
   983
	test(a.Length()==2);
sl@0
   984
	aWidth=5; // Width > String length
sl@0
   985
	a.Justify(b,aWidth,ELeft,c);
sl@0
   986
	test(a==_TL("abcxx"));
sl@0
   987
	test(a.Length()==5);
sl@0
   988
	a.AppendJustify(b,aWidth,ELeft,c);
sl@0
   989
	test(a==_TL("abcxxabcxx"));
sl@0
   990
	test(a.Length()==10);
sl@0
   991
sl@0
   992
	aWidth=KDefaultJustifyWidth; // Right justified, Default width
sl@0
   993
	a.Justify(b,aWidth,ERight,c);
sl@0
   994
	test(a==b);
sl@0
   995
	test(a.Length()==3);
sl@0
   996
	a.AppendJustify(b,aWidth,ERight,c);
sl@0
   997
	test(a==_TL("abcabc"));
sl@0
   998
	test(a.Length()==6);
sl@0
   999
	aWidth=1; // Right justified, Width < String length
sl@0
  1000
	a.Justify(b,aWidth,ERight,c);
sl@0
  1001
	test(a==_TL("a"));
sl@0
  1002
	test(a.Length()==1);
sl@0
  1003
	a.AppendJustify(b,aWidth,ERight,c);
sl@0
  1004
	test(a==_TL("aa"));
sl@0
  1005
	test(a.Length()==2);
sl@0
  1006
	aWidth=5; // Right justified, width > String length
sl@0
  1007
	a.Justify(b,aWidth,ERight,c);
sl@0
  1008
	test(a==_TL("xxabc"));
sl@0
  1009
	test(a.Length()==5);
sl@0
  1010
	a.AppendJustify(b,aWidth,ERight,c);
sl@0
  1011
	test(a==_TL("xxabcxxabc"));
sl@0
  1012
	test(a.Length()==10);
sl@0
  1013
sl@0
  1014
	aWidth=KDefaultJustifyWidth; // Center justified, Default width
sl@0
  1015
	a.Justify(b,aWidth,ECenter,c);
sl@0
  1016
	test(a==b);
sl@0
  1017
	test(a.Length()==3);
sl@0
  1018
	a.AppendJustify(b,aWidth,ECenter,c);
sl@0
  1019
	test(a==_TL("abcabc"));
sl@0
  1020
	test(a.Length()==6);
sl@0
  1021
	aWidth=1; // Centre justified, width < String length
sl@0
  1022
	a.Justify(b,aWidth,ECenter,c);
sl@0
  1023
	test(a==_TL("a"));
sl@0
  1024
	test(a.Length()==1);
sl@0
  1025
	a.AppendJustify(b,aWidth,ECenter,c);
sl@0
  1026
	test(a==_TL("aa"));
sl@0
  1027
	test(a.Length()==2);
sl@0
  1028
	aWidth=5; // Centre justified, width > String length
sl@0
  1029
	a.Justify(b,aWidth,ECenter,c);
sl@0
  1030
	test(a==_TL("xabcx"));
sl@0
  1031
	test(a.Length()==5);
sl@0
  1032
	a.AppendJustify(b,aWidth,ECenter,c);
sl@0
  1033
	test(a==_TL("xabcxxabcx"));
sl@0
  1034
	test(a.Length()==10);
sl@0
  1035
sl@0
  1036
	test.Next(_L("Num"));
sl@0
  1037
	TInt j=-2147483647-1; 
sl@0
  1038
	a.Num(j);
sl@0
  1039
	test(a==_TL("-2147483648"));
sl@0
  1040
	test(a.Length()==11);
sl@0
  1041
	TUint i=2147483648u;
sl@0
  1042
	a.Num(i);
sl@0
  1043
	test(a==_TL("2147483648"));
sl@0
  1044
	test(a.Length()==10);
sl@0
  1045
	if (a.MaxLength()>31)
sl@0
  1046
		{
sl@0
  1047
		a.Num(i,EBinary);
sl@0
  1048
		test(a==_TL("10000000000000000000000000000000"));
sl@0
  1049
		test(a.Length()==32);
sl@0
  1050
		a=_TL("");
sl@0
  1051
		a.NumUC(i,EBinary);
sl@0
  1052
		test(a==_TL("10000000000000000000000000000000"));
sl@0
  1053
		test(a.Length()==32);
sl@0
  1054
		}
sl@0
  1055
	i=31;
sl@0
  1056
	a.Num(i,EBinary);
sl@0
  1057
	test(a==_TL("11111"));
sl@0
  1058
	test(a.Length()==5);
sl@0
  1059
	a=_TL("");
sl@0
  1060
	a.NumUC(i,EBinary);
sl@0
  1061
	test(a==_TL("11111"));
sl@0
  1062
	test(a.Length()==5);
sl@0
  1063
	i=2147483648u;
sl@0
  1064
	a.Num(i,EOctal);
sl@0
  1065
	test(a==_TL("20000000000"));
sl@0
  1066
	test(a.Length()==11);
sl@0
  1067
	a=_TL("");
sl@0
  1068
	a.NumUC(i,EOctal);
sl@0
  1069
	test(a==_TL("20000000000"));
sl@0
  1070
	test(a.Length()==11);
sl@0
  1071
	a.Num(i,EDecimal);
sl@0
  1072
	test(a==_TL("2147483648"));
sl@0
  1073
	test(a.Length()==10);
sl@0
  1074
	a=_TL("");
sl@0
  1075
	a.NumUC(i,EDecimal);
sl@0
  1076
	test(a==_TL("2147483648"));
sl@0
  1077
	test(a.Length()==10);
sl@0
  1078
	a.Num(i,EHex);
sl@0
  1079
	test(a==_TL("80000000"));
sl@0
  1080
	test(a.Length()==8);
sl@0
  1081
	a=_TL("");
sl@0
  1082
	a.NumUC(i,EHex);
sl@0
  1083
	test(a==_TL("80000000"));
sl@0
  1084
	test(a.Length()==8);
sl@0
  1085
	i=0;
sl@0
  1086
	a.Num(i);
sl@0
  1087
	test(a==_TL("0"));
sl@0
  1088
	test(a.Length()==1);
sl@0
  1089
	a=_TL("abc");
sl@0
  1090
	a.Num(i,EBinary);
sl@0
  1091
	test(a==_TL("0"));
sl@0
  1092
	test(a.Length()==1);
sl@0
  1093
	a=_TL("abc");
sl@0
  1094
	a.NumUC(i,EBinary);
sl@0
  1095
	test(a==_TL("0"));
sl@0
  1096
	test(a.Length()==1);
sl@0
  1097
	a=_TL("abc");
sl@0
  1098
	a.Num(i,EOctal);
sl@0
  1099
	test(a==_TL("0"));
sl@0
  1100
	test(a.Length()==1);
sl@0
  1101
	a=_TL("");
sl@0
  1102
	a.NumUC(i,EOctal);
sl@0
  1103
	test(a==_TL("0"));
sl@0
  1104
	test(a.Length()==1);
sl@0
  1105
	a=_TL("abc");
sl@0
  1106
	a.Num(i,EDecimal);
sl@0
  1107
	test(a==_TL("0"));
sl@0
  1108
	test(a.Length()==1);
sl@0
  1109
	a=_TL("");
sl@0
  1110
	a.NumUC(i,EDecimal);
sl@0
  1111
	test(a==_TL("0"));
sl@0
  1112
	test(a.Length()==1);
sl@0
  1113
	a=_TL("abc");
sl@0
  1114
	a.Num(i,EHex);
sl@0
  1115
	test(a==_TL("0"));
sl@0
  1116
	test(a.Length()==1);
sl@0
  1117
	a=_TL("");
sl@0
  1118
	a.NumUC(i,EHex);
sl@0
  1119
	test(a==_TL("0"));
sl@0
  1120
	test(a.Length()==1);
sl@0
  1121
//	TInt i=a.Num(6.2,format); NOT IMPLEMENTED
sl@0
  1122
	a.AppendNum(j);
sl@0
  1123
	test(a==_TL("0-2147483648"));
sl@0
  1124
	test(a.Length()==12);
sl@0
  1125
	a=_TL("abc");
sl@0
  1126
	i=4294967295u;
sl@0
  1127
	a.AppendNum(i);
sl@0
  1128
	test(a==_TL("abc4294967295"));
sl@0
  1129
	test(a.Length()==13);
sl@0
  1130
	j=2147483647;
sl@0
  1131
	a=_TL("abc");
sl@0
  1132
	a.AppendNum(j);
sl@0
  1133
	test(a==_TL("abc2147483647"));
sl@0
  1134
	test(a.Length()==13);
sl@0
  1135
	a=_TL("a");
sl@0
  1136
	i=180150000;
sl@0
  1137
	if (a.MaxLength()>28)
sl@0
  1138
		{
sl@0
  1139
		a.AppendNum(i,EBinary);
sl@0
  1140
		test(a==_TL("a1010101111001101111011110000"));
sl@0
  1141
		test(a.Length()==29);
sl@0
  1142
		}
sl@0
  1143
	a=_TL("a");
sl@0
  1144
	a.AppendNum(15,EBinary);
sl@0
  1145
	test(a==_TL("a1111"));
sl@0
  1146
	test(a.Length()==5);
sl@0
  1147
	a=_TL("a");
sl@0
  1148
	a.AppendNum(i,EDecimal);
sl@0
  1149
	test(a==_TL("a180150000"));
sl@0
  1150
	test(a.Length()==10);
sl@0
  1151
	a=_TL("a");
sl@0
  1152
	a.AppendNum(i,EOctal);
sl@0
  1153
	test(a==_TL("a1257157360"));
sl@0
  1154
	test(a.Length()==11);
sl@0
  1155
	a=_TL("a");
sl@0
  1156
	a.AppendNumUC(i,EHex);
sl@0
  1157
	test(a==_TL("aABCDEF0"));
sl@0
  1158
	test(a.Length()==8);
sl@0
  1159
//	i=a.AppendNum(6.32, format); NOT IMPLEMENTED
sl@0
  1160
sl@0
  1161
	test.Next(_L("Format"));
sl@0
  1162
	a=_TL("");
sl@0
  1163
	b=_TL("cde");
sl@0
  1164
	a.Format(_TL("%S"),&b);
sl@0
  1165
	test(a==b);
sl@0
  1166
	test(a.Length()==3);
sl@0
  1167
    DESTEMPLATE xyz=_TL("xyzwpq");
sl@0
  1168
	a.Format(_TL("%S"),&xyz);
sl@0
  1169
	test(a==_TL("xyzwpq"));
sl@0
  1170
	test(a.Length()==6);
sl@0
  1171
    DESTEMPLATE cde=_TL("cde");
sl@0
  1172
	a.Format(_TL("ab %-x5S"),&cde);
sl@0
  1173
	test(a==_TL("ab cdexx"));
sl@0
  1174
	test(a.Length()==8);
sl@0
  1175
	a.Format(_TL("ab %=x5S"),&cde);
sl@0
  1176
	test(a==_TL("ab xcdex"));
sl@0
  1177
	test(a.Length()==8);
sl@0
  1178
	a.Format(_TL("ab %+x5S"),&cde);
sl@0
  1179
	test(a==_TL("ab xxcde"));
sl@0
  1180
	test(a.Length()==8);
sl@0
  1181
	a.Format(_TL("ab %5S"),&cde);
sl@0
  1182
	test(a==_TL("ab   cde"));
sl@0
  1183
	test(a.Length()==8);
sl@0
  1184
	a.Format(_TL("ab %-**S"),'x',5,&cde);
sl@0
  1185
	test(a==_TL("ab cdexx"));
sl@0
  1186
	test(a.Length()==8);
sl@0
  1187
	a.Format(_TL("ab %*S"),5,&cde);
sl@0
  1188
	test(a==_TL("ab   cde"));
sl@0
  1189
	test(a.Length()==8);
sl@0
  1190
	a=_TL("xyz");
sl@0
  1191
	a.Format(_TL("ab %-x5S"),&b);
sl@0
  1192
	test(a==_TL("ab cdexx"));
sl@0
  1193
	test(a.Length()==8);
sl@0
  1194
	a=_TL("xyz");
sl@0
  1195
	a.Format(_TL("ab %-**S"),'x',5,&b);
sl@0
  1196
	test(a==_TL("ab cdexx"));
sl@0
  1197
	test(a.Length()==8);
sl@0
  1198
	a=_TL("xyz");
sl@0
  1199
	a.Format(_TL("ab %*S"),5,&b);
sl@0
  1200
	test(a==_TL("ab   cde"));
sl@0
  1201
	test(a.Length()==8);
sl@0
  1202
sl@0
  1203
	DESTEMPLATE fred=_TL("fred");
sl@0
  1204
	a.Format(_TL("%+0*S"),10,&fred);
sl@0
  1205
	test(a==_TL("000000fred"));
sl@0
  1206
	test(a.Length()==10);
sl@0
  1207
	a.Format(_TL("%-0*S"),7,&fred);
sl@0
  1208
	test(a==_TL("fred000"));
sl@0
  1209
	test(a.Length()==7);
sl@0
  1210
	a.Format(_TL("%0*S"),11,&fred);
sl@0
  1211
	test(a==_TL("0000000fred"));
sl@0
  1212
	test(a.Length()==11);
sl@0
  1213
	a.Format(_TL("c=%s"),pD);
sl@0
  1214
	TESTEQ(a,_TL("c=299792458"));
sl@0
  1215
	a.Format(_TL("c=%10.6s"),pD);
sl@0
  1216
	test(a==_TL("c=    299792"));
sl@0
  1217
	a.Format(_TL("c=%*.*s"),5,4,pD);
sl@0
  1218
	test(a==_TL("c= 2997"));
sl@0
  1219
	a.Format(_TL("%S"),&d);
sl@0
  1220
	test(a==_TL("linearisation"));
sl@0
  1221
	a.Format(_TL("%10.6S"),&d);
sl@0
  1222
	test(a==_TL("    linear"));
sl@0
  1223
	a.Format(_TL("%*.*S"),5,4,&d);
sl@0
  1224
	test(a==_TL(" line"));
sl@0
  1225
	a.Format(_TL("%*.*Sed"),10,8,&d);
sl@0
  1226
	test(a==_TL("  linearised"));
sl@0
  1227
	a.Format(_TL("%*.*S"),14,20,&d);
sl@0
  1228
	test(a==_TL(" linearisation"));
sl@0
  1229
sl@0
  1230
	a.Format(_TL("ab %-,5b"),7);
sl@0
  1231
	test(a==_TL("ab 111,,"));
sl@0
  1232
	test(a.Length()==8);
sl@0
  1233
	a.Format(_TL("ab %=,5O"),31);
sl@0
  1234
	test(a==_TL("ab ,37,,"));
sl@0
  1235
	test(a.Length()==8);
sl@0
  1236
	a.Format(_TL("ab %+xlx"),TInt64(171));
sl@0
  1237
	test(a==_TL("ab ab"));
sl@0
  1238
	test(a.Length()==5);
sl@0
  1239
	a.Format(_TL("ab %+xlX %+xlx"),TInt64(171),TInt64(171));
sl@0
  1240
	TESTEQ(a,_TL("ab AB ab"));
sl@0
  1241
	test(a.Length()==8);
sl@0
  1242
	a.Format(_TL("ab %lu"),MAKE_TINT64((TUint)(KMinTInt),0));
sl@0
  1243
	test(a==_TL("ab 9223372036854775808"));
sl@0
  1244
	test(a.Length()==22);
sl@0
  1245
	a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),1));
sl@0
  1246
	test(a==_TL("ab -9223372036854775807"));
sl@0
  1247
	test(a.Length()==23);
sl@0
  1248
	a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),0));
sl@0
  1249
	test(a==_TL("ab -9223372036854775808"));
sl@0
  1250
	test(a.Length()==23);
sl@0
  1251
	a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
sl@0
  1252
	test(a==_TL("ab 9223372036854775807"));
sl@0
  1253
	test(a.Length()==22);
sl@0
  1254
	a.Format(_TL("ab %ld"),MAKE_TINT64(KMaxTUint,KMaxTUint));
sl@0
  1255
	test(a==_TL("ab -1"));
sl@0
  1256
	test(a.Length()==5);
sl@0
  1257
	a.Format(_TL("ab %lu"),MAKE_TINT64(KMaxTUint,KMaxTUint));
sl@0
  1258
	test(a==_TL("ab 18446744073709551615"));
sl@0
  1259
	test(a.Length()==23);
sl@0
  1260
	a.Format(_TL("ab %ld"),TInt64(0));
sl@0
  1261
	test(a==_TL("ab 0"));
sl@0
  1262
	test(a.Length()==4);
sl@0
  1263
	a.Format(_TL("ab %lb"),TInt64(0));
sl@0
  1264
	test(a==_TL("ab 0"));
sl@0
  1265
	test(a.Length()==4);
sl@0
  1266
	a.Format(_TL("ab %lx"),TInt64(0));
sl@0
  1267
	test(a==_TL("ab 0"));
sl@0
  1268
	test(a.Length()==4);
sl@0
  1269
	a.Format(_TL("ab %lo"),TInt64(0));
sl@0
  1270
	test(a==_TL("ab 0"));
sl@0
  1271
	test(a.Length()==4);
sl@0
  1272
	a.Format(_TL("ab %lu"),TInt64(0));
sl@0
  1273
	test(a==_TL("ab 0"));
sl@0
  1274
	test(a.Length()==4);
sl@0
  1275
	a.Format(_TL("ab %lb"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
sl@0
  1276
	test(a==_TL("ab 111111111111111111111111111111111111111111111111111111111111111"));
sl@0
  1277
	test(a.Length()==66);
sl@0
  1278
	a.Format(_TL("ab %lb"),MAKE_TINT64(KMaxTUint,KMaxTUint));
sl@0
  1279
	test(a==_TL("ab 1111111111111111111111111111111111111111111111111111111111111111"));
sl@0
  1280
	test(a.Length()==67);
sl@0
  1281
	a.Format(_TL("ab %lx"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
sl@0
  1282
	test(a==_TL("ab 7fffffffffffffff"));
sl@0
  1283
	test(a.Length()==19);
sl@0
  1284
	a.Format(_TL("ab %lx"),MAKE_TINT64(KMaxTUint,KMaxTUint));
sl@0
  1285
	test(a==_TL("ab ffffffffffffffff"));
sl@0
  1286
	test(a.Length()==19);
sl@0
  1287
	a.Format(_TL("ab %lo"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
sl@0
  1288
	test(a==_TL("ab 777777777777777777777"));
sl@0
  1289
	test(a.Length()==24);
sl@0
  1290
	// tests which excercise any 8 byte alignment requirement on 64bit integers
sl@0
  1291
	a.Format(_TL("%li%S"),MAKE_TINT64(1,2),&fred);
sl@0
  1292
	test(a==_TL("4294967298fred"));
sl@0
  1293
	a.Format(_TL("%S%li%S"),&fred,MAKE_TINT64(1,2),&fred);
sl@0
  1294
	test(a==_TL("fred4294967298fred"));
sl@0
  1295
	a.Format(_TL("%lu%S"),MAKE_TINT64(1,2),&fred);
sl@0
  1296
	test(a==_TL("4294967298fred"));
sl@0
  1297
	a.Format(_TL("%S%lu%S"),&fred,MAKE_TINT64(1,2),&fred);
sl@0
  1298
	test(a==_TL("fred4294967298fred"));
sl@0
  1299
sl@0
  1300
	a.Format(_TL("ab %U"),233);
sl@0
  1301
	test(a==_TL("ab 233"));
sl@0
  1302
	test(a.Length()==6);
sl@0
  1303
	a.Format(_TL("ab %*d"),5,-131);
sl@0
  1304
	test(a==_TL("ab  -131"));
sl@0
  1305
	test(a.Length()==8);
sl@0
  1306
	a.Format(_TL("ab%c"),'x');
sl@0
  1307
	test(a==_TL("abx"));
sl@0
  1308
	test(a.Length()==3);
sl@0
  1309
	a.Format(_TL("%W"),-131);
sl@0
  1310
	test(*(TInt32*)a.Ptr()==-131);
sl@0
  1311
	a.Format(_TL("%M"),-131);
sl@0
  1312
	test(*(TInt32*)a.Ptr()==2113929215);
sl@0
  1313
	a.Format(_TL("%w"),-131);
sl@0
  1314
	test(*(TInt16*)a.Ptr()==-131);
sl@0
  1315
	a.Format(_TL("%m"),-131);
sl@0
  1316
	test(*(TInt16*)a.Ptr()==32255);
sl@0
  1317
	a=_TL("xyz");
sl@0
  1318
	a.AppendFormat(_TL("ab %+xlx"),TInt64(171));
sl@0
  1319
	test(a==_TL("xyzab ab"));
sl@0
  1320
	test(a.Length()==8);
sl@0
  1321
	a=_TL("xyz");
sl@0
  1322
	a.AppendFormat(_TL("ab %5S"),&b);
sl@0
  1323
	test(a==_TL("xyzab   cde"));
sl@0
  1324
	test(a.Length()==11);
sl@0
  1325
	a=_TL("xyz");
sl@0
  1326
	a.AppendFormat(_TL("%W"),-131);
sl@0
  1327
//	test(*(TInt32*)(a.Ptr()+3)==-131); // Alignment-safe version:
sl@0
  1328
    TInt val;
sl@0
  1329
    Mem::Copy(&val,&a[3],4);
sl@0
  1330
	test(val==-131);
sl@0
  1331
	a=_TL("xyz");
sl@0
  1332
//	a.Append(_TL("abc"),3);
sl@0
  1333
//	test(a==_TL("xyzabc"));
sl@0
  1334
sl@0
  1335
	a.Format(_TL(""));
sl@0
  1336
	test(a==_TL(""));
sl@0
  1337
	a.Format(_TL(""),9,5);
sl@0
  1338
	test(a==_TL(""));
sl@0
  1339
	a.Format(_TL("qwerty"));
sl@0
  1340
	test(a==_TL("qwerty"));
sl@0
  1341
	a.Format(_TL("qwerty"),9,5);
sl@0
  1342
	test(a==_TL("qwerty"));
sl@0
  1343
	a.Format(_TL("%$1$d%$2$d"),9,5);
sl@0
  1344
	test(a==_TL("95"));
sl@0
  1345
	test(a.Length()==2);
sl@0
  1346
	a.Format(_TL("%$2$d%$1$d"),9,5);
sl@0
  1347
	test(a==_TL("59"));
sl@0
  1348
	test(a.Length()==2);
sl@0
  1349
	b=_TL("eb");
sl@0
  1350
	a.Format(_TL("%$1$S%$2$d"),&b,205);
sl@0
  1351
	test(a==_TL("eb205"));
sl@0
  1352
	test(a.Length()==5);
sl@0
  1353
	a.Format(_TL("%$2$d%$1$S"),&b,205);
sl@0
  1354
	test(a==_TL("205eb"));
sl@0
  1355
	test(a.Length()==5);
sl@0
  1356
	b=_TL("ebdb");
sl@0
  1357
sl@0
  1358
// Cannot do this on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
sl@0
  1359
#if !(defined(__GCC32__) && defined(__X86__))
sl@0
  1360
	const TAny* const zeroTerminatedString=(sizeof(S)==2)? (const TAny*)_S16(":-)E"): (const TAny*)_S8(":-)E");
sl@0
  1361
	const TInt dummyParameter=0;
sl@0
  1362
	Test14_ReorderedParameterFormatting(dummyParameter, 0x20ac, 11, 3, 13.89543, zeroTerminatedString, '!', TInt64(199), 2, &b, 6, 30005, TRealX(0.125), 0x8bdd);
sl@0
  1363
#endif
sl@0
  1364
sl@0
  1365
	test.Next(_L("Print some numbers"));
sl@0
  1366
	TInt64 TI64 = MAKE_TINT64(0x101010u,0x10101010u);
sl@0
  1367
	test.Printf(_L("    %%ld: %ld\n"),TI64);
sl@0
  1368
	test.Printf(_L("    %%lu: %lu\n"),TI64);
sl@0
  1369
	test.Printf(_L("    %%lx: %lx\n"),TI64);
sl@0
  1370
	test.Printf(_L("    %%lb: %lb\n"),TI64);
sl@0
  1371
	test.Printf(_L("    %%lo: %lo\n\n"),TI64);
sl@0
  1372
	TI64 = UI64LIT(0xabcdef12345678);
sl@0
  1373
	test.Printf(_L("    %%ld: %ld\n"),TI64);
sl@0
  1374
	test.Printf(_L("    %%lu: %lu\n"),TI64);
sl@0
  1375
	test.Printf(_L("    %%lx: %lx\n"),TI64);
sl@0
  1376
	test.Printf(_L("    %%lb: %lb\n"),TI64);
sl@0
  1377
	test.Printf(_L("    %%lo: %lo\n\n"),TI64);
sl@0
  1378
	TI64 = UI64LIT(0x7fffffffffffffff);
sl@0
  1379
	test.Printf(_L("    %%ld: %ld\n"),TI64);
sl@0
  1380
	test.Printf(_L("    %%lu: %lu\n"),TI64);
sl@0
  1381
	test.Printf(_L("    %%lx: %lx\n"),TI64);
sl@0
  1382
	test.Printf(_L("    %%lb: %lb\n"),TI64);
sl@0
  1383
	test.Printf(_L("    %%lo: %lo\n\n"),TI64);
sl@0
  1384
	TI64 = UI64LIT(0x8000000000000000);
sl@0
  1385
	test.Printf(_L("    %%ld: %ld\n"),TI64);
sl@0
  1386
	test.Printf(_L("    %%lu: %lu\n"),TI64);
sl@0
  1387
	test.Printf(_L("    %%lx: %lx\n"),TI64);
sl@0
  1388
	test.Printf(_L("    %%lb: %lb\n"),TI64);
sl@0
  1389
	test.Printf(_L("    %%lo: %lo\n\n"),TI64);
sl@0
  1390
	TI64 = UI64LIT(0xffffffffffffffff);
sl@0
  1391
	test.Printf(_L("    %%ld: %ld\n"),TI64);
sl@0
  1392
	test.Printf(_L("    %%lu: %lu\n"),TI64);
sl@0
  1393
	test.Printf(_L("    %%lx: %lx\n"),TI64);
sl@0
  1394
	test.Printf(_L("    %%lb: %lb\n"),TI64);
sl@0
  1395
	test.Printf(_L("    %%lo: %lo\n\n"),TI64);
sl@0
  1396
sl@0
  1397
	test.Next(_L("Regression tests"));
sl@0
  1398
	a.Format(_TL("[%-A4p]"));
sl@0
  1399
	test(a==_TL("[AAAA]"));
sl@0
  1400
sl@0
  1401
	test.End();
sl@0
  1402
	}
sl@0
  1403
sl@0
  1404
template <class T,class S,class DESTEMPLATE>
sl@0
  1405
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...)
sl@0
  1406
	{
sl@0
  1407
	VA_LIST parameterList;
sl@0
  1408
	T generated;
sl@0
  1409
	T expected;
sl@0
  1410
sl@0
  1411
	VA_START(parameterList, aDummyParameter);
sl@0
  1412
	generated.FormatList(_TL("\t%-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList);
sl@0
  1413
	test(generated.Length()==61);
sl@0
  1414
	expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeeeebrrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1415
	test(generated.Left(generated.Length()-1)==expected);
sl@0
  1416
	test(generated[generated.Length()-1]==(S)0x8bdd);
sl@0
  1417
sl@0
  1418
	VA_START(parameterList, aDummyParameter);
sl@0
  1419
	generated.FormatList(_TL("\t%$1$-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$6$.3Fyyyyyyy%c"), parameterList);
sl@0
  1420
	test(generated.Length()==61);
sl@0
  1421
	expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeeeebrrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1422
	test(generated.Left(generated.Length()-1)==expected);
sl@0
  1423
	test(generated[generated.Length()-1]==(S)0x8bdd);
sl@0
  1424
sl@0
  1425
	VA_START(parameterList, aDummyParameter);
sl@0
  1426
	generated.FormatList(_TL("\t%$6$.3Fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList);
sl@0
  1427
	test(generated.Length()==61);
sl@0
  1428
	expected.Format(_TL("\t0.125qq:-)www!!199eeeeebrrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1429
	test(generated.Left(generated.Length()-1)==expected);
sl@0
  1430
	test(generated[generated.Length()-1]==(S)0x8bdd);
sl@0
  1431
sl@0
  1432
	VA_START(parameterList, aDummyParameter);
sl@0
  1433
	generated.FormatList(_TL("\t%-**.*fqq%.3swww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%.3Fyyyyyyy%c"), parameterList);
sl@0
  1434
	test(generated.Length()==61);
sl@0
  1435
	expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www007535eeeeebrrrrr!!199tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1436
	test(generated.Left(generated.Length()-1)==expected);
sl@0
  1437
	test(generated[generated.Length()-1]==(S)0x8bdd);
sl@0
  1438
sl@0
  1439
	VA_START(parameterList, aDummyParameter);
sl@0
  1440
	generated.FormatList(_TL("\t%-**.*fqq%$4$.*Swww%+*5Ldeeee%$2$.3srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList);
sl@0
  1441
	test(generated.Length()==61);
sl@0
  1442
	expected.Format(_TL("\t13.895%c%c%c%c%cqqebwww!!199eeee:-)rrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1443
	test(generated.Left(generated.Length()-1)==expected);
sl@0
  1444
	test(generated[generated.Length()-1]==(S)0x8bdd);
sl@0
  1445
sl@0
  1446
	VA_START(parameterList, aDummyParameter);
sl@0
  1447
	generated.FormatList(_TL("\t%-**.*fqq%.3swww%+*5Ldeeee%$7$crrrrr%0*xtttttt%.3Fyyyyyyy%$4$.*S"), parameterList);
sl@0
  1448
	test(generated.Length()==61);
sl@0
  1449
	expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeee"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1450
	test(generated.Left(29)==expected);
sl@0
  1451
	test(generated[29]==(S)0x8bdd);
sl@0
  1452
	test(generated.Mid(29+1)==_TL("rrrrr007535tttttt0.125yyyyyyyeb"));
sl@0
  1453
sl@0
  1454
	VA_START(parameterList, aDummyParameter);
sl@0
  1455
	generated.FormatList(_TL("\t%$4$.*Sqq%.3swww%+*5Ldeeee%$6$.3Frrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList);
sl@0
  1456
	test(generated.Length()==61);
sl@0
  1457
	expected.Format(_TL("\tebqq:-)www!!199eeee0.125rrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1458
	test(generated.Left(generated.Length()-1)==expected);
sl@0
  1459
	test(generated[generated.Length()-1]==(S)0x8bdd);
sl@0
  1460
sl@0
  1461
	VA_START(parameterList, aDummyParameter);
sl@0
  1462
	generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList);
sl@0
  1463
	test(generated.Length()==61);
sl@0
  1464
	test(generated.Left(1)==_TL("\t"));
sl@0
  1465
	test(generated[1]==(S)0x8bdd);
sl@0
  1466
	expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1467
	test(generated.Mid(2)==expected);
sl@0
  1468
sl@0
  1469
	VA_START(parameterList, aDummyParameter);
sl@0
  1470
	generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%$4$.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList);
sl@0
  1471
	test(generated.Length()==61);
sl@0
  1472
	test(generated.Left(1)==_TL("\t"));
sl@0
  1473
	test(generated[1]==(S)0x8bdd);
sl@0
  1474
	expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
sl@0
  1475
	test(generated.Mid(2)==expected);
sl@0
  1476
	}
sl@0
  1477
sl@0
  1478
template <class T,class S,class DESTEMPLATE>
sl@0
  1479
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test15()
sl@0
  1480
// Replacing
sl@0
  1481
	{
sl@0
  1482
	test.Start(_L("Replace"));
sl@0
  1483
	T a,b;
sl@0
  1484
	test(a.MaxLength()>=9);
sl@0
  1485
	a=_TL("abccccc");
sl@0
  1486
	b=_TL("def");
sl@0
  1487
	a.Replace(3,4,b); // Replace with smaller in middle (insert and delete)
sl@0
  1488
	test(a==_TL("abcdef"));
sl@0
  1489
	a.Replace(1,1,b); // Replace with larger in middle (insert and delete)
sl@0
  1490
	test(a==_TL("adefcdef"));
sl@0
  1491
	a.Replace(0,8,_TL("")); // Replace complete string (delete)
sl@0
  1492
	test(a==_TL(""));
sl@0
  1493
	a.Replace(0,0,b); // Replace at beginning (insert)
sl@0
  1494
	test(a==b);
sl@0
  1495
	a.Replace(3,0,_TL("xyz")); // Replace at end (append)
sl@0
  1496
	test(a==_TL("defxyz"));
sl@0
  1497
	a.Replace(0,0,_TL("")); // Replace nothing at beginning (do nothing)
sl@0
  1498
	test(a==_TL("defxyz"));
sl@0
  1499
	a.Replace(6,0,_TL("")); // Replace nothing at end (do nothing)
sl@0
  1500
	test(a==_TL("defxyz"));
sl@0
  1501
	//a.Replace(6,1,_TL("")); // this will panic - no char after end to replace
sl@0
  1502
	//a.Replace(0,7,_TL("")); // this will panic - aint 7 chars to replace
sl@0
  1503
	test.End();
sl@0
  1504
	}
sl@0
  1505
sl@0
  1506
template<class T,class S,class DESTEMPLATE>
sl@0
  1507
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::test_TBuf()
sl@0
  1508
// Test the TBuf class.
sl@0
  1509
	{
sl@0
  1510
	test.Start(_L("All operations"));
sl@0
  1511
	Test1();
sl@0
  1512
	test.Next(_L("Constructors"));
sl@0
  1513
	Test2();
sl@0
  1514
	test.Next(_L("Additional tests"));
sl@0
  1515
	Test3();
sl@0
  1516
	test.Next(_L("Comparison operators"));
sl@0
  1517
	Test4();
sl@0
  1518
	test.Next(_L("Property access"));
sl@0
  1519
	Test5();
sl@0
  1520
	test.Next(_L("Fill and swap"));
sl@0
  1521
	Test6();
sl@0
  1522
	test.Next(_L("Conversion operators"));
sl@0
  1523
	Test7();
sl@0
  1524
	test.Next(_L("Comparison"));
sl@0
  1525
	Test8();
sl@0
  1526
	test.Next(_L("Matching"));
sl@0
  1527
	Test9();
sl@0
  1528
	test.Next(_L("Locating"));
sl@0
  1529
	Test10();
sl@0
  1530
	test.Next(_L("Copying"));
sl@0
  1531
	Test11();
sl@0
  1532
	test.Next(_L("Finding"));
sl@0
  1533
	Test12();
sl@0
  1534
	test.Next(_L("Basic like ops"));
sl@0
  1535
	Test13();
sl@0
  1536
	test.Next(_L("Formating"));
sl@0
  1537
	Test14();
sl@0
  1538
	test.Next(_L("Replacing"));
sl@0
  1539
	Test15();
sl@0
  1540
	test.End();
sl@0
  1541
	}
sl@0
  1542
sl@0
  1543
LOCAL_C void testFormat()
sl@0
  1544
	{
sl@0
  1545
	TBuf<0x100> aa;
sl@0
  1546
	aa.Format(_L("x%- 5fx"), 6.2345678);
sl@0
  1547
	test(aa==_L("x6.234568x"));
sl@0
  1548
	aa.Format(_L("x%+ 5fx"), 6.2345678);
sl@0
  1549
	test(aa==_L("x6.234568x"));
sl@0
  1550
	aa.Format(_L("x% 5fx"), 6.2345678);
sl@0
  1551
	test(aa==_L("x6.234568x"));
sl@0
  1552
	aa.Format(_L("x%= 5fx"), 6.2345678);
sl@0
  1553
	test(aa==_L("x6.234568x"));
sl@0
  1554
	aa.Format(_L("x%- 10fx"), 6.2345);
sl@0
  1555
	test(aa==_L("x6.234500  x"));
sl@0
  1556
	aa.Format(_L("x%+ 10fx"), 6.2345);
sl@0
  1557
	test(aa==_L("x  6.234500x"));
sl@0
  1558
	aa.Format(_L("x% 10fx"), 6.2345);
sl@0
  1559
	test(aa==_L("x  6.234500x"));
sl@0
  1560
	aa.Format(_L("x%= 10fx"), 6.2345);
sl@0
  1561
	test(aa==_L("x 6.234500 x"));
sl@0
  1562
	aa.Format(_L("x%10fx"), 12345352342.545);
sl@0
  1563
	test(aa==_L("x12,345,352,342.545000x"));
sl@0
  1564
	aa.Format(_L("x%20.9fx"), 1.0123456789);
sl@0
  1565
	test(aa==_L("x         1.012345679x"));
sl@0
  1566
	aa.Format(_L("x%5.1fx"), 1.99);
sl@0
  1567
	test(aa==_L("x  2.0x"));
sl@0
  1568
sl@0
  1569
// Cannot do these on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
sl@0
  1570
#if !(defined(__GCC32__) && defined(__X86__))
sl@0
  1571
	aa.Format(_L("x%- 5Fx"), TRealX(6.2345678));
sl@0
  1572
	test(aa==_L("x6.234568x"));
sl@0
  1573
	aa.Format(_L("x%+ 5Fx"), TRealX(6.2345678));
sl@0
  1574
	test(aa==_L("x6.234568x"));
sl@0
  1575
	aa.Format(_L("x% 5Fx"), TRealX(6.2345678));
sl@0
  1576
	test(aa==_L("x6.234568x"));
sl@0
  1577
	aa.Format(_L("x%= 5Fx"), TRealX(6.2345678));
sl@0
  1578
	test(aa==_L("x6.234568x"));
sl@0
  1579
	aa.Format(_L("x%- 10Fx"), TRealX(6.2345));
sl@0
  1580
	test(aa==_L("x6.234500  x"));
sl@0
  1581
	aa.Format(_L("x%+ 10Fx"), TRealX(6.2345));
sl@0
  1582
	test(aa==_L("x  6.234500x"));
sl@0
  1583
	aa.Format(_L("x% 10Fx"), TRealX(6.2345));
sl@0
  1584
	test(aa==_L("x  6.234500x"));
sl@0
  1585
	aa.Format(_L("x%+010Fx"), TRealX(6.2345));
sl@0
  1586
	test(aa==_L("x006.234500x"));
sl@0
  1587
	aa.Format(_L("x%+10Fx"), TRealX(6.2345));
sl@0
  1588
	test(aa==_L("x  6.234500x"));
sl@0
  1589
	aa.Format(_L("x%10Fx"), TRealX(6.2345));
sl@0
  1590
	test(aa==_L("x  6.234500x"));
sl@0
  1591
	aa.Format(_L("x%010Fx"), TRealX(6.2345));
sl@0
  1592
	test(aa==_L("x006.234500x"));
sl@0
  1593
	aa.Format(_L("x%= 10Fx"), TRealX(6.2345));
sl@0
  1594
	test(aa==_L("x 6.234500 x"));
sl@0
  1595
	aa.Format(_L("x%10Fx"), TRealX(12345352342.545));
sl@0
  1596
	test(aa==_L("x12,345,352,342.545000x"));
sl@0
  1597
	aa.Format(_L("x%20.9Fx"), TRealX(1.0123456789));
sl@0
  1598
	test(aa==_L("x         1.012345679x"));
sl@0
  1599
	aa.Format(_L("x%5.1Fx"), TRealX(1.99));
sl@0
  1600
	test(aa==_L("x  2.0x"));
sl@0
  1601
#endif
sl@0
  1602
sl@0
  1603
	aa.Format(_L("x%- 5ex"), 6.2345678);
sl@0
  1604
	test(aa==_L("x6.234568E+00x"));
sl@0
  1605
	aa.Format(_L("x%+ 5ex"), 6.2345678);
sl@0
  1606
	test(aa==_L("x6.234568E+00x"));
sl@0
  1607
	aa.Format(_L("x% 5ex"), 6.2345678);
sl@0
  1608
	test(aa==_L("x6.234568E+00x"));
sl@0
  1609
	aa.Format(_L("x%= 5ex"), 6.2345678);
sl@0
  1610
	test(aa==_L("x6.234568E+00x"));
sl@0
  1611
	aa.Format(_L("x%- 14ex"), 6.2345);
sl@0
  1612
	test(aa==_L("x6.234500E+00  x"));
sl@0
  1613
	aa.Format(_L("x%+ 14ex"), 6.2345);
sl@0
  1614
	test(aa==_L("x  6.234500E+00x"));
sl@0
  1615
	aa.Format(_L("x% 14ex"), 6.2345);
sl@0
  1616
	test(aa==_L("x  6.234500E+00x"));
sl@0
  1617
	aa.Format(_L("x%= 14ex"), 6.2345);
sl@0
  1618
	test(aa==_L("x 6.234500E+00 x"));
sl@0
  1619
	aa.Format(_L("x%10ex"), 12345352342.545);
sl@0
  1620
	test(aa==_L("x1.234535E+10x"));
sl@0
  1621
	aa.Format(_L("x%20.9ex"), 1.0123456789);
sl@0
  1622
	test(aa==_L("x     1.012345679E+00x"));
sl@0
  1623
	aa.Format(_L("x%5.1ex"), 1.99);
sl@0
  1624
	test(aa==_L("x2.0E+00x"));
sl@0
  1625
	}
sl@0
  1626
sl@0
  1627
sl@0
  1628
class TO8 : public TDes8Overflow
sl@0
  1629
	{
sl@0
  1630
public:
sl@0
  1631
	virtual void Overflow(TDes8 &aDes);
sl@0
  1632
	};
sl@0
  1633
sl@0
  1634
void TO8::Overflow(TDes8 &aDes)
sl@0
  1635
	{
sl@0
  1636
	aDes=_L8("OVERFLOW");
sl@0
  1637
	}
sl@0
  1638
sl@0
  1639
class TO8L : public TDes8Overflow
sl@0
  1640
	{
sl@0
  1641
public:
sl@0
  1642
	virtual void Overflow(TDes8 &aDes);
sl@0
  1643
	};
sl@0
  1644
sl@0
  1645
void TO8L::Overflow(TDes8 &/*aDes*/)
sl@0
  1646
	{
sl@0
  1647
	User::Leave(KErrOverflow);
sl@0
  1648
	}
sl@0
  1649
sl@0
  1650
class TO16 : public TDes16Overflow
sl@0
  1651
	{
sl@0
  1652
public:
sl@0
  1653
	virtual void Overflow(TDes16 &aDes);
sl@0
  1654
	};
sl@0
  1655
sl@0
  1656
void TO16::Overflow(TDes16 &aDes)
sl@0
  1657
	{
sl@0
  1658
	aDes=_L16("OVERFLOW");
sl@0
  1659
	}
sl@0
  1660
sl@0
  1661
class TO16L : public TDes16Overflow
sl@0
  1662
	{
sl@0
  1663
public:
sl@0
  1664
	virtual void Overflow(TDes16 &aDes);
sl@0
  1665
	};
sl@0
  1666
sl@0
  1667
void TO16L::Overflow(TDes16 &/*aDes*/)
sl@0
  1668
	{
sl@0
  1669
	User::Leave(KErrOverflow);
sl@0
  1670
	}
sl@0
  1671
sl@0
  1672
void append8(TDes8 &aBuf, TDes8Overflow *aHandler, TRefByValue<const TDesC8> aFmt, ...)
sl@0
  1673
	{
sl@0
  1674
	VA_LIST list;
sl@0
  1675
	VA_START(list, aFmt);
sl@0
  1676
	aBuf.AppendFormatList(aFmt, list, aHandler);
sl@0
  1677
	}
sl@0
  1678
sl@0
  1679
void append16(TDes16 &aBuf, TDes16Overflow *aHandler, TRefByValue<const TDesC16> aFmt, ...)
sl@0
  1680
	{
sl@0
  1681
	VA_LIST list;
sl@0
  1682
	VA_START(list, aFmt);
sl@0
  1683
	aBuf.AppendFormatList(aFmt, list, aHandler);
sl@0
  1684
	}
sl@0
  1685
sl@0
  1686
void testOverflow()
sl@0
  1687
	{
sl@0
  1688
	test.Start(_L("Test no overflow"));
sl@0
  1689
	TBuf8<16> buf=_L8("A ");
sl@0
  1690
	append8(buf, NULL, _L8("Descriptor"));
sl@0
  1691
	test(buf==_L8("A Descriptor"));
sl@0
  1692
sl@0
  1693
	test.Printf(_L("Use a non-leaving overflow handler\n"));
sl@0
  1694
	test.Next(_L("Force overflow with no conversions"));
sl@0
  1695
    TO8 overflow;
sl@0
  1696
	append8(buf, &overflow, _L8("12345678901234567"));
sl@0
  1697
	test(buf==_L8("OVERFLOW"));
sl@0
  1698
sl@0
  1699
	test.Next(_L("Force overflow with decimal conversion"));
sl@0
  1700
	buf=_L8("A Descriptor");
sl@0
  1701
	append8(buf, &overflow,  _L8("%d"), 12345678);
sl@0
  1702
	test(buf==_L8("OVERFLOW"));
sl@0
  1703
sl@0
  1704
	test.Printf(_L("Use a leaving overflow handler\n"));
sl@0
  1705
	test.Next(_L("AppendFormatList with no overflow"));
sl@0
  1706
	buf=_L8("A Descriptor");
sl@0
  1707
    TO8L overflowLeave;
sl@0
  1708
	TRAPD(r, append8(buf, &overflowLeave, _L8("ONE")));
sl@0
  1709
	test(r==KErrNone);
sl@0
  1710
	test(buf==_L8("A DescriptorONE"));
sl@0
  1711
	test.Next(_L("Force overflow with hexadecimal conversion"));
sl@0
  1712
	buf=_L8("A Descriptor");
sl@0
  1713
	TRAP(r, append8(buf, &overflowLeave, _L8("%08x"), 0));
sl@0
  1714
	test(r==KErrOverflow);
sl@0
  1715
		{
sl@0
  1716
		test.Printf(_L("Repeat tests with TBuf16\n"));
sl@0
  1717
		test.Next(_L("Test no overflow"));
sl@0
  1718
		TBuf16<16> buf=_L16("A ");
sl@0
  1719
		append16(buf, NULL, _L16("Descriptor"));
sl@0
  1720
		test(buf==_L16("A Descriptor"));
sl@0
  1721
sl@0
  1722
		test.Printf(_L("Use a non-leaving overflow handler\n"));
sl@0
  1723
		test.Next(_L("Force overflow with no conversions"));
sl@0
  1724
		TO16 overflow;
sl@0
  1725
		append16(buf, &overflow, _L16("12345678901234567"));
sl@0
  1726
		test(buf==_L16("OVERFLOW"));
sl@0
  1727
sl@0
  1728
		test.Next(_L("Force overflow with decimal conversion"));
sl@0
  1729
		buf=_L16("A Descriptor");
sl@0
  1730
		append16(buf, &overflow,  _L16("%d"), 12345678);
sl@0
  1731
		test(buf==_L16("OVERFLOW"));
sl@0
  1732
sl@0
  1733
		test.Printf(_L("Use a leaving overflow handler\n"));
sl@0
  1734
		test.Next(_L("AppendFormatList with no overflow"));
sl@0
  1735
		buf=_L16("A Descriptor");
sl@0
  1736
		TO16L overflowLeave;
sl@0
  1737
		TRAPD(r, append16(buf, &overflowLeave, _L16("ONE")));
sl@0
  1738
		test(r==KErrNone);
sl@0
  1739
		test(buf==_L16("A DescriptorONE"));
sl@0
  1740
		test.Next(_L("Force overflow with hexadecimal conversion"));
sl@0
  1741
		buf=_L16("A Descriptor");
sl@0
  1742
		TRAP(r, append16(buf, &overflowLeave, _L16("%08x"), 0));
sl@0
  1743
		test(r==KErrOverflow);
sl@0
  1744
		}
sl@0
  1745
	test.End();
sl@0
  1746
	}
sl@0
  1747
sl@0
  1748
void testIgnoreOverflow()
sl@0
  1749
	{
sl@0
  1750
	test.Start(_L("Test no overflow"));
sl@0
  1751
	TBuf8<16> buf=_L8("A ");
sl@0
  1752
	append8(buf, NULL, _L8("Descriptor"));
sl@0
  1753
	test(buf==_L8("A Descriptor"));
sl@0
  1754
sl@0
  1755
	test.Printf(_L("Use a non-leaving overflow handler\n"));
sl@0
  1756
	test.Next(_L("Force overflow with no conversions"));
sl@0
  1757
    TDes8IgnoreOverflow overflow;
sl@0
  1758
	append8(buf, &overflow, _L8("12345678901234567"));
sl@0
  1759
	test(buf==_L8("A Descriptor1234"));
sl@0
  1760
sl@0
  1761
	test.Next(_L("Force overflow with decimal conversion"));
sl@0
  1762
	buf=_L8("A Descriptor");
sl@0
  1763
	append8(buf, &overflow,  _L8("%d"), 123456789);
sl@0
  1764
	test(buf==_L8("A Descriptor"));
sl@0
  1765
sl@0
  1766
	//test.Printf(_L("Repeat tests with TBuf16\n"));
sl@0
  1767
	test.Next(_L("Test no overflow"));
sl@0
  1768
	TBuf16<17> buf2=_L16("A ");
sl@0
  1769
	append16(buf2, NULL, _L16("Descriptor"));
sl@0
  1770
	test(buf2==_L16("A Descriptor"));
sl@0
  1771
sl@0
  1772
	test.Printf(_L("Use a non-leaving overflow handler\n"));
sl@0
  1773
	test.Next(_L("Force overflow with no conversions"));
sl@0
  1774
	TDes16IgnoreOverflow overflow2;
sl@0
  1775
	append16(buf2, &overflow2, _L16("12345678901234567"));
sl@0
  1776
	test(buf2==_L16("A Descriptor12345"));
sl@0
  1777
sl@0
  1778
	test.Next(_L("Force overflow with decimal conversion"));
sl@0
  1779
	buf2=_L16("A Descriptor");
sl@0
  1780
	append16(buf2, &overflow2,  _L16("%d"), 123456789);
sl@0
  1781
	test(buf2==_L16("A Descriptor"));
sl@0
  1782
sl@0
  1783
	test.End();
sl@0
  1784
	}
sl@0
  1785
sl@0
  1786
void testAppendFormatIgnoreOverflow()
sl@0
  1787
	{
sl@0
  1788
	test.Start(_L("Test no overflow"));
sl@0
  1789
	TBuf8<16> buf;
sl@0
  1790
	buf.AppendFormat(_L8("A Descriptor"));	
sl@0
  1791
	test(buf==_L8("A Descriptor"));
sl@0
  1792
	
sl@0
  1793
	test.Next(_L("Force overflow with no conversions"));
sl@0
  1794
    TDes8IgnoreOverflow overflow;
sl@0
  1795
	buf.AppendFormat(_L8("123456789012345679"),&overflow);
sl@0
  1796
	test(buf==_L8("A Descriptor1234"));
sl@0
  1797
	
sl@0
  1798
	test.Next(_L("Force overflow with decimal conversion"));
sl@0
  1799
	buf = _L8("Symbian OS");
sl@0
  1800
	buf.AppendFormat(_L8("%d"), &overflow, 1234567);
sl@0
  1801
	test(buf==_L8("Symbian OS"));
sl@0
  1802
	
sl@0
  1803
	test.Next(_L("Test no overflow"));
sl@0
  1804
	TBuf16<16> buf2;
sl@0
  1805
	buf2.AppendFormat(_L16("A Descriptor"));	
sl@0
  1806
	test(buf2==_L16("A Descriptor"));
sl@0
  1807
	
sl@0
  1808
	test.Next(_L("Force overflow with no conversions"));
sl@0
  1809
    TDes16IgnoreOverflow overflow2;
sl@0
  1810
	buf2.AppendFormat(_L16("123456789012345679"),&overflow2);
sl@0
  1811
	test(buf2==_L16("A Descriptor1234"));
sl@0
  1812
	
sl@0
  1813
	test.Next(_L("Force overflow with decimal conversion"));
sl@0
  1814
	buf2 = _L16("Symbian OS");
sl@0
  1815
	buf2.AppendFormat(_L16("%d"), &overflow2, 1234567);
sl@0
  1816
	test(buf2==_L16("Symbian OS"));
sl@0
  1817
sl@0
  1818
	test.End();
sl@0
  1819
sl@0
  1820
sl@0
  1821
	}
sl@0
  1822
sl@0
  1823
// INC061330  AV28Crit: NTT - TInt TDesC16.FindC -method is giving strange output values 
sl@0
  1824
// This test should pass with "ELangPrcChinese" locale.
sl@0
  1825
void INC061330()
sl@0
  1826
	{
sl@0
  1827
	TLanguage defaultLang = User::Language();
sl@0
  1828
sl@0
  1829
	TInt err = HAL::Set(HAL::ELanguageIndex, ELangPrcChinese);
sl@0
  1830
	test(err == KErrNone);	
sl@0
  1831
sl@0
  1832
	TBuf<50> libraryName;
sl@0
  1833
sl@0
  1834
	libraryName.Format(_L("ELOCL.%02d"), ELangPrcChinese);
sl@0
  1835
sl@0
  1836
	//Reset the locale
sl@0
  1837
	err=UserSvr::ChangeLocale(KNullDesC);
sl@0
  1838
	test(err==KErrNone);
sl@0
  1839
sl@0
  1840
	//Now change to chinese locale
sl@0
  1841
	err = UserSvr::ChangeLocale(libraryName);
sl@0
  1842
	if(err==KErrNotFound)
sl@0
  1843
		{
sl@0
  1844
		test.Printf(_L("TEST CASE NOT RUN BECAUSE ELangPrcChinese LOCALE NOT FOUND!\n"));
sl@0
  1845
		HAL::Set(HAL::ELanguageIndex, defaultLang);
sl@0
  1846
		return;
sl@0
  1847
		}
sl@0
  1848
	test(err == KErrNone);
sl@0
  1849
	
sl@0
  1850
	TLanguage lang = User::Language();
sl@0
  1851
	test(lang == ELangPrcChinese);
sl@0
  1852
sl@0
  1853
	TInt pos;
sl@0
  1854
	_LIT(KBuf, "hello");
sl@0
  1855
sl@0
  1856
	pos = KBuf().FindC(_L("a"));
sl@0
  1857
	test(pos == KErrNotFound);
sl@0
  1858
sl@0
  1859
	pos = KBuf().FindC(_L("zzz"));
sl@0
  1860
	test(pos == KErrNotFound);
sl@0
  1861
sl@0
  1862
	pos = KBuf().FindC(_L("."));
sl@0
  1863
	test(pos == KErrNotFound);
sl@0
  1864
sl@0
  1865
	pos = KBuf().FindC(_L(":"));
sl@0
  1866
	test(pos == KErrNotFound);
sl@0
  1867
sl@0
  1868
	pos = KBuf().FindC(_L("hela"));
sl@0
  1869
	test(pos == KErrNotFound);
sl@0
  1870
sl@0
  1871
	//Reset the locale
sl@0
  1872
	err=UserSvr::ChangeLocale(KNullDesC);
sl@0
  1873
	test(err==KErrNone);
sl@0
  1874
	
sl@0
  1875
	//Now revert to the original default english locale
sl@0
  1876
	libraryName.Format(_L("ELOCL.%02d"), defaultLang);
sl@0
  1877
	test(err == KErrNone);
sl@0
  1878
	err = UserSvr::ChangeLocale(libraryName);
sl@0
  1879
	test(err == KErrNone);
sl@0
  1880
	
sl@0
  1881
	lang = User::Language();
sl@0
  1882
	test(lang == defaultLang);
sl@0
  1883
	}
sl@0
  1884
#ifndef _DEBUG
sl@0
  1885
#pragma warning( disable : 4702) //Unreachable code
sl@0
  1886
#pragma warning( disable : 4710) //Function not expanded
sl@0
  1887
#endif
sl@0
  1888
GLDEF_C TInt E32Main()
sl@0
  1889
// Test the TBuf type.
sl@0
  1890
    {
sl@0
  1891
	test.Title();
sl@0
  1892
sl@0
  1893
	test.Start(_L("class TBuf16<0x50>"));
sl@0
  1894
	TestTBuf<TBuf16<0x50>,TText16,TPtrC16> c(0x50);
sl@0
  1895
	c.test_TBuf();
sl@0
  1896
	
sl@0
  1897
	test.Next(_L("class TBuf8<0x50>"));
sl@0
  1898
	TestTBuf<TBuf8<0x50>,TText8,TPtrC8> b(0x50);
sl@0
  1899
	b.test_TBuf();
sl@0
  1900
	
sl@0
  1901
	test.Next(_L("class TBuf<0x50>"));
sl@0
  1902
	TestTBuf<TBuf<0x50>,TText,TPtrC> a(0x50);
sl@0
  1903
	a.test_TBuf();
sl@0
  1904
sl@0
  1905
	test.Next(_L("TReal formating"));
sl@0
  1906
	testFormat();
sl@0
  1907
sl@0
  1908
	test.Next(_L("Test overflow handler"));
sl@0
  1909
	testOverflow();
sl@0
  1910
sl@0
  1911
	test.Next(_L("Test ignore overflow handler"));
sl@0
  1912
	testIgnoreOverflow();
sl@0
  1913
sl@0
  1914
	test.Next(_L("Test Format ignore overflow handler"));
sl@0
  1915
	testAppendFormatIgnoreOverflow();
sl@0
  1916
sl@0
  1917
	test.Next(_L("INC061330"));
sl@0
  1918
	INC061330();
sl@0
  1919
sl@0
  1920
	test.End();
sl@0
  1921
sl@0
  1922
	return(KErrNone);
sl@0
  1923
    }
sl@0
  1924
sl@0
  1925
//#pragma warning( default : 4702)
sl@0
  1926
//#pragma warning( default : 4710)
sl@0
  1927
sl@0
  1928