os/kernelhwsrv/kerneltest/e32test/buffer/t_match.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) 1996-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_match.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test the match methods of TPtrC8 and TPtrC16 objects and the 
sl@0
    17
// TCharIterator TCombiningCharIterator, TCollationValueIterator
sl@0
    18
// and TCollationRawValueIterator classes.
sl@0
    19
// API Information:
sl@0
    20
// TPtrC8, TPtrC16, TCharIterator, TCombiningCharIterator,
sl@0
    21
// TCollationValueIterator, TCollationRawValueIterator
sl@0
    22
// Details:
sl@0
    23
// - Test and verify the results of TPtrC8 Match and MatchF methods
sl@0
    24
// on a variety of constant strings. Verify both match and mismatch
sl@0
    25
// conditions.
sl@0
    26
// - Test and verify the results of TPtrC16 Match and MatchF methods
sl@0
    27
// on a variety of constant strings. Verify both match and mismatch
sl@0
    28
// conditions.
sl@0
    29
// - For a TCharIterator object, test and verify:
sl@0
    30
// - basic character handling
sl@0
    31
// - ability to reset the iterator correctly
sl@0
    32
// - combining characters works as expected
sl@0
    33
// - ability to jump into the middle of combined characters
sl@0
    34
// - full-width variants are not modified
sl@0
    35
// - narrow strings work as expected
sl@0
    36
// - surrogate pairs work as expected
sl@0
    37
// - Using a TCombiningCharIterator object with a variety of character 
sl@0
    38
// strings as input, verify that the output is as expected.
sl@0
    39
// - Using TCollationValueIterator and TCollationRawValueIterator objects:
sl@0
    40
// - test the raw iterator 
sl@0
    41
// - test starting at different points in the iteration and verify capitals 
sl@0
    42
// are ignored at level 0
sl@0
    43
// - verify capitals are ignored at level 1
sl@0
    44
// - verify capitals do not match at level 2
sl@0
    45
// - check the TCollationValueIterator Restart method
sl@0
    46
// - test collation keys, when they success and when they fail halfway
sl@0
    47
// - exhaust the internal cache, verify object still works
sl@0
    48
// - test different decompositions at level 3
sl@0
    49
// - verify results are as expected
sl@0
    50
// - Test and verify the results of the TUnicodeFold::FindWildcardMatchFolded()
sl@0
    51
// method on a variety of constant strings: find a string within another 
sl@0
    52
// string, verify the offset into the candidate string if it is present, or 
sl@0
    53
// KErrNotFound if it is not.
sl@0
    54
// - Test and verify the results of the TUnicodeFold::FindFolded() method on 
sl@0
    55
// a variety of constant strings: compare two strings, verify return value.
sl@0
    56
// - Test and verify results of UnicodeFoldCase() on a variety of characters.
sl@0
    57
// - Test and verify results of MatchLeadingWildcards() on a variety of strings.
sl@0
    58
// - Test and verify results of MatchesHereFoldedWithPrefixTest() on a variety 
sl@0
    59
// of strings.
sl@0
    60
// - Test and verify results of LocateFolded() on a variety of strings.
sl@0
    61
// - Test and verify results of FindFoldedWithWildcard() and FindMatchFolded()
sl@0
    62
// on a variety of strings.
sl@0
    63
// - Test and verify results of TDesc.CompareF() on a variety of strings.
sl@0
    64
// Platforms/Drives/Compatibility:
sl@0
    65
// All 
sl@0
    66
// Assumptions/Requirement/Pre-requisites:
sl@0
    67
// Failures and causes:
sl@0
    68
// Base Port information:
sl@0
    69
// 
sl@0
    70
//
sl@0
    71
sl@0
    72
#include <e32test.h>
sl@0
    73
#include <f32file.h>
sl@0
    74
#include <collate.h>
sl@0
    75
#include "collateimp.h"
sl@0
    76
#include "CompareImp.h"
sl@0
    77
#include "u32std.h"
sl@0
    78
sl@0
    79
static inline TBool IsSupplementary(TUint aChar)
sl@0
    80
/**
sl@0
    81
@param aChar The 32-bit code point value of a Unicode character.
sl@0
    82
sl@0
    83
@return True, if aChar is supplementary character; false, otherwise.
sl@0
    84
*/
sl@0
    85
        {
sl@0
    86
        return (aChar > 0xFFFF);
sl@0
    87
        }
sl@0
    88
sl@0
    89
static inline TText16 GetHighSurrogate(TUint aChar)
sl@0
    90
/**
sl@0
    91
Retrieve the high surrogate of a supplementary character.
sl@0
    92
sl@0
    93
@param aChar The 32-bit code point value of a Unicode character.
sl@0
    94
sl@0
    95
@return High surrogate of aChar, if aChar is a supplementary character;
sl@0
    96
        aChar itself, if aChar is not a supplementary character.
sl@0
    97
sl@0
    98
@see TChar::GetLowSurrogate
sl@0
    99
*/
sl@0
   100
        {
sl@0
   101
        return STATIC_CAST(TText16, 0xD7C0 + (aChar >> 10));
sl@0
   102
        }
sl@0
   103
sl@0
   104
static inline TText16 GetLowSurrogate(TUint aChar)
sl@0
   105
/**
sl@0
   106
Retrieve the low surrogate of a supplementary character.
sl@0
   107
sl@0
   108
@param aChar The 32-bit code point value of a Unicode character.
sl@0
   109
sl@0
   110
@return Low surrogate of aChar, if aChar is a supplementary character;
sl@0
   111
        zero, if aChar is not a supplementary character.
sl@0
   112
sl@0
   113
@see TChar::GetHighSurrogate
sl@0
   114
*/
sl@0
   115
        {
sl@0
   116
        return STATIC_CAST(TText16, 0xDC00 | (aChar & 0x3FF));
sl@0
   117
        }
sl@0
   118
sl@0
   119
sl@0
   120
///***************** copied from locale euser source code ***********************
sl@0
   121
static const TCollationMethod TheCollationMethod[] =
sl@0
   122
	{
sl@0
   123
		{
sl@0
   124
		KUidBasicCollationMethod,				// this is the standard unlocalised method
sl@0
   125
		NULL,									// null means use the standard table
sl@0
   126
		NULL,									// there's no override table
sl@0
   127
		0										// the flags are standard
sl@0
   128
		}
sl@0
   129
	};
sl@0
   130
static const TCollationDataSet TheCollationDataSet =
sl@0
   131
	{
sl@0
   132
	TheCollationMethod,
sl@0
   133
	1
sl@0
   134
	};
sl@0
   135
const LCharSet TheCharSet =
sl@0
   136
	{
sl@0
   137
	NULL,
sl@0
   138
	&TheCollationDataSet
sl@0
   139
	};
sl@0
   140
const LCharSet* GetLocaleCharSet()
sl@0
   141
	{
sl@0
   142
	return &TheCharSet;
sl@0
   143
	}
sl@0
   144
///*******************************************************************************
sl@0
   145
sl@0
   146
sl@0
   147
#ifdef __VC32__
sl@0
   148
    // Solve compilation problem caused by non-English locale
sl@0
   149
    #pragma setlocale("english")
sl@0
   150
#endif
sl@0
   151
sl@0
   152
#define ARRAY_SIZE(ar) (sizeof(ar) / (sizeof(ar[0])))
sl@0
   153
sl@0
   154
LOCAL_D RTest test(_L("T_MATCH"));
sl@0
   155
sl@0
   156
_LIT(KUnicodeTestDataFile, "z:\\Test\\UnicodeData.txt");
sl@0
   157
sl@0
   158
static const TUint32 TheDevanagariKey[] = 
sl@0
   159
	{
sl@0
   160
	0x22a010b,0x22b010b,0x285010b,0xb109,0xb209,0xb309,0xb409,0xb509,
sl@0
   161
	0x6c5e609,0x6c6e609,0x6c7e609,0x6c8e609,0x6c9e609,0x6cae609,0x6cbe609,0x6cce609,
sl@0
   162
	0x6cde609,0x6cee609,0xba40109,0xba50109,0xba60109,0xba70109,0xba80109,0xba90109,
sl@0
   163
	0xbaa0109,0xbab0109,0xbac0109,0xbad0109,0xbae0109,0xbaf0109,0xbb00109,0xbb10109,
sl@0
   164
	0xbb20109,0xbb30109,0xbb40109,0xbb50109,0xbb60109,0xbb70109,0xbb80109,0xbb90109,
sl@0
   165
	0xbb9b109,0xbba0109,0xbbab109,0xbbb0109,0xbbbb109,0xbbc0109,0xbbd0109,0xbbe0109,
sl@0
   166
	0xbbf0109,0xbc00109,0xbc0b109,0xbc10109,0xbc20109,0xbc30109,0xbc40109,0xbc50109,
sl@0
   167
	0xbc5b109,0xbc60109,0xbc6b109,0xbc70109,0xbc80109,0xbc90109,0xbca0109,0xbcb0109,
sl@0
   168
	0xbcc0109,0xbccb109,0xbcd0109,0xbce0109,0xbceb109,0xbcf0109,0xbd00109,0xbd10109,
sl@0
   169
	0xbd20109,0xbd2b109,0xbd30109,0xbd3b109,0xbd40109,0xbd50109,0xbd5b109,0xbd60109,
sl@0
   170
	0xbd70109,0xbd80109,0xbd90109,0xbda0109,0xbdb0109,0xbdc0109,0xbdd0109,0xbde0109,
sl@0
   171
	0xbdf0109,0xbe00109,0xbe10109,0xbe20109,0xbe30109,0xbe40109,0xbe50109,0xbe60109,
sl@0
   172
	0xbe70109,0xbe80109,0xbe90109,0xbea0109,0xbeb0109,0xbec0109,0xbed0109,
sl@0
   173
	};
sl@0
   174
sl@0
   175
static const TUint32 TheDevanagariIndex[] = 
sl@0
   176
	{
sl@0
   177
	0x9010012,0x9020013,0x9030014,0x9050015,0x9060016,0x9070017,0x9080018,0x9090019,
sl@0
   178
	0x90a001a,0x90b001b,0x90c001d,0x90d001f,0x90e0020,0x90f0021,0x9100022,0x9110023,
sl@0
   179
	0x9120024,0x9130025,0x9140026,0x9150027,0x9160029,0x917002b,0x918002d,0x919002e,
sl@0
   180
	0x91a002f,0x91b0030,0x91c0031,0x91d0033,0x91e0034,0x91f0035,0x9200036,0x9210037,
sl@0
   181
	0x9220039,0x923003b,0x924003c,0x925003d,0x926003e,0x927003f,0x9280040,0x9290041,
sl@0
   182
	0x92a0042,0x92b0043,0x92c0045,0x92d0046,0x92e0047,0x92f0048,0x930004a,0x931004b,
sl@0
   183
	0x932004c,0x933004d,0x934004e,0x935004f,0x9360050,0x9370051,0x9380052,0x9390053,
sl@0
   184
	0x93c0003,0x93d0054,0x93e0055,0x93f0056,0x9400057,0x9410058,0x9420059,0x943005a,
sl@0
   185
	0x944005b,0x945005e,0x946005f,0x9470060,0x9480061,0x9490062,0x94a0063,0x94b0064,
sl@0
   186
	0x94c0065,0x94d0066,0x9510004,0x9520005,0x9530006,0x9540007,0x9580028,0x959002a,
sl@0
   187
	0x95a002c,0x95b0032,0x95c0038,0x95d003a,0x95e0044,0x95f0049,0x960001c,0x961001e,
sl@0
   188
	0x962005c,0x963005d,0x9640000,0x9650001,0x9660008,0x9670009,0x968000a,0x969000b,
sl@0
   189
	0x96a000c,0x96b000d,0x96c000e,0x96d000f,0x96e0010,0x96f0011,0x9700002,
sl@0
   190
	};
sl@0
   191
sl@0
   192
static const TCollationKeyTable TheDevanagariTable = 
sl@0
   193
	{ TheDevanagariKey, TheDevanagariIndex, 103, 0, 0, 0 };
sl@0
   194
sl@0
   195
static const TCollationMethod TheDevanagariMethod =
sl@0
   196
	{ 0, 0, &TheDevanagariTable, 0 };
sl@0
   197
sl@0
   198
static const TCollationMethod TheDevanagariIgnoreCombiningMethod =
sl@0
   199
	{ 0, 0, &TheDevanagariTable, TCollationMethod::EIgnoreCombining };
sl@0
   200
sl@0
   201
static const TUint32 TheSwedishKey[] = 
sl@0
   202
	{
sl@0
   203
	0x8f60109,0x8f70109,0x8f80109,0x8f60121,0x8f70121,0x8f80121,0x8dd0109,0x8dd0121,
sl@0
   204
	0x8c50121,0x8c50109,
sl@0
   205
	};
sl@0
   206
sl@0
   207
static const TUint32 TheSwedishIndex[] = 
sl@0
   208
	{
sl@0
   209
	0x570008,0x770009,
sl@0
   210
	};
sl@0
   211
sl@0
   212
static const TUint16 TheSwedishStringElement[] = 
sl@0
   213
	{
sl@0
   214
	0x2,0x61,0x30a,0x2,0x61,0x308,0x2,0x6f,
sl@0
   215
	0x308,0x2,0x41,0x30a,0x2,0x41,0x308,0x2,
sl@0
   216
	0x4f,0x308,0x2,0x75,0x308,0x2,0x55,0x308,
sl@0
   217
	};
sl@0
   218
sl@0
   219
static const TUint32 TheSwedishStringIndex[] = 
sl@0
   220
	{
sl@0
   221
	0xc0004,0x90003,0xf0005,0x150007,0x30001,0x0,0x60002,0x120006,
sl@0
   222
	};
sl@0
   223
sl@0
   224
static const TCollationKeyTable TheSwedishTable = 
sl@0
   225
	{ TheSwedishKey, TheSwedishIndex, 2, TheSwedishStringElement, TheSwedishStringIndex, 8 };
sl@0
   226
sl@0
   227
static const TCollationMethod TheSwedishMethod =
sl@0
   228
	{ 0, 0, &TheSwedishTable, TCollationMethod::EIgnoreNone };
sl@0
   229
sl@0
   230
static const TCollationMethod TheIgnoreNoneMethod =
sl@0
   231
	{ 0, 0, 0, TCollationMethod::EIgnoreNone };
sl@0
   232
sl@0
   233
void TestPrintCaption(const TDesC& aTestName, const TText16 aStr[], TInt aLen)
sl@0
   234
	{
sl@0
   235
	test.Next(aTestName);
sl@0
   236
	RDebug::Print(_L("Char seq: "));
sl@0
   237
	for(TInt i=0;i<aLen;++i)
sl@0
   238
		{
sl@0
   239
		RDebug::Print(_L("%04X "), aStr[i]);
sl@0
   240
		}
sl@0
   241
	RDebug::Print(_L("\nOutput: "));
sl@0
   242
	}
sl@0
   243
sl@0
   244
TInt MatchC(const TDesC16& aCandidate, const TDesC16& aSearchTerm,
sl@0
   245
	const TCollationMethod* aMethod, TInt aLevel)
sl@0
   246
	{
sl@0
   247
	TCollate method(0);
sl@0
   248
	if (aMethod)
sl@0
   249
		{
sl@0
   250
		TCollate m(*aMethod);
sl@0
   251
		method = m;
sl@0
   252
		}
sl@0
   253
	return method.Match(aCandidate.Ptr(), aCandidate.Length(),
sl@0
   254
		aSearchTerm.Ptr(), aSearchTerm.Length(), aLevel);
sl@0
   255
	}
sl@0
   256
sl@0
   257
_LIT(KCand1, "baot");
sl@0
   258
_LIT(KCand2, "ba\x308o\x308t");
sl@0
   259
_LIT(KCand3, "b\xe4\xf6t");
sl@0
   260
_LIT(KSearch1, "BAOT");
sl@0
   261
_LIT(KSearch2, "?AO?");
sl@0
   262
_LIT(KSearch3, "?\xe4o?");
sl@0
   263
_LIT(KSearch4, "*o*");
sl@0
   264
_LIT(KSearch5, "*ao*");
sl@0
   265
_LIT(KSearch6, "*b\x308*");
sl@0
   266
_LIT(KSearch7, "ba\x308*");
sl@0
   267
_LIT(KSearch8, "ba*");
sl@0
   268
sl@0
   269
void TestMatchC()
sl@0
   270
	{
sl@0
   271
	// MatchC should be working at level 0, let us test that this is so.
sl@0
   272
	test(0 == KCand1().MatchC(KSearch1));
sl@0
   273
	test(0 == KCand1().MatchC(KCand2));
sl@0
   274
	test(1 == KCand1().MatchC(KSearch5));
sl@0
   275
	test(1 == KCand2().MatchC(KSearch5));
sl@0
   276
	test(0 <= KCand1().MatchC(KSearch2));
sl@0
   277
	// Test the internals at level 0: It must fail to match Swedish accents
sl@0
   278
	// with the Swedish collation algorithm.
sl@0
   279
	test(0 == MatchC(KCand1, KSearch1, &TheIgnoreNoneMethod, 0));
sl@0
   280
	test(0 == MatchC(KCand1, KSearch1, &TheSwedishMethod, 0));
sl@0
   281
	test(0 == MatchC(KCand2, KSearch1, &TheIgnoreNoneMethod, 0));
sl@0
   282
	test(KErrNotFound == MatchC(KCand2, KSearch1, &TheSwedishMethod, 0));
sl@0
   283
	test(0 == MatchC(KCand3, KSearch1, &TheIgnoreNoneMethod, 0));
sl@0
   284
	test(KErrNotFound == MatchC(KCand3, KSearch1, &TheSwedishMethod, 0));
sl@0
   285
	test(0 <= MatchC(KCand1, KSearch2, &TheIgnoreNoneMethod, 0));
sl@0
   286
	test(0 <= MatchC(KCand1, KSearch2, &TheSwedishMethod, 0));
sl@0
   287
	test(0 <= MatchC(KCand2, KSearch2, &TheIgnoreNoneMethod, 0));
sl@0
   288
	test(KErrNotFound == MatchC(KCand2, KSearch2, &TheSwedishMethod, 0));
sl@0
   289
	test(0 <= MatchC(KCand3, KSearch2, &TheIgnoreNoneMethod, 0));
sl@0
   290
	test(KErrNotFound == MatchC(KCand3, KSearch2, &TheSwedishMethod, 0));
sl@0
   291
	test(0 <= MatchC(KCand2, KSearch3, &TheIgnoreNoneMethod, 0));
sl@0
   292
	test(KErrNotFound == MatchC(KCand3, KSearch2, &TheSwedishMethod, 0));
sl@0
   293
	test(3 == MatchC(KCand2, KSearch4, &TheIgnoreNoneMethod, 0));
sl@0
   294
	test(KErrNotFound == MatchC(KCand2, KSearch4, &TheSwedishMethod, 0));
sl@0
   295
	test(1 == MatchC(KCand2, KSearch5, &TheIgnoreNoneMethod, 0));
sl@0
   296
	test(KErrNotFound == MatchC(KCand2, KSearch5, &TheSwedishMethod, 0));
sl@0
   297
	test(0 == MatchC(KCand2, KSearch6, &TheIgnoreNoneMethod, 0));
sl@0
   298
	test(0 == MatchC(KCand2, KSearch6, &TheSwedishMethod, 0));
sl@0
   299
	test(0 == MatchC(KCand1, KSearch7, &TheIgnoreNoneMethod, 0));
sl@0
   300
	test(KErrNotFound == MatchC(KCand1, KSearch7, &TheSwedishMethod, 0));
sl@0
   301
	test(0 == MatchC(KCand1, KSearch8, &TheIgnoreNoneMethod, 0));
sl@0
   302
	test(0 == MatchC(KCand1, KSearch8, &TheSwedishMethod, 0));
sl@0
   303
	test(0 == MatchC(KCand2, KSearch7, &TheIgnoreNoneMethod, 0));
sl@0
   304
	test(0 == MatchC(KCand2, KSearch7, &TheSwedishMethod, 0));
sl@0
   305
	test(0 == MatchC(KCand2, KSearch8, &TheIgnoreNoneMethod, 0));
sl@0
   306
	test(KErrNotFound == MatchC(KCand2, KSearch8, &TheSwedishMethod, 0));
sl@0
   307
	test(0 == MatchC(KCand3, KSearch7, &TheIgnoreNoneMethod, 0));
sl@0
   308
	test(0 == MatchC(KCand3, KSearch7, &TheSwedishMethod, 0));
sl@0
   309
	test(0 == MatchC(KCand3, KSearch8, &TheIgnoreNoneMethod, 0));
sl@0
   310
	test(KErrNotFound == MatchC(KCand3, KSearch8, &TheSwedishMethod, 0));
sl@0
   311
	_LIT(KCandidate1, "axyz");
sl@0
   312
	_LIT(KSearchStr1, "a*z");
sl@0
   313
	test(0 == KCandidate1().MatchC(KSearchStr1()));
sl@0
   314
	_LIT(KCandidate2, "azzz");
sl@0
   315
	_LIT(KSearchStr2, "a*z");
sl@0
   316
	test(0 == KCandidate2().MatchC(KSearchStr2()));
sl@0
   317
	
sl@0
   318
	// Added tests for INC105311...
sl@0
   319
	_LIT(KCandJpg1, "jpg_jjg.jpg");
sl@0
   320
	_LIT(KCandJpg2, "jpgAjjg.jpg");
sl@0
   321
	_LIT(KCandJpg3, "jpg@jjg.jpg");
sl@0
   322
	_LIT(KCandJpg4, "hpg&jjg.jpg");
sl@0
   323
	_LIT(KCandJpg5, "hpg&jpg.jpg");
sl@0
   324
	_LIT(KSearchJpg1, "*jp?");
sl@0
   325
	_LIT(KSearchJpg2, "*jpg");
sl@0
   326
	_LIT(KSearchJpg3, "*jpg*");
sl@0
   327
	_LIT(KSearchJpg4, "*jpg*jpg");
sl@0
   328
	test(8 == KCandJpg1().MatchC(KSearchJpg1));
sl@0
   329
	test(8 == KCandJpg2().MatchC(KSearchJpg1));
sl@0
   330
	test(8 == KCandJpg3().MatchC(KSearchJpg1));
sl@0
   331
	test(8 == KCandJpg4().MatchC(KSearchJpg1));
sl@0
   332
	test(8 == KCandJpg5().MatchC(KSearchJpg1));
sl@0
   333
	test(8 == KCandJpg1().MatchC(KSearchJpg2));
sl@0
   334
	test(8 == KCandJpg2().MatchC(KSearchJpg2));
sl@0
   335
	test(8 == KCandJpg3().MatchC(KSearchJpg2));
sl@0
   336
	test(8 == KCandJpg4().MatchC(KSearchJpg2));
sl@0
   337
	test(8 == KCandJpg5().MatchC(KSearchJpg2));
sl@0
   338
	test(0 == KCandJpg1().MatchC(KSearchJpg3));
sl@0
   339
	test(0 == KCandJpg2().MatchC(KSearchJpg3));
sl@0
   340
	test(0 == KCandJpg3().MatchC(KSearchJpg3));
sl@0
   341
	test(8 == KCandJpg4().MatchC(KSearchJpg3));
sl@0
   342
	test(4 == KCandJpg5().MatchC(KSearchJpg3));
sl@0
   343
	test(0 == KCandJpg1().MatchC(KSearchJpg4));
sl@0
   344
	test(0 == KCandJpg2().MatchC(KSearchJpg4));
sl@0
   345
	test(0 == KCandJpg3().MatchC(KSearchJpg4));
sl@0
   346
	test(KErrNotFound == KCandJpg4().MatchC(KSearchJpg4)); 
sl@0
   347
	test(4 == KCandJpg5().MatchC(KSearchJpg4));
sl@0
   348
	_LIT(KCand4, "abcxaxaxa");
sl@0
   349
	_LIT(KSearch9, "*xaxa");
sl@0
   350
	test(5 == KCand4().MatchC(KSearch9));
sl@0
   351
	_LIT(KCand6, "abxa");
sl@0
   352
	_LIT(KSearch10, "*x?");
sl@0
   353
	test(2 == KCand6().MatchC(KSearch10));
sl@0
   354
	_LIT(KCand7, "xab"); 
sl@0
   355
	_LIT(KSearch11, "x?");
sl@0
   356
	test(KErrNotFound == KCand7().MatchC(KSearch11));
sl@0
   357
	_LIT(KCand8, "xa"); 
sl@0
   358
	_LIT(KSearch12, "x?");
sl@0
   359
	test(0 == KCand8().MatchC(KSearch12));
sl@0
   360
	_LIT(KCand9, "xaxa"); 
sl@0
   361
	_LIT(KSearch13, "*x?");
sl@0
   362
	test(2 == KCand9().MatchC(KSearch13));
sl@0
   363
	_LIT(KCand10, "abjpgcjig.jpg"); 
sl@0
   364
	_LIT(KSearch14, "*jp?");
sl@0
   365
	test(10 == KCand10().MatchC(KSearch14));
sl@0
   366
	_LIT(KCand11, "abjpg_jig.jpg"); 
sl@0
   367
	_LIT(KSearch15, "*jp?");
sl@0
   368
	test(10 == KCand11().MatchC(KSearch15));
sl@0
   369
	_LIT(KCand12, "jpg"); 
sl@0
   370
	_LIT(KSearch16, "*jp?");
sl@0
   371
	test(0 == KCand12().MatchC(KSearch16));
sl@0
   372
	_LIT(KCand13, "abjpgig.jpg"); 
sl@0
   373
	_LIT(KSearch17, "*jp?");
sl@0
   374
	test(8 == KCand13().MatchC(KSearch17));
sl@0
   375
	_LIT(KCand14, "abjcgig.jpg"); 
sl@0
   376
	_LIT(KSearch18, "jp?");
sl@0
   377
	test(KErrNotFound == KCand14().MatchC(KSearch18));
sl@0
   378
	_LIT(KCand15, "xax\xE2"); 
sl@0
   379
	_LIT(KSearch19, "*xa\x302");
sl@0
   380
	test(2 == KCand15().MatchC(KSearch19));
sl@0
   381
	_LIT(KCand5, "blahblahblah\xE2");
sl@0
   382
	_LIT(KSearch20, "*a\x302");
sl@0
   383
	test(12 == KCand5().MatchC(KSearch20));
sl@0
   384
	_LIT(KCand16, "bl\xE2hblahblaha\x302");
sl@0
   385
	_LIT(KSearch21, "*a\x302*\xE2");
sl@0
   386
	test(2 == KCand16().MatchC(KSearch21));
sl@0
   387
	_LIT(KCand17, "abcxaxaxa");
sl@0
   388
	_LIT(KSearch22, "*x?x?");
sl@0
   389
	test(5 == KCand17().MatchC(KSearch22));
sl@0
   390
	}
sl@0
   391
sl@0
   392
/**
sl@0
   393
@SYMTestCaseID SYSLIB-EUSER-CT-1759
sl@0
   394
@SYMTestCaseDesc Various tests for the new TDesC16::MatchC() method. Testing that the new method works with
sl@0
   395
				 different wild card characters and different escape characters.
sl@0
   396
@SYMTestPriority High
sl@0
   397
@SYMTestActions  Test for TDesC16::MatchC(const TDesC16 &aPattern, TInt aMaxLevel, TInt aWildChar, TInt aWildSequenceChar, TInt aEscapeChar, const TCollationMethod* aCollationMethod = NULL).
sl@0
   398
@SYMTestExpectedResults The test must not fail.
sl@0
   399
@SYMREQ REQ5907
sl@0
   400
*/
sl@0
   401
void TestMatchC2()
sl@0
   402
	{
sl@0
   403
	_LIT(KCandidate1, "ab/cRRRdef__grt");
sl@0
   404
	_LIT(KSearchStr1, "ab//c%def/_/_grt");
sl@0
   405
	TInt rc = KCandidate1().MatchC(KSearchStr1(), '_', '%', '/', 0);
sl@0
   406
	test(rc == 0);
sl@0
   407
	_LIT(KCandidate2, "_*");
sl@0
   408
	_LIT(KSearchStr2, "/_/*");
sl@0
   409
	rc = KCandidate2().MatchC(KSearchStr2(), '_', '*', '/', 0);
sl@0
   410
	test(rc == 0);
sl@0
   411
	_LIT(KCandidate3, "aa");
sl@0
   412
	_LIT(KSearchStr3, "aaaa");
sl@0
   413
	rc = KCandidate3().MatchC(KSearchStr3(), '_', '%', 'a', 0);
sl@0
   414
	test(rc == 0);
sl@0
   415
	_LIT(KCandidate4, "\\4%3=1");
sl@0
   416
	_LIT(KSearchStr4, "\\\\4_3%");
sl@0
   417
	rc = KCandidate4().MatchC(KSearchStr4(), '_', '%', '\\', 0);
sl@0
   418
	test(rc == 0);
sl@0
   419
	_LIT(KCandidate5, "abcd&efgh");
sl@0
   420
	_LIT(KSearchStr5, "----!&efgh");
sl@0
   421
	rc = KCandidate5().MatchC(KSearchStr5(), '-', '&', '!', 0);
sl@0
   422
	test(rc == 0);
sl@0
   423
	_LIT(KCandidate6, "abc#1234:5678#xyz");
sl@0
   424
	_LIT(KSearchStr6, "#!#1234!:56::!##z");
sl@0
   425
	rc = KCandidate6().MatchC(KSearchStr6(), ':', '#', '!', 0);
sl@0
   426
	test(rc == 3);
sl@0
   427
	_LIT(KCandidate7, "abc#1234:5678#zzz");
sl@0
   428
	_LIT(KSearchStr7, "#!#1234!:56::!##z");
sl@0
   429
	rc = KCandidate7().MatchC(KSearchStr7(), ':', '#', '!', 0);
sl@0
   430
	test(rc == 3);
sl@0
   431
	_LIT(KCandidate8, "abc");
sl@0
   432
	_LIT(KSearchStr8, "a_c");
sl@0
   433
	rc = KCandidate8().MatchC(KSearchStr8(), '_', '%', '7', 0);
sl@0
   434
	test(rc == 0);
sl@0
   435
	_LIT(KCandidate9, "abc");
sl@0
   436
	_LIT(KSearchStr9, "A_C");
sl@0
   437
	rc = KCandidate9().MatchC(KSearchStr9(), '_', '%', '7', 0);
sl@0
   438
	test(rc == 0);
sl@0
   439
	_LIT(KCandidate10, "a_c");
sl@0
   440
	_LIT(KSearchStr10, "a7_c");
sl@0
   441
	rc = KCandidate10().MatchC(KSearchStr10(), '_', '%', '7', 0);
sl@0
   442
	test(rc == 0);
sl@0
   443
	_LIT(KCandidate11, "a_c");
sl@0
   444
	_LIT(KSearchStr11, "A7_C");
sl@0
   445
	rc = KCandidate11().MatchC(KSearchStr11(), '_', '%', '7', 0);
sl@0
   446
	test(rc == 0);
sl@0
   447
	_LIT(KCandidate12, "abc");
sl@0
   448
	_LIT(KSearchStr12, "a7_c");
sl@0
   449
	rc = KCandidate12().MatchC(KSearchStr12(), '_', '%', '7', 0);
sl@0
   450
	test(rc == KErrNotFound);
sl@0
   451
	_LIT(KCandidate13, "abc");
sl@0
   452
	_LIT(KSearchStr13, "A7_C");
sl@0
   453
	rc = KCandidate13().MatchC(KSearchStr13(), '_', '%', '7', 0);
sl@0
   454
	test(rc == KErrNotFound);
sl@0
   455
	_LIT(KCandidate14, "a7Xc");
sl@0
   456
	_LIT(KSearchStr14, "a7_c");
sl@0
   457
	rc = KCandidate14().MatchC(KSearchStr14(), '_', '%', '7', 0);
sl@0
   458
	test(rc == KErrNotFound);
sl@0
   459
	_LIT(KCandidate15, "a7Xc");
sl@0
   460
	_LIT(KSearchStr15, "A7_C");
sl@0
   461
	rc = KCandidate15().MatchC(KSearchStr15(), '_', '%', '7', 0);
sl@0
   462
	test(rc == KErrNotFound);
sl@0
   463
	_LIT(KCandidate16, "abcde");
sl@0
   464
	_LIT(KSearchStr16, "a%e");
sl@0
   465
	rc = KCandidate16().MatchC(KSearchStr16(), '_', '%', '7', 0);
sl@0
   466
	test(rc == 0);
sl@0
   467
	_LIT(KCandidate17, "abcde");
sl@0
   468
	_LIT(KSearchStr17, "A%E");
sl@0
   469
	rc = KCandidate17().MatchC(KSearchStr17(), '_', '%', '7', 0);
sl@0
   470
	test(rc == 0);
sl@0
   471
	_LIT(KCandidate18, "abcde");
sl@0
   472
	_LIT(KSearchStr18, "a7%e");
sl@0
   473
	rc = KCandidate18().MatchC(KSearchStr18(), '_', '%', '7', 0);
sl@0
   474
	test(rc == KErrNotFound);
sl@0
   475
	_LIT(KCandidate19, "abcde");
sl@0
   476
	_LIT(KSearchStr19, "A7%E");
sl@0
   477
	rc = KCandidate19().MatchC(KSearchStr19(), '_', '%', '7', 0);
sl@0
   478
	test(rc == KErrNotFound);
sl@0
   479
	_LIT(KCandidate20, "a7cde");
sl@0
   480
	_LIT(KSearchStr20, "a7%e");
sl@0
   481
	rc = KCandidate20().MatchC(KSearchStr20(), '_', '%', '7', 0);
sl@0
   482
	test(rc == KErrNotFound);
sl@0
   483
	_LIT(KCandidate21, "a7cde");
sl@0
   484
	_LIT(KSearchStr21, "A7%E");
sl@0
   485
	rc = KCandidate21().MatchC(KSearchStr21(), '_', '%', '7', 0);
sl@0
   486
	test(rc == KErrNotFound);
sl@0
   487
	_LIT(KCandidate22, "a7cde");
sl@0
   488
	_LIT(KSearchStr22, "a77%e");
sl@0
   489
	rc = KCandidate22().MatchC(KSearchStr22(), '_', '%', '7', 0);
sl@0
   490
	test(rc == 0);
sl@0
   491
	_LIT(KCandidate23, "a7cde");
sl@0
   492
	_LIT(KSearchStr23, "A77%E");
sl@0
   493
	rc = KCandidate23().MatchC(KSearchStr23(), '_', '%', '7', 0);
sl@0
   494
	test(rc == 0);
sl@0
   495
	_LIT(KCandidate24, "abc7");
sl@0
   496
	_LIT(KSearchStr24, "a%77");
sl@0
   497
	rc = KCandidate24().MatchC(KSearchStr24(), '_', '%', '7', 0);
sl@0
   498
	test(rc == 0);
sl@0
   499
	_LIT(KCandidate25, "abc7");
sl@0
   500
	_LIT(KSearchStr25, "A%77");
sl@0
   501
	rc = KCandidate25().MatchC(KSearchStr25(), '_', '%', '7', 0);
sl@0
   502
	test(rc == 0);
sl@0
   503
	_LIT(KCandidate26, "abc_");
sl@0
   504
	_LIT(KSearchStr26, "a%7_");
sl@0
   505
	rc = KCandidate26().MatchC(KSearchStr26(), '_', '%', '7', 0);
sl@0
   506
	test(rc == 0);
sl@0
   507
	_LIT(KCandidate27, "abc_");
sl@0
   508
	_LIT(KSearchStr27, "A%7_");
sl@0
   509
	rc = KCandidate27().MatchC(KSearchStr27(), '_', '%', '7', 0);
sl@0
   510
	test(rc == 0);
sl@0
   511
	_LIT(KCandidate28, "abc7");
sl@0
   512
	_LIT(KSearchStr28, "a%7_");
sl@0
   513
	rc = KCandidate28().MatchC(KSearchStr28(), '_', '%', '7', 0);
sl@0
   514
	test(rc == KErrNotFound);
sl@0
   515
	_LIT(KCandidate29, "abc7");
sl@0
   516
	_LIT(KSearchStr29, "A%7_");
sl@0
   517
	rc = KCandidate29().MatchC(KSearchStr29(), '_', '%', '7', 0);
sl@0
   518
	test(rc == KErrNotFound);
sl@0
   519
	_LIT(KCandidate30, "ba\x308o\x308t");
sl@0
   520
	_LIT(KSearchStr30, "-b\x308-");
sl@0
   521
	rc = KCandidate30().MatchC(KSearchStr30(), '%', '-', 0, 0);
sl@0
   522
	test(rc == 0);
sl@0
   523
	rc = KCandidate30().MatchC(KSearchStr30(), '%', '-', 0, 0, &TheSwedishMethod);
sl@0
   524
	test(rc == 0);
sl@0
   525
	_LIT(KSearchStr31, "ba\x308*");
sl@0
   526
	rc = KCandidate30().MatchC(KSearchStr31(), '%', '*', 0, 0, &TheSwedishMethod);
sl@0
   527
	test(rc == 0);
sl@0
   528
	}
sl@0
   529
sl@0
   530
void DoTestCanonicalDecompositionIterator(const TDesC& aTest, const TDesC& aCanonical)
sl@0
   531
	{
sl@0
   532
	TUTF32Iterator i(aTest.Ptr(), aTest.Ptr() + aTest.Length());
sl@0
   533
	TCanonicalDecompositionIterator cci;
sl@0
   534
	cci.Set(i);
sl@0
   535
	TInt index = 0;
sl@0
   536
	while (!cci.AtEnd())
sl@0
   537
		{
sl@0
   538
		test(index != aCanonical.Length());
sl@0
   539
		TChar ch1 = aCanonical[index];
sl@0
   540
		TChar ch2 = cci.Current();
sl@0
   541
		test(ch1 == ch2);
sl@0
   542
		++index;
sl@0
   543
		cci.Next();
sl@0
   544
		}
sl@0
   545
	test(index == aCanonical.Length());
sl@0
   546
	}
sl@0
   547
sl@0
   548
// exciting combining characters include:
sl@0
   549
// U+0327 cedilla, class = 202
sl@0
   550
// U+031B horn, class = 216
sl@0
   551
// U+0316 grave below, class = 220
sl@0
   552
// U+0300 grave above, class = 230
sl@0
   553
// U+031A left angle above, class = 232
sl@0
   554
// U+0360 double tilde, class = 234
sl@0
   555
// U+0345 ypogegrameni, class = 240
sl@0
   556
sl@0
   557
_LIT(KAllOnce, "\x327\x31b\x316\x300\x31a\x360\x345xyz");
sl@0
   558
_LIT(KBackwards, "\x345\x360\x31a\x300\x316\x31b\x327xyz");
sl@0
   559
_LIT(KRandom, "\x300\x316\x31b\x327\x31a\x345\x360xyz");
sl@0
   560
_LIT(KAllOnceThenAcute, "\x327\x31b\x316\x300\x301\x31a\x360\x345");
sl@0
   561
_LIT(KBackwardsThenAcute, "\x345\x360\x31a\x300\x301\x316\x31b\x327");
sl@0
   562
_LIT(KRandomThenAcute, "\x300\x316\x31b\x327\x31a\x301\x345\x360");
sl@0
   563
_LIT(KAllSame, "\x300\x301\x302\x303\x304\x306\x307\x308\x30b\x30c\x30f");
sl@0
   564
_LIT(KLotsSameCanonical, "\x327\x31b\x316\x300\x301\x302\x303\x304\x306\x307\x308\x30b\x30c\x30f\x31a\x360\x345xyz");
sl@0
   565
_LIT(KLotsSameNotCanonical, "\x31b\x300\x345\x301\x302\x316\x303\x304\x31a\x306\x307\x327\x308\x30b\x30c\x30f\x360xyz");
sl@0
   566
sl@0
   567
/**
sl@0
   568
@SYMTestCaseID SYSLIB-UNICODE-CT-0106
sl@0
   569
@SYMTestCaseDesc TCanonicalDecompositionIterator test 
sl@0
   570
@SYMTestPriority High
sl@0
   571
@SYMTestActions  TCanonicalDecompositionIterator test
sl@0
   572
@SYMTestExpectedResults The test must not fail.
sl@0
   573
@SYMPREQ814 Optimise folded string comparisons.
sl@0
   574
*/
sl@0
   575
void TestCanonicalDecompositionIterator()
sl@0
   576
	{
sl@0
   577
	DoTestCanonicalDecompositionIterator(KAllOnce, KAllOnce);
sl@0
   578
	DoTestCanonicalDecompositionIterator(KBackwards, KAllOnce);
sl@0
   579
	DoTestCanonicalDecompositionIterator(KRandom, KAllOnce);
sl@0
   580
	DoTestCanonicalDecompositionIterator(KBackwardsThenAcute, KAllOnceThenAcute);
sl@0
   581
	DoTestCanonicalDecompositionIterator(KRandomThenAcute, KAllOnceThenAcute);
sl@0
   582
	DoTestCanonicalDecompositionIterator(KAllSame, KAllSame);
sl@0
   583
	DoTestCanonicalDecompositionIterator(KLotsSameCanonical, KLotsSameCanonical);
sl@0
   584
	DoTestCanonicalDecompositionIterator(KLotsSameNotCanonical, KLotsSameCanonical);
sl@0
   585
	}
sl@0
   586
sl@0
   587
/**
sl@0
   588
@SYMTestCaseID SYSLIB-UNICODE-CT-3337
sl@0
   589
@SYMTestCaseDesc Test latest MatchC override that has the advanced TCollationMethod flag input 
sl@0
   590
@SYMTestPriority High
sl@0
   591
@SYMTestActions Test matching of combined characters with simple character.
sl@0
   592
Note- this action only applies to certain classes of combining characters
sl@0
   593
@SYMTestExpectedResults Old MatchC character against character + combining character
sl@0
   594
will not match but new MatchC with same characters and flag set will match.
sl@0
   595
@SYMINC092513: RR S60: Variant testing: Searching does not work properly in contacts
sl@0
   596
*/
sl@0
   597
void TestDisableCombiningCharacterCheckFlag(const TDesC16 &aLeft, const TDesC16 &aRight)
sl@0
   598
	{
sl@0
   599
	//Without flag, characters combine to make new character not matched by search
sl@0
   600
	test(KErrNotFound ==aLeft.MatchC(aRight,&TheDevanagariMethod));
sl@0
   601
	//With flag, combining character check is disabled so that search is matched
sl@0
   602
	test(KErrNone     ==aLeft.MatchC(aRight,&TheDevanagariIgnoreCombiningMethod));
sl@0
   603
	}
sl@0
   604
void TestDisableCombiningCharacterCheck()
sl@0
   605
	{
sl@0
   606
	test.Next(_L("INC092513"));
sl@0
   607
	TBuf<2> search, target;
sl@0
   608
	//All Devanagari dependant vowels are in the following range
sl@0
   609
	for(TInt dependantVowel=0x93e; dependantVowel<=0x94c; dependantVowel++)
sl@0
   610
		{
sl@0
   611
		//Most of the Devanagari consonants are in the following range
sl@0
   612
		for(TInt consonant=0x915; consonant<=0x939; consonant++)
sl@0
   613
			{
sl@0
   614
			target.Format(_L("%c%c"),consonant,dependantVowel);
sl@0
   615
			search.Format(_L("%c*"),consonant);
sl@0
   616
			TestDisableCombiningCharacterCheckFlag(target, search);
sl@0
   617
			}
sl@0
   618
		}
sl@0
   619
	//Test same situation but where consonants decompose to consonant + dependant vowel
sl@0
   620
	TestDisableCombiningCharacterCheckFlag(_L("\x929"), _L("\x928*"));
sl@0
   621
	TestDisableCombiningCharacterCheckFlag(_L("\x931"), _L("\x930*"));
sl@0
   622
	TestDisableCombiningCharacterCheckFlag(_L("\x934"), _L("\x933*"));
sl@0
   623
	TestDisableCombiningCharacterCheckFlag(_L("\x958"), _L("\x915*"));
sl@0
   624
	TestDisableCombiningCharacterCheckFlag(_L("\x959"), _L("\x916*"));
sl@0
   625
	TestDisableCombiningCharacterCheckFlag(_L("\x95a"), _L("\x917*"));
sl@0
   626
	TestDisableCombiningCharacterCheckFlag(_L("\x95b"), _L("\x91c*"));
sl@0
   627
	TestDisableCombiningCharacterCheckFlag(_L("\x95c"), _L("\x921*"));
sl@0
   628
	TestDisableCombiningCharacterCheckFlag(_L("\x95d"), _L("\x922*"));
sl@0
   629
	TestDisableCombiningCharacterCheckFlag(_L("\x95e"), _L("\x92b*"));
sl@0
   630
	TestDisableCombiningCharacterCheckFlag(_L("\x95f"), _L("\x92f*"));
sl@0
   631
	}
sl@0
   632
sl@0
   633
_LIT(KHelloT, "Hello");
sl@0
   634
_LIT(KLatin1AccentsC, "\xE0\xD2p\xE2\xEB\xED\xF1\xC7");
sl@0
   635
_LIT(KLatin1AccentsD, "a\x300O\x300pa\x302\x65\x308i\x301n\x303\x43\x327");
sl@0
   636
// four alpha + psili + varia + ypogegrameni
sl@0
   637
_LIT(KGreekAccentsC, "\x1f82\x1f82\x1f82\x1f82");
sl@0
   638
// decomposed in four different ways
sl@0
   639
_LIT(KGreekAccentsS, "\x1f82\x1f02\x345\x1f00\x300\x345\x3b1\x313\x300\x345");
sl@0
   640
// completely decomposed
sl@0
   641
_LIT(KGreekAccentsD, "\x3b1\x313\x300\x345\x3b1\x313\x300\x345\x3b1\x313\x300\x345\x3b1\x313\x300\x345");
sl@0
   642
// full-width variants
sl@0
   643
_LIT(KFullWidth, "\xFF21\xFF42\xFF43");
sl@0
   644
// surrogate pair, unpaired low surrogate, unpaired high surrogate, unpaired
sl@0
   645
// high surrogate at end of string
sl@0
   646
_LIT(KSurrogates, "\xD965\xDEF0\xDF12\xDB10\xDA4E");
sl@0
   647
_LIT(KSurrogatesTest, "\xD965\xDEF0");
sl@0
   648
sl@0
   649
void TestIteratorOutput(TDecompositionIterator& aIt, const TDesC& aCheck)
sl@0
   650
	{
sl@0
   651
	TBool unpairedHighSurrogate = EFalse;
sl@0
   652
	for(TInt i = 0; i != aCheck.Length(); aIt.Next())
sl@0
   653
		{
sl@0
   654
		if (aIt.AtEnd())
sl@0
   655
			{
sl@0
   656
			test(0);
sl@0
   657
			return;
sl@0
   658
			}
sl@0
   659
		TInt c = aIt.Current();
sl@0
   660
		// test that we are not looking at an unpaired low surrogate that
sl@0
   661
		// follows an unpaired high surrogate: this is not possible.
sl@0
   662
		test((c & 0xFC00) != 0xDC00 || !unpairedHighSurrogate);
sl@0
   663
		unpairedHighSurrogate = (c & 0xFC00) == 0xD800? (TBool)ETrue : (TBool)EFalse;
sl@0
   664
		if (c < 0x10000)
sl@0
   665
			{
sl@0
   666
			test(c == aCheck[i]);
sl@0
   667
			++i;
sl@0
   668
			}
sl@0
   669
		else
sl@0
   670
			{
sl@0
   671
			TInt sp = ((aCheck[i] - 0xD7F7) << 10) + aCheck[i + 1];
sl@0
   672
			test(c == sp);
sl@0
   673
			i += 2;
sl@0
   674
			}
sl@0
   675
		}
sl@0
   676
	test(aIt.AtEnd());
sl@0
   677
	}
sl@0
   678
sl@0
   679
/**
sl@0
   680
@SYMTestCaseID SYSLIB-UNICODE-CT-0097
sl@0
   681
@SYMTestCaseDesc TUTF32Iterator functionality tested on 2 character sequences: 
sl@0
   682
	(1) single character 
sl@0
   683
	(2) surrogate pair
sl@0
   684
@SYMTestPriority High
sl@0
   685
@SYMTestActions  TUTF32Iterator test.
sl@0
   686
@SYMTestExpectedResults The test must not fail.
sl@0
   687
@SYMPREQ814 Optimise folded string comparisons.
sl@0
   688
*/
sl@0
   689
void TestUTF32Iterator()
sl@0
   690
	{
sl@0
   691
	//Single character
sl@0
   692
	const TText16 KStr[] = {0x01D5};
sl@0
   693
	::TestPrintCaption(_L("TUTF32Iterator"), KStr, ARRAY_SIZE(KStr));
sl@0
   694
	TUTF32Iterator it(KStr, KStr + ARRAY_SIZE(KStr));
sl@0
   695
	TInt itCount = 0;
sl@0
   696
	for(;!it.AtEnd();++itCount, it.Next())
sl@0
   697
		{
sl@0
   698
		TChar ch = it.Current();
sl@0
   699
		test(ch == static_cast <TUint> (KStr[0]));
sl@0
   700
		RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
   701
		}
sl@0
   702
	test(itCount == 1);
sl@0
   703
	RDebug::Print(_L("\n"));
sl@0
   704
	
sl@0
   705
	//Surrogate pair
sl@0
   706
	::TestPrintCaption(_L("TUTF32Iterator-surrogates"), KSurrogatesTest().Ptr(), KSurrogatesTest().Length());
sl@0
   707
	it = TUTF32Iterator(KSurrogatesTest().Ptr(), KSurrogatesTest().Ptr() + KSurrogatesTest().Length());
sl@0
   708
	for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   709
		{
sl@0
   710
		TChar ch = it.Current();
sl@0
   711
		test(ch == 0x696F0);
sl@0
   712
		RDebug::Print(_L("%06X "), (TUint)ch);
sl@0
   713
		}
sl@0
   714
	test(itCount == 1);
sl@0
   715
	RDebug::Print(_L("\n"));
sl@0
   716
sl@0
   717
	//	surrogate 0x10000
sl@0
   718
	_LIT( KSurrogatesTest2, "\xd800\xdc00" );
sl@0
   719
	::TestPrintCaption(_L("TUTF32Iterator-surrogates2"), KSurrogatesTest2().Ptr(), KSurrogatesTest2().Length());
sl@0
   720
	it = TUTF32Iterator(KSurrogatesTest2().Ptr(), KSurrogatesTest2().Ptr() + KSurrogatesTest2().Length());
sl@0
   721
	for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   722
		{
sl@0
   723
		TChar ch = it.Current();
sl@0
   724
		test(ch == 0x10000);
sl@0
   725
		RDebug::Print(_L("%06X "), (TUint)ch);
sl@0
   726
		}
sl@0
   727
	test(itCount == 1);
sl@0
   728
	RDebug::Print(_L("\n"));
sl@0
   729
	
sl@0
   730
	//	surrogate 0x20000
sl@0
   731
	_LIT( KSurrogatesTest3, "\xd840\xdc00" );
sl@0
   732
	::TestPrintCaption(_L("TUTF32Iterator-surrogates3"), KSurrogatesTest3().Ptr(), KSurrogatesTest3().Length());
sl@0
   733
	it = TUTF32Iterator(KSurrogatesTest3().Ptr(), KSurrogatesTest3().Ptr() + KSurrogatesTest3().Length());
sl@0
   734
	for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   735
		{
sl@0
   736
		TChar ch = it.Current();
sl@0
   737
		test(ch == 0x20000);
sl@0
   738
		RDebug::Print(_L("%06X "), (TUint)ch);
sl@0
   739
		}
sl@0
   740
	test(itCount == 1);
sl@0
   741
	RDebug::Print(_L("\n"));
sl@0
   742
	
sl@0
   743
	//	surrogate 0x2ffff
sl@0
   744
	_LIT( KSurrogatesTest4, "\xD87F\xDFFF" );
sl@0
   745
	::TestPrintCaption(_L("TUTF32Iterator-surrogates4"), KSurrogatesTest4().Ptr(), KSurrogatesTest4().Length());
sl@0
   746
	it = TUTF32Iterator(KSurrogatesTest4().Ptr(), KSurrogatesTest4().Ptr() + KSurrogatesTest4().Length());
sl@0
   747
	for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   748
		{
sl@0
   749
		TChar ch = it.Current();
sl@0
   750
		test(ch == 0x2ffff);
sl@0
   751
		RDebug::Print(_L("%06X "), (TUint)ch);
sl@0
   752
		}
sl@0
   753
	//test(itCount == 1);
sl@0
   754
	RDebug::Print(_L("\n"));
sl@0
   755
sl@0
   756
	//	surrogate 0xd800
sl@0
   757
	_LIT( KSurrogatesTest5, "\xD800" );
sl@0
   758
	::TestPrintCaption(_L("TUTF32Iterator-surrogates5"), KSurrogatesTest5().Ptr(), KSurrogatesTest5().Length());
sl@0
   759
	it = TUTF32Iterator(KSurrogatesTest5().Ptr(), KSurrogatesTest5().Ptr() + KSurrogatesTest5().Length());
sl@0
   760
	for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   761
		{
sl@0
   762
		TChar ch = it.Current();
sl@0
   763
		RDebug::Print(_L("%06X "), (TUint)ch);
sl@0
   764
		}
sl@0
   765
	test(itCount == 0);
sl@0
   766
	RDebug::Print(_L("\n"));	
sl@0
   767
sl@0
   768
	//	surrogate 0xdc00
sl@0
   769
	_LIT( KSurrogatesTest6, "\xDc00" );
sl@0
   770
	::TestPrintCaption(_L("TUTF32Iterator-surrogates6"), KSurrogatesTest6().Ptr(), KSurrogatesTest6().Length());
sl@0
   771
	it = TUTF32Iterator(KSurrogatesTest6().Ptr(), KSurrogatesTest6().Ptr() + KSurrogatesTest6().Length());
sl@0
   772
	for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   773
		{
sl@0
   774
		TChar ch = it.Current();
sl@0
   775
		RDebug::Print(_L("%06X "), (TUint)ch);
sl@0
   776
		}
sl@0
   777
	test(itCount == 0);
sl@0
   778
	RDebug::Print(_L("\n"));	
sl@0
   779
	
sl@0
   780
	//	surrogate 0xdfff
sl@0
   781
	_LIT( KSurrogatesTest7, "\xDfff" );
sl@0
   782
	::TestPrintCaption(_L("TUTF32Iterator-surrogates7"), KSurrogatesTest7().Ptr(), KSurrogatesTest7().Length());
sl@0
   783
	it = TUTF32Iterator(KSurrogatesTest7().Ptr(), KSurrogatesTest7().Ptr() + KSurrogatesTest7().Length());
sl@0
   784
	for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   785
		{
sl@0
   786
		TChar ch = it.Current();
sl@0
   787
		RDebug::Print(_L("%06X "), (TUint)ch);
sl@0
   788
		}
sl@0
   789
	test(itCount == 0);
sl@0
   790
	RDebug::Print(_L("\n"));	
sl@0
   791
	}
sl@0
   792
sl@0
   793
/**
sl@0
   794
@SYMTestCaseID SYSLIB-UNICODE-CT-0098
sl@0
   795
@SYMTestCaseDesc TFoldedDecompIterator functionality tested on 2 character sequences.
sl@0
   796
@SYMTestPriority High
sl@0
   797
@SYMTestActions  TFoldedDecompIterator test.
sl@0
   798
@SYMTestExpectedResults The test must not fail.
sl@0
   799
@SYMPREQ814 Optimise folded string comparisons.
sl@0
   800
*/
sl@0
   801
void TestFoldedDecompIterator()
sl@0
   802
    {
sl@0
   803
    //Character sequence 1:
sl@0
   804
    //(1) DEVANAGARI LETTER FA - 0x095E
sl@0
   805
    //(2) LATIN CAPITAL LETTER U WITH DIAERESIS AND MACRON - 0x01D5
sl@0
   806
    //Decompositions:
sl@0
   807
    //(1) 0x095E decomposed to: 0x092B 0x093C
sl@0
   808
    //(2) 0x01D5 decomposed to: 0x00DC 0x0304
sl@0
   809
    //    0x00DC decomposed to: 0x0055 0x0308
sl@0
   810
    //    0x0055 decomposed to: 0x0075
sl@0
   811
    const TText16 KStr[] = {0x095E, 0x01D5};
sl@0
   812
    const TText16 KStrOut[] = {0x092B, 0x093C, 0x0075, 0x0308, 0x0304};
sl@0
   813
    ::TestPrintCaption(_L("TFoldedDecompIterator-1"), KStr, ARRAY_SIZE(KStr));
sl@0
   814
    TUTF32Iterator itSrc(KStr, KStr + ARRAY_SIZE(KStr));
sl@0
   815
    TFoldedDecompIterator it(itSrc);
sl@0
   816
    TInt itCount = 0;
sl@0
   817
    for(;!it.AtEnd();++itCount, it.Next())
sl@0
   818
        {
sl@0
   819
        if(!it.IsInFoldedSequence())
sl@0
   820
            {
sl@0
   821
            it.EnterFoldedSequence();
sl@0
   822
            }
sl@0
   823
        TChar ch = it.Current();
sl@0
   824
        test(ch == static_cast <TUint> (KStrOut[itCount]));
sl@0
   825
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
   826
        }
sl@0
   827
    test(itCount == ARRAY_SIZE(KStrOut));
sl@0
   828
    RDebug::Print(_L("\n"));
sl@0
   829
    
sl@0
   830
    //Character sequence 2:
sl@0
   831
    //(1) GREEK CAPITAL LETTER BETA - 0x0392
sl@0
   832
    //(2) COMBINING GRAVE ACCENT - 0x0300
sl@0
   833
    //(3) COMBINING GRAVE ACCENT BELOW - 0x0316
sl@0
   834
    //(4) GREEK CAPITAL LETTER GAMMA - 0x0393
sl@0
   835
    //(5) HEBREW POINT TSERE - 0x05B5
sl@0
   836
    //(6) TIBETAN MARK HALANTA - 0x0F84
sl@0
   837
    //Decompositions:
sl@0
   838
    //(1) 0x0392 decomposed to: 0x03B2
sl@0
   839
    //(2) 0x0300 decomposed to: 0x0300
sl@0
   840
    //(3) 0x0316 decomposed to: 0x0316
sl@0
   841
    //(4) 0x0393 decomposed to: 0x03B3
sl@0
   842
    //(5) 0x05B5 decomposed to: 0x05B5
sl@0
   843
    //(6) 0x0F84 decomposed to: 0x0F84
sl@0
   844
    const TText16 KStr2[] = {0x0392, 0x0300, 0x0316, 0x0393, 0x05B5, 0x0F84};
sl@0
   845
    const TText16 KStrOut2[] = {0x03B2, 0x0300, 0x0316, 0x03B3, 0x05B5, 0x0F84};
sl@0
   846
    ::TestPrintCaption(_L("TFoldedDecompIterator-2"), KStr2, ARRAY_SIZE(KStr2));
sl@0
   847
    itSrc = TUTF32Iterator(KStr2, KStr2 + ARRAY_SIZE(KStr2));
sl@0
   848
    it = TFoldedDecompIterator(itSrc);
sl@0
   849
    for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   850
        {
sl@0
   851
        if(!it.IsInFoldedSequence())
sl@0
   852
            {
sl@0
   853
            it.EnterFoldedSequence();
sl@0
   854
            }
sl@0
   855
        TChar ch = it.Current();
sl@0
   856
        test(ch == static_cast <TUint> (KStrOut2[itCount]));
sl@0
   857
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
   858
        }
sl@0
   859
    test(itCount == ARRAY_SIZE(KStrOut2));
sl@0
   860
    RDebug::Print(_L("\n"));
sl@0
   861
    
sl@0
   862
    //Character sequence 3:
sl@0
   863
    //(1) MUSICAL SYMBOL EIGHTH NOTE - 0x1D161 (D834, DD61)
sl@0
   864
    //Decompositions:
sl@0
   865
    //(1) 0x1D161 decomposed to: 0x1D15F 0x1D16F
sl@0
   866
    //    0x1D15F decomposed to: 0x1D158 0x1D165
sl@0
   867
    const TText16 KStr3[] = {0xD834, 0xDD61};
sl@0
   868
    const TUint32 KStrOut3[] = {0x1D158, 0x1D165, 0x1D16F};
sl@0
   869
    ::TestPrintCaption(_L("TFoldedDecompIterator-3"), KStr3, ARRAY_SIZE(KStr3));
sl@0
   870
    itSrc = TUTF32Iterator(KStr3, KStr3 + ARRAY_SIZE(KStr3));
sl@0
   871
    it = TFoldedDecompIterator(itSrc);
sl@0
   872
    for(itCount=0;!it.AtEnd();++itCount, it.Next())
sl@0
   873
        {
sl@0
   874
        if(!it.IsInFoldedSequence())
sl@0
   875
            {
sl@0
   876
            it.EnterFoldedSequence();
sl@0
   877
            }
sl@0
   878
        TChar ch = it.Current();
sl@0
   879
        test(ch == static_cast <TUint> (KStrOut3[itCount]));
sl@0
   880
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
   881
        }
sl@0
   882
    test(itCount == ARRAY_SIZE(KStrOut3));
sl@0
   883
    RDebug::Print(_L("\n"));
sl@0
   884
    }
sl@0
   885
sl@0
   886
/**
sl@0
   887
@SYMTestCaseID SYSLIB-UNICODE-CT-0099
sl@0
   888
@SYMTestCaseDesc TFoldedSortedDecompIterator functionality tested on 1 character sequence.
sl@0
   889
@SYMTestPriority High
sl@0
   890
@SYMTestActions  TFoldedSortedDecompIterator test.
sl@0
   891
@SYMTestExpectedResults The test must not fail.
sl@0
   892
@SYMPREQ814 Optimise folded string comparisons.
sl@0
   893
*/
sl@0
   894
void TestFoldedSortedDecompIterator()
sl@0
   895
    {
sl@0
   896
    //Character sequence 1:
sl@0
   897
    //(1) GREEK CAPITAL LETTER BETA - 0x0392	(fold: 0x3B2, ccc=0)
sl@0
   898
    //(2) COMBINING GRAVE ACCENT - 0x0300		(no fold, ccc=230)
sl@0
   899
    //(3) COMBINING GRAVE ACCENT BELOW - 0x0316	(no fold, ccc=220)
sl@0
   900
    //(4) GREEK CAPITAL LETTER GAMMA - 0x0393	(fold: 0x3B3, ccc=0)
sl@0
   901
    //(5) HEBREW POINT TSERE - 0x05B5			(no fold, ccc=15)
sl@0
   902
    //(6) 0x10A39								(no fold, ccc=1)
sl@0
   903
    //(7) TIBETAN MARK HALANTA - 0x0F84			(no fold, ccc=9)
sl@0
   904
    //(8) 0x10400								(fold: 0x10428, ccc=0)
sl@0
   905
    //(9) 0x10A38								(no fold, ccc=230)
sl@0
   906
    //(10) 0xFB1E								(no fold, ccc=26)
sl@0
   907
    //Decompositions:
sl@0
   908
    //0x03B2 Class 0
sl@0
   909
    //0x0316 Class 220
sl@0
   910
    //0x0300 Class 230
sl@0
   911
    //0x03B3 Class 0
sl@0
   912
    //0x10A39 Class 1
sl@0
   913
    //0x0F84 Class 9
sl@0
   914
    //0x05B5 Class 15
sl@0
   915
    //0x10428 Class 0
sl@0
   916
    //0xFB1E Class 26
sl@0
   917
    //0x10A38 Class 230
sl@0
   918
    //const TText16 KStr[] = {0x0392, 0x0300, 0x0316, 0x0393, 0x05B5, 0x0F84};
sl@0
   919
    //const TText16 KStrOut[] = {0x03B2, 0x0316, 0x0300, 0x03B3, 0x0F84, 0x05B5};
sl@0
   920
    //const TInt KClass[] = {0, 220, 230, 0, 9, 15};
sl@0
   921
    const TText16 KStr[] = {0x0392, 0x0300, 0x0316, 0x0393, 0x05B5, 0xD802, 0xDE39, 0x0F84, 0xD801, 0xDC00, 0xD802, 0xDE38, 0xFB1E};
sl@0
   922
    const TUint32 KStrOut[] = {0x03B2, 0x0316, 0x0300, 0x03B3, 0x10A39, 0x0F84, 0x05B5, 0x10428, 0xFB1E, 0x10A38};
sl@0
   923
    const TInt KClass[] = {0, 220, 230, 0, 1, 9, 15, 0, 26, 230};
sl@0
   924
    ::TestPrintCaption(_L("TFoldedSortedDecompIterator"), KStr, ARRAY_SIZE(KStr));
sl@0
   925
    RDebug::Print(_L("\n"));
sl@0
   926
    TUTF32Iterator itSrc(KStr, KStr + ARRAY_SIZE(KStr));
sl@0
   927
    TFoldedDecompIterator itDecomp(itSrc);
sl@0
   928
    TInt itCount = 0;
sl@0
   929
    while(!itDecomp.AtEnd())
sl@0
   930
        {
sl@0
   931
        if(!itDecomp.IsInFoldedSequence())
sl@0
   932
            {
sl@0
   933
            itDecomp.EnterFoldedSequence();
sl@0
   934
            }
sl@0
   935
        if(itDecomp.Current().GetCombiningClass() == 0)
sl@0
   936
            {
sl@0
   937
            TChar ch = itDecomp.Current();
sl@0
   938
            TInt clss = itDecomp.Current().GetCombiningClass();
sl@0
   939
            RDebug::Print(_L("BaseCh %04X Class %d\n"), (TUint)ch, clss);
sl@0
   940
            test(ch == static_cast <TUint> (KStrOut[itCount]));
sl@0
   941
            test(clss == KClass[itCount]);
sl@0
   942
            itDecomp.Next();
sl@0
   943
            ++itCount;
sl@0
   944
            }
sl@0
   945
        else
sl@0
   946
            {
sl@0
   947
            TFoldedSortedDecompIterator it;
sl@0
   948
            it.Set(itDecomp);
sl@0
   949
            while(!it.AtEnd())
sl@0
   950
                {
sl@0
   951
                TChar ch = it.Current();
sl@0
   952
                TInt clss = it.Current().GetCombiningClass();
sl@0
   953
                RDebug::Print(_L("CombCh %08X Class %d\n"), (TUint)ch, clss);
sl@0
   954
                test(ch == static_cast <TUint> (KStrOut[itCount]));
sl@0
   955
                test(clss == KClass[itCount]);
sl@0
   956
                it.Next();
sl@0
   957
                ++itCount;
sl@0
   958
                }
sl@0
   959
            }
sl@0
   960
        }
sl@0
   961
    test(itCount == ARRAY_SIZE(KStrOut));
sl@0
   962
    }
sl@0
   963
sl@0
   964
/**
sl@0
   965
@SYMTestCaseID SYSLIB-UNICODE-CT-0100
sl@0
   966
@SYMTestCaseDesc TFoldedCanonicalIterator functionality tested on 1 character sequence.
sl@0
   967
@SYMTestPriority High
sl@0
   968
@SYMTestActions  TFoldedCanonicalIterator test.
sl@0
   969
@SYMTestExpectedResults The test must not fail.
sl@0
   970
@SYMPREQ814 Optimise folded string comparisons.
sl@0
   971
*/
sl@0
   972
void TestFoldedCanonicalIterator()
sl@0
   973
    {
sl@0
   974
    //Character sequence 1:
sl@0
   975
    //(1) GREEK CAPITAL LETTER BETA - 0x0392
sl@0
   976
    //(2) COMBINING GRAVE ACCENT - 0x0300
sl@0
   977
    //(3) COMBINING GRAVE ACCENT BELOW - 0x0316
sl@0
   978
    //(4) GREEK CAPITAL LETTER GAMMA - 0x0393
sl@0
   979
    //(5) HEBREW POINT TSERE - 0x05B5
sl@0
   980
    //(6) TIBETAN MARK HALANTA - 0x0F84
sl@0
   981
    //(7) MUSICAL SYMBOL EIGHTH NOTE - 0x1D161 (D834, DD61)
sl@0
   982
    //(8) LATIN CAPITAL LETTER U WITH DIAERESIS AND MACRON - 0x01D5
sl@0
   983
    //Decompositions:
sl@0
   984
    //0x0392 to 0x03B2 
sl@0
   985
    //0x0316 to 0x0316 
sl@0
   986
    //0x0300 to 0x0300
sl@0
   987
    //0x0393 to 0x03B3
sl@0
   988
    //0x0F84 to 0x0F84
sl@0
   989
    //0x05B5 to 0x05B5
sl@0
   990
    //0x1D161 to 0x1D158 0x1D165 0x1D16F
sl@0
   991
    //0x01D5 to 0x0075 0x0308 0x0304
sl@0
   992
    const TText16 KStr[] = {0x0392, 0x0300, 0x0316, 0x0393, 0x05B5, 0x0F84, 0xD834, 0xDD61, 0x01D5};
sl@0
   993
    const TUint32 KStrOut[] = {0x03B2, 0x0316, 0x0300, 0x03B3, 0x0F84, 0x05B5, 0x1D158, 0x1D165, 0x1D16F, 0x0075, 0x0308, 0x0304};
sl@0
   994
    TestPrintCaption(_L("TFoldedCanonicalIterator"), KStr, ARRAY_SIZE(KStr));
sl@0
   995
    TUTF32Iterator itSrc(KStr, KStr + ARRAY_SIZE(KStr));
sl@0
   996
	TFoldedCanonicalIterator it(itSrc);
sl@0
   997
    TInt itCount = 0;
sl@0
   998
sl@0
   999
	const TUnicodeDataSet* charDataSet = GetLocaleCharSet()->iCharDataSet;
sl@0
  1000
sl@0
  1001
    for(;!it.AtEnd();++itCount, it.Next(charDataSet))
sl@0
  1002
        {
sl@0
  1003
        TChar ch = it.Current();
sl@0
  1004
        test(ch == static_cast <TUint> (KStrOut[itCount]));
sl@0
  1005
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
  1006
        }
sl@0
  1007
    test(itCount == ARRAY_SIZE(KStrOut));
sl@0
  1008
    RDebug::Print(_L("\n"));
sl@0
  1009
    
sl@0
  1010
    //10400
sl@0
  1011
    //103ff
sl@0
  1012
    }
sl@0
  1013
sl@0
  1014
/**
sl@0
  1015
@SYMTestCaseID SYSLIB-UNICODE-CT-0101
sl@0
  1016
@SYMTestCaseDesc TDecompositionIterator functionality tested on 1 character sequence
sl@0
  1017
@SYMTestPriority High
sl@0
  1018
@SYMTestActions  TDecompositionIterator test.
sl@0
  1019
@SYMTestExpectedResults The test must not fail.
sl@0
  1020
@SYMPREQ814 Optimise folded string comparisons.
sl@0
  1021
*/
sl@0
  1022
void TestDecompositionIterator2()
sl@0
  1023
    {
sl@0
  1024
    //Character sequence 1
sl@0
  1025
    //LATIN CAPITAL LETTER U WITH DIAERESIS AND MACRON - 0x01D5
sl@0
  1026
    //Decomposition:
sl@0
  1027
    //0x01D5 to: 0x0055 0x0308 0x0304 
sl@0
  1028
    const TText16 KStr[] = {0x01D5};
sl@0
  1029
    const TText16 KStrOut[] = {0x0055, 0x0308, 0x0304};
sl@0
  1030
    TestPrintCaption(_L("TDecompositionIterator"), KStr, ARRAY_SIZE(KStr));
sl@0
  1031
    TUTF32Iterator itSrc(KStr, KStr + ARRAY_SIZE(KStr));
sl@0
  1032
    TDecompositionIterator it;
sl@0
  1033
    it.Set(itSrc);
sl@0
  1034
    TInt itCount = 0;
sl@0
  1035
    for(;!it.AtEnd(); ++itCount, it.Next())
sl@0
  1036
        {
sl@0
  1037
        TChar ch = it.Current();
sl@0
  1038
        test(ch == static_cast <TUint> (KStrOut[itCount]));
sl@0
  1039
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
  1040
        }
sl@0
  1041
    test(itCount == ARRAY_SIZE(KStrOut));
sl@0
  1042
    RDebug::Print(_L("\n"));
sl@0
  1043
sl@0
  1044
    // Character sequence 2
sl@0
  1045
    // MUSICAL SYMBOL THIRTY-SECOND NOTE - 0x1D162 (D834, DD62)
sl@0
  1046
    // Decomposition:
sl@0
  1047
    // 0x1D162 to: 0x1D15F 0x1D170, then to: 0x1D158 0x1D165 0x1D170
sl@0
  1048
    const TText16 KStr2[] = {0xD834, 0xDD62};
sl@0
  1049
    const TUint32 KStrOut2[] = {0x1D158, 0x1D165, 0x1D170};
sl@0
  1050
    TestPrintCaption(_L("TDecompositionIterator"), KStr2, ARRAY_SIZE(KStr2));
sl@0
  1051
    TUTF32Iterator itSrc2(KStr2, KStr2 + ARRAY_SIZE(KStr2));
sl@0
  1052
    TDecompositionIterator it2;
sl@0
  1053
    it2.Set(itSrc2);
sl@0
  1054
    TInt itCount2 = 0;
sl@0
  1055
    for(;!it2.AtEnd(); ++itCount2, it2.Next())
sl@0
  1056
        {
sl@0
  1057
        TChar ch = it2.Current();
sl@0
  1058
        //test.Printf(_L("    expect = %08X, result = %08X\n"), KStrOut2[itCount2], ch);
sl@0
  1059
        test(ch == KStrOut2[itCount2]);
sl@0
  1060
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
  1061
        }
sl@0
  1062
    test(itCount2 == ARRAY_SIZE(KStrOut2));
sl@0
  1063
    RDebug::Print(_L("\n"));
sl@0
  1064
    }
sl@0
  1065
sl@0
  1066
/**
sl@0
  1067
@SYMTestCaseID SYSLIB-UNICODE-CT-0102
sl@0
  1068
@SYMTestCaseDesc TCanonicalDecompositionIterator functionality tested on 1 character sequence
sl@0
  1069
@SYMTestPriority High
sl@0
  1070
@SYMTestActions  TCanonicalDecompositionIterator test.
sl@0
  1071
@SYMTestExpectedResults The test must not fail.
sl@0
  1072
@SYMPREQ814 Optimise folded string comparisons.
sl@0
  1073
*/
sl@0
  1074
void TestCanonicalDecompositionIterator2()
sl@0
  1075
    {
sl@0
  1076
    //Character sequence 1
sl@0
  1077
    //(1) LATIN CAPITAL LETTER U WITH DIAERESIS AND MACRON - 0x01D5
sl@0
  1078
    //(2) MUSICAL SYMBOL THIRTY-SECOND NOTE - 0x1D162 (D834, DD62)
sl@0
  1079
    //Decomposition:
sl@0
  1080
    //0x01D5 to: 0x0055 0x0308 0x0304
sl@0
  1081
    //0x1D162 to: 0x1D15F 0x1D170, then to: 0x1D158 0x1D165 0x1D170
sl@0
  1082
    const TText16 KStr[] = {0x01D5, 0xD834, 0xDD62};
sl@0
  1083
    const TUint32 KStrOut[] = {0x0055, 0x0308, 0x0304, 0x1D158, 0x1D165, 0x1D170};
sl@0
  1084
    TestPrintCaption(_L("TCanonicalDecompositionIterator"), KStr, ARRAY_SIZE(KStr));
sl@0
  1085
    TUTF32Iterator itSrc(KStr, KStr + ARRAY_SIZE(KStr));
sl@0
  1086
    TCanonicalDecompositionIterator it;
sl@0
  1087
    it.Set(itSrc);
sl@0
  1088
    TInt itCount = 0;
sl@0
  1089
    for(;!it.AtEnd();++itCount, it.Next())
sl@0
  1090
        {
sl@0
  1091
        TChar ch = it.Current();
sl@0
  1092
        test(ch == static_cast <TUint> (KStrOut[itCount]));
sl@0
  1093
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
  1094
        }
sl@0
  1095
    test(itCount == ARRAY_SIZE(KStrOut));
sl@0
  1096
    RDebug::Print(_L("\n"));
sl@0
  1097
    }
sl@0
  1098
sl@0
  1099
/**
sl@0
  1100
@SYMTestCaseID SYSLIB-UNICODE-CT-0103
sl@0
  1101
@SYMTestCaseDesc TCanonicalDecompositionIteratorCached functionality tested on 1 character sequence
sl@0
  1102
@SYMTestPriority High
sl@0
  1103
@SYMTestActions  TCanonicalDecompositionIteratorCached test.
sl@0
  1104
@SYMTestExpectedResults The test must not fail.
sl@0
  1105
@SYMPREQ814 Optimise folded string comparisons.
sl@0
  1106
*/
sl@0
  1107
void TestCanonicalDecompositionIteratorCached()
sl@0
  1108
    {
sl@0
  1109
    //Character sequence 1
sl@0
  1110
    //(1) LATIN CAPITAL LETTER U WITH DIAERESIS AND MACRON - 0x01D5
sl@0
  1111
    //(2) MUSICAL SYMBOL THIRTY-SECOND NOTE - 0x1D162 (D834, DD62)
sl@0
  1112
    //Decomposition:
sl@0
  1113
    //0x01D5 to: 0x0055 0x0308 0x0304
sl@0
  1114
    //0x1D162 to: 0x1D15F 0x1D170, then to: 0x1D158 0x1D165 0x1D170
sl@0
  1115
    const TText16 KStr[] = {0x01D5, 0xD834, 0xDD62};
sl@0
  1116
    const TUint32 KStrOut[] = {0x0055, 0x0308, 0x0304, 0x1D158, 0x1D165, 0x1D170};
sl@0
  1117
    TestPrintCaption(_L("TCanonicalDecompositionIteratorCached"), KStr, ARRAY_SIZE(KStr));
sl@0
  1118
    TUTF32Iterator itSrc(KStr, KStr + ARRAY_SIZE(KStr));
sl@0
  1119
    TCanonicalDecompositionIteratorCached it;
sl@0
  1120
    it.Set(itSrc);
sl@0
  1121
    TInt itCount = 0;
sl@0
  1122
    for(;!it.AtEnd();++itCount, it.Next(1))
sl@0
  1123
        {
sl@0
  1124
        TChar ch = it.Get(0);
sl@0
  1125
        test(ch == static_cast <TUint> (KStrOut[itCount]));
sl@0
  1126
        RDebug::Print(_L("%04X "), (TUint)ch);
sl@0
  1127
        }
sl@0
  1128
    test(itCount == ARRAY_SIZE(KStrOut));
sl@0
  1129
    RDebug::Print(_L("\n"));
sl@0
  1130
    }
sl@0
  1131
sl@0
  1132
/**
sl@0
  1133
@SYMTestCaseID SYSLIB-UNICODE-CT-0104
sl@0
  1134
@SYMTestCaseDesc TDecompositionIterator test
sl@0
  1135
@SYMTestPriority High
sl@0
  1136
@SYMTestActions  TDecompositionIterator test.
sl@0
  1137
@SYMTestExpectedResults The test must not fail.
sl@0
  1138
@SYMPREQ814 Optimise folded string comparisons.
sl@0
  1139
*/
sl@0
  1140
void TestDecompositionIterator()
sl@0
  1141
	{
sl@0
  1142
    TDecompositionIterator i;
sl@0
  1143
sl@0
  1144
	// test basic character handling
sl@0
  1145
	TUTF32Iterator i1(KHelloT().Ptr(), KHelloT().Ptr() + KHelloT().Length());
sl@0
  1146
    i.Set(i1);
sl@0
  1147
	TestIteratorOutput(i, KHelloT);
sl@0
  1148
sl@0
  1149
	TUTF32Iterator i2(KHelloT().Ptr() + 3, KHelloT().Ptr() + KHelloT().Length());
sl@0
  1150
    i.Set(i2);
sl@0
  1151
	TestIteratorOutput(i, KHelloT().Mid(3));
sl@0
  1152
sl@0
  1153
	// test combining characters
sl@0
  1154
	TUTF32Iterator i3(KLatin1AccentsC().Ptr(), KLatin1AccentsC().Ptr() + KLatin1AccentsC().Length());
sl@0
  1155
    i.Set(i3);
sl@0
  1156
	TestIteratorOutput(i, KLatin1AccentsD);
sl@0
  1157
sl@0
  1158
	TUTF32Iterator i4(KGreekAccentsC().Ptr(), KGreekAccentsC().Ptr() + KGreekAccentsC().Length());
sl@0
  1159
    i.Set(i4);
sl@0
  1160
	TestIteratorOutput(i, KGreekAccentsD);
sl@0
  1161
sl@0
  1162
	TUTF32Iterator i5(KGreekAccentsS().Ptr(), KGreekAccentsS().Ptr() + KGreekAccentsS().Length());
sl@0
  1163
    i.Set(i5);
sl@0
  1164
	TestIteratorOutput(i, KGreekAccentsD);
sl@0
  1165
sl@0
  1166
	// test that full-width variants are not fiddled with
sl@0
  1167
	TUTF32Iterator i6(KFullWidth().Ptr(), KFullWidth().Ptr() + KFullWidth().Length());
sl@0
  1168
    i.Set(i6);
sl@0
  1169
	TestIteratorOutput(i, KFullWidth);
sl@0
  1170
sl@0
  1171
	TUTF32Iterator i7(KSurrogates().Ptr(), KSurrogates().Ptr() + KSurrogates().Length());
sl@0
  1172
    i.Set(i7);
sl@0
  1173
	TestIteratorOutput(i, KSurrogatesTest);
sl@0
  1174
	}
sl@0
  1175
sl@0
  1176
//The function collects collation keys at the specified level aLevel from aIt iterator 
sl@0
  1177
//and stores them in aBuf output parameter.
sl@0
  1178
//aExpectedNumKeys value specifies the count of expected collation keys.
sl@0
  1179
void GetKeys(TCollationValueIterator& aIt, TUint32* aBuf, TInt aLevel, TInt aExpectedNumKeys)
sl@0
  1180
	{
sl@0
  1181
	//Zero the output parameter
sl@0
  1182
	Mem::FillZ(aBuf, sizeof(TUint32) * aExpectedNumKeys);
sl@0
  1183
	//Get the keys
sl@0
  1184
	TInt i = 0;
sl@0
  1185
	for(;i!=aExpectedNumKeys;++i)
sl@0
  1186
		{
sl@0
  1187
		for (;;)
sl@0
  1188
			{
sl@0
  1189
			(void)aIt.GetCurrentKey(aLevel, aBuf[i]);
sl@0
  1190
			test(aIt.Increment());
sl@0
  1191
			if(aBuf[i] != 0)
sl@0
  1192
				{
sl@0
  1193
				break;
sl@0
  1194
				}
sl@0
  1195
			}
sl@0
  1196
		}
sl@0
  1197
	//The rest of the keys at that level should have 0 value.
sl@0
  1198
	for(;aIt.Increment();)
sl@0
  1199
		{
sl@0
  1200
		TUint32 key = 0;
sl@0
  1201
		(void)aIt.GetCurrentKey(aLevel, key);
sl@0
  1202
		test(key == 0);
sl@0
  1203
		}
sl@0
  1204
	}
sl@0
  1205
sl@0
  1206
//The function collects the raw keys from aIt iterator and stores them in aBuf output parameter.
sl@0
  1207
//aExpectedNumKeys value specifies the count of expected raw collation keys.
sl@0
  1208
void GetRawKeys(TCollationValueIterator& aIt, TCollationKey* aBuf, TInt aExpectedNumKeys)
sl@0
  1209
	{
sl@0
  1210
	//Zero the output parameter
sl@0
  1211
	Mem::FillZ(aBuf, sizeof(TCollationKey) * aExpectedNumKeys);
sl@0
  1212
	//Get the keys
sl@0
  1213
	for(TInt i=0;i!=aExpectedNumKeys;++i)
sl@0
  1214
		{
sl@0
  1215
		test(aIt.GetCurrentKey(aBuf[i]));
sl@0
  1216
		aIt.Increment();
sl@0
  1217
		}
sl@0
  1218
	//One additional GetCurrentKey() call. Because there shouldn't be more raw keys than  
sl@0
  1219
	//aExpectedNumKeys, the call should fail returning EFalse.
sl@0
  1220
	TCollationKey dummy;
sl@0
  1221
	test(!aIt.GetCurrentKey(dummy));
sl@0
  1222
	}
sl@0
  1223
sl@0
  1224
//The function gets a sequence of raw collation keys in aBuf parameter and a character number
sl@0
  1225
//aCharNo in the original string.
sl@0
  1226
//It returns the position in aBuf where raw collation key sequence for aCharNo starts.
sl@0
  1227
TInt CharNo2CollKeyPos(const TCollationKey* aBuf, TInt aBufLen, TInt aCharNo)
sl@0
  1228
    {
sl@0
  1229
    TInt starterCnt = 0;
sl@0
  1230
    TInt pos = 0;
sl@0
  1231
    do
sl@0
  1232
        {
sl@0
  1233
        if(aBuf[pos].IsStarter())
sl@0
  1234
            {
sl@0
  1235
            ++starterCnt;
sl@0
  1236
            }
sl@0
  1237
        } while(starterCnt!=(aCharNo+1) && ++pos!=aBufLen);
sl@0
  1238
    test(pos != aBufLen);
sl@0
  1239
    return pos;
sl@0
  1240
    }
sl@0
  1241
sl@0
  1242
//The function compares aBuf1 and aBuf2 and returns how many elements in aBuf1 differ
sl@0
  1243
//from the elements in aBuf2 at the same position.
sl@0
  1244
TInt CountDiscrepancies(TUint32* aBuf1, TUint32* aBuf2, TInt aCount)
sl@0
  1245
	{
sl@0
  1246
	TInt discrepancies = 0;
sl@0
  1247
	for (; aCount; --aCount)
sl@0
  1248
		{
sl@0
  1249
		if (*aBuf1++ != *aBuf2++)
sl@0
  1250
			++discrepancies;
sl@0
  1251
		}
sl@0
  1252
	return discrepancies;
sl@0
  1253
	}
sl@0
  1254
sl@0
  1255
TInt CountDiscrepancies(TCollationKey* aBuf1, TCollationKey* aBuf2, TInt aCount)
sl@0
  1256
	{
sl@0
  1257
	TInt discrepancies = 0;
sl@0
  1258
	for (; aCount; --aCount)
sl@0
  1259
		{
sl@0
  1260
		if (aBuf1->iHigh != aBuf2->iHigh || aBuf1->iLow != aBuf2->iLow)
sl@0
  1261
			++discrepancies;
sl@0
  1262
		++aBuf1;
sl@0
  1263
		++aBuf2;
sl@0
  1264
		}
sl@0
  1265
	return discrepancies;
sl@0
  1266
	}
sl@0
  1267
sl@0
  1268
_LIT(KAYZAccentsAbove, "\xE0\x301y\x302z\x303\x304");
sl@0
  1269
_LIT(KCapitalAYZAccentsAbove, "A\x300\x301Y\x302Z\x303\x304");
sl@0
  1270
_LIT(KCapitalYAYZAccentsAbove, "a\x300\x301Y\x302z\x303\x304");
sl@0
  1271
_LIT(KABCRuleTest, "abcwabkakb");
sl@0
  1272
_LIT(KABCRuleExpected, "eeabkakb");
sl@0
  1273
//_LIT(KExhaustCaches, "0123456789ABCDEFexhausted");
sl@0
  1274
_LIT(KGreekOPVY1, "\x1f82");
sl@0
  1275
_LIT(KGreekOPVY2, "\x1f02\x345");
sl@0
  1276
_LIT(KGreekOPVY3, "\x1f00\x300\x345");
sl@0
  1277
_LIT(KGreekOPVY4, "\x3b1\x313\x300\x345");
sl@0
  1278
_LIT(KGreekOPVY5, "\x3b1\x313\x345\x300");
sl@0
  1279
_LIT(KGreekOPVY6, "\x3b1\x345\x313\x300");
sl@0
  1280
sl@0
  1281
/**
sl@0
  1282
@SYMTestCaseID SYSLIB-UNICODE-CT-0105
sl@0
  1283
@SYMTestCaseDesc TCollationValueIterator test
sl@0
  1284
@SYMTestPriority High
sl@0
  1285
@SYMTestActions  TCollationValueIterator tests
sl@0
  1286
@SYMTestExpectedResults The test must not fail.
sl@0
  1287
@SYMPREQ814 Optimise folded string comparisons.
sl@0
  1288
*/
sl@0
  1289
void TestCollationValueIterator()
sl@0
  1290
	{
sl@0
  1291
   	// a funny pair of extra collation rules: w and abc both collate as e.
sl@0
  1292
   	TUint32 abcWTLKey[] = {0/* key for 'e' will go here */,
sl@0
  1293
   		0x8ff00101, 0x8ff10101, 0x8ff20101, 0x8ff30101,
sl@0
  1294
   		0x8ff40101, 0x8ff50101, 0x8ff60101};
sl@0
  1295
   	const TUint32 overrideIndex[] = {0x00770000, 0x0E010001, 0x0E400002, 0x0E440003,
sl@0
  1296
   		0x0E810004, 0x0EC10005, 0x0EC20006, 0xEC30007};
sl@0
  1297
   	const TUint16 abcString[4] = {0x0003, 0x0061, 0x0062, 0x0063};
sl@0
  1298
   	const TUint32 abcStringIndex = 0;
sl@0
  1299
   	TCollationMethod method;
sl@0
  1300
   	method.iId = 0;
sl@0
  1301
   	method.iMainTable = StandardCollationMethod();
sl@0
  1302
   	method.iFlags = TCollationMethod::EIgnoreNone;
sl@0
  1303
   	TInt charindex;
sl@0
  1304
   	for (charindex = 0; method.iMainTable->iIndex[charindex] >> 16 != 'e'; ++charindex)
sl@0
  1305
		{
sl@0
  1306
		}
sl@0
  1307
	abcWTLKey[0] = method.iMainTable->iKey[method.iMainTable->iIndex[charindex] & 0xFFFF];
sl@0
  1308
	TCollationKeyTable overrideTable = {abcWTLKey, overrideIndex, sizeof(abcWTLKey)/4, abcString, &abcStringIndex, 1};
sl@0
  1309
	method.iOverrideTable = &overrideTable;
sl@0
  1310
	
sl@0
  1311
   	TCollationValueIterator v(method);
sl@0
  1312
	TCollationValueIterator rv(method);
sl@0
  1313
sl@0
  1314
   	TUint32 buf1[32];
sl@0
  1315
   	TUint32 buf2[32];
sl@0
  1316
sl@0
  1317
   	TCollationKey raw1[32];
sl@0
  1318
   	TCollationKey raw2[32];
sl@0
  1319
	const TInt KRawKeyCnt = 8;//Raw collation key count produced from KAYZAccentsAbove string.
sl@0
  1320
	
sl@0
  1321
	//Get the raw key sequence for the whole KAYZAccentsAbove string.
sl@0
  1322
	TUTF32Iterator it(KAYZAccentsAbove().Ptr(), KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1323
	rv.SetSourceIt(it);
sl@0
  1324
	::GetRawKeys(rv, raw1, KRawKeyCnt);
sl@0
  1325
	
sl@0
  1326
	//KAYZAccentsAbove related constants
sl@0
  1327
	const TInt KBaseCharCnt = 3;//The number of base characters (A, y, z) in KAYZAccentsAbove string.
sl@0
  1328
	const TInt KOrgPosA = 0;//A position in KAYZAccentsAbove
sl@0
  1329
	const TInt KOrgPosY = 2;//y position in KAYZAccentsAbove
sl@0
  1330
	const TInt KOrgPosZ = 4;//z position in KAYZAccentsAbove
sl@0
  1331
	//Find where the collation key sequences start for A, y, z characters in KAYZAccentsAbove string.
sl@0
  1332
	const TInt KCollKeyPosA = ::CharNo2CollKeyPos(raw1, KRawKeyCnt, 0);
sl@0
  1333
	const TInt KCollKeyPosY = ::CharNo2CollKeyPos(raw1, KRawKeyCnt, 1);
sl@0
  1334
	const TInt KCollKeyPosZ = ::CharNo2CollKeyPos(raw1, KRawKeyCnt, 2);
sl@0
  1335
   
sl@0
  1336
	//Get the raw key sequence for character A in KAYZAccentsAbove string.
sl@0
  1337
	it = TUTF32Iterator(KAYZAccentsAbove().Ptr() + KOrgPosA, KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1338
	rv.SetSourceIt(it);
sl@0
  1339
	::GetRawKeys(rv, raw2 + KCollKeyPosA, KRawKeyCnt - KCollKeyPosA);
sl@0
  1340
	//
sl@0
  1341
	test(0 == ::CountDiscrepancies(raw1, raw2, KRawKeyCnt));
sl@0
  1342
	
sl@0
  1343
	//Get the raw key sequence for character Y in KAYZAccentsAbove string.
sl@0
  1344
	it = TUTF32Iterator(KAYZAccentsAbove().Ptr() + KOrgPosY, KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1345
	rv.SetSourceIt(it);
sl@0
  1346
	::GetRawKeys(rv, raw2 + KCollKeyPosY, KRawKeyCnt - KCollKeyPosY);
sl@0
  1347
	//
sl@0
  1348
	test(0 == ::CountDiscrepancies(raw1, raw2, KRawKeyCnt));
sl@0
  1349
   
sl@0
  1350
	//Get the raw key sequence for character Z in KAYZAccentsAbove string.
sl@0
  1351
	it = TUTF32Iterator(KAYZAccentsAbove().Ptr() + KOrgPosZ, KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1352
	rv.SetSourceIt(it);
sl@0
  1353
	::GetRawKeys(rv, raw2 + KCollKeyPosZ, KRawKeyCnt - KCollKeyPosZ);
sl@0
  1354
	//
sl@0
  1355
	test(0 == ::CountDiscrepancies(raw1, raw2, KRawKeyCnt));
sl@0
  1356
   
sl@0
  1357
	//Test starting at different points in the iteration
sl@0
  1358
	
sl@0
  1359
	//Level 0
sl@0
  1360
	//The whole string
sl@0
  1361
	it = TUTF32Iterator(KAYZAccentsAbove().Ptr(), KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1362
	v.SetSourceIt(it);
sl@0
  1363
	::GetKeys(v, buf1, 0, KBaseCharCnt);
sl@0
  1364
	//String from Y pos.
sl@0
  1365
	it = TUTF32Iterator(KAYZAccentsAbove().Ptr() + KOrgPosY, KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1366
	v.SetSourceIt(it);
sl@0
  1367
	::GetKeys(v, buf2, 0, KBaseCharCnt - 1);
sl@0
  1368
	//
sl@0
  1369
	test(0 == ::CountDiscrepancies(buf1 + 1, buf2, KBaseCharCnt - 1));
sl@0
  1370
	//String from Z pos.
sl@0
  1371
	it = TUTF32Iterator(KAYZAccentsAbove().Ptr() + KOrgPosZ, KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1372
	v.SetSourceIt(it);
sl@0
  1373
	::GetKeys(v, buf2, 0, KBaseCharCnt - 2);
sl@0
  1374
	//
sl@0
  1375
	test(0 == ::CountDiscrepancies(buf1 + 2, buf2, KBaseCharCnt - 2));
sl@0
  1376
   
sl@0
  1377
	//Level 1
sl@0
  1378
	//KCapitalAYZAccentsAbove is used in this test.
sl@0
  1379
	it = TUTF32Iterator(KCapitalAYZAccentsAbove().Ptr(), KCapitalAYZAccentsAbove().Ptr() + KCapitalAYZAccentsAbove().Length());
sl@0
  1380
	v.SetSourceIt(it);
sl@0
  1381
	::GetRawKeys(v, raw1, 8);
sl@0
  1382
	const TInt KOrgPosY2 = 3;//Y position in KCapitalAYZAccentsAbove
sl@0
  1383
	const TInt KCollKeyPosY2 = ::CharNo2CollKeyPos(raw1, KRawKeyCnt, 1);
sl@0
  1384
	//The whole string
sl@0
  1385
	it = TUTF32Iterator(KCapitalAYZAccentsAbove().Ptr(), KCapitalAYZAccentsAbove().Ptr() + KCapitalAYZAccentsAbove().Length());
sl@0
  1386
	v.SetSourceIt(it);
sl@0
  1387
	::GetKeys(v, buf1, 1, 8);
sl@0
  1388
	//String from Y pos.
sl@0
  1389
	it = TUTF32Iterator(KCapitalAYZAccentsAbove().Ptr() + KOrgPosY2, KCapitalAYZAccentsAbove().Ptr() + KCapitalAYZAccentsAbove().Length());
sl@0
  1390
	v.SetSourceIt(it);
sl@0
  1391
	::GetKeys(v, buf2, 1, 8 - KCollKeyPosY2);
sl@0
  1392
	//
sl@0
  1393
	test(0 == ::CountDiscrepancies(buf1 + KCollKeyPosY2, buf2, 8 - KCollKeyPosY2));
sl@0
  1394
   
sl@0
  1395
	//Level 2
sl@0
  1396
	//Capitals do not match at level 2
sl@0
  1397
	it = TUTF32Iterator(KAYZAccentsAbove().Ptr(), KAYZAccentsAbove().Ptr() + KAYZAccentsAbove().Length());
sl@0
  1398
	v.SetSourceIt(it);
sl@0
  1399
	::GetKeys(v, buf1, 2, 8);
sl@0
  1400
	it = TUTF32Iterator(KCapitalYAYZAccentsAbove().Ptr(), KCapitalYAYZAccentsAbove().Ptr() + KCapitalYAYZAccentsAbove().Length());
sl@0
  1401
	v.SetSourceIt(it);
sl@0
  1402
	::GetKeys(v, buf2, 2, 8);
sl@0
  1403
	//
sl@0
  1404
   	test(1 == CountDiscrepancies(buf1, buf2, 8));
sl@0
  1405
   	test(buf1[3] != buf2[3]);
sl@0
  1406
   
sl@0
  1407
	//Test funny collation keys, when they succeed and when they fail half way.
sl@0
  1408
	it = TUTF32Iterator(KABCRuleTest().Ptr(), KABCRuleTest().Ptr() + KABCRuleTest().Length());
sl@0
  1409
	v.SetSourceIt(it);
sl@0
  1410
	::GetKeys(v, buf1, 0, 8);
sl@0
  1411
	it = TUTF32Iterator(KABCRuleExpected().Ptr(), KABCRuleExpected().Ptr() + KABCRuleExpected().Length());
sl@0
  1412
	v.SetSourceIt(it);
sl@0
  1413
	::GetKeys(v, buf2, 0, 8);
sl@0
  1414
	//
sl@0
  1415
	test(0 == ::CountDiscrepancies(buf1, buf2, 8));
sl@0
  1416
   
sl@0
  1417
	//Test different decompositions at level 3
sl@0
  1418
	it = TUTF32Iterator(KGreekOPVY1().Ptr(), KGreekOPVY1().Ptr() + KGreekOPVY1().Length());
sl@0
  1419
	v.SetSourceIt(it);
sl@0
  1420
	::GetKeys(v, buf1, 3, 4);
sl@0
  1421
	//
sl@0
  1422
	it = TUTF32Iterator(KGreekOPVY2().Ptr(), KGreekOPVY2().Ptr() + KGreekOPVY2().Length());
sl@0
  1423
	v.SetSourceIt(it);
sl@0
  1424
	::GetKeys(v, buf2, 3, 4);
sl@0
  1425
	//
sl@0
  1426
	test(0 == ::CountDiscrepancies(buf1, buf2, 4));
sl@0
  1427
	//
sl@0
  1428
	it = TUTF32Iterator(KGreekOPVY3().Ptr(), KGreekOPVY3().Ptr() + KGreekOPVY3().Length());
sl@0
  1429
	v.SetSourceIt(it);
sl@0
  1430
	::GetKeys(v, buf2, 3, 4);
sl@0
  1431
	//
sl@0
  1432
	test(0 == ::CountDiscrepancies(buf1, buf2, 4));
sl@0
  1433
	//
sl@0
  1434
	it = TUTF32Iterator(KGreekOPVY4().Ptr(), KGreekOPVY4().Ptr() + KGreekOPVY4().Length());
sl@0
  1435
	v.SetSourceIt(it);
sl@0
  1436
	::GetKeys(v, buf2, 3, 4);
sl@0
  1437
	//
sl@0
  1438
	test(0 == ::CountDiscrepancies(buf1, buf2, 4));
sl@0
  1439
	//
sl@0
  1440
	it = TUTF32Iterator(KGreekOPVY5().Ptr(), KGreekOPVY5().Ptr() + KGreekOPVY5().Length());
sl@0
  1441
	v.SetSourceIt(it);
sl@0
  1442
	::GetKeys(v, buf2, 3, 4);
sl@0
  1443
	//
sl@0
  1444
	test(0 == ::CountDiscrepancies(buf1, buf2, 4));
sl@0
  1445
	//
sl@0
  1446
	it = TUTF32Iterator(KGreekOPVY6().Ptr(), KGreekOPVY6().Ptr() + KGreekOPVY6().Length());
sl@0
  1447
	v.SetSourceIt(it);
sl@0
  1448
	::GetKeys(v, buf2, 3, 4);
sl@0
  1449
	//
sl@0
  1450
	test(0 == ::CountDiscrepancies(buf1, buf2, 4));
sl@0
  1451
	}
sl@0
  1452
sl@0
  1453
// folding tests
sl@0
  1454
sl@0
  1455
// equivalence classes: all codes that fold to the same letter (which must be present
sl@0
  1456
// in the list). The lists are separated by -1. The end is marked with two -1s.
sl@0
  1457
// Each list must be in increasing order.
sl@0
  1458
TInt FoldingEquivalenceClasses[] =
sl@0
  1459
	{
sl@0
  1460
	'A', 'a', -1, 'Z', 'z', -1, '@', -1, '[', -1, '{', -1, 127, -1, 'I', 'i', 0x131, -1, 0, -1,
sl@0
  1461
	' ', 0xA0, -1,
sl@0
  1462
	0x300, -1, 0x301, -1,
sl@0
  1463
	0x141, 0x142, -1,
sl@0
  1464
	0x1c4, 0x1c5, 0x1c6, -1, 0x1c7, 0x1c8, 0x1c9, -1, 0x1ca, 0x1cb, 0x1cc, -1,
sl@0
  1465
	0x1f1, 0x1f2, 0x1f3, -1, 0x3a3, 0x3c2, 0x3c3, 0x3f2, -1,
sl@0
  1466
	0x402, 0x452, -1, 0x40F, 0x45F, -1, 0x460, 0x461, -1, 0x480, 0x481, -1, 0x482, -1,
sl@0
  1467
	0x410, 0x430, -1, 0x42F, 0x44f, -1, 0x48C, 0x48D, -1, 0x4e8, 0x4e9, -1,
sl@0
  1468
	0x531, 0x561, -1, 0x556, 0x586, -1, 0x559, -1, 0x55f, -1, -1
sl@0
  1469
	};
sl@0
  1470
sl@0
  1471
//_LIT(KMatchLeadingCandidate1, "\xE1\x65\x300\x301\x302\x303pqa\x301");
sl@0
  1472
//_LIT(KNoQMs, "a???");
sl@0
  1473
//_LIT(KOneQM, "?a");
sl@0
  1474
//_LIT(KTwoQMs, "??");
sl@0
  1475
//_LIT(KThreeQMs, "???*?");
sl@0
  1476
sl@0
  1477
//Constructs TUTF32Iterator iterator from aStr
sl@0
  1478
TUTF32Iterator UTF32It(const TDesC16& aStr)
sl@0
  1479
    {
sl@0
  1480
    return TUTF32Iterator(aStr.Ptr(), aStr.Ptr() + aStr.Length());
sl@0
  1481
    }
sl@0
  1482
sl@0
  1483
/**
sl@0
  1484
@SYMTestCaseID SYSLIB-UNICODE-CT-0107
sl@0
  1485
@SYMTestCaseDesc MatchSectionFolded test
sl@0
  1486
@SYMTestPriority High
sl@0
  1487
@SYMTestActions  MatchSectionFolded test
sl@0
  1488
@SYMTestExpectedResults The test must not fail.
sl@0
  1489
@SYMPREQ814 Optimise folded string comparisons.
sl@0
  1490
*/
sl@0
  1491
void MatchSectionFoldedTest()
sl@0
  1492
    {
sl@0
  1493
    TUTF32Iterator candidateIt, searchTermIt;
sl@0
  1494
sl@0
  1495
    candidateIt = UTF32It(_L16("\xE1"));
sl@0
  1496
    searchTermIt = UTF32It(_L16("a"));
sl@0
  1497
    test(!MatchSectionFolded(candidateIt, searchTermIt));
sl@0
  1498
sl@0
  1499
    candidateIt = UTF32It(_L16("a"));
sl@0
  1500
    searchTermIt = UTF32It(_L16("\xE1"));
sl@0
  1501
    test(!MatchSectionFolded(candidateIt, searchTermIt));
sl@0
  1502
sl@0
  1503
    candidateIt = UTF32It(_L16("abca\xE1\x62\x62\x61\x61\x61\x62\x63\x62\x61"));
sl@0
  1504
    searchTermIt = UTF32It(_L16("aBc"));
sl@0
  1505
    test(MatchSectionFolded(candidateIt, searchTermIt));
sl@0
  1506
    test(searchTermIt.AtEnd());
sl@0
  1507
    TPtrC16 p1(_L16("a\xE1\x62\x62\x61\x61\x61\x62\x63\x62\x61"));
sl@0
  1508
    TPtrC16 p2(candidateIt.CurrentPosition(), 11);
sl@0
  1509
    test(p1 == p2);
sl@0
  1510
sl@0
  1511
    candidateIt = UTF32It(_L16("aaaacdeiooo"));
sl@0
  1512
    searchTermIt = UTF32It(_L16("acde"));
sl@0
  1513
    test(!MatchSectionFolded(candidateIt, searchTermIt));
sl@0
  1514
    }
sl@0
  1515
sl@0
  1516
//FindMatchSectionFolded test
sl@0
  1517
void DoFindMatchSectionFoldedTest(const TDesC16& aCandidate, const TDesC16& aSearchTerm, TInt aPos)
sl@0
  1518
    {
sl@0
  1519
    TUTF32Iterator candidateIt, searchTermIt;
sl@0
  1520
    candidateIt = UTF32It(aCandidate);
sl@0
  1521
    searchTermIt = UTF32It(aSearchTerm);
sl@0
  1522
    if(aPos >= 0)
sl@0
  1523
        {
sl@0
  1524
        test(FindMatchSectionFolded(candidateIt, searchTermIt));
sl@0
  1525
        test(searchTermIt.AtEnd());
sl@0
  1526
        }
sl@0
  1527
    else
sl@0
  1528
        {
sl@0
  1529
        test(!FindMatchSectionFolded(candidateIt, searchTermIt));
sl@0
  1530
        }
sl@0
  1531
    }
sl@0
  1532
sl@0
  1533
//This class is used for reading lines from the unicode data file.
sl@0
  1534
class RUnicodeTestDataFile
sl@0
  1535
    {
sl@0
  1536
public:
sl@0
  1537
    RUnicodeTestDataFile();
sl@0
  1538
    void OpenLC();
sl@0
  1539
    void Close();
sl@0
  1540
    TBool NextStmt(TPtrC8& aStmt);
sl@0
  1541
private:
sl@0
  1542
    HBufC8* iFileData;
sl@0
  1543
    TInt iStartPos;
sl@0
  1544
    };
sl@0
  1545
sl@0
  1546
RUnicodeTestDataFile::RUnicodeTestDataFile() :
sl@0
  1547
    iFileData(NULL),
sl@0
  1548
    iStartPos(0)
sl@0
  1549
    {
sl@0
  1550
    }
sl@0
  1551
sl@0
  1552
void RUnicodeTestDataFile::OpenLC()
sl@0
  1553
    {
sl@0
  1554
    __ASSERT_ALWAYS(!iFileData && !iStartPos, User::Invariant());
sl@0
  1555
    iFileData = NULL;
sl@0
  1556
    iStartPos = 0;
sl@0
  1557
    CleanupClosePushL(*this);
sl@0
  1558
sl@0
  1559
    RFs fileSess;
sl@0
  1560
    CleanupClosePushL(fileSess);
sl@0
  1561
    User::LeaveIfError(fileSess.Connect());
sl@0
  1562
sl@0
  1563
    RFile file;
sl@0
  1564
    CleanupClosePushL(file);
sl@0
  1565
    User::LeaveIfError(file.Open(fileSess, KUnicodeTestDataFile, EFileRead));
sl@0
  1566
sl@0
  1567
    TInt fileSize;
sl@0
  1568
    User::LeaveIfError(file.Size(fileSize));
sl@0
  1569
    __ASSERT_ALWAYS(fileSize > 0, User::Invariant());
sl@0
  1570
sl@0
  1571
    iFileData = HBufC8::NewL(fileSize + 1);
sl@0
  1572
sl@0
  1573
    TPtr8 p = iFileData->Des();
sl@0
  1574
	User::LeaveIfError(file.Read(p));
sl@0
  1575
sl@0
  1576
    CleanupStack::PopAndDestroy(2, &fileSess);
sl@0
  1577
    }
sl@0
  1578
sl@0
  1579
void RUnicodeTestDataFile::Close()
sl@0
  1580
    {
sl@0
  1581
    delete iFileData;
sl@0
  1582
    iFileData = NULL;
sl@0
  1583
    iStartPos = 0;
sl@0
  1584
    }
sl@0
  1585
sl@0
  1586
TBool RUnicodeTestDataFile::NextStmt(TPtrC8& aStmt)
sl@0
  1587
    {
sl@0
  1588
    aStmt.Set(NULL, 0);
sl@0
  1589
    if(iStartPos < iFileData->Length())
sl@0
  1590
        {
sl@0
  1591
        const TUint8* pStart = iFileData->Des().Ptr() + iStartPos;
sl@0
  1592
        const TUint8* pEnd = pStart;
sl@0
  1593
        while(*pEnd++ != 0x0A)
sl@0
  1594
            {
sl@0
  1595
            }
sl@0
  1596
        iStartPos += pEnd - pStart;
sl@0
  1597
        aStmt.Set(pStart, pEnd - pStart - 1);
sl@0
  1598
        return ETrue;
sl@0
  1599
        }
sl@0
  1600
    return EFalse;
sl@0
  1601
    }
sl@0
  1602
sl@0
  1603
//Get a field "aFieldNo" from "aStr" statement containing encoded unicode character data
sl@0
  1604
TPtrC8 GetUnicodeDataField(const TPtrC8& aStr, TInt aFieldNo)
sl@0
  1605
    {
sl@0
  1606
    const TUint8* pStart = aStr.Ptr();
sl@0
  1607
    //Find the beginning of the field
sl@0
  1608
    TInt count = 0;
sl@0
  1609
    while(count < aFieldNo)
sl@0
  1610
        {
sl@0
  1611
        if(*pStart++ == ';')
sl@0
  1612
            {
sl@0
  1613
            ++count;
sl@0
  1614
            }
sl@0
  1615
        }
sl@0
  1616
    //Find the end of the field
sl@0
  1617
    const TUint8* pEnd = pStart;
sl@0
  1618
    while(*pEnd++ != ';')
sl@0
  1619
        {
sl@0
  1620
        }
sl@0
  1621
    //Construct a string from the field data
sl@0
  1622
    TPtrC8 ptr(pStart, pEnd - pStart - 1);
sl@0
  1623
    return ptr;
sl@0
  1624
    }
sl@0
  1625
   
sl@0
  1626
//Construct a string "aStr" with the extracted hex codes from "aUnicodeData"
sl@0
  1627
//The extracted unicodes are placed not from position 0, because some of 
sl@0
  1628
//the decomposable unicode characters are combining characters. If "aStr" is a search
sl@0
  1629
//string, then the searching algorithm will not work.
sl@0
  1630
void FillStringL(TDes16& aStr, const TDesC8& aUnicodeData)
sl@0
  1631
    {
sl@0
  1632
    aStr.SetLength(aStr.MaxLength());
sl@0
  1633
    TLex8 lex(aUnicodeData);
sl@0
  1634
    TInt len = 0;
sl@0
  1635
    for(len=0;!lex.Eos();++len)
sl@0
  1636
        {
sl@0
  1637
        TUint32 code;
sl@0
  1638
        User::LeaveIfError(lex.Val(code, EHex));
sl@0
  1639
        lex.Assign(lex.NextToken());
sl@0
  1640
        if (!IsSupplementary(code))
sl@0
  1641
        	{
sl@0
  1642
        	aStr[1+len] = (TUint16)code;
sl@0
  1643
        	}
sl@0
  1644
        else
sl@0
  1645
        	{
sl@0
  1646
        	aStr[1+len] = GetHighSurrogate(code);
sl@0
  1647
        	++len;
sl@0
  1648
        	aStr[1+len] = GetLowSurrogate(code);
sl@0
  1649
        	}
sl@0
  1650
        }
sl@0
  1651
    __ASSERT_ALWAYS(len > 0, User::Invariant());
sl@0
  1652
    aStr.SetLength(1 + len);
sl@0
  1653
    }
sl@0
  1654
   
sl@0
  1655
//Get the character unicode, which is at position 0
sl@0
  1656
TUint32 GetChCodeL(const TDesC8& aStr)
sl@0
  1657
    {
sl@0
  1658
    TLex8 lex(aStr);
sl@0
  1659
    TUint32 chCode;
sl@0
  1660
    User::LeaveIfError(lex.Val(chCode, EHex));
sl@0
  1661
    return chCode;
sl@0
  1662
    }
sl@0
  1663
sl@0
  1664
//Simple unicode folding tests
sl@0
  1665
void FindMatchSectionFoldedTestSimple()
sl@0
  1666
    {
sl@0
  1667
	_LIT16(KCandidate, "abca\xE1\x62\x62\x61\x61\x61\x62\x63\x62\x61");
sl@0
  1668
	DoFindMatchSectionFoldedTest(KCandidate, _L("abc"), 0);
sl@0
  1669
	DoFindMatchSectionFoldedTest(KCandidate, _L("abb"), -1);
sl@0
  1670
	DoFindMatchSectionFoldedTest(KCandidate, _L("caa"), -1);
sl@0
  1671
	DoFindMatchSectionFoldedTest(KCandidate, _L("abcb"), 9);
sl@0
  1672
	DoFindMatchSectionFoldedTest(KCandidate, _L("\xE1"), 4);
sl@0
  1673
	DoFindMatchSectionFoldedTest(KCandidate, _L("a\x301"), 4);
sl@0
  1674
	DoFindMatchSectionFoldedTest(KCandidate, _L("A\xC1\x42\x42"), 3);
sl@0
  1675
	DoFindMatchSectionFoldedTest(KCandidate, _L("a\x301\x42\x42"), 4);
sl@0
  1676
	DoFindMatchSectionFoldedTest(KCandidate, _L("a?BB"), 3);
sl@0
  1677
	DoFindMatchSectionFoldedTest(KCandidate, _L(""), 0);
sl@0
  1678
	DoFindMatchSectionFoldedTest(KCandidate, _L("?"), 0);
sl@0
  1679
	DoFindMatchSectionFoldedTest(KCandidate, _L("??????????????"), 0);
sl@0
  1680
	DoFindMatchSectionFoldedTest(KCandidate, _L("???????????????"), -1);
sl@0
  1681
	DoFindMatchSectionFoldedTest(KCandidate, _L("????a?????????"), -1);
sl@0
  1682
	DoFindMatchSectionFoldedTest(KCandidate, _L("???a??????????"), 0);
sl@0
  1683
	DoFindMatchSectionFoldedTest(KCandidate, _L("caa?"), -1);
sl@0
  1684
	DoFindMatchSectionFoldedTest(KCandidate, _L("abcb?"), 9);
sl@0
  1685
	DoFindMatchSectionFoldedTest(KCandidate, _L("abcb??"), -1);
sl@0
  1686
	DoFindMatchSectionFoldedTest(KCandidate, _L("b?aa"), 5);
sl@0
  1687
    }
sl@0
  1688
sl@0
  1689
//Extended tests - all characters, having non-zero "character decomposition mapping" field
sl@0
  1690
//or non-zero "upper case mapping" field
sl@0
  1691
void FindMatchSectionFoldedTestComplexL()
sl@0
  1692
    {
sl@0
  1693
    TBuf16<10> candidate;
sl@0
  1694
    candidate.Copy(_L16("abcdefghij"));
sl@0
  1695
    TBuf16<10> searchTerm;
sl@0
  1696
    searchTerm.Copy(_L16("eeeeefghij"));
sl@0
  1697
    const TInt KChPos = 5;
sl@0
  1698
    //Read and parse each line from the unicode data file.
sl@0
  1699
    RUnicodeTestDataFile unicodeTestDataFile;
sl@0
  1700
    unicodeTestDataFile.OpenLC();
sl@0
  1701
    TPtrC8 stmt;
sl@0
  1702
    while(unicodeTestDataFile.NextStmt(stmt) && stmt.Length() > 0)
sl@0
  1703
        {
sl@0
  1704
        //Get the character code
sl@0
  1705
        TUint32 chCode = GetChCodeL(stmt);
sl@0
  1706
        //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
sl@0
  1707
        if(chCode == (TUint32)0x0130)
sl@0
  1708
            {
sl@0
  1709
            continue;
sl@0
  1710
            }
sl@0
  1711
        if (!IsSupplementary(chCode))
sl@0
  1712
        	{
sl@0
  1713
        	candidate[KChPos] = (TUint16)chCode;
sl@0
  1714
        	}
sl@0
  1715
        else
sl@0
  1716
        	{
sl@0
  1717
            candidate[KChPos] = GetHighSurrogate(chCode);
sl@0
  1718
            candidate[KChPos+1] = GetLowSurrogate(chCode);
sl@0
  1719
        	}
sl@0
  1720
        //"Character decomposition mapping" is the 5th field, starting from 0.
sl@0
  1721
        TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
sl@0
  1722
        if(decomp.Length() > 1 && decomp[0] != '<')
sl@0
  1723
            {
sl@0
  1724
            //This character has valid decomposition mapping - test it.
sl@0
  1725
            //Construct the search string
sl@0
  1726
            FillStringL(searchTerm, decomp);
sl@0
  1727
            //Test
sl@0
  1728
            DoFindMatchSectionFoldedTest(candidate, searchTerm, KChPos);
sl@0
  1729
            }
sl@0
  1730
        //"Uppercase mapping" is the 12th field, starting from 0.
sl@0
  1731
        TPtrC8 upperc(GetUnicodeDataField(stmt, 12));
sl@0
  1732
        if(upperc.Length() > 1)
sl@0
  1733
            {
sl@0
  1734
            //This character has valid uppercase mapping - test it.
sl@0
  1735
            //Construct the search string
sl@0
  1736
            FillStringL(searchTerm, upperc);
sl@0
  1737
            //Test
sl@0
  1738
            DoFindMatchSectionFoldedTest(candidate, searchTerm, KChPos);
sl@0
  1739
            }
sl@0
  1740
        }//end of "while" - for each file statement
sl@0
  1741
    CleanupStack::PopAndDestroy(&unicodeTestDataFile);
sl@0
  1742
    }
sl@0
  1743
sl@0
  1744
//MatchStringFolded test
sl@0
  1745
void MatchStringFoldedTestL()
sl@0
  1746
    {
sl@0
  1747
    TBuf16<3> candidate;
sl@0
  1748
    candidate.Copy(_L16("aa"));
sl@0
  1749
    TBuf16<10> searchTerm;
sl@0
  1750
    searchTerm.Copy(_L16("aaaaaaaaaa"));
sl@0
  1751
    const TInt KChPos = 1;
sl@0
  1752
    //Read and parse each line from the unicode data file.
sl@0
  1753
    RUnicodeTestDataFile unicodeTestDataFile;
sl@0
  1754
    unicodeTestDataFile.OpenLC();
sl@0
  1755
    TPtrC8 stmt;
sl@0
  1756
    while(unicodeTestDataFile.NextStmt(stmt) && stmt.Length() > 0)
sl@0
  1757
        {
sl@0
  1758
        //Get the character code
sl@0
  1759
        TUint32 chCode = GetChCodeL(stmt);
sl@0
  1760
        //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
sl@0
  1761
        if(chCode == (TUint32)0x0130)
sl@0
  1762
            {
sl@0
  1763
            continue;
sl@0
  1764
            }
sl@0
  1765
        if (!IsSupplementary(chCode))
sl@0
  1766
        	{
sl@0
  1767
        	candidate[KChPos] = (TUint16)chCode;
sl@0
  1768
        	candidate.SetLength(2);
sl@0
  1769
        	}
sl@0
  1770
        else
sl@0
  1771
        	{
sl@0
  1772
            candidate[KChPos] = GetHighSurrogate(chCode);
sl@0
  1773
            candidate.SetLength(3);
sl@0
  1774
            candidate[KChPos+1] = GetLowSurrogate(chCode);
sl@0
  1775
        	}
sl@0
  1776
        //"Character decomposition mapping" is the 5th field, starting from 0.
sl@0
  1777
        TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
sl@0
  1778
        if(decomp.Length() > 1 && decomp[0] != '<')
sl@0
  1779
            {
sl@0
  1780
            //This character has valid decomposition mapping - test it.
sl@0
  1781
            //Construct the search string
sl@0
  1782
            FillStringL(searchTerm, decomp);
sl@0
  1783
            //Test
sl@0
  1784
            test(MatchStringFolded(candidate.Ptr(), candidate.Ptr() + candidate.Length(),
sl@0
  1785
                                   searchTerm.Ptr(), searchTerm.Ptr() + searchTerm.Length()));
sl@0
  1786
            }
sl@0
  1787
        //"Uppercase mapping" is the 12th field, starting from 0.
sl@0
  1788
        TPtrC8 upperc(GetUnicodeDataField(stmt, 12));
sl@0
  1789
        if(upperc.Length() > 1)
sl@0
  1790
            {
sl@0
  1791
            //This character has valid uppercase mapping - test it.
sl@0
  1792
            //Construct the search string
sl@0
  1793
            FillStringL(searchTerm, upperc);
sl@0
  1794
            //Test
sl@0
  1795
            test(MatchStringFolded(candidate.Ptr(), candidate.Ptr() + candidate.Length(),
sl@0
  1796
                                   searchTerm.Ptr(), searchTerm.Ptr() + searchTerm.Length()));
sl@0
  1797
            }
sl@0
  1798
        }//end of "while" - for each file statement
sl@0
  1799
    CleanupStack::PopAndDestroy(&unicodeTestDataFile);
sl@0
  1800
    }
sl@0
  1801
sl@0
  1802
void FindMatchSectionFoldedTestL()
sl@0
  1803
    {
sl@0
  1804
    FindMatchSectionFoldedTestSimple();
sl@0
  1805
    FindMatchSectionFoldedTestComplexL();
sl@0
  1806
    }
sl@0
  1807
sl@0
  1808
void TestFindMatchFoldedL()
sl@0
  1809
	{
sl@0
  1810
	MatchSectionFoldedTest();
sl@0
  1811
	FindMatchSectionFoldedTestL();
sl@0
  1812
	MatchStringFoldedTestL();
sl@0
  1813
	}
sl@0
  1814
sl@0
  1815
void TestCompareFoldedEqual(const TDesC& a, const TDesC& b)
sl@0
  1816
	{
sl@0
  1817
	test(a.CompareF(b) == 0);
sl@0
  1818
	test(b.CompareF(a) == 0);
sl@0
  1819
	}
sl@0
  1820
	
sl@0
  1821
void TestCompareFolded()
sl@0
  1822
	{
sl@0
  1823
	// Latin Extended A
sl@0
  1824
	TestCompareFoldedEqual(_L("\x100"), _L("\x101"));
sl@0
  1825
	TestCompareFoldedEqual(_L("\x100"), _L("A\x304"));
sl@0
  1826
	TestCompareFoldedEqual(_L("\x100"), _L("a\x304"));
sl@0
  1827
	TestCompareFoldedEqual(_L("\x104"), _L("\x105"));
sl@0
  1828
	TestCompareFoldedEqual(_L("\x104"), _L("a\x328"));
sl@0
  1829
	TestCompareFoldedEqual(_L("\x107"), _L("C\x301"));
sl@0
  1830
	TestCompareFoldedEqual(_L("\x10F"), _L("\x10E"));
sl@0
  1831
	TestCompareFoldedEqual(_L("\x10F"), _L("D\x30C"));
sl@0
  1832
	TestCompareFoldedEqual(_L("\x110"), _L("\x111"));
sl@0
  1833
	TestCompareFoldedEqual(_L("\x123"), _L("G\x327"));
sl@0
  1834
	TestCompareFoldedEqual(_L("\x132"), _L("\x133"));
sl@0
  1835
	TestCompareFoldedEqual(_L("\x131"), _L("i"));
sl@0
  1836
	TestCompareFoldedEqual(_L("\x131"), _L("I"));
sl@0
  1837
	TestCompareFoldedEqual(_L("i"), _L("I"));
sl@0
  1838
	TestCompareFoldedEqual(_L("\x13F"), _L("\x140"));
sl@0
  1839
	TestCompareFoldedEqual(_L("\x141"), _L("\x142"));
sl@0
  1840
	TestCompareFoldedEqual(_L("\x14A"), _L("\x14B"));
sl@0
  1841
	TestCompareFoldedEqual(_L("\x150"), _L("\x151"));
sl@0
  1842
	TestCompareFoldedEqual(_L("\x150"), _L("o\x30B"));
sl@0
  1843
	TestCompareFoldedEqual(_L("\x152"), _L("\x153"));
sl@0
  1844
	TestCompareFoldedEqual(_L("\x17D"), _L("\x17E"));
sl@0
  1845
	TestCompareFoldedEqual(_L("\x17D"), _L("z\x30C"));
sl@0
  1846
	// Latin Extended B
sl@0
  1847
	TestCompareFoldedEqual(_L("\x182"), _L("\x183"));
sl@0
  1848
	TestCompareFoldedEqual(_L("\x184"), _L("\x185"));
sl@0
  1849
	TestCompareFoldedEqual(_L("\x187"), _L("\x188"));
sl@0
  1850
	TestCompareFoldedEqual(_L("\x18A"), _L("\x257"));
sl@0
  1851
	TestCompareFoldedEqual(_L("\x194"), _L("\x263"));
sl@0
  1852
	TestCompareFoldedEqual(_L("\x195"), _L("\x1F6"));
sl@0
  1853
	TestCompareFoldedEqual(_L("\x196"), _L("\x269"));
sl@0
  1854
	TestCompareFoldedEqual(_L("\x1A2"), _L("\x1A3"));
sl@0
  1855
	TestCompareFoldedEqual(_L("\x1A6"), _L("\x280"));
sl@0
  1856
	TestCompareFoldedEqual(_L("\x1BF"), _L("\x1F7"));
sl@0
  1857
	TestCompareFoldedEqual(_L("\x1DC"), _L("\x1DB"));
sl@0
  1858
	TestCompareFoldedEqual(_L("\x1DC"), _L("u\x308\x300"));
sl@0
  1859
	TestCompareFoldedEqual(_L("\x1DD"), _L("\x18E"));
sl@0
  1860
	TestCompareFoldedEqual(_L("\x1EC"), _L("\x1ED"));
sl@0
  1861
	TestCompareFoldedEqual(_L("\x1FC"), _L("\x1FD"));
sl@0
  1862
	TestCompareFoldedEqual(_L("\x200"), _L("\x201"));
sl@0
  1863
	TestCompareFoldedEqual(_L("\x216"), _L("u\x311"));
sl@0
  1864
	TestCompareFoldedEqual(_L("\x21B"), _L("T\x326"));
sl@0
  1865
	TestCompareFoldedEqual(_L("\x21C"), _L("\x21D"));
sl@0
  1866
	TestCompareFoldedEqual(_L("\x229"), _L("E\x327"));
sl@0
  1867
	TestCompareFoldedEqual(_L("\x22A"), _L("\x22B"));
sl@0
  1868
	TestCompareFoldedEqual(_L("\x22A"), _L("O\x308\x304"));
sl@0
  1869
	TestCompareFoldedEqual(_L("\x22A"), _L("\xF6\x304"));
sl@0
  1870
	TestCompareFoldedEqual(_L("\x233"), _L("y\x304"));
sl@0
  1871
	TestCompareFoldedEqual(_L("\x233"), _L("\x232"));
sl@0
  1872
	}
sl@0
  1873
	
sl@0
  1874
void TestCompareFoldedNotEqual(TDesC& a, TDesC& b, TInt aValue)
sl@0
  1875
	{
sl@0
  1876
	test(a.CompareF(b) == aValue);
sl@0
  1877
	}
sl@0
  1878
	
sl@0
  1879
static void TestCompareFoldedAdditional()
sl@0
  1880
	{
sl@0
  1881
	const TText16 UnicodeTextOne16[] = {'a', 0};
sl@0
  1882
	const TText16 ErrUnicodeTextOne16[] = {'[', 0};
sl@0
  1883
	
sl@0
  1884
	const TText16 UnicodeTextTwo16[] = {0x00EA, 0x0323, 0};
sl@0
  1885
	const TText16 ErrUnicodeTextTwo16[] = {0x00EA, 't', 0};
sl@0
  1886
	
sl@0
  1887
	const TText16 UnicodeTextThree16[] = {0x00EA, 0x03B1, 0};
sl@0
  1888
	const TText16 ErrUnicodeTextThree16[] = {0x00EA, 0x0323, 0};
sl@0
  1889
	
sl@0
  1890
	TBufC16<ARRAY_SIZE(UnicodeTextOne16) - 1> oriUnicodeSmallTextOne(UnicodeTextOne16);
sl@0
  1891
	TBufC16<ARRAY_SIZE(ErrUnicodeTextOne16) - 1> nonMatchUnicodeSmallTextOne(ErrUnicodeTextOne16);
sl@0
  1892
	
sl@0
  1893
	TBufC16<ARRAY_SIZE(UnicodeTextTwo16) - 1> oriUnicodeSmallTextTwo(UnicodeTextTwo16);
sl@0
  1894
	TBufC16<ARRAY_SIZE(ErrUnicodeTextTwo16) - 1> nonMatchUnicodeSmallTextTwo(ErrUnicodeTextTwo16);
sl@0
  1895
	
sl@0
  1896
	TBufC16<ARRAY_SIZE(UnicodeTextThree16) - 1> oriUnicodeSmallTextThree(UnicodeTextThree16);
sl@0
  1897
	TBufC16<ARRAY_SIZE(ErrUnicodeTextThree16) - 1> nonMatchUnicodeSmallTextThree(ErrUnicodeTextThree16);
sl@0
  1898
	
sl@0
  1899
	const TText16 AsciiText16[] = {'A', 'B', 'C', 'D', 'E', 0};
sl@0
  1900
	
sl@0
  1901
    TBufC16<5> oriAsciiSmallText(_L("ABCDE"));
sl@0
  1902
    
sl@0
  1903
	// Check that characters are non matching with return value as stated
sl@0
  1904
	
sl@0
  1905
	TestCompareFoldedNotEqual(oriUnicodeSmallTextOne, nonMatchUnicodeSmallTextOne, 6);
sl@0
  1906
	TestCompareFoldedNotEqual(oriUnicodeSmallTextTwo, nonMatchUnicodeSmallTextTwo, 33);
sl@0
  1907
	TestCompareFoldedNotEqual(oriUnicodeSmallTextThree, nonMatchUnicodeSmallTextThree, -33);
sl@0
  1908
	
sl@0
  1909
	// Try other way around...
sl@0
  1910
	
sl@0
  1911
	TestCompareFoldedNotEqual(nonMatchUnicodeSmallTextOne, oriUnicodeSmallTextOne, -6);
sl@0
  1912
	TestCompareFoldedNotEqual(nonMatchUnicodeSmallTextTwo, oriUnicodeSmallTextTwo, -33);
sl@0
  1913
	TestCompareFoldedNotEqual(nonMatchUnicodeSmallTextThree, oriUnicodeSmallTextThree, 33);
sl@0
  1914
	
sl@0
  1915
	// Declare a TPtrC16 which is base from AsciiText16...
sl@0
  1916
sl@0
  1917
	TPtrC16 AsciiSmallText;
sl@0
  1918
sl@0
  1919
	AsciiSmallText.Set(AsciiText16, 4);
sl@0
  1920
sl@0
  1921
	// Check the boundary case
sl@0
  1922
sl@0
  1923
	TestCompareFoldedNotEqual(oriAsciiSmallText, AsciiSmallText, 1);
sl@0
  1924
sl@0
  1925
	// Try other way around...
sl@0
  1926
sl@0
  1927
	TestCompareFoldedNotEqual(AsciiSmallText, oriAsciiSmallText, -1);
sl@0
  1928
sl@0
  1929
	}
sl@0
  1930
sl@0
  1931
void TestFoldingL()
sl@0
  1932
	{
sl@0
  1933
	TestFindMatchFoldedL();
sl@0
  1934
	TestCompareFolded();
sl@0
  1935
	TestCompareFoldedAdditional();
sl@0
  1936
	}
sl@0
  1937
sl@0
  1938
// collation tests
sl@0
  1939
_LIT(KCandidateString1, "abcdefg");
sl@0
  1940
_LIT(KCandidateString2, "\x1f82\x1f02\x345\x1f00\x300\x345\x3b1\x313\x300\x345");
sl@0
  1941
_LIT(KCandidateString3, "abcabcdababc");
sl@0
  1942
_LIT(KCandidateString4, "xyzxyxyzxyxyyxyzxyy");
sl@0
  1943
sl@0
  1944
_LIT(KMatch1, "abc");
sl@0
  1945
_LIT(KMatch2, "abc*");
sl@0
  1946
_LIT(KMatch3, "*abc*");
sl@0
  1947
_LIT(KMatch4, "abc*def");
sl@0
  1948
_LIT(KMatch5, "abc*def*g*");
sl@0
  1949
_LIT(KMatch6, "*def");
sl@0
  1950
_LIT(KMatch7, "**d?f?");
sl@0
  1951
_LIT(KMatch8, "*d?f??");
sl@0
  1952
_LIT(KMatch9, "***d?f??*");
sl@0
  1953
_LIT(KMatch10, "a*c*g");
sl@0
  1954
_LIT(KMatch11, "*c*g");
sl@0
  1955
sl@0
  1956
_LIT(KMatch12, "*\x1f82");
sl@0
  1957
_LIT(KMatch13, "*\x1f82*");
sl@0
  1958
//_LIT(KMatch14, "*\x3b1*");
sl@0
  1959
_LIT(KMatch15, "*\x313*");
sl@0
  1960
_LIT(KMatch16, "*\x300*");
sl@0
  1961
//_LIT(KMatch17, "*\x345*");
sl@0
  1962
//_LIT(KMatch18, "*\x3b1\x313*");
sl@0
  1963
//_LIT(KMatch19, "*\x3b1\x313\x300*");
sl@0
  1964
_LIT(KMatch20, "*\x1f82*\x1f82*\x1f82\x1f82");
sl@0
  1965
_LIT(KMatch21, "*\x1f82*\x1f82*\x1f82\x1f82*\x1f82*");
sl@0
  1966
sl@0
  1967
_LIT(KMatch22, "*aba*");
sl@0
  1968
_LIT(KMatch23, "*abc");
sl@0
  1969
_LIT(KMatch24, "a*abc");
sl@0
  1970
_LIT(KMatch25, "a*ab");
sl@0
  1971
_LIT(KMatch26, "*ca*abc");
sl@0
  1972
_LIT(KMatch27, "*ca*??c");
sl@0
  1973
_LIT(KMatch28, "*??c");
sl@0
  1974
_LIT(KMatch29, "a*babc");
sl@0
  1975
_LIT(KMatch30, "*xyy");
sl@0
  1976
sl@0
  1977
_LIT(KFoo1, "foo");
sl@0
  1978
_LIT(KPeach, "pe\x302\x63he");
sl@0
  1979
_LIT(KFooMatch1, "fo*");
sl@0
  1980
_LIT(KFooMatch2, "*Fo*");
sl@0
  1981
_LIT(KFooMatch3, "*f*O*o");
sl@0
  1982
_LIT(KFooMatch4, "*f*o*o*");
sl@0
  1983
_LIT(KFooMatch5, "*o");
sl@0
  1984
_LIT(KFooMatch6, "???");
sl@0
  1985
_LIT(KFooMatch7, "*?o?*");
sl@0
  1986
_LIT(KFooMatch8, "*?");
sl@0
  1987
_LIT(KFooNonMatch1, "oo*");
sl@0
  1988
_LIT(KFooNonMatch2, "??");
sl@0
  1989
_LIT(KFooNonMatch3, "????");
sl@0
  1990
_LIT(KFooNonMatch4, "*?f*");
sl@0
  1991
_LIT(KFooNonMatch5, "*f*f*");
sl@0
  1992
_LIT(KFooNonMatch6, "*?*f*");
sl@0
  1993
_LIT(KPeachMatch1, "p?che");
sl@0
  1994
_LIT(KPeachNonMatch1, "peche");
sl@0
  1995
_LIT(KPeachNonMatch2, "pe?che");
sl@0
  1996
_LIT(KPeachNonMatch3, "pe?he");
sl@0
  1997
_LIT(KPeachNonMatch4, "pe*");
sl@0
  1998
sl@0
  1999
void TestMatchIdentifiersTDesC(const TDesC& aCandidate, const TDesC& aSearchTerm, TInt aExpectedResult)
sl@0
  2000
	{
sl@0
  2001
	const TText16* candidateStart = aCandidate.Ptr();
sl@0
  2002
	const TText16* candidateEnd = candidateStart + aCandidate.Length();
sl@0
  2003
	const TText16* searchTermStart = aSearchTerm.Ptr();
sl@0
  2004
	const TText16* searchTermEnd = searchTermStart + aSearchTerm.Length();
sl@0
  2005
	TInt pos = ::LocateMatchStringFolded(candidateStart, candidateEnd, searchTermStart, searchTermEnd);
sl@0
  2006
	test(aExpectedResult == pos);
sl@0
  2007
	}
sl@0
  2008
sl@0
  2009
void TestMatchIdentifiers()
sl@0
  2010
	{
sl@0
  2011
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch1, KErrNotFound);
sl@0
  2012
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch2, 0);
sl@0
  2013
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch3, 0);
sl@0
  2014
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch4, KErrNotFound);
sl@0
  2015
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch5, 0);
sl@0
  2016
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch6, KErrNotFound);
sl@0
  2017
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch7, 3);
sl@0
  2018
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch8, KErrNotFound);
sl@0
  2019
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch9, KErrNotFound);
sl@0
  2020
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch10, 0);
sl@0
  2021
	TestMatchIdentifiersTDesC(KCandidateString1, KMatch11, 2);
sl@0
  2022
	TestMatchIdentifiersTDesC(KCandidateString2, KMatch12, 6);
sl@0
  2023
	TestMatchIdentifiersTDesC(KCandidateString2, KMatch13, 0);
sl@0
  2024
	//The next test does not pass with the new optimised methods
sl@0
  2025
	//TestMatchIdentifiersTDesC(KCandidateString2, KMatch14, KErrNotFound);
sl@0
  2026
	TestMatchIdentifiersTDesC(KCandidateString2, KMatch15, KErrNotFound);
sl@0
  2027
	TestMatchIdentifiersTDesC(KCandidateString2, KMatch16, KErrNotFound);
sl@0
  2028
	// I have taken this test out: it tests that combining ypogegrammeni is not
sl@0
  2029
	// found on its own: but with case folding it can become a non-combining
sl@0
  2030
	// character (iota), so this test is not relevant.
sl@0
  2031
	// TestMatchIdentifiersTDesC(KCandidateString2, KMatch17, KErrNotFound);
sl@0
  2032
	//The next tests do not pass with the new optimised methods
sl@0
  2033
	//TestMatchIdentifiersTDesC(KCandidateString2, KMatch18, KErrNotFound);
sl@0
  2034
	//TestMatchIdentifiersTDesC(KCandidateString2, KMatch19, KErrNotFound);
sl@0
  2035
	TestMatchIdentifiersTDesC(KCandidateString2, KMatch20, 0);
sl@0
  2036
	TestMatchIdentifiersTDesC(KCandidateString2, KMatch21, KErrNotFound);
sl@0
  2037
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch22, 7);
sl@0
  2038
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch23, 9);
sl@0
  2039
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch24, 0);
sl@0
  2040
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch25, KErrNotFound);
sl@0
  2041
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch26, 2);
sl@0
  2042
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch27, 2);
sl@0
  2043
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch28, 9);
sl@0
  2044
	TestMatchIdentifiersTDesC(KCandidateString3, KMatch29, 0);
sl@0
  2045
	TestMatchIdentifiersTDesC(KCandidateString4, KMatch30, 16);
sl@0
  2046
sl@0
  2047
	TestMatchIdentifiersTDesC(KFoo1, KFoo1, 0);
sl@0
  2048
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch1, 0);
sl@0
  2049
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch2, 0);
sl@0
  2050
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch3, 0);
sl@0
  2051
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch4, 0);
sl@0
  2052
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch5, 2);
sl@0
  2053
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch6, 0);
sl@0
  2054
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch7, 0);
sl@0
  2055
	TestMatchIdentifiersTDesC(KFoo1, KFooMatch8, 2);
sl@0
  2056
	TestMatchIdentifiersTDesC(KFoo1, KFooNonMatch1, KErrNotFound);
sl@0
  2057
	TestMatchIdentifiersTDesC(KFoo1, KFooNonMatch2, KErrNotFound);
sl@0
  2058
	TestMatchIdentifiersTDesC(KFoo1, KFooNonMatch3, KErrNotFound);
sl@0
  2059
	TestMatchIdentifiersTDesC(KFoo1, KFooNonMatch4, KErrNotFound);
sl@0
  2060
	TestMatchIdentifiersTDesC(KFoo1, KFooNonMatch5, KErrNotFound);
sl@0
  2061
	TestMatchIdentifiersTDesC(KFoo1, KFooNonMatch6, KErrNotFound);
sl@0
  2062
	TestMatchIdentifiersTDesC(KPeach, KPeachMatch1, 0);
sl@0
  2063
	TestMatchIdentifiersTDesC(KPeach, KPeachNonMatch1, KErrNotFound);
sl@0
  2064
	TestMatchIdentifiersTDesC(KPeach, KPeachNonMatch2, KErrNotFound);
sl@0
  2065
	TestMatchIdentifiersTDesC(KPeach, KPeachNonMatch3, KErrNotFound);
sl@0
  2066
	TestMatchIdentifiersTDesC(KPeach, KPeachNonMatch4, KErrNotFound);
sl@0
  2067
sl@0
  2068
	TestMatchIdentifiersTDesC(_L(""), _L(""), 0);
sl@0
  2069
	TestMatchIdentifiersTDesC(_L("a"), _L(""), KErrNotFound);
sl@0
  2070
	TestMatchIdentifiersTDesC(_L(""), _L("*"), 0);
sl@0
  2071
	}
sl@0
  2072
sl@0
  2073
void TestFindIdentifierTDesC(const TDesC& aCandidateString, const TDesC& aSearchTerm, TInt /*aExpectedResult*/)
sl@0
  2074
	{
sl@0
  2075
	TUTF32Iterator candidateIt(aCandidateString.Ptr(), aCandidateString.Ptr() + aCandidateString.Length());
sl@0
  2076
	TUTF32Iterator searchIt(aSearchTerm.Ptr(), aSearchTerm.Ptr() + aSearchTerm.Length());
sl@0
  2077
	/*aExpectedResult = */::FindFolded(candidateIt, searchIt);
sl@0
  2078
	}
sl@0
  2079
sl@0
  2080
//INC057641 - NTT Functional BC break in 8.1a: string comparison changed
sl@0
  2081
static void INC057641L()
sl@0
  2082
	{
sl@0
  2083
	_LIT16(KEmptyText, "");        
sl@0
  2084
	HBufC16* str = HBufC16::NewLC(4);
sl@0
  2085
	str->Des().Copy(_L("****"));
sl@0
  2086
	TInt res = str->CompareC(KEmptyText);
sl@0
  2087
	CleanupStack::PopAndDestroy(str);
sl@0
  2088
	test(res == 1);
sl@0
  2089
	}
sl@0
  2090
sl@0
  2091
_LIT(KFind1, "abc");
sl@0
  2092
_LIT(KFind2, "def");
sl@0
  2093
_LIT(KFind3, "efg");
sl@0
  2094
_LIT(KFind4, "fga");
sl@0
  2095
_LIT(KFind5, "acd");
sl@0
  2096
_LIT(KFind6, "\x1f82");
sl@0
  2097
_LIT(KFind7, "\x3b1\x313\x300\x345");
sl@0
  2098
_LIT(KFind8, "\x3b1");
sl@0
  2099
_LIT(KFind9, "aba");
sl@0
  2100
_LIT(KFind10, "abc");
sl@0
  2101
sl@0
  2102
void TestFindIdentifier()
sl@0
  2103
	{
sl@0
  2104
	TestFindIdentifierTDesC(KCandidateString1, TPtrC(), 0);
sl@0
  2105
	TestFindIdentifierTDesC(KCandidateString1, KFind1, 0);
sl@0
  2106
	TestFindIdentifierTDesC(KCandidateString1, KFind2, 3);
sl@0
  2107
	TestFindIdentifierTDesC(KCandidateString1, KFind3, 4);
sl@0
  2108
	TestFindIdentifierTDesC(KCandidateString1, KFind4, KErrNotFound);
sl@0
  2109
	TestFindIdentifierTDesC(KCandidateString1, KFind5, KErrNotFound);
sl@0
  2110
	TestFindIdentifierTDesC(KCandidateString2, KFind6, 0);
sl@0
  2111
	TestFindIdentifierTDesC(KCandidateString2, KFind7, 0);
sl@0
  2112
	TestFindIdentifierTDesC(KCandidateString2, KFind8, KErrNotFound);
sl@0
  2113
	TestFindIdentifierTDesC(KCandidateString3, KFind9, 7);
sl@0
  2114
	TestFindIdentifierTDesC(KCandidateString3, KFind10, 0);
sl@0
  2115
	}
sl@0
  2116
sl@0
  2117
struct TestMatch8
sl@0
  2118
	{
sl@0
  2119
	TText8 const* iLeft;
sl@0
  2120
	TText8 const* iRight;
sl@0
  2121
	TInt iResult;
sl@0
  2122
	};
sl@0
  2123
sl@0
  2124
TestMatch8 const Tests8[]=
sl@0
  2125
	{
sl@0
  2126
	{_S8(""),_S8(""),0},
sl@0
  2127
	{_S8(""),_S8("?"),KErrNotFound},
sl@0
  2128
	{_S8(""),_S8("*"),0},
sl@0
  2129
	{_S8(""),_S8("**"),0},
sl@0
  2130
	{_S8(""),_S8("*x*"),KErrNotFound},
sl@0
  2131
	{_S8("x"),_S8(""),KErrNotFound},
sl@0
  2132
	{_S8("x"),_S8("?"),0},
sl@0
  2133
	{_S8("x"),_S8("*"),0},
sl@0
  2134
	{_S8("x"),_S8("**"),0},
sl@0
  2135
	{_S8("x"),_S8("**?"),0},
sl@0
  2136
	{_S8("x"),_S8("?**"),0},
sl@0
  2137
	{_S8("x"),_S8("**?*"),0},
sl@0
  2138
	{_S8("x"),_S8("x"),0},
sl@0
  2139
	{_S8("x"),_S8("a"),KErrNotFound},
sl@0
  2140
	{_S8("x"),_S8("xx"),KErrNotFound},
sl@0
  2141
	{_S8("x"),_S8("?x"),KErrNotFound},
sl@0
  2142
	{_S8("x"),_S8("x*"),0},
sl@0
  2143
	{_S8("x"),_S8("*x"),0},
sl@0
  2144
	{_S8("x"),_S8("*x*"),0},
sl@0
  2145
	{_S8("x"),_S8("**x*"),0},
sl@0
  2146
	{_S8("abc"),_S8(""),KErrNotFound},
sl@0
  2147
	{_S8("abc"),_S8("?*"),0},
sl@0
  2148
	{_S8("abc"),_S8("*?"),2},
sl@0
  2149
	{_S8("abc"),_S8("*?*?"),0},
sl@0
  2150
	{_S8("abc"),_S8("*a*"),0},
sl@0
  2151
	{_S8("abc"),_S8("*b*"),1},
sl@0
  2152
	{_S8("abc"),_S8("*c*"),2},
sl@0
  2153
	{_S8("abc"),_S8("*a"),KErrNotFound},
sl@0
  2154
	{_S8("abc"),_S8("*c"),2},
sl@0
  2155
	{_S8("abc"),_S8("*?c"),1},
sl@0
  2156
	{_S8("abc"),_S8("??c"),0},
sl@0
  2157
	{_S8("abc"),_S8("*b?"),1},
sl@0
  2158
	};
sl@0
  2159
sl@0
  2160
struct TestMatch16
sl@0
  2161
	{
sl@0
  2162
	TText16 const* iLeft;
sl@0
  2163
	TText16 const* iRight;
sl@0
  2164
	TInt iResult;
sl@0
  2165
	};
sl@0
  2166
sl@0
  2167
TestMatch16 const Tests16[]=
sl@0
  2168
	{
sl@0
  2169
	{_S16(""),_S16(""),0},
sl@0
  2170
	{_S16(""),_S16("?"),KErrNotFound},
sl@0
  2171
	{_S16(""),_S16("*"),0},
sl@0
  2172
	{_S16(""),_S16("**"),0},
sl@0
  2173
	{_S16(""),_S16("*x*"),KErrNotFound},
sl@0
  2174
	{_S16("x"),_S16(""),KErrNotFound},
sl@0
  2175
	{_S16("x"),_S16("?"),0},
sl@0
  2176
	{_S16("x"),_S16("*"),0},
sl@0
  2177
	{_S16("x"),_S16("**"),0},
sl@0
  2178
	{_S16("x"),_S16("**?"),0},
sl@0
  2179
	{_S16("x"),_S16("?**"),0},
sl@0
  2180
	{_S16("x"),_S16("**?*"),0},
sl@0
  2181
	{_S16("x"),_S16("x"),0},
sl@0
  2182
	{_S16("x"),_S16("a"),KErrNotFound},
sl@0
  2183
	{_S16("x"),_S16("xx"),KErrNotFound},
sl@0
  2184
	{_S16("x"),_S16("?x"),KErrNotFound},
sl@0
  2185
	{_S16("x"),_S16("x*"),0},
sl@0
  2186
	{_S16("x"),_S16("*x"),0},
sl@0
  2187
	{_S16("x"),_S16("*x*"),0},
sl@0
  2188
	{_S16("x"),_S16("**x*"),0},
sl@0
  2189
	{_S16("abc"),_S16(""),KErrNotFound},
sl@0
  2190
	{_S16("abc"),_S16("?*"),0},
sl@0
  2191
	{_S16("abc"),_S16("*?"),2},
sl@0
  2192
	{_S16("abc"),_S16("*?*?"),0},
sl@0
  2193
	{_S16("abc"),_S16("*a*"),0},
sl@0
  2194
	{_S16("abc"),_S16("*b*"),1},
sl@0
  2195
	{_S16("abc"),_S16("*c*"),2},
sl@0
  2196
	{_S16("abc"),_S16("*a"),KErrNotFound},
sl@0
  2197
	{_S16("abc"),_S16("*c"),2},
sl@0
  2198
	{_S16("abc"),_S16("*?c"),1},
sl@0
  2199
	{_S16("abc"),_S16("??c"),0},
sl@0
  2200
	{_S16("abc"),_S16("*b?"),1},
sl@0
  2201
	{_S16("\x0100"),_S16("\x0100"),0},
sl@0
  2202
	{_S16("\x0100"),_S16("*"),0},
sl@0
  2203
	{_S16("\x0100"),_S16("?"),0},
sl@0
  2204
	{_S16("\x0100"),_S16("*\x0100"),0},
sl@0
  2205
	{_S16("\x0100"),_S16("*\x0100?"),KErrNotFound},
sl@0
  2206
	{_S16("\x0101"),_S16("\x0101"),0},
sl@0
  2207
	{_S16("\x0101"),_S16("*"),0},
sl@0
  2208
	{_S16("\x0101"),_S16("?"),0},
sl@0
  2209
	{_S16("\x0101"),_S16("*\x0101"),0},
sl@0
  2210
	{_S16("\x0101"),_S16("*\x0101?"),KErrNotFound},
sl@0
  2211
	{_S16("\x0ffe"),_S16("\x0ffe"),0},
sl@0
  2212
	{_S16("\x0ffe"),_S16("*"),0},
sl@0
  2213
	{_S16("\x0ffe"),_S16("?"),0},
sl@0
  2214
	{_S16("\x0ffe"),_S16("*\x0ffe"),0},
sl@0
  2215
	{_S16("\x0ffe"),_S16("*\x0ffe?"),KErrNotFound},
sl@0
  2216
	{_S16("\x0fff"),_S16("\x0fff"),0},
sl@0
  2217
	{_S16("\x0fff"),_S16("*"),0},
sl@0
  2218
	{_S16("\x0fff"),_S16("?"),0},
sl@0
  2219
	{_S16("\x0fff"),_S16("*\x0fff"),0},
sl@0
  2220
	{_S16("\x0fff"),_S16("*\x0fff?"),KErrNotFound},
sl@0
  2221
	{_S16("\x1000"),_S16("\x1000"),0},
sl@0
  2222
	{_S16("\x1000"),_S16("*"),0},
sl@0
  2223
	{_S16("\x1000"),_S16("?"),0},
sl@0
  2224
	{_S16("\x1000"),_S16("*\x1000"),0},
sl@0
  2225
	{_S16("\x1000"),_S16("*\x1000?"),KErrNotFound},
sl@0
  2226
	{_S16("\x1001"),_S16("\x1001"),0},
sl@0
  2227
	{_S16("\x1001"),_S16("*"),0},
sl@0
  2228
	{_S16("\x1001"),_S16("?"),0},
sl@0
  2229
	{_S16("\x1001"),_S16("*\x1001"),0},
sl@0
  2230
	{_S16("\x1001"),_S16("*\x1001?"),KErrNotFound},
sl@0
  2231
	//	fffe, ffff is special
sl@0
  2232
	//{_S16("\xfffe"),_S16("\xfffe"),0},
sl@0
  2233
	//{_S16("\xfffe"),_S16("*"),0},
sl@0
  2234
	//{_S16("\xfffe"),_S16("?"),0},
sl@0
  2235
	//{_S16("\xfffe"),_S16("*\xfffe"),0},	//reserved
sl@0
  2236
	//{_S16("\xfffe"),_S16("*\xfffe?"),KErrNotFound},
sl@0
  2237
	//{_S16("\xffff"),_S16("\xffff"),0},
sl@0
  2238
	//{_S16("\xffff"),_S16("*"),0},
sl@0
  2239
	//{_S16("\xffff"),_S16("?"),0},
sl@0
  2240
	//{_S16("\xffff"),_S16("*\xffff?"),KErrNotFound},
sl@0
  2241
	//{_S16("\x0101\xffff\x0ffe"),_S16("*\xffff"),0},
sl@0
  2242
	//{_S16("\x0101\xffff\x0ffe"),_S16("*\xffff"),0},
sl@0
  2243
	//{_S16("\x0101\xfffe\x0ffe"),_S16("\xffff?"),0},
sl@0
  2244
	//{_S16("\x0101\xfffe\x0ffe"),_S16("*\xffff?"),0},
sl@0
  2245
	{_S16("\x04fa"),_S16("*"),0},		
sl@0
  2246
	};
sl@0
  2247
sl@0
  2248
TInt KTests=sizeof(Tests8)/sizeof(Tests8[0]);
sl@0
  2249
TInt KTests16=sizeof(Tests16)/sizeof(Tests16[0]);
sl@0
  2250
sl@0
  2251
TestMatch16 const TestsSurrogate[]=
sl@0
  2252
	{
sl@0
  2253
	//	not duplicate, test MatchSurrogate here
sl@0
  2254
	{_S16(""),_S16(""),0},
sl@0
  2255
	{_S16(""),_S16("?"),KErrNotFound},
sl@0
  2256
	{_S16(""),_S16("*"),0},
sl@0
  2257
	{_S16(""),_S16("**"),0},
sl@0
  2258
	{_S16(""),_S16("*x*"),KErrNotFound},
sl@0
  2259
	{_S16("x"),_S16(""),KErrNotFound},
sl@0
  2260
	{_S16("x"),_S16("?"),0},
sl@0
  2261
	{_S16("x"),_S16("*"),0},
sl@0
  2262
	{_S16("x"),_S16("**"),0},
sl@0
  2263
	{_S16("x"),_S16("**?"),0},
sl@0
  2264
	{_S16("x"),_S16("?**"),0},				// 10
sl@0
  2265
	{_S16("x"),_S16("**?*"),0},
sl@0
  2266
	{_S16("x"),_S16("x"),0},
sl@0
  2267
	{_S16("x"),_S16("a"),KErrNotFound},
sl@0
  2268
	{_S16("x"),_S16("xx"),KErrNotFound},
sl@0
  2269
	{_S16("x"),_S16("?x"),KErrNotFound},
sl@0
  2270
	{_S16("x"),_S16("x*"),0},
sl@0
  2271
	{_S16("x"),_S16("*x"),0},
sl@0
  2272
	{_S16("x"),_S16("*x*"),0},
sl@0
  2273
	{_S16("x"),_S16("**x*"),0},
sl@0
  2274
	{_S16("abc"),_S16(""),KErrNotFound},	// 20
sl@0
  2275
	{_S16("abc"),_S16("?*"),0},
sl@0
  2276
	{_S16("abc"),_S16("*?"),2},
sl@0
  2277
	{_S16("abc"),_S16("*?*?"),0},
sl@0
  2278
	{_S16("abc"),_S16("*a*"),0},
sl@0
  2279
	{_S16("abc"),_S16("*b*"),1},
sl@0
  2280
	{_S16("abc"),_S16("*c*"),2},
sl@0
  2281
	{_S16("abc"),_S16("*a"),KErrNotFound},
sl@0
  2282
	{_S16("abc"),_S16("*c"),2},
sl@0
  2283
	{_S16("abc"),_S16("*?c"),1},
sl@0
  2284
	{_S16("abc"),_S16("??c"),0},			// 30
sl@0
  2285
	{_S16("abc"),_S16("*b?"),1},
sl@0
  2286
sl@0
  2287
	// ones containing supplementary characters
sl@0
  2288
	{_S16("ab\xD840\xDDAD"),_S16("*b*"),1},
sl@0
  2289
	{_S16("ab\xD840\xDDAD"),_S16("*b?"),1},
sl@0
  2290
	{_S16("a\xD840\xDDAD\x0063"),_S16("*c*"),3},
sl@0
  2291
	{_S16("a\xD840\xDDAD\x0063"),_S16("*\xD840\xDDAD*"),1},
sl@0
  2292
	{_S16("a\xD840\xDDAB\xD830\xDDAC\xD840\xDDAC\x0063"),_S16("*\xD840\xDDAC*"),5},
sl@0
  2293
	{_S16("\xD840\xDDAB\xD840\xDDAC\x0063"),_S16("?\xD840\xDDAC*"),0},
sl@0
  2294
	{_S16("\xD840\xDDAB\xD840\xDDAC\x0063"),_S16("\xD840\xDDAB*"),0},
sl@0
  2295
	{_S16("\xD840\xDDAB\xD840\xDDAC\x0063"),_S16("*?\xD840\xDDAC*"),0},
sl@0
  2296
	{_S16("\xD840\xDDAB\xD840\xDDAC\xD840\xDDAD\x0063"),_S16("*?\xD840\xDDAD*"),2},		// 40
sl@0
  2297
	};
sl@0
  2298
sl@0
  2299
TInt KTestsSurrogate=sizeof(TestsSurrogate)/sizeof(TestsSurrogate[0]);
sl@0
  2300
sl@0
  2301
sl@0
  2302
/**
sl@0
  2303
@SYMTestCaseID SYSLIB-UNICODE-CT-1770
sl@0
  2304
@SYMTestCaseDesc TDes16 Collation conversion function test
sl@0
  2305
@SYMTestPriority High
sl@0
  2306
@SYMTestActions  Testing the three collation conversion function
sl@0
  2307
                 in TDesC16::GetNormalizedDecomposedFormL,
sl@0
  2308
                    TDesC16::GetFoldedDecomposedFormL,
sl@0
  2309
                    TDesC16::GetCollationKeysL  
sl@0
  2310
@SYMTestExpectedResults The test must not fail.
sl@0
  2311
@SYMREQ 6178 Add several new Unicode utility functions
sl@0
  2312
*/
sl@0
  2313
static void TestDes16CollationFunctionL()
sl@0
  2314
	{
sl@0
  2315
	/**----------------Test TDesC16::GetNormalizedDecomposedFormL------------------*/
sl@0
  2316
	
sl@0
  2317
	HBufC16* outputBuffer=NULL;
sl@0
  2318
	_LIT16(KTestString1,"abc")	;
sl@0
  2319
	//LATIN CAPITAL LETTER W WITH DIAERESIS(\x0057\x0308)
sl@0
  2320
	//LATIN SMALL LETTER A(\x0061)
sl@0
  2321
	//LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND TILDE(\x006F\x0302\x0303)
sl@0
  2322
	//GREEK SMALL LETTER ALPHA WITH PSILI AND PERISPOMENI AND YPOGEGRAMMENI(\x03B1\x0313\x0342\x0345)
sl@0
  2323
	_LIT16(KTestString2,"\x1E84\x0061\x1ED7\x1F86");
sl@0
  2324
	_LIT16(KTestStringNDF2,"\x0057\x0308\x0061\x006F\x0302\x0303\x03B1\x0313\x0342\x0345");
sl@0
  2325
sl@0
  2326
	outputBuffer=KTestString1().GetNormalizedDecomposedFormL();
sl@0
  2327
	test(outputBuffer->Compare(KTestString1())==0);
sl@0
  2328
	delete outputBuffer;
sl@0
  2329
	
sl@0
  2330
	outputBuffer=KTestString2().GetNormalizedDecomposedFormL();
sl@0
  2331
	test(outputBuffer->Compare(KTestStringNDF2())==0);
sl@0
  2332
	delete outputBuffer;
sl@0
  2333
sl@0
  2334
	/**----------------Test TDesC16::GetFoldedDecomposedFormL------------------*/
sl@0
  2335
	_LIT16(KTestString6,"AbC");
sl@0
  2336
	_LIT16(KTestStringFolded6,"abc");
sl@0
  2337
	//GREEK CAPITAL LETTER OMICRON WITH PSILI =>\x03BF\x0313
sl@0
  2338
	//LATIN SMALL LETTER M WITH ACUTE =>\x006D\x0301
sl@0
  2339
	//LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND HOOK ABOVE => \x006F\x0302\x0309
sl@0
  2340
	_LIT16(KTestString7,"\x1F48\x1E3F\x1ED4");
sl@0
  2341
	_LIT16(KTestStringFolded7,"\x03BF\x0313\x006D\x0301\x006F\x0302\x0309");
sl@0
  2342
	
sl@0
  2343
	outputBuffer=KTestString6().GetFoldedDecomposedFormL();
sl@0
  2344
	test(outputBuffer->Compare(KTestStringFolded6())==0);
sl@0
  2345
	delete outputBuffer;
sl@0
  2346
	
sl@0
  2347
	outputBuffer=KTestString7().GetFoldedDecomposedFormL();
sl@0
  2348
	test(outputBuffer->Compare(KTestStringFolded7())==0);
sl@0
  2349
	delete outputBuffer;
sl@0
  2350
	
sl@0
  2351
	/**----------------Test TDesC16::GetCollationKeysL------------------*/
sl@0
  2352
	TCollationMethod method;
sl@0
  2353
   	method.iId = 0;
sl@0
  2354
   	//purposely set the maintable to NULL, this will result in the DefaultTable being used
sl@0
  2355
   	method.iMainTable = 0;
sl@0
  2356
   	method.iOverrideTable = 0;
sl@0
  2357
   	method.iFlags = TCollationMethod::EIgnoreNone;
sl@0
  2358
	
sl@0
  2359
	//---------------Test key generation functionality----------------
sl@0
  2360
	/** 
sl@0
  2361
	Collation keys for
sl@0
  2362
	x=08b90108-00000078
sl@0
  2363
    y=08bd0108-00000079
sl@0
  2364
    z=08c90108-0000007a
sl@0
  2365
    */
sl@0
  2366
	_LIT(KInputString1,"xyz");
sl@0
  2367
	HBufC8* outbuf=NULL;	
sl@0
  2368
	//Max Level 0 keys
sl@0
  2369
	_LIT8(KMaxLevel0Key,"\x08\xb9\x08\xbd\x08\xc9");
sl@0
  2370
	outbuf=KInputString1().GetCollationKeysL(0,&method);
sl@0
  2371
	test(outbuf->Compare(KMaxLevel0Key())==0);
sl@0
  2372
	delete outbuf;	
sl@0
  2373
	//Max Level 1 keys
sl@0
  2374
	_LIT8(KMaxLevel1Key,"\x08\xb9\x08\xbd\x08\xc9\x00\x00\x01\x01\x01");	
sl@0
  2375
	outbuf=KInputString1().GetCollationKeysL(1,&method);
sl@0
  2376
	test(outbuf->Compare(KMaxLevel1Key())==0);
sl@0
  2377
	delete outbuf;	
sl@0
  2378
	//Max Level 2 keys
sl@0
  2379
	_LIT8(KMaxLevel2Key,"\x08\xb9\x08\xbd\x08\xc9\x00\x00\x01\x01\x01\x00\x08\x08\x08");	
sl@0
  2380
	outbuf=KInputString1().GetCollationKeysL(2,&method);
sl@0
  2381
	test(outbuf->Compare(KMaxLevel2Key())==0);
sl@0
  2382
	delete outbuf;
sl@0
  2383
	//Max Level 3 keys
sl@0
  2384
	_LIT8(KMaxLevel3Key,"\x08\xb9\x08\xbd\x08\xc9\x00\x00\x01\x01\x01\x00\x08\x08\x08\x00\x00\x00\x78\x00\x00\x79\x00\x00\x7A");	
sl@0
  2385
	outbuf=KInputString1().GetCollationKeysL(3,&method);
sl@0
  2386
	test(outbuf->Compare(KMaxLevel3Key())==0);
sl@0
  2387
	delete outbuf;	
sl@0
  2388
	
sl@0
  2389
	/**
sl@0
  2390
	Decomposition for 1F70
sl@0
  2391
	1F70=03B1 0300
sl@0
  2392
	Collation keys for
sl@0
  2393
	\x03B1	=09360108-000003B1	
sl@0
  2394
	\x0300	=00001609-00000300
sl@0
  2395
	y		=08bd0108-00000079
sl@0
  2396
	*/
sl@0
  2397
	_LIT(KInputString2,"\x1F70y");
sl@0
  2398
	//Max Level 2 keys
sl@0
  2399
	_LIT8(KCollationString22,"\x09\x36\x08\xBD\x00\x00\x01\x16\x01\x00\x08\x08\x08");
sl@0
  2400
	outbuf=KInputString2().GetCollationKeysL(2,&method);
sl@0
  2401
	test(outbuf->Compare(KCollationString22())==0);
sl@0
  2402
	delete outbuf;
sl@0
  2403
		
sl@0
  2404
	//Max Level 3 keys
sl@0
  2405
	_LIT8(KCollationString23,"\x09\x36\x08\xBD\x00\x00\x01\x16\x01\x00\x08\x08\x08\x00\x00\x03\xB1\x00\x03\x00\x00\x00\x79");
sl@0
  2406
	outbuf=KInputString2().GetCollationKeysL(3,&method);
sl@0
  2407
	test(outbuf->Compare(KCollationString23())==0);
sl@0
  2408
	delete outbuf;
sl@0
  2409
sl@0
  2410
	/**
sl@0
  2411
	Decomposition for 1EAC
sl@0
  2412
	1EAC= 1EA0 0302 = 0041 0323 0302
sl@0
  2413
	Collation keys for
sl@0
  2414
	\x0041	=06CF0121-00000041		
sl@0
  2415
	\x0323	=FF800104-00000001,83230105-00000000(2 keys for one character)
sl@0
  2416
	\x0302	=00001D09-00000302
sl@0
  2417
	*/
sl@0
  2418
	_LIT(KInputString3,"\x1EAC");
sl@0
  2419
	//Max Level 0 keys
sl@0
  2420
	_LIT8(KCollationString30,"\x06\xCF\xFF\x80\x83\x23");
sl@0
  2421
	//Max Level 1 keys
sl@0
  2422
	_LIT8(KCollationString31,"\x06\xCF\xFF\x80\x83\x23\x00\x00\x01\x01\x01\x1d");	
sl@0
  2423
	outbuf=KInputString3().GetCollationKeysL(1,&method);
sl@0
  2424
	test(outbuf->Compare(KCollationString31())==0);
sl@0
  2425
	delete outbuf;
sl@0
  2426
	
sl@0
  2427
	//Max Level 3 keys
sl@0
  2428
	_LIT8(KCollationString33,"\x06\xCF\xFF\x80\x83\x23\x00\x00\x01\x01\x01\x1d\x00\x20\x04\x04\x08\x00\x00\x00\x41\x00\x00\x01\x00\x03\x02");
sl@0
  2429
	outbuf=KInputString3().GetCollationKeysL(3,&method);
sl@0
  2430
	test(outbuf->Compare(KCollationString33())==0);
sl@0
  2431
	delete outbuf;
sl@0
  2432
	
sl@0
  2433
	//--------------Test using NULL collationMethod-----------------------
sl@0
  2434
	outbuf=KInputString3().GetCollationKeysL(3,NULL);
sl@0
  2435
	test(outbuf->Compare(KCollationString33())==0);
sl@0
  2436
	delete outbuf;
sl@0
  2437
	
sl@0
  2438
	//--------------Test using out of limit level-------------------------
sl@0
  2439
	outbuf=KInputString3().GetCollationKeysL(6,NULL);
sl@0
  2440
	test(outbuf->Compare(KCollationString33())==0);
sl@0
  2441
	delete outbuf;
sl@0
  2442
sl@0
  2443
	outbuf=KInputString3().GetCollationKeysL(-1,NULL);
sl@0
  2444
	test(outbuf->Compare(KCollationString30())==0);
sl@0
  2445
	delete outbuf;	
sl@0
  2446
				
sl@0
  2447
	}
sl@0
  2448
sl@0
  2449
/**
sl@0
  2450
@SYMTestCaseID SYSLIB-UNICODE-CT-1771
sl@0
  2451
@SYMTestCaseDesc TDes16 Collation conversion function OOM test
sl@0
  2452
@SYMTestPriority High
sl@0
  2453
@SYMTestActions  OOM Testing the three collation conversion function
sl@0
  2454
                 in TDesC16::GetNormalizedDecomposedFormL,
sl@0
  2455
                    TDesC16::GetFoldedDecomposedFormL,
sl@0
  2456
                    TDesC16::GetCollationKeysL  
sl@0
  2457
@SYMTestExpectedResults The test must not fail.
sl@0
  2458
@SYMREQ 6178 Add several new Unicode utility functions
sl@0
  2459
*/	
sl@0
  2460
static void TestDes16CollationFunctionOOM()
sl@0
  2461
	{
sl@0
  2462
	test.Next(_L("TestDes16CollationFunctionOOM"));
sl@0
  2463
sl@0
  2464
	TInt err, tryCount = 0;
sl@0
  2465
	do
sl@0
  2466
		{
sl@0
  2467
		__UHEAP_MARK;
sl@0
  2468
  		// find out the number of open handles
sl@0
  2469
		TInt startProcessHandleCount;
sl@0
  2470
		TInt startThreadHandleCount;
sl@0
  2471
		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
sl@0
  2472
sl@0
  2473
		// Setting Heap failure for OOM test
sl@0
  2474
		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
sl@0
  2475
		TRAP(err,TestDes16CollationFunctionL() );
sl@0
  2476
		__UHEAP_SETFAIL(RHeap::ENone, 0);
sl@0
  2477
sl@0
  2478
		// check that no handles have leaked
sl@0
  2479
		TInt endProcessHandleCount;
sl@0
  2480
		TInt endThreadHandleCount;
sl@0
  2481
		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
sl@0
  2482
sl@0
  2483
		test(startProcessHandleCount == endProcessHandleCount);
sl@0
  2484
		test(startThreadHandleCount  == endThreadHandleCount);
sl@0
  2485
sl@0
  2486
		__UHEAP_MARKEND;
sl@0
  2487
		} while(err == KErrNoMemory);
sl@0
  2488
sl@0
  2489
	test(err == KErrNone);
sl@0
  2490
	test.Printf(_L("- TestDes16CollationFunctionOOM succeeded at heap failure rate of %i\n"), tryCount);	
sl@0
  2491
	}
sl@0
  2492
sl@0
  2493
GLDEF_C TInt E32Main()
sl@0
  2494
//
sl@0
  2495
// entry point
sl@0
  2496
//
sl@0
  2497
    {
sl@0
  2498
	CTrapCleanup* trapCleanup = CTrapCleanup::New();
sl@0
  2499
	test(trapCleanup != NULL);
sl@0
  2500
sl@0
  2501
	test.Title();
sl@0
  2502
//
sl@0
  2503
sl@0
  2504
	test.Start(_L("Match8"));
sl@0
  2505
	TInt ii;
sl@0
  2506
	for (ii=0;ii<KTests;++ii)
sl@0
  2507
		{
sl@0
  2508
		TInt r=TPtrC8(Tests8[ii].iLeft).Match(TPtrC8(Tests8[ii].iRight));
sl@0
  2509
		test (r==Tests8[ii].iResult);
sl@0
  2510
		r=TPtrC8(Tests8[ii].iLeft).MatchF(TPtrC8(Tests8[ii].iRight));
sl@0
  2511
		test (r==Tests8[ii].iResult);
sl@0
  2512
		}
sl@0
  2513
	test.Next(_L("Match16"));
sl@0
  2514
	for (ii=0;ii<KTests16;++ii)
sl@0
  2515
		{
sl@0
  2516
		TInt r=TPtrC16(Tests16[ii].iLeft).Match(TPtrC16(Tests16[ii].iRight));
sl@0
  2517
		test (r==Tests16[ii].iResult);
sl@0
  2518
		r=TPtrC16(Tests16[ii].iLeft).MatchF(TPtrC16(Tests16[ii].iRight));
sl@0
  2519
		test (r==Tests16[ii].iResult);
sl@0
  2520
		}
sl@0
  2521
	//	check code points with upper case
sl@0
  2522
	test.Next( _L("Check characters with upper case") );
sl@0
  2523
	//039c: lower 03bc, folded 03bc
sl@0
  2524
	//00b5: upper 039c, folded 03bc
sl@0
  2525
	_LIT( K00b5, "\x00b5" );
sl@0
  2526
	_LIT( K039c, "\x039c" );
sl@0
  2527
	_LIT( K03bc, "\x03bc" );
sl@0
  2528
	test( 0 == TPtrC16( K00b5() ).MatchF( TPtrC16( K039c() ) ) );
sl@0
  2529
	test( 0 == TPtrC16( K00b5() ).MatchF( TPtrC16( K00b5() ) ) );
sl@0
  2530
	test( 0 == TPtrC16( K00b5() ).MatchF( TPtrC16( K039c() ) ) );
sl@0
  2531
	test( 0 == TPtrC16( K00b5() ).MatchF( TPtrC16( K03bc() ) ) );
sl@0
  2532
	TBuf<20> buf00b5;
sl@0
  2533
	buf00b5.Copy( K00b5() );
sl@0
  2534
	buf00b5.UpperCase();
sl@0
  2535
	test( 0 == buf00b5.Find( K039c() ) );
sl@0
  2536
	test( 0 == buf00b5.MatchF( K039c() ) );
sl@0
  2537
	
sl@0
  2538
	//	check code points with both upper and lower cases
sl@0
  2539
	test.Next( _L("Check characters with upper and lower cases") );
sl@0
  2540
	//	01C5: upper 01C4, folded 01C6
sl@0
  2541
	_LIT( K01c5, "\x01c5" );
sl@0
  2542
	_LIT( K01c4, "\x01c4" );
sl@0
  2543
	_LIT( K01c6, "\x01c6" );
sl@0
  2544
	test( 0 == TPtrC16( K01c5() ).MatchF( TPtrC16( K01c6() ) ) );
sl@0
  2545
	test( 0 == TPtrC16( K01c5() ).MatchF( TPtrC16( K01c4() ) ) );
sl@0
  2546
	test( 0 == TPtrC16( K01c4() ).MatchF( TPtrC16( K01c5() ) ) );
sl@0
  2547
	test( 0 == TPtrC16( K01c4() ).MatchF( TPtrC16( K01c6() ) ) );
sl@0
  2548
	TBuf<20> buf01c5;
sl@0
  2549
	buf01c5.Copy( K01c5() );
sl@0
  2550
	buf01c5.UpperCase();
sl@0
  2551
	test( 0 == buf01c5.Find( K01c4() ) );
sl@0
  2552
	test( 0 == buf01c5.MatchF( K01c6() ) );
sl@0
  2553
	
sl@0
  2554
	test.Next(_L("MatchSurrogate"));
sl@0
  2555
	for (ii=0;ii<KTestsSurrogate;++ii)
sl@0
  2556
		{
sl@0
  2557
		TInt r=TPtrC16(TestsSurrogate[ii].iLeft).MatchF(TPtrC16(TestsSurrogate[ii].iRight));
sl@0
  2558
		test (r==TestsSurrogate[ii].iResult);
sl@0
  2559
		}
sl@0
  2560
	
sl@0
  2561
	_LIT( KD800, "\xd800" );
sl@0
  2562
	_LIT( KQuestion, "?" );
sl@0
  2563
	_LIT( KDC00, "\xdc00" );
sl@0
  2564
	_LIT( KDFFF, "\xdfff" );
sl@0
  2565
sl@0
  2566
    test( KErrNotFound == TPtrC16( KD800() ).MatchF( TPtrC16( KQuestion() ) ) );
sl@0
  2567
    test( 0 == TPtrC16( KD800() ).MatchF( TPtrC16( KD800() ) ) );
sl@0
  2568
    test( KErrNotFound == TPtrC16( KDC00() ).MatchF( TPtrC16( KQuestion() ) ) );
sl@0
  2569
    test( KErrNotFound == TPtrC16( KDFFF() ).MatchF( TPtrC16( KQuestion() ) ) );
sl@0
  2570
sl@0
  2571
	test.Next(_L("Iterator tests"));
sl@0
  2572
	
sl@0
  2573
	::TestUTF32Iterator();
sl@0
  2574
	::TestFoldedDecompIterator();
sl@0
  2575
	::TestFoldedSortedDecompIterator();
sl@0
  2576
	::TestFoldedCanonicalIterator();
sl@0
  2577
	::TestDecompositionIterator2();
sl@0
  2578
	::TestCanonicalDecompositionIterator2();
sl@0
  2579
	::TestCanonicalDecompositionIteratorCached();
sl@0
  2580
	
sl@0
  2581
	test.Next(_L("Unit tests"));
sl@0
  2582
	
sl@0
  2583
	TestDecompositionIterator();
sl@0
  2584
	TestCanonicalDecompositionIterator();
sl@0
  2585
	TestCollationValueIterator();
sl@0
  2586
	TestMatchIdentifiers();
sl@0
  2587
	TestFindIdentifier();
sl@0
  2588
	
sl@0
  2589
	TRAPD(err, TestFoldingL());
sl@0
  2590
	test(err == KErrNone);
sl@0
  2591
	
sl@0
  2592
	test.Next(_L("INC057641"));
sl@0
  2593
	TRAP(err, INC057641L());
sl@0
  2594
	test(err == KErrNone);
sl@0
  2595
sl@0
  2596
	TestMatchC();
sl@0
  2597
	TestMatchC2();
sl@0
  2598
sl@0
  2599
	test.Next(_L("TestDes16CollationFunctionL"));
sl@0
  2600
	TRAP(err,TestDes16CollationFunctionL());
sl@0
  2601
	test(err==KErrNone);
sl@0
  2602
	::TestDes16CollationFunctionOOM();
sl@0
  2603
sl@0
  2604
	TestDisableCombiningCharacterCheck();
sl@0
  2605
sl@0
  2606
	test.End();
sl@0
  2607
	test.Close();
sl@0
  2608
	
sl@0
  2609
	delete trapCleanup;
sl@0
  2610
	
sl@0
  2611
	return 0;
sl@0
  2612
    }