userlibandfileserver/fatfilenameconversionplugins/test/T_CP949.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_CP949.exe"));
       
    23 
       
    24 _LIT16(Uni_1, "\xFFFF\x0053\x0059\x004D\x0042\x0049\x0041\x004E\xAC21\xC6AA\xFFFF\x9673\x8A70");
       
    25 _LIT8(CP949_1, "\x5F\x53\x59\x4D\x42\x49\x41\x4E\x81\x4D\x9F\x42\x5F\xF2\xE7\xFD\xFE");
       
    26 _LIT16(Uni_2, "\xFFFD\x005F\x304A\xFFFD\xFFFD");
       
    27 _LIT8(CP949_2, "\xAA\x40\x5F\xAA\xAA\xFF\xFE");
       
    28 
       
    29 _LIT(KName,"CP949");
       
    30 const TUid KPluginUid={0x10206A90};
       
    31 
       
    32 
       
    33 // Used for supressing warning in OOM tests
       
    34 #define __UNUSED_VAR(var) var = var
       
    35 
       
    36 /**
       
    37 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1777
       
    38 @SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class
       
    39 @SYMTestPriority 	    High
       
    40 @SYMTestActions  	    Tests for conversions from/to Unicode, using a function pointer
       
    41 @SYMTestExpectedResults Test must not fail
       
    42 */
       
    43 void Test()
       
    44 	{
       
    45 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1777 "));
       
    46 	RLibrary lib;
       
    47 
       
    48 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
       
    49 	// load the dll
       
    50 	TInt returnValue = lib.Load(KName,serverUid);
       
    51 	test(returnValue==0);
       
    52 
       
    53 	// get a pointer to the specified ordinal function and call it
       
    54 	TLibraryFunction function1 = lib.Lookup(1);
       
    55 	TLibraryFunction function2 = lib.Lookup(2);
       
    56 	TLibraryFunction function3 = lib.Lookup(3);
       
    57 
       
    58 	//cast the function pointer f to a function of type void with two arguments
       
    59 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
       
    60 	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
    61 
       
    62 	typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&);
       
    63 	TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2);
       
    64 
       
    65 	typedef TBool (*TIsLegalShortNameCharacter)(TUint);
       
    66 	TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3);
       
    67 
       
    68 
       
    69 	TBuf8<20> foreign1;
       
    70 	TBuf16<15> unicode2;
       
    71 
       
    72 	const TDesC16& unicode1(Uni_1);
       
    73 	TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); 	//testing conversion from Unicode
       
    74 	test(err==0);
       
    75 	TInt error = foreign1.Compare(CP949_1);
       
    76 	test(error==0);
       
    77 	foreign1.Zero();
       
    78 
       
    79 	const TDesC8& foreign2(CP949_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)(0xAC02); //testing for double byte character
       
    94 	test(result==1);
       
    95 
       
    96 	lib.Close();
       
    97 	}
       
    98 
       
    99 /**
       
   100 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1847-0002
       
   101 @SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class as part of INC090073
       
   102 @SYMTestPriority 	    High
       
   103 @SYMTestActions  	    Tests for correct character conversion on certain chinese characters for CP936
       
   104 @SYMTestExpectedResults Test must not fail
       
   105 */
       
   106 void TestINC090073()
       
   107 	{
       
   108 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847-0002 "));
       
   109  	_LIT16(unicode, "\x715C\x7A37\x61A9\x80B1\x86A3\x6B46\x6615");
       
   110 	_LIT8(CP932Code, "\xE9\xF2\xF2\xC3\xCC\xA8\xCE\xDD\xCD\xF7\xFD\xE4\xFD\xDA");
       
   111 
       
   112 	RLibrary lib;
       
   113 
       
   114 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
       
   115 	// load the dll
       
   116 	TInt returnValue = lib.Load(KName,serverUid);
       
   117 	test(returnValue==0);
       
   118 
       
   119 	// get a pointer to the specified ordinal function and call it
       
   120 	TLibraryFunction function1 = lib.Lookup(1);
       
   121 
       
   122 
       
   123 	//cast the function pointer f to a function of type void with two arguments
       
   124 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
       
   125 	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
   126 
       
   127 	TBuf8<15> foreign1;
       
   128 
       
   129 	foreign1.Zero();
       
   130 	const TDesC16& unicode1(unicode);
       
   131 	TRAPD(err,(*aConvertFromUnicodeL)(foreign1, unicode1)); 	//testing conversion from Unicode
       
   132 	test(err==0);
       
   133 	TInt error = foreign1.Compare(CP932Code);
       
   134 	test(error==0);
       
   135 	foreign1.Zero();
       
   136 
       
   137 	lib.Close();
       
   138 	}
       
   139 
       
   140 void OOMTest()
       
   141 	{
       
   142 	test.Next(_L("OOM testing"));
       
   143 	TInt err, tryCount = 0;
       
   144 	do
       
   145 		{
       
   146 			__UHEAP_MARK;
       
   147   		// find out the number of open handles
       
   148 		TInt startProcessHandleCount;
       
   149 		TInt startThreadHandleCount;
       
   150 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   151 
       
   152 			// Setting Heap failure for OOM test
       
   153 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   154 
       
   155 		TRAP(err,Test());
       
   156 
       
   157 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   158 
       
   159 		// check that no handles have leaked
       
   160 		TInt endProcessHandleCount;
       
   161 		TInt endThreadHandleCount;
       
   162 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   163 
       
   164 		test(startProcessHandleCount == endProcessHandleCount);
       
   165 		test(startThreadHandleCount  == endThreadHandleCount);
       
   166 
       
   167 		__UHEAP_MARKEND;
       
   168 		}while (err == KErrNoMemory);
       
   169 
       
   170 	test(err == KErrNone);
       
   171 	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   172 	}
       
   173 
       
   174 
       
   175 LOCAL_C void DoE32MainL()
       
   176 	{
       
   177 	__UHEAP_MARK;
       
   178 
       
   179 	Test();
       
   180 	TestINC090073();
       
   181 	OOMTest();
       
   182 
       
   183 	__UHEAP_MARKEND;
       
   184 	}
       
   185 
       
   186 GLDEF_C TInt E32Main()
       
   187 	{
       
   188 	__UHEAP_MARK;
       
   189 
       
   190 	test.Title();
       
   191 	test.Start(_L("CP949 test..."));
       
   192 
       
   193 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   194 	TRAPD(error, DoE32MainL());
       
   195 	test(error==KErrNone);
       
   196 
       
   197 	delete trapCleanup;
       
   198 
       
   199 	test.End();
       
   200 	test.Close();
       
   201 
       
   202 	__UHEAP_MARKEND;
       
   203 	return error;
       
   204 	}