charconvfw/fatfilenameconversionplugins/test/T_CP950.CPP
changeset 0 1fb32624e06b
child 51 a7c938434754
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <e32des8.h>
       
    21 
       
    22 LOCAL_D RTest test(_L("T_CP950.exe"));
       
    23 
       
    24 _LIT16(Uni_1, "\x0053\x3125\x3122\xAAAA\x9673\x2593\xFA0C\x3000");
       
    25 _LIT8(CP950_1, "\x53\xA3\xB6\xA3\xB3\x5F\xB3\xAF\xF9\xFE\xC9\x4A\xA1\x40");
       
    26 _LIT16(Uni_2, "\x0032\xFFFD\xFE3E\xFFFD\xFFFD");
       
    27 _LIT8(CP950_2, "\x32\x80\xA1\x70\xC1\x7F\xA7");
       
    28 
       
    29 _LIT(KName,"CP950");
       
    30 const TUid KPluginUid={0x10206A8C};
       
    31 
       
    32 
       
    33 // Used for supressing warning in OOM tests
       
    34 #define __UNUSED_VAR(var) var = var
       
    35 
       
    36 //
       
    37 /**
       
    38 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1776
       
    39 @SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class
       
    40 @SYMTestPriority 	    High
       
    41 @SYMTestActions  	    Tests for conversions from/to Unicode, using a function pointer
       
    42 @SYMTestExpectedResults Test must not fail
       
    43 */
       
    44 void Test()
       
    45 	{
       
    46 	test.Next(_L("@SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1776"));
       
    47 	RLibrary lib;
       
    48 
       
    49 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
       
    50 	// load the dll
       
    51 	TInt returnValue = lib.Load(KName,serverUid);
       
    52 	test(returnValue==0);
       
    53 
       
    54 	// get a pointer to the specified ordinal function and call it
       
    55 	TLibraryFunction function1 = lib.Lookup(1);
       
    56 	TLibraryFunction function2 = lib.Lookup(2);
       
    57 	TLibraryFunction function3 = lib.Lookup(3);
       
    58 
       
    59 	//cast the function pointer f to a function of type void with two arguments
       
    60 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
       
    61 	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
    62 
       
    63 	typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&);
       
    64 	TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2);
       
    65 
       
    66 	typedef TBool (*TIsLegalShortNameCharacter)(TUint);
       
    67 	TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3);
       
    68 
       
    69 	TBuf8<20> foreign1;
       
    70 	TBuf16<20> unicode2;
       
    71 
       
    72 	const TDesC16& unicode1(Uni_1);
       
    73 	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
       
    74 	TInt error = foreign1.Compare(CP950_1);
       
    75 
       
    76 	test(error==0);
       
    77 	foreign1.Zero();
       
    78 
       
    79 	const TDesC8& foreign2(CP950_2);
       
    80 	(*aConvertToUnicodeL)(unicode2,foreign2); 	//testing conversion to Unicode
       
    81 	error = unicode2.Compare(Uni_2);
       
    82 	test(error==0);
       
    83 	unicode2.Zero();
       
    84 
       
    85 
       
    86 	//testing for legal short name character
       
    87 	TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character
       
    88 	test(result==1);
       
    89 	result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character
       
    90 	test(result==0);
       
    91 	result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character
       
    92 	test(result==0);
       
    93 	result = (*aIsLegalShortNameCharacter)(0x3000); //testing for a double byte character
       
    94 	test(result==1);
       
    95 
       
    96 	lib.Close();
       
    97 	}
       
    98 
       
    99 // test code for INC080460: FATCharsetConv panics - stops china build booting
       
   100 void TestINC080460()
       
   101 	{
       
   102 	RLibrary lib;
       
   103 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
       
   104 
       
   105 	// load the dll
       
   106 	TInt returnValue = lib.Load(KName,serverUid);
       
   107 	test(returnValue==0);
       
   108 
       
   109 	// get a pointer to the specified ordinal function and call it
       
   110 	TLibraryFunction function1 = lib.Lookup(1);
       
   111 	TLibraryFunction function2 = lib.Lookup(2);
       
   112 
       
   113 	//cast the function pointer f to a function of type void with two arguments
       
   114 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
       
   115 	TConvertFromUnicodeL ConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
   116 
       
   117 	typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&);
       
   118 	TConvertToUnicodeL ConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2);
       
   119 
       
   120 	// the problem in this defect is when the foreign buffer is not big enough the code panics
       
   121 	// the solution is for the code to leave
       
   122 
       
   123 	// the foreign buffer is 11 (8+3) and there are 17 unicode characters
       
   124 	TBuf8<11> foreign;
       
   125 	_LIT16(longUnicode, "\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA\x0053\x3125\x3122\xAAAA");
       
   126 	const TDesC16& testUnicode1(longUnicode);
       
   127 	TInt error = KErrNone;
       
   128 
       
   129 	// ConvertFromUnicodeL - check that this call leaves
       
   130 	foreign.Zero();
       
   131 	TRAP( error, ConvertFromUnicodeL(foreign, testUnicode1)); 	//testing conversion from Unicode
       
   132 	test(error == KErrOverflow );
       
   133 
       
   134 	// ConvertFromUnicodeL - test 1 character to long leaves
       
   135 	_LIT16(longUnicode2, "FilenameEx\x3122");
       
   136 	const TDesC16& testUnicode2(longUnicode2);
       
   137 	foreign.Zero();
       
   138 	error = KErrNone;
       
   139 	TRAP( error, ConvertFromUnicodeL(foreign, testUnicode2)); 	//testing conversion from Unicode
       
   140 	test(error == KErrOverflow );
       
   141 
       
   142 	// ConvertFromUnicodeL - test 11 character does not leave
       
   143 	_LIT16(longUnicode3, "FilenameExt");
       
   144 	const TDesC16& testUnicode3(longUnicode3);
       
   145 	foreign.Zero();
       
   146 	error = KErrNone;
       
   147 	TRAP( error, ConvertFromUnicodeL(foreign, testUnicode3)); 	//testing conversion from Unicode
       
   148 	test(error == KErrNone );
       
   149 
       
   150 	// check ConvertToUnicodeL leaves when the buffer is too small
       
   151 	TBuf16<6> unicodeBuffer;
       
   152 	_LIT8(sampletext, "this is far to big to fit");
       
   153 	const TDesC8& sample(sampletext);
       
   154 
       
   155 	unicodeBuffer.Zero();
       
   156 	error = KErrNone;
       
   157 	TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample)); 	//testing conversion to Unicode
       
   158 	test(error==KErrOverflow);
       
   159 
       
   160 	// test 6 characters does NOT leave
       
   161 	_LIT8( chars6, "abcdef");
       
   162 	const TDesC8& sample6(chars6);
       
   163 	unicodeBuffer.Zero();
       
   164 	error = KErrNone;
       
   165 	TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample6)); 	//testing conversion to Unicode
       
   166 	test(error==KErrNone);
       
   167 
       
   168 	// test 7 characters does leave
       
   169 	_LIT8( chars7, "abcdefg");
       
   170 	const TDesC8& sample7(chars7);
       
   171 	unicodeBuffer.Zero();
       
   172 	error = KErrNone;
       
   173 	TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample7)); 	//testing conversion to Unicode
       
   174 	test(error==KErrOverflow);
       
   175 
       
   176 	// test when 7 foreign characters fits in 5 unicode it does NOT leave
       
   177 	_LIT8( CP950_sample, "\x32\x80\xA1\x70\xC1\x7F\xA7");
       
   178 	const TDesC8& sample7to5(CP950_sample);
       
   179 	unicodeBuffer.Zero();
       
   180 	error = KErrNone;
       
   181 	TRAP( error,ConvertToUnicodeL(unicodeBuffer,sample7to5)); 	//testing conversion to Unicode
       
   182 	test(error==KErrNone);
       
   183 
       
   184 	lib.Close();
       
   185 	}
       
   186 
       
   187 
       
   188 /**
       
   189 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1847-0003
       
   190 @SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class as part of INC090073
       
   191 @SYMTestPriority 	    High
       
   192 @SYMTestActions  	    Tests for correct character conversion on certain chinese characters for CP936
       
   193 @SYMTestExpectedResults Test must not fail
       
   194 */
       
   195 void TestINC090073()
       
   196 	{
       
   197 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847-0003 "));
       
   198  	_LIT16(unicode, "\x7C91\x8026\x8160\x7633\x6DFC\x715C\x6600\x9785\x86D8\x7A37\x61A9\x80B1\x86A3\x89E5\x80F2\x9B48\x6C19\x7B71\x946B\x6B46\x6615");
       
   199 	_LIT8(CP950Code, "\xD3\x4A\xBD\xA2\xDF\x73\xEA\x6F\xD9\xE7\xB7\xD4\xA9\xFB\xBB\xDF\xDB\xB1\xBD\x5E\xBE\xCD\xAA\xD0\xB0\x47\xDF\xFD\xD3\x6A\xEF\x69\xCB\x49\xDF\x4E\xF8\xCA\xDD\xF5\xA9\xFD");
       
   200 
       
   201 	RLibrary lib;
       
   202 
       
   203 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
       
   204 	// load the dll
       
   205 	TInt returnValue = lib.Load(KName,serverUid);
       
   206 	test(returnValue==0);
       
   207 
       
   208 	// get a pointer to the specified ordinal function and call it
       
   209 	TLibraryFunction function1 = lib.Lookup(1);
       
   210 
       
   211 	//cast the function pointer f to a function of type void with two arguments
       
   212 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
       
   213 	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
   214 
       
   215 	TBuf8<50> foreign1;
       
   216 
       
   217 	foreign1.Zero();
       
   218 	const TDesC16& unicode1(unicode);
       
   219 	TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); 	//testing conversion from Unicode
       
   220 	test(err==0);
       
   221 	TInt error = foreign1.Compare(CP950Code);
       
   222 	test(error==0);
       
   223 	foreign1.Zero();
       
   224 
       
   225 	lib.Close();
       
   226 	}
       
   227 
       
   228 void OOMTest()
       
   229 	{
       
   230 	test.Next(_L("OOM testing"));
       
   231 	TInt err, tryCount = 0;
       
   232 	do
       
   233 		{
       
   234 			__UHEAP_MARK;
       
   235   		// find out the number of open handles
       
   236 		TInt startProcessHandleCount;
       
   237 		TInt startThreadHandleCount;
       
   238 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   239 
       
   240 			// Setting Heap failure for OOM test
       
   241 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   242 
       
   243 		TRAP(err,Test());
       
   244 
       
   245 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   246 
       
   247 		// check that no handles have leaked
       
   248 		TInt endProcessHandleCount;
       
   249 		TInt endThreadHandleCount;
       
   250 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   251 
       
   252 		test(startProcessHandleCount == endProcessHandleCount);
       
   253 		test(startThreadHandleCount  == endThreadHandleCount);
       
   254 
       
   255 		__UHEAP_MARKEND;
       
   256 		}while (err == KErrNoMemory);
       
   257 
       
   258 	test(err == KErrNone);
       
   259 	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   260 	}
       
   261 
       
   262 
       
   263 LOCAL_C void DoE32MainL()
       
   264 	{
       
   265 	Test();
       
   266 	TestINC090073();
       
   267 	TestINC080460();
       
   268 	OOMTest();
       
   269 	}
       
   270 
       
   271 GLDEF_C TInt E32Main()
       
   272 	{
       
   273 	__UHEAP_MARK;
       
   274 
       
   275 	test.Title();
       
   276 	test.Start(_L("CP950 test..."));
       
   277 
       
   278 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   279 	TRAPD(error, DoE32MainL());
       
   280 	delete trapCleanup;
       
   281 
       
   282 	test.End();
       
   283 	test.Close();
       
   284 
       
   285 	__UHEAP_MARKEND;
       
   286 	return error;
       
   287 	}