userlibandfileserver/fatfilenameconversionplugins/test/T_CP932.CPP
changeset 31 56f325a607ea
parent 15 4122176ea935
child 32 c9417927a896
child 33 0173bcd7697c
equal deleted inserted replaced
15:4122176ea935 31:56f325a607ea
     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_CP932.exe"));
       
    23 
       
    24 _LIT16(Uni_1, "\x0053\x0059\x004D\x3125\x6349\xAAAA\x9673\x9ED1\x3000\xFF9F");
       
    25 _LIT8(CP932_1, "\x53\x59\x4D\x5F\x91\xA8\x5F\x92\xC2\xEE\xEC\x81\x40\xDF");
       
    26 _LIT16(Uni_2, "\x0032\x0070\xFFFD\xFF61\x8D77\xFFFD\xFFFD");
       
    27 _LIT8(CP932_2, "\x32\x70\x80\xA1\x8B\x4E\xA0\x96\x7F");
       
    28 _LIT16(Uni_3, "\x4E00\x5141\x674F\x95C7\x58F1");
       
    29 _LIT8(CP932_3, "\x88\xEA\x88\xF2\x88\xC7\x88\xC5\x88\xEB");
       
    30 
       
    31 _LIT(KName,"CP932");
       
    32 const TUid KPluginUid={0x10206A92};
       
    33 
       
    34 
       
    35 // Used for supressing warning in OOM tests
       
    36 #define __UNUSED_VAR(var) var = var
       
    37 
       
    38 /**
       
    39 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1779
       
    40 @SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class
       
    41 @SYMTestPriority 	    High
       
    42 @SYMTestActions  	    Tests for conversions from/to Unicode, using a function pointer
       
    43 @SYMTestExpectedResults Test must not fail 
       
    44 */void Test()
       
    45 	{ 
       
    46 		test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1779 "));
       
    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 	
       
    70 	TBuf8<15> foreign1;
       
    71 	TBuf8<15> foreign3;
       
    72 	TBuf16<15> unicode2;
       
    73 	
       
    74 	const TDesC16& unicode1(Uni_1);
       
    75 	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
       
    76 	TInt error = foreign1.Compare(CP932_1);
       
    77 	test(error==0);
       
    78 	foreign1.Zero();
       
    79 	
       
    80 	const TDesC16& unicode3(Uni_3);
       
    81 	(*aConvertFromUnicodeL)(foreign3, unicode3); 	//testing conversion from Unicode for INC112715
       
    82 	error = foreign3.Compare(CP932_3);
       
    83 	test(error==0);
       
    84 	foreign3.Zero();
       
    85 	
       
    86 	const TDesC8& foreign2(CP932_2);
       
    87 	(*aConvertToUnicodeL)(unicode2,foreign2); 	//testing conversion to Unicode
       
    88 	error = unicode2.Compare(Uni_2);
       
    89 	test(error==0);
       
    90 	unicode2.Zero();
       
    91 	
       
    92 	
       
    93 	//testing for legal short name character
       
    94 	TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character
       
    95 	test(result==1);
       
    96 	result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character
       
    97 	test(result==0);
       
    98 	result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character
       
    99 	test(result==0);
       
   100 	result = (*aIsLegalShortNameCharacter)(0xFF61); //testing for a double byte character
       
   101 	test(result==1);
       
   102 
       
   103 	lib.Close();
       
   104 	}
       
   105 
       
   106 /**
       
   107 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1847
       
   108 @SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class as part of INC090073
       
   109 @SYMTestPriority 	    High
       
   110 @SYMTestActions  	    Tests for correct character conversion on certain chinese characters 
       
   111 @SYMTestExpectedResults Test must not fail 
       
   112 */	
       
   113 void TestINC090073()
       
   114 	{
       
   115 		test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847 "));
       
   116  	_LIT16(unicode, "\x6DFC\x715C\x9785\x7A37\x61A9\x80B1\x86A3\x7B71\x6615\x6600");
       
   117 	_LIT8(CP932Code, "\xED\xE6\xED\xF6\xE8\xD7\xE2\x6C\x8C\x65\x8D\x6E\xE5\x6E\xE2\xAA\xED\xB3\xED\xB2");
       
   118 
       
   119 	RLibrary lib;
       
   120 
       
   121 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);	
       
   122 	// load the dll	
       
   123 	TInt returnValue = lib.Load(KName,serverUid);
       
   124 	test(returnValue==0);
       
   125 
       
   126 	// get a pointer to the specified ordinal function and call it	
       
   127 	TLibraryFunction function1 = lib.Lookup(1);
       
   128 
       
   129 
       
   130 	//cast the function pointer f to a function of type void with two arguments
       
   131 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);	
       
   132 	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
   133 	
       
   134 	TBuf8<20> foreign1;
       
   135 	
       
   136 	const TDesC16& unicode1(unicode);
       
   137 	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
       
   138 	TInt error = foreign1.Compare(CP932Code);
       
   139 	test(error==0);
       
   140 	foreign1.Zero();
       
   141 
       
   142 	lib.Close();
       
   143 	}	
       
   144 
       
   145 void OOMTest()
       
   146 	{
       
   147 	test.Next(_L("OOM testing"));
       
   148 	TInt err, tryCount = 0;
       
   149 	do	
       
   150 		{
       
   151 			__UHEAP_MARK;
       
   152   		// find out the number of open handles
       
   153 		TInt startProcessHandleCount;
       
   154 		TInt startThreadHandleCount;
       
   155 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   156 		
       
   157 			// Setting Heap failure for OOM test
       
   158 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   159 
       
   160 		TRAP(err,Test());
       
   161 			
       
   162 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   163 		
       
   164 		// check that no handles have leaked
       
   165 		TInt endProcessHandleCount;
       
   166 		TInt endThreadHandleCount;
       
   167 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   168 
       
   169 		test(startProcessHandleCount == endProcessHandleCount);
       
   170 		test(startThreadHandleCount  == endThreadHandleCount);
       
   171 
       
   172 		__UHEAP_MARKEND;
       
   173 		}while (err == KErrNoMemory);
       
   174 		
       
   175 	test(err == KErrNone);
       
   176 	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   177 	}
       
   178 
       
   179 
       
   180 LOCAL_C void DoE32MainL()
       
   181 	{
       
   182 	__UHEAP_MARK;
       
   183 
       
   184 	Test();
       
   185 	TestINC090073();
       
   186 	OOMTest();
       
   187 
       
   188 	__UHEAP_MARKEND;
       
   189 	}
       
   190 
       
   191 GLDEF_C TInt E32Main()
       
   192 	{
       
   193 	__UHEAP_MARK;
       
   194 
       
   195 	test.Title();
       
   196 	test.Start(_L("CP932 test..."));
       
   197 
       
   198 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   199 	TRAPD(error, DoE32MainL());
       
   200 	test(error==KErrNone);
       
   201 
       
   202 	delete trapCleanup;
       
   203 
       
   204 	test.End();
       
   205 	test.Close();
       
   206 
       
   207 	__UHEAP_MARKEND;
       
   208 	return error;
       
   209 	}