charconvfw/fatfilenameconversionplugins/test/T_CP1258.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_CP1258.exe"));
       
    23 
       
    24 _LIT16(Uni_1, "\x006D\xAAAA\x00DC\x0111\x20AC\xFFFF\x0070");
       
    25 _LIT8(CP1258_1, "\x6D\x5F\xDC\xF0\x80\x5F\x70");
       
    26 _LIT16(Uni_2, "\x0017\x005F\x201A\x00A0\x0303");
       
    27 _LIT8(CP1258_2, "\x17\x5F\x82\xA0\xDE");
       
    28 
       
    29 
       
    30 _LIT(KName,"CP1258");
       
    31 const TUid KPluginUid={0x10206A94};
       
    32 
       
    33 
       
    34 // Used for supressing warning in OOM tests
       
    35 #define __UNUSED_VAR(var) var = var
       
    36 
       
    37 /**
       
    38 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1781
       
    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 	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<20> unicode2;
       
    71 
       
    72 	const TDesC16& unicode1(Uni_1);
       
    73 	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
       
    74 	TInt error = foreign1.Compare(CP1258_1);
       
    75 	test(error==0);
       
    76 	foreign1.Zero();
       
    77 
       
    78 	const TDesC8& foreign2(CP1258_2);
       
    79 	(*aConvertToUnicodeL)(unicode2,foreign2); 	//testing conversion to Unicode
       
    80 	error = unicode2.Compare(Uni_2);
       
    81 	test(error==0);
       
    82 	unicode2.Zero();
       
    83 
       
    84 
       
    85 	//testing for legal short name character
       
    86 	TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character
       
    87 	test(result==1);
       
    88 	result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character
       
    89 	test(result==0);
       
    90 	result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character
       
    91 	test(result==0);
       
    92 
       
    93 	lib.Close();
       
    94 	}
       
    95 
       
    96 void OOMTest()
       
    97 	{
       
    98 	test.Next(_L("OOM testing"));
       
    99 	TInt err, tryCount = 0;
       
   100 	do
       
   101 		{
       
   102 			__UHEAP_MARK;
       
   103   		// find out the number of open handles
       
   104 		TInt startProcessHandleCount;
       
   105 		TInt startThreadHandleCount;
       
   106 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   107 
       
   108 			// Setting Heap failure for OOM test
       
   109 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   110 
       
   111 		TRAP(err,Test());
       
   112 
       
   113 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   114 
       
   115 		// check that no handles have leaked
       
   116 		TInt endProcessHandleCount;
       
   117 		TInt endThreadHandleCount;
       
   118 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   119 
       
   120 		test(startProcessHandleCount == endProcessHandleCount);
       
   121 		test(startThreadHandleCount  == endThreadHandleCount);
       
   122 
       
   123 		__UHEAP_MARKEND;
       
   124 		}while (err == KErrNoMemory);
       
   125 
       
   126 	test(err == KErrNone);
       
   127 	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   128 	}
       
   129 
       
   130 
       
   131 LOCAL_C void DoE32MainL()
       
   132 	{
       
   133 	Test();
       
   134 	OOMTest();
       
   135 	}
       
   136 
       
   137 GLDEF_C TInt E32Main()
       
   138 	{
       
   139 	__UHEAP_MARK;
       
   140 
       
   141 	test.Title();
       
   142 	test.Start(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1781 CP1258 test... "));
       
   143 
       
   144 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   145 	TRAPD(error, DoE32MainL());
       
   146 	delete trapCleanup;
       
   147 
       
   148 	test.End();
       
   149 	test.Close();
       
   150 
       
   151 	__UHEAP_MARKEND;
       
   152 	return error;
       
   153 	}