os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_gb18030.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <e32base.h>
sl@0
    21
#include <f32file.h>
sl@0
    22
#include <charconv.h>
sl@0
    23
#include "t_gb18030.h"
sl@0
    24
#define test(cond)                                  \
sl@0
    25
    {                                               \
sl@0
    26
    TBool __bb = (cond);                            \
sl@0
    27
    TEST(__bb);                                     \
sl@0
    28
    if (!__bb)                                      \
sl@0
    29
        {                                           \
sl@0
    30
        ERR_PRINTF1(_L("ERROR: Test Failed"));      \
sl@0
    31
        User::Leave(1);                             \
sl@0
    32
        }                                           \
sl@0
    33
    }
sl@0
    34
sl@0
    35
const TInt KMibValue = 114;
sl@0
    36
const TInt KBufferLength=100;
sl@0
    37
sl@0
    38
void CT_GB18030::TestTruncatedConversionFromUnicodeToGb18030(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode)
sl@0
    39
	{
sl@0
    40
	for (TInt i=aOriginalUnicode.Length(); i>=0; --i)
sl@0
    41
		{
sl@0
    42
		TBuf8<KBufferLength> generatedGb18030;
sl@0
    43
		const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedGb18030, aOriginalUnicode.Left(i));
sl@0
    44
		test(returnValue>=0);
sl@0
    45
		TBuf8<KBufferLength> generatedsecondPartOfGb18030;
sl@0
    46
		test(aCharacterSetConverter.ConvertFromUnicode(generatedsecondPartOfGb18030, aOriginalUnicode.Mid(i-returnValue))==0);
sl@0
    47
		generatedGb18030.Append(generatedsecondPartOfGb18030);
sl@0
    48
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
    49
		TBuf16<KBufferLength> generatedUnicode;
sl@0
    50
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedGb18030, state)==0);
sl@0
    51
		test(generatedUnicode==aOriginalUnicode);
sl@0
    52
		}
sl@0
    53
	}
sl@0
    54
sl@0
    55
void CT_GB18030::TestSplittingConvertingFromUnicodeToGb18030(CCnvCharacterSetConverter& aCharacterSetConverter,
sl@0
    56
		TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit,
sl@0
    57
		TInt aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfGb18030,
sl@0
    58
		const TDesC8& aExpectedGb18030, const TDesC16& aOriginalUnicode)
sl@0
    59
	{
sl@0
    60
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
sl@0
    61
	test(aMaximumLengthUpperLimit<=KBufferLength);
sl@0
    62
	TUint8 gb18030Buffer[KBufferLength];
sl@0
    63
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
sl@0
    64
		{
sl@0
    65
		TPtr8 generatedFirstPartOfGb18030(gb18030Buffer, i);
sl@0
    66
		test(aCharacterSetConverter.ConvertFromUnicode(generatedFirstPartOfGb18030, aOriginalUnicode)==aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit);
sl@0
    67
		test(generatedFirstPartOfGb18030==aExpectedGb18030.Left(aExpectedLengthOfFirstPartOfGb18030));
sl@0
    68
		TBuf8<KBufferLength> generatedSecondPartOfGb18030;
sl@0
    69
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfGb18030, aOriginalUnicode.Right(aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit))==0);
sl@0
    70
		test(generatedSecondPartOfGb18030==aExpectedGb18030.Mid(aExpectedLengthOfFirstPartOfGb18030));
sl@0
    71
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
    72
		TBuf16<KBufferLength> generatedUnicode;
sl@0
    73
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedFirstPartOfGb18030, state)==0);
sl@0
    74
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
    75
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
sl@0
    76
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, generatedSecondPartOfGb18030, state)==0);
sl@0
    77
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
    78
		generatedUnicode.Append(generatedSecondPartOfUnicode);
sl@0
    79
		test(generatedUnicode==aOriginalUnicode);
sl@0
    80
		}
sl@0
    81
	}
sl@0
    82
sl@0
    83
void CT_GB18030::TestTruncatedConversionToUnicodeFromGb18030(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalGb18030)
sl@0
    84
	{
sl@0
    85
	for (TInt i=aOriginalGb18030.Length(); i>=4; --i) // 4 is the length of GB18030's longest multi-byte characters
sl@0
    86
		{
sl@0
    87
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
    88
		TBuf16<KBufferLength> generatedUnicode;
sl@0
    89
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalGb18030.Left(i), state);
sl@0
    90
		test(returnValue>=0);
sl@0
    91
		TBuf16<KBufferLength> generatedsecondPartOfUnicode;
sl@0
    92
		test(aCharacterSetConverter.ConvertToUnicode(generatedsecondPartOfUnicode, aOriginalGb18030.Mid(i-returnValue), state)==0);
sl@0
    93
		generatedUnicode.Append(generatedsecondPartOfUnicode);
sl@0
    94
		test(generatedUnicode==aExpectedUnicode);
sl@0
    95
		}
sl@0
    96
	}
sl@0
    97
sl@0
    98
void CT_GB18030::TestSplittingConvertingToUnicodeFromGb18030(CCnvCharacterSetConverter& aCharacterSetConverter,
sl@0
    99
        
sl@0
   100
				TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit,
sl@0
   101
				TInt aExpectedNumberOfGb18030BytesNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfUnicode,
sl@0
   102
				const TDesC16& aExpectedUnicode, const TDesC8& aOriginalGb18030)
sl@0
   103
	{
sl@0
   104
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
sl@0
   105
	test(aMaximumLengthUpperLimit<=KBufferLength);
sl@0
   106
	TUint16 unicodeBuffer[KBufferLength];
sl@0
   107
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
sl@0
   108
		{
sl@0
   109
		TPtr16 generatedFirstPartOfUnicode(unicodeBuffer, i);
sl@0
   110
		TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
   111
		test(aCharacterSetConverter.ConvertToUnicode(generatedFirstPartOfUnicode, aOriginalGb18030, state)==aExpectedNumberOfGb18030BytesNotConvertedAtSplit);
sl@0
   112
		test(generatedFirstPartOfUnicode==aExpectedUnicode.Left(aExpectedLengthOfFirstPartOfUnicode));
sl@0
   113
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
   114
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
sl@0
   115
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, aOriginalGb18030.Right(aExpectedNumberOfGb18030BytesNotConvertedAtSplit), state)==0);
sl@0
   116
		test(generatedSecondPartOfUnicode==aExpectedUnicode.Mid(aExpectedLengthOfFirstPartOfUnicode));
sl@0
   117
		test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
   118
		TBuf8<KBufferLength> generatedGb18030;
sl@0
   119
		test(aCharacterSetConverter.ConvertFromUnicode(generatedGb18030, generatedFirstPartOfUnicode)==0);
sl@0
   120
		TBuf8<KBufferLength> generatedSecondPartOfGb18030;
sl@0
   121
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfGb18030, generatedSecondPartOfUnicode)==0);
sl@0
   122
		generatedGb18030.Append(generatedSecondPartOfGb18030);
sl@0
   123
		test(generatedGb18030==aOriginalGb18030);
sl@0
   124
		}
sl@0
   125
	}
sl@0
   126
sl@0
   127
sl@0
   128
void CT_GB18030::CharacterSetValueAndMIBTests(CCnvCharacterSetConverter& aCharacterSetConverter, RFs& aFileServerSession)
sl@0
   129
{
sl@0
   130
	// check that the character set value of '114' is converted to the GB18030 UID (0x10287038)
sl@0
   131
	test(aCharacterSetConverter.ConvertMibEnumOfCharacterSetToIdentifierL(KMibValue,aFileServerSession)==KCharacterSetIdentifierGb18030);
sl@0
   132
	INFO_PRINTF1(_L("\nMIB->Char Set UID - OK"));
sl@0
   133
sl@0
   134
	// check that the UCS2 GUID (0x10287038) is converted to the character set value of '114'
sl@0
   135
	test(aCharacterSetConverter.ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierGb18030,aFileServerSession)==KMibValue);
sl@0
   136
	INFO_PRINTF1(_L("\nChar Set UID->MIB - OK"));
sl@0
   137
}
sl@0
   138
sl@0
   139
sl@0
   140
/**
sl@0
   141
*/
sl@0
   142
void CT_GB18030::TestConversionToUnicodeFromGb18030(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalGb18030, TInt aExpectedResult)
sl@0
   143
	{
sl@0
   144
	TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
   145
	TBuf16<KBufferLength> generatedUnicode;
sl@0
   146
	const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalGb18030, state);
sl@0
   147
	test(returnValue == aExpectedResult );
sl@0
   148
	test(generatedUnicode==aExpectedUnicode);
sl@0
   149
	}
sl@0
   150
sl@0
   151
sl@0
   152
/**
sl@0
   153
*/
sl@0
   154
void CT_GB18030::TestConversionFromUnicodeToGb18030(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode, TInt aExpectedResult)
sl@0
   155
	{
sl@0
   156
	TBuf8<KBufferLength> generatedGb18030;
sl@0
   157
	const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedGb18030, aOriginalUnicode);
sl@0
   158
	test(returnValue == aExpectedResult);
sl@0
   159
	TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
   160
	TBuf16<KBufferLength> generatedUnicode;
sl@0
   161
	test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedGb18030, state)==0);
sl@0
   162
	test(generatedUnicode==aOriginalUnicode);
sl@0
   163
	}
sl@0
   164
sl@0
   165
/**
sl@0
   166
@SYMTestCaseID          TI18N-CHARCONV-CT-4051
sl@0
   167
@SYMTestCaseDesc        Check GB18030 plugin support  conversion between one byte GB18030 character and Unicode
sl@0
   168
@SYMTestPriority        High
sl@0
   169
@SYMTestActions         1. Select characters from one-byte character set of GB2312-80
sl@0
   170
						2. Pass it to charconv and convert it to Unicode
sl@0
   171
						3. Pass the above Unicode to charconv and convert it to GB18030
sl@0
   172
@SYMTestExpectedResults Conversion is successful, and the returned Unicode/GB18030 is as defined
sl@0
   173
@SYMREQ                 REQ12065 PREQ12066
sl@0
   174
*/
sl@0
   175
sl@0
   176
void CT_GB18030::OneByteConversion( CCnvCharacterSetConverter& aCharacterSetConverter )
sl@0
   177
{
sl@0
   178
	TPtrC8 originalGb18030;
sl@0
   179
	TBuf16<KBufferLength> originalUnicode;
sl@0
   180
sl@0
   181
	//	One-byte gb
sl@0
   182
	originalGb18030.Set(_L8("\x40"));
sl@0
   183
	originalUnicode.Format(_L16("%c"), 0x40);
sl@0
   184
sl@0
   185
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   186
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   187
	
sl@0
   188
	//	one-byte uincode
sl@0
   189
	_LIT16(Uni_0, "\x0000");
sl@0
   190
	_LIT8(Gb_0, "\x00");
sl@0
   191
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_0);
sl@0
   192
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_0, Gb_0);
sl@0
   193
sl@0
   194
	_LIT16(Uni_1, "\x0079");
sl@0
   195
	_LIT8(Gb_1, "\x79");
sl@0
   196
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_1);
sl@0
   197
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_1, Gb_1);
sl@0
   198
sl@0
   199
	_LIT16(Uni_2, "\x0080");
sl@0
   200
	_LIT8(Gb_2, "\x81\x30\x81\x30");
sl@0
   201
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_2);
sl@0
   202
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_2, Gb_2);
sl@0
   203
sl@0
   204
	_LIT16(Uni_3, "\x0081");
sl@0
   205
	_LIT8(Gb_3, "\x81\x30\x81\x31");
sl@0
   206
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_3);
sl@0
   207
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_3, Gb_3);
sl@0
   208
	
sl@0
   209
	_LIT16(Uni_4, "\x00fe");
sl@0
   210
	_LIT8(Gb_4, "\x81\x30\x8B\x36");
sl@0
   211
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_4);
sl@0
   212
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_4, Gb_4);
sl@0
   213
sl@0
   214
	_LIT16(Uni_5, "\x00ff");
sl@0
   215
	_LIT8(Gb_5, "\x81\x30\x8B\x37");
sl@0
   216
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_5);
sl@0
   217
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_5, Gb_5);
sl@0
   218
}
sl@0
   219
sl@0
   220
sl@0
   221
/**
sl@0
   222
@SYMTestCaseID          TI18N-CHARCONV-CT-4052
sl@0
   223
@SYMTestCaseDesc        Check GB18030 plug-in support  conversion between two-byte GB18030 character and Unicode
sl@0
   224
@SYMTestPriority        High
sl@0
   225
@SYMTestActions         1. Select characters from two-byte character set from GB2312-80
sl@0
   226
						2. Pass it to charconv and convert it to Unicode
sl@0
   227
						3. Pass the above Unicode to charconv and convert it to GB18030
sl@0
   228
						4. Select characters from two-byte characters set from GBK, outside of GB2312-80, same with GBK
sl@0
   229
						5. Pass to charconv and convert to Unicode
sl@0
   230
						6. Pass the above Unicode to charconv, and conver it to GB18030
sl@0
   231
						7. Select characters from two-byte characters set from GBK, outside of GB2312-80, different from GBK
sl@0
   232
						8. Pass to charconv and convert to Unicode
sl@0
   233
						9. Pass the above Unicode to charconv, and conver it to GB18030
sl@0
   234
@SYMTestExpectedResults Conversion is successful, and the returned Unicode/GB18030 is as defined
sl@0
   235
@SYMREQ                 REQ12065 REQ12066
sl@0
   236
*/
sl@0
   237
sl@0
   238
void CT_GB18030::TwoByteConversion( CCnvCharacterSetConverter& aCharacterSetConverter )
sl@0
   239
{
sl@0
   240
	TPtrC8 originalGb18030;
sl@0
   241
	TBuf16<KBufferLength> originalUnicode;
sl@0
   242
sl@0
   243
	//	two-byte gb
sl@0
   244
	originalGb18030.Set(_L8("\xec\xe1"));
sl@0
   245
	originalUnicode.Format(_L16("%c"), 0x706c);
sl@0
   246
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   247
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   248
sl@0
   249
	originalGb18030.Set(_L8("\x81\x81"));
sl@0
   250
	originalUnicode.Format(_L16("%c"), 0x4e96);
sl@0
   251
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   252
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   253
sl@0
   254
	originalGb18030.Set(_L8("\xa2\xe3"));
sl@0
   255
	originalUnicode.Format(_L16("%c"), 0x20ac);
sl@0
   256
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   257
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   258
	originalGb18030.Set(_L8("\xa6\xd9"));
sl@0
   259
	originalUnicode.Format(_L16("%c"), 0xe78d);
sl@0
   260
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   261
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   262
	originalGb18030.Set(_L8("\xa8\xbc"));
sl@0
   263
	originalUnicode.Format(_L16("%c"), 0x1e3f);
sl@0
   264
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   265
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   266
	
sl@0
   267
	
sl@0
   268
	//	two-byte unicode
sl@0
   269
	_LIT16(Uni_6, "\x0100");
sl@0
   270
	_LIT8(Gb_6, "\x81\x30\x8B\x38");
sl@0
   271
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_6);
sl@0
   272
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_6, Gb_6);
sl@0
   273
sl@0
   274
	_LIT16(Uni_7, "\x0101");
sl@0
   275
	_LIT8(Gb_7, "\xA8\xA1");
sl@0
   276
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_7);
sl@0
   277
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_7, Gb_7);
sl@0
   278
sl@0
   279
	_LIT16(Uni_8, "\x0ffe");
sl@0
   280
	_LIT8(Gb_8, "\x81\x33\x83\x38");
sl@0
   281
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_8);
sl@0
   282
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_8, Gb_8);
sl@0
   283
sl@0
   284
	_LIT16(Uni_9, "\x0fff");
sl@0
   285
	_LIT8(Gb_9, "\x81\x33\x83\x39");
sl@0
   286
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_9);
sl@0
   287
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_9, Gb_9);
sl@0
   288
sl@0
   289
	_LIT16(Uni_10, "\x1000");
sl@0
   290
	_LIT8(Gb_10, "\x81\x33\x84\x30");
sl@0
   291
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_10);
sl@0
   292
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_10, Gb_10);
sl@0
   293
sl@0
   294
	_LIT16(Uni_11, "\x1001");
sl@0
   295
	_LIT8(Gb_11, "\x81\x33\x84\x31");
sl@0
   296
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_11);
sl@0
   297
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_11, Gb_11);
sl@0
   298
sl@0
   299
	_LIT16(Uni_12, "\xfffe");
sl@0
   300
	_LIT8(Gb_12, "\x84\x31\xA4\x38");
sl@0
   301
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_12);
sl@0
   302
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_12, Gb_12);
sl@0
   303
sl@0
   304
	_LIT16(Uni_13, "\xffff");
sl@0
   305
	_LIT8(Gb_13, "\x84\x31\xA4\x39");
sl@0
   306
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_13);
sl@0
   307
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_13, Gb_13);	
sl@0
   308
}
sl@0
   309
sl@0
   310
/**
sl@0
   311
@SYMTestCaseID          TI18N-CHARCONV-CT-4056
sl@0
   312
@SYMTestCaseDesc        Check GB18030 plug-in support  conversion between four-byte GB18030 character and Unicode
sl@0
   313
@SYMTestPriority        High
sl@0
   314
@SYMTestActions         1. Select characters from CJK A
sl@0
   315
						2. Pass it to charconv and convert it to Unicode 
sl@0
   316
						3. Pass the above Unicode to charconv and convert it to GB18030
sl@0
   317
						4. Select characters from CJK B
sl@0
   318
						5. Pass it to charconv and convert it to Unicode 
sl@0
   319
						6. Pass the above Unicode to charconv and convert it to GB18030
sl@0
   320
@SYMTestExpectedResults Conversion is successful, and the returned Unicode/GB18030 is as defined
sl@0
   321
@SYMREQ                 REQ12065 REQ12066
sl@0
   322
*/
sl@0
   323
sl@0
   324
void CT_GB18030::FourByteConversion( CCnvCharacterSetConverter& aCharacterSetConverter )
sl@0
   325
{
sl@0
   326
	TPtrC8 originalGb18030;
sl@0
   327
	TBuf16<KBufferLength> originalUnicode;
sl@0
   328
sl@0
   329
	//	four-byte gb
sl@0
   330
	originalGb18030.Set(_L8("\x82\x30\xA7\x30"));
sl@0
   331
	originalUnicode.Format(_L16("%c"), 0x3622);
sl@0
   332
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   333
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   334
sl@0
   335
	originalGb18030.Set(_L8("\x95\x32\xad\x35"));
sl@0
   336
	originalUnicode.Format(_L16("%c%c"), 0xd840, 0xddad );//0x201ad)
sl@0
   337
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   338
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   339
	
sl@0
   340
	//	four-byte unicode
sl@0
   341
	_LIT16(Uni_14, "\xd840\xdc00");
sl@0
   342
	_LIT8(gb_14, "\x95\x32\x82\x36");
sl@0
   343
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_14);
sl@0
   344
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_14, gb_14);
sl@0
   345
sl@0
   346
	_LIT16(Uni_15, "\xd840\xdc01");
sl@0
   347
	_LIT8(gb_15, "\x95\x32\x82\x37");
sl@0
   348
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_15);
sl@0
   349
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_15, gb_15);
sl@0
   350
	
sl@0
   351
	_LIT16(Uni_16, "\xD87F\xdffe");
sl@0
   352
	_LIT8(gb_16, "\x9a\x34\x84\x30");
sl@0
   353
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_16);
sl@0
   354
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_16, gb_16);
sl@0
   355
sl@0
   356
	_LIT16(Uni_17, "\xD87F\xdfff");
sl@0
   357
	_LIT8(gb_17, "\x9a\x34\x84\x31");
sl@0
   358
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, Uni_17);
sl@0
   359
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, Uni_17, gb_17);
sl@0
   360
}
sl@0
   361
sl@0
   362
sl@0
   363
/**
sl@0
   364
@SYMTestCaseID          TI18N-CHARCONV-CT-4054
sl@0
   365
@SYMTestCaseDesc        Check GB18030 plug-in support  conversion between one-byte GB18030 character and Unicode, negative input 
sl@0
   366
@SYMTestPriority        High
sl@0
   367
@SYMTestActions         1. Select one-byte characters which are not mapped to Unicode
sl@0
   368
						2. Pass it to charconv and convert it to Unicode 
sl@0
   369
						3. Select one-byte code point which is not valid in GB18030
sl@0
   370
						4. Pass it to charconv and convert it to Unicode 
sl@0
   371
@SYMTestExpectedResults No side effect
sl@0
   372
@SYMREQ                 REQ12065 REQ12066
sl@0
   373
*/
sl@0
   374
sl@0
   375
void CT_GB18030::OneByteConversionNegative( CCnvCharacterSetConverter& aCharacterSetConverter )
sl@0
   376
{
sl@0
   377
	TPtrC8 originalGb18030;
sl@0
   378
	TBuf16<KBufferLength> originalUnicode;
sl@0
   379
sl@0
   380
	originalGb18030.Set(_L8("\x0e"));
sl@0
   381
	originalUnicode.Format(_L16("%c"), 0x0e);
sl@0
   382
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   383
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030);
sl@0
   384
sl@0
   385
	originalGb18030.Set(_L8("\xa0"));
sl@0
   386
	originalUnicode.Copy( _L("") );
sl@0
   387
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   388
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030, CCnvCharacterSetConverter::EErrorIllFormedInput );
sl@0
   389
}
sl@0
   390
sl@0
   391
sl@0
   392
/**
sl@0
   393
@SYMTestCaseID          TI18N-CHARCONV-CT-4055
sl@0
   394
@SYMTestCaseDesc        Check GB18030 plug-in support  conversion between two-byte GB18030 character and Unicode, negative input 
sl@0
   395
@SYMTestPriority        High
sl@0
   396
@SYMTestActions         1. Select two-byte characters which are not mapped to Unicode
sl@0
   397
						2. Pass it to charconv and convert it to Unicode 
sl@0
   398
						3. Select two-byte code points which are not valid in GB18030
sl@0
   399
						4. Pass it to charconv and convert it to Unicode
sl@0
   400
@SYMTestExpectedResults No side effect
sl@0
   401
@SYMREQ                 REQ12065 REQ12066
sl@0
   402
*/
sl@0
   403
sl@0
   404
void CT_GB18030::TwoByteConversionNegative( CCnvCharacterSetConverter& aCharacterSetConverter )
sl@0
   405
{
sl@0
   406
	TPtrC8 originalGb18030;
sl@0
   407
	TBuf16<KBufferLength> originalUnicode;
sl@0
   408
sl@0
   409
	originalGb18030.Set(_L8("\xa0\x7f"));
sl@0
   410
	originalUnicode.Copy( _L("") );
sl@0
   411
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   412
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030, CCnvCharacterSetConverter::EErrorIllFormedInput );
sl@0
   413
}
sl@0
   414
sl@0
   415
sl@0
   416
/**
sl@0
   417
@SYMTestCaseID          TI18N-CHARCONV-CT-4056
sl@0
   418
@SYMTestCaseDesc        Check GB18030 plug-in support  conversion between four-byte GB18030 character and Unicode, negative input 
sl@0
   419
@SYMTestPriority        High
sl@0
   420
@SYMTestActions         1. Select four-byte characters which are not mapped to Unicode
sl@0
   421
						2. Pass it to charconv and convert it to Unicode 
sl@0
   422
						3. Select four-byte code points which are not valid in GB18030
sl@0
   423
						4. Pass it to charconv and convert it to Unicode
sl@0
   424
@SYMTestExpectedResults No side effect
sl@0
   425
@SYMREQ                 REQ12065 REQ12066
sl@0
   426
*/
sl@0
   427
sl@0
   428
void CT_GB18030::FourByteConversionNegative( CCnvCharacterSetConverter& aCharacterSetConverter )
sl@0
   429
{
sl@0
   430
	TPtrC8 originalGb18030;
sl@0
   431
	TBuf16<KBufferLength> originalUnicode;
sl@0
   432
sl@0
   433
	originalGb18030.Set(_L8("\x81\x30\x81\x3a"));
sl@0
   434
	originalUnicode.Copy( _L("") );
sl@0
   435
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   436
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030, CCnvCharacterSetConverter::EErrorIllFormedInput );
sl@0
   437
}
sl@0
   438
sl@0
   439
sl@0
   440
/**
sl@0
   441
@SYMTestCaseID          TI18N-CHARCONV-CT-4053
sl@0
   442
@SYMTestCaseDesc        Check GB18030 plug-in support  conversion between problematic GB18030 character and Unicode, negative input 
sl@0
   443
@SYMTestPriority        High
sl@0
   444
@SYMTestActions         1. Select characters whose trailing byte is in the range of leading bytes
sl@0
   445
						2. Pass it to charconv and convert it to Unicode 
sl@0
   446
						3. Select Unicode whose leading/trailing byte is in the range of low-ANSI 
sl@0
   447
						4. Pass it to charconv and convert it to GB18030
sl@0
   448
						5. Select characters whose trailing byte is special symbol like backslash
sl@0
   449
						6. Pass it to charconv and convert it to Unicode
sl@0
   450
@SYMTestExpectedResults No side effect
sl@0
   451
@SYMREQ                 REQ12065 REQ12066
sl@0
   452
*/
sl@0
   453
sl@0
   454
void CT_GB18030::ProblemProneCharcters( CCnvCharacterSetConverter& aCharacterSetConverter )
sl@0
   455
{
sl@0
   456
	TPtrC8 originalGb18030;
sl@0
   457
	TBuf16<KBufferLength> originalUnicode;
sl@0
   458
sl@0
   459
	originalGb18030.Set(_L8("\x81\x81\xba\xba\xa0\xa0\xf7\xf7"));
sl@0
   460
	originalUnicode.Format(_L16("%c%c%c%c"), 0x4e96, 0x6c49, 0x724b, 0x9f22);
sl@0
   461
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   462
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030 );
sl@0
   463
	
sl@0
   464
	originalGb18030.Set(_L8("\xc4\x40\x83\xa0\xa0\x7c\xa0\x86"));
sl@0
   465
	originalUnicode.Format(_L16("%c%c%c%c"), 0x8140, 0x512c, 0x7218, 0x7222);
sl@0
   466
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   467
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030 );
sl@0
   468
sl@0
   469
	originalGb18030.Set(_L8("\x81\x43\x81\x63\xf7\x4d\xf7\x6d\xa0\x53\xa0\x73"));
sl@0
   470
	originalUnicode.Format(_L16("%c%c%c%c%c%c"), 0x4E06, 0x4E67, 0x9C49, 0x9C69, 0x71EC, 0x720F);
sl@0
   471
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   472
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030 );
sl@0
   473
sl@0
   474
	originalGb18030.Set(_L8("\x9f\xaa\x81\xae\xf7\xbf\xbf\xaa\xb0\x5b\xb1\x5b\xb1\x5c\xb2\x5c\xb2\x5d\xc3\x5d\xd4\x5f\xe5\x5f\xd6\x7b\xe7\x7b\xF7\x7C\xFD\x7C\xAA\x7D\xFE\x7D"));
sl@0
   475
	originalUnicode.Format(_L16("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"), 0x716A, 0x4F04, 0x9ABA, 0x5F00, 0x7667, 0x76F5, 0x76F6, 0x7788, 0x7789, 0x80C5, 0x8a3D, 0x9329, 0x8B20, 0x940A, 0x9C78, 0x9F76, 0x7347, 0x464c);
sl@0
   476
	TestConversionFromUnicodeToGb18030(aCharacterSetConverter, originalUnicode);
sl@0
   477
	TestConversionToUnicodeFromGb18030(aCharacterSetConverter, originalUnicode, originalGb18030 );
sl@0
   478
}
sl@0
   479
sl@0
   480
sl@0
   481
void CT_GB18030::DoE32MainL()
sl@0
   482
	{
sl@0
   483
	RFs fileServerSession;
sl@0
   484
	CleanupClosePushL(fileServerSession);
sl@0
   485
	User::LeaveIfError(fileServerSession.Connect());
sl@0
   486
	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
sl@0
   487
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
sl@0
   488
	INFO_PRINTF1(_L("Available:\n"));
sl@0
   489
	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
sl@0
   490
		{
sl@0
   491
		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
sl@0
   492
		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
sl@0
   493
		TPtrC charactersSetName(charactersSet.Name());
sl@0
   494
		if (charactersSet.NameIsFileName())
sl@0
   495
			{
sl@0
   496
			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
sl@0
   497
			}
sl@0
   498
		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
sl@0
   499
		}
sl@0
   500
	TPtrC8 originalGb18030;
sl@0
   501
	TBuf16<KBufferLength> originalUnicode;
sl@0
   502
	TBuf8<KBufferLength> generatedGb18030;
sl@0
   503
	TBuf16<KBufferLength> generatedUnicode;
sl@0
   504
	TInt state=CCnvCharacterSetConverter::KStateDefault;
sl@0
   505
	
sl@0
   506
	// test that we can get MIB and Charset values
sl@0
   507
	CharacterSetValueAndMIBTests(*characterSetConverter, fileServerSession);
sl@0
   508
sl@0
   509
	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb18030, *arrayOfCharacterSetsAvailable, fileServerSession);
sl@0
   510
sl@0
   511
	INFO_PRINTF1( _L("GB18030 one byte support") );
sl@0
   512
	OneByteConversion( *characterSetConverter );
sl@0
   513
	
sl@0
   514
	INFO_PRINTF1( _L("GB18030 two byte support") );
sl@0
   515
	TwoByteConversion( *characterSetConverter );
sl@0
   516
	
sl@0
   517
	INFO_PRINTF1( _L("GB18030 four byte support") );
sl@0
   518
	FourByteConversion( *characterSetConverter );
sl@0
   519
	
sl@0
   520
	INFO_PRINTF1( _L("GB18030 one byte support with negative input") );
sl@0
   521
	OneByteConversionNegative( *characterSetConverter );
sl@0
   522
sl@0
   523
	INFO_PRINTF1( _L("GB18030 two byte support with negative input") );
sl@0
   524
	TwoByteConversionNegative( *characterSetConverter );
sl@0
   525
	
sl@0
   526
	INFO_PRINTF1( _L("GB18030 four byte support with negative input") );
sl@0
   527
	FourByteConversionNegative( *characterSetConverter );
sl@0
   528
	
sl@0
   529
	INFO_PRINTF1( _L("Problem prone characters") );
sl@0
   530
	ProblemProneCharcters( *characterSetConverter );
sl@0
   531
	
sl@0
   532
	INFO_PRINTF1(_L("Testing characters shared with GB 2312-80 and characters only in GBK"));
sl@0
   533
sl@0
   534
	originalGb18030.Set(_L8("A\xfd\x7d\xdd\xb6\xb1\xc9\xe9\x8e\xe8\x9d""E b\xd3\x59\xd2\x40\x95\xc0"));		// 20 byte, 12 char
sl@0
   535
	originalUnicode.Format(_L16("A%c%c%c%c%cE b%c%c%c"), 0x9f77, 0x837b, 0x9119, 0x95b9, 0x94e6, 0x89bb, 0x8938, 0x66b2);
sl@0
   536
	TestTruncatedConversionFromUnicodeToGb18030(*characterSetConverter, originalUnicode);
sl@0
   537
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 0, 0, 12, 0, originalGb18030, originalUnicode);
sl@0
   538
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 1, 2, 11, 1, originalGb18030, originalUnicode);
sl@0
   539
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 3, 4, 10, 3, originalGb18030, originalUnicode);
sl@0
   540
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 5, 6, 9, 5, originalGb18030, originalUnicode);
sl@0
   541
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 7, 8, 8, 7, originalGb18030, originalUnicode);
sl@0
   542
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 9, 10, 7, 9, originalGb18030, originalUnicode);
sl@0
   543
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 11, 11, 6, 11, originalGb18030, originalUnicode);
sl@0
   544
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 12, 12, 5, 12, originalGb18030, originalUnicode);
sl@0
   545
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 13, 13, 4, 13, originalGb18030, originalUnicode);
sl@0
   546
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 14, 15, 3, 14, originalGb18030, originalUnicode);
sl@0
   547
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 16, 17, 2, 16, originalGb18030, originalUnicode);
sl@0
   548
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 18, 19, 1, 18, originalGb18030, originalUnicode);
sl@0
   549
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 20, 40, 0, 20, originalGb18030, originalUnicode);
sl@0
   550
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode, originalGb18030);
sl@0
   551
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(1, 2), originalGb18030.Mid(1, 4));
sl@0
   552
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 0, 0, 20, 0, originalUnicode, originalGb18030);
sl@0
   553
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 1, 1, 19, 1, originalUnicode, originalGb18030);
sl@0
   554
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 2, 2, 17, 2, originalUnicode, originalGb18030);
sl@0
   555
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 3, 3, 15, 3, originalUnicode, originalGb18030);
sl@0
   556
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 4, 4, 13, 4, originalUnicode, originalGb18030);
sl@0
   557
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 5, 5, 11, 5, originalUnicode, originalGb18030);
sl@0
   558
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 6, 6, 9, 6, originalUnicode, originalGb18030);
sl@0
   559
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 7, 7, 8, 7, originalUnicode, originalGb18030);
sl@0
   560
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 8, 8, 7, 8, originalUnicode, originalGb18030);
sl@0
   561
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 9, 9, 6, 9, originalUnicode, originalGb18030);
sl@0
   562
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 10, 10, 4, 10, originalUnicode, originalGb18030);
sl@0
   563
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 11, 11, 2, 11, originalUnicode, originalGb18030);
sl@0
   564
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 12, 30, 0, 12, originalUnicode, originalGb18030);
sl@0
   565
sl@0
   566
	INFO_PRINTF1(_L("Testing GB18030 characters where the first byte has the high-bit set and the second byte doesn't"));
sl@0
   567
	originalGb18030.Set(_L8("\x20\x5d\xa0\x5d\xa0\xdd"));
sl@0
   568
	originalUnicode.Format(_L16(" ]%c%c"), 0x71f7, 0x72a6);
sl@0
   569
	TestTruncatedConversionFromUnicodeToGb18030(*characterSetConverter, originalUnicode);
sl@0
   570
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 0, 0, 4, 0, originalGb18030, originalUnicode);
sl@0
   571
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 1, 1, 3, 1, originalGb18030, originalUnicode);
sl@0
   572
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 2, 3, 2, 2, originalGb18030, originalUnicode);
sl@0
   573
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 4, 5, 1, 4, originalGb18030, originalUnicode);
sl@0
   574
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 6, 20, 0, 6, originalGb18030, originalUnicode);
sl@0
   575
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode, originalGb18030);
sl@0
   576
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 0, 0, 6, 0, originalUnicode, originalGb18030);
sl@0
   577
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 1, 1, 5, 1, originalUnicode, originalGb18030);
sl@0
   578
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 2, 2, 4, 2, originalUnicode, originalGb18030);
sl@0
   579
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 3, 3, 2, 3, originalUnicode, originalGb18030);
sl@0
   580
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 4, 20, 0, 4, originalUnicode, originalGb18030);
sl@0
   581
sl@0
   582
	INFO_PRINTF1(_L("Testing truncated GB18030 sequences"));
sl@0
   583
	originalGb18030.Set(_L8("qwe\xb5"));
sl@0
   584
	test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb18030, state)==1);
sl@0
   585
	test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
   586
	test(generatedUnicode==_L16("qwe"));
sl@0
   587
sl@0
   588
	originalGb18030.Set(_L8("qwe\x81\x30"));
sl@0
   589
	test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb18030, state)==2);
sl@0
   590
	test(state==CCnvCharacterSetConverter::KStateDefault);
sl@0
   591
	test(generatedUnicode==_L16("qwe"));
sl@0
   592
sl@0
   593
	INFO_PRINTF1(_L("Testing 4 byte characters, including surrogate pair"));
sl@0
   594
	originalGb18030.Set(_L8("C\x81\x30\x81\x30\x82\x30\x81\x30\x95\x32\x82\x36"));		// 13 byte
sl@0
   595
	originalUnicode.Format(_L16("C%c%c%c%c"), 0x0080, 0x34A3, 0xD840, 0xDC00);			// 4 Char (3 UCS2, 1 surrogate pair)
sl@0
   596
	TestTruncatedConversionFromUnicodeToGb18030(*characterSetConverter, originalUnicode);
sl@0
   597
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 0, 0, 5, 0, originalGb18030, originalUnicode);
sl@0
   598
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 1, 4, 4, 1, originalGb18030, originalUnicode);
sl@0
   599
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 5, 8, 3, 5, originalGb18030, originalUnicode);
sl@0
   600
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 9, 12, 2, 9, originalGb18030, originalUnicode);
sl@0
   601
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 13, 40, 0, 13, originalGb18030, originalUnicode);
sl@0
   602
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode, originalGb18030);
sl@0
   603
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(1, 2), originalGb18030.Mid(1, 8));
sl@0
   604
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(3, 2), originalGb18030.Mid(9, 4));
sl@0
   605
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 0, 0, 13, 0, originalUnicode, originalGb18030);
sl@0
   606
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 1, 1, 12, 1, originalUnicode, originalGb18030);
sl@0
   607
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 2, 2, 8, 2, originalUnicode, originalGb18030);
sl@0
   608
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 3, 4, 4, 3, originalUnicode, originalGb18030);
sl@0
   609
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 5, 30, 0, 5, originalUnicode, originalGb18030);
sl@0
   610
	
sl@0
   611
	INFO_PRINTF1(_L("Testing GB18030 characters which have different mapping with GB2312-80"));
sl@0
   612
	originalGb18030.Set(_L8("\xa1\xaa\xa1\xa4\xa8\x44\x81\x39\xa7\x39"));		// 10 byte
sl@0
   613
	originalUnicode.Format(_L16("%c%c%c%c"), 0x2014, 0x00B7, 0x2015, 0x30FB);			// 4 char (UCS2)
sl@0
   614
	TestTruncatedConversionFromUnicodeToGb18030(*characterSetConverter, originalUnicode);
sl@0
   615
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 0, 1, 4, 0, originalGb18030, originalUnicode);
sl@0
   616
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 2, 3, 3, 2, originalGb18030, originalUnicode);
sl@0
   617
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 4, 5, 2, 4, originalGb18030, originalUnicode);
sl@0
   618
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 6, 9, 1, 6, originalGb18030, originalUnicode);
sl@0
   619
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 10, 20, 0, 10, originalGb18030, originalUnicode);
sl@0
   620
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode, originalGb18030);
sl@0
   621
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(0, 2), originalGb18030.Mid(0, 4));
sl@0
   622
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(2, 2), originalGb18030.Mid(4, 6));
sl@0
   623
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 0, 0, 10, 0, originalUnicode, originalGb18030);
sl@0
   624
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 1, 1, 8, 1, originalUnicode, originalGb18030);
sl@0
   625
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 2, 2, 6, 2, originalUnicode, originalGb18030);
sl@0
   626
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 3, 3, 4, 3, originalUnicode, originalGb18030);
sl@0
   627
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 4, 10, 0, 4, originalUnicode, originalGb18030);
sl@0
   628
	
sl@0
   629
	INFO_PRINTF1(_L("Testing 2 byte GB18030 characters which have different mapping with GBK"));
sl@0
   630
	originalGb18030.Set(_L8("\xa1\xa4\xa1\xaa\xa8\xbc\xa8\xbf\xa9\x8a"));		// 10 byte
sl@0
   631
	originalUnicode.Format(_L16("%c%c%c%c%c"), 0x00b7, 0x2014, 0x1e3f, 0x01f9, 0x2ff0);			// 5 char (UCS2)
sl@0
   632
	TestTruncatedConversionFromUnicodeToGb18030(*characterSetConverter, originalUnicode);
sl@0
   633
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 0, 1, 5, 0, originalGb18030, originalUnicode);
sl@0
   634
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 2, 3, 4, 2, originalGb18030, originalUnicode);
sl@0
   635
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 4, 5, 3, 4, originalGb18030, originalUnicode);
sl@0
   636
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 10, 20, 0, 10, originalGb18030, originalUnicode);
sl@0
   637
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode, originalGb18030);
sl@0
   638
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(0, 2), originalGb18030.Mid(0, 4));
sl@0
   639
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(2, 3), originalGb18030.Mid(4, 6));
sl@0
   640
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 0, 0, 10, 0, originalUnicode, originalGb18030);
sl@0
   641
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 1, 1, 8, 1, originalUnicode, originalGb18030);
sl@0
   642
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 2, 2, 6, 2, originalUnicode, originalGb18030);
sl@0
   643
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 5, 10, 0, 5, originalUnicode, originalGb18030);
sl@0
   644
	
sl@0
   645
	INFO_PRINTF1(_L("Testing 2/4 byte GB18030 characters mapping to PUA codes"));
sl@0
   646
	originalGb18030.Set(_L8("\xFE\xFE\xFE\xD4\xFD\xE8\xA7\xFE\xA3\xEB\x84\x31\xA4\x39\x83\x36\xF0\x37\xA3\xB1"));		// 20 byte
sl@0
   647
	originalUnicode.Format(_L16("%c%c%c%c%c%c%c%c"), 0xE4C5, 0xE49B, 0xE451, 0xE7BB, 0xFF4B, 0xFFFF, 0xE9AC, 0xFF11);		// 8 char (UCS2)
sl@0
   648
	TestTruncatedConversionFromUnicodeToGb18030(*characterSetConverter, originalUnicode);
sl@0
   649
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 0, 1, 8, 0, originalGb18030, originalUnicode);
sl@0
   650
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 2, 3, 7, 2, originalGb18030, originalUnicode);
sl@0
   651
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 4, 5, 6, 4, originalGb18030, originalUnicode);
sl@0
   652
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 10, 13, 3, 10, originalGb18030, originalUnicode);
sl@0
   653
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 14, 17, 2, 14, originalGb18030, originalUnicode);
sl@0
   654
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 18, 19, 1, 18, originalGb18030, originalUnicode);
sl@0
   655
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 20, 40, 0, 20, originalGb18030, originalUnicode);
sl@0
   656
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode, originalGb18030);
sl@0
   657
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(0, 2), originalGb18030.Mid(0, 4));
sl@0
   658
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(2, 3), originalGb18030.Mid(4, 6));
sl@0
   659
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(5, 2), originalGb18030.Mid(10, 8));
sl@0
   660
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(7, 1), originalGb18030.Mid(18, 2));
sl@0
   661
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 0, 0, 20, 0, originalUnicode, originalGb18030);
sl@0
   662
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 1, 1, 18, 1, originalUnicode, originalGb18030);
sl@0
   663
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 2, 2, 16, 2, originalUnicode, originalGb18030);
sl@0
   664
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 6, 6, 6, 6, originalUnicode, originalGb18030);
sl@0
   665
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 7, 7, 2, 7, originalUnicode, originalGb18030);
sl@0
   666
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 8, 10, 0, 8, originalUnicode, originalGb18030);	
sl@0
   667
	
sl@0
   668
	INFO_PRINTF1(_L("Testing combined GB18030 characters including 1/2/4 byte"));
sl@0
   669
	originalGb18030.Set(_L8("A\x95\x32\x82\x36\x32\x81\x40\xC2\xB7\x8E\xEB\x95\x33\x96\x30\x81\x37\x81\x30\xFE\xF1")); //22 bytes
sl@0
   670
	originalUnicode.Format(_L16("A%c%c%c%c%c%c%c%c%c%c"), 0xD840, 0xDC00, 0x0032, 0x4E02, 0x8DEF, 0x5EAA, 0xD841, 0xDDAE, 0x23EC, 0xE4B8 ); //11 chars (UCS2)
sl@0
   671
	TestTruncatedConversionFromUnicodeToGb18030(*characterSetConverter, originalUnicode);
sl@0
   672
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 0, 0, 11, 0, originalGb18030, originalUnicode);
sl@0
   673
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 1, 4, 10, 1, originalGb18030, originalUnicode);
sl@0
   674
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 5, 5, 8, 5, originalGb18030, originalUnicode);
sl@0
   675
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 6, 6, 7, 6, originalGb18030, originalUnicode);
sl@0
   676
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 8, 9, 6, 8, originalGb18030, originalUnicode);
sl@0
   677
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 10, 11, 5, 10, originalGb18030, originalUnicode);
sl@0
   678
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 12, 15, 4, 12, originalGb18030, originalUnicode);
sl@0
   679
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 16, 19, 2, 16, originalGb18030, originalUnicode);
sl@0
   680
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 20, 21, 1, 20, originalGb18030, originalUnicode);
sl@0
   681
	TestSplittingConvertingFromUnicodeToGb18030(*characterSetConverter, 22, 30, 0, 22, originalGb18030, originalUnicode);
sl@0
   682
	
sl@0
   683
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode, originalGb18030);
sl@0
   684
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(0, 1), originalGb18030.Mid(0, 1));
sl@0
   685
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(1, 2), originalGb18030.Mid(1, 4));
sl@0
   686
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(3, 1), originalGb18030.Mid(5, 1));
sl@0
   687
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(4, 3), originalGb18030.Mid(6, 6));
sl@0
   688
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(7, 3), originalGb18030.Mid(12, 8));
sl@0
   689
	TestTruncatedConversionToUnicodeFromGb18030(*characterSetConverter, originalUnicode.Mid(10, 1), originalGb18030.Mid(20, 2));
sl@0
   690
	
sl@0
   691
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 0, 0, 22, 0, originalUnicode, originalGb18030);
sl@0
   692
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 1, 2, 21, 1, originalUnicode, originalGb18030);
sl@0
   693
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 3, 3, 17, 3, originalUnicode, originalGb18030);
sl@0
   694
	
sl@0
   695
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 4, 4, 16, 4, originalUnicode, originalGb18030);
sl@0
   696
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 7, 8, 10, 7, originalUnicode, originalGb18030);
sl@0
   697
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 9, 9, 6, 9, originalUnicode, originalGb18030);
sl@0
   698
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 10, 10, 2, 10, originalUnicode, originalGb18030);
sl@0
   699
	TestSplittingConvertingToUnicodeFromGb18030(*characterSetConverter, 11, 20, 0, 11, originalUnicode, originalGb18030);		
sl@0
   700
	
sl@0
   701
	CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
sl@0
   702
	}
sl@0
   703
sl@0
   704
CT_GB18030::CT_GB18030()
sl@0
   705
    {
sl@0
   706
    SetTestStepName(KTestStep_T_GB18030);
sl@0
   707
    }
sl@0
   708
sl@0
   709
TVerdict CT_GB18030::doTestStepL()
sl@0
   710
    {
sl@0
   711
    SetTestStepResult(EFail);
sl@0
   712
sl@0
   713
    __UHEAP_MARK;
sl@0
   714
    TRAPD(error1, DoE32MainL());    
sl@0
   715
    __UHEAP_MARKEND;
sl@0
   716
sl@0
   717
    if(error1 == KErrNone)
sl@0
   718
        {
sl@0
   719
        SetTestStepResult(EPass);
sl@0
   720
        }
sl@0
   721
sl@0
   722
    return TestStepResult();
sl@0
   723
    }