userlibandfileserver/fatfilenameconversionplugins/test/T_CP1258.CPP
changeset 0 a41df078684a
child 2 4122176ea935
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <e32des8.h>
       
    18 
       
    19 LOCAL_D RTest test(_L("T_CP1258.exe"));
       
    20 
       
    21 _LIT16(Uni_1, "\x006D\xAAAA\x00DC\x0111\x20AC\xFFFF\x0070");
       
    22 _LIT8(CP1258_1, "\x6D\x5F\xDC\xF0\x80\x5F\x70");
       
    23 _LIT16(Uni_2, "\x0017\x005F\x201A\x00A0\x0303");
       
    24 _LIT8(CP1258_2, "\x17\x5F\x82\xA0\xDE");
       
    25 
       
    26 
       
    27 _LIT(KName,"CP1258");
       
    28 const TUid KPluginUid={0x10206A94};
       
    29 
       
    30 
       
    31 // Used for supressing warning in OOM tests
       
    32 #define __UNUSED_VAR(var) var = var
       
    33 
       
    34 /**
       
    35 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1781
       
    36 @SYMTestCaseDesc	    Tests API behaviours of UnicodeConv class
       
    37 @SYMTestPriority 	    High
       
    38 @SYMTestActions  	    Tests for conversions from/to Unicode, using a function pointer
       
    39 @SYMTestExpectedResults Test must not fail
       
    40 */
       
    41 void Test()
       
    42 	{
       
    43 	RLibrary lib;
       
    44 
       
    45 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
       
    46 	// load the dll
       
    47 	TInt returnValue = lib.Load(KName,serverUid);
       
    48 	test(returnValue==0);
       
    49 
       
    50 	// get a pointer to the specified ordinal function and call it
       
    51 	TLibraryFunction function1 = lib.Lookup(1);
       
    52 	TLibraryFunction function2 = lib.Lookup(2);
       
    53 	TLibraryFunction function3 = lib.Lookup(3);
       
    54 
       
    55 	//cast the function pointer f to a function of type void with two arguments
       
    56 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
       
    57 	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
    58 
       
    59 	typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&);
       
    60 	TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2);
       
    61 
       
    62 	typedef TBool (*TIsLegalShortNameCharacter)(TUint);
       
    63 	TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3);
       
    64 
       
    65 
       
    66 	TBuf8<20> foreign1;
       
    67 	TBuf16<20> unicode2;
       
    68 
       
    69 	const TDesC16& unicode1(Uni_1);
       
    70 	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
       
    71 	TInt error = foreign1.Compare(CP1258_1);
       
    72 	test(error==0);
       
    73 	foreign1.Zero();
       
    74 
       
    75 	const TDesC8& foreign2(CP1258_2);
       
    76 	(*aConvertToUnicodeL)(unicode2,foreign2); 	//testing conversion to Unicode
       
    77 	error = unicode2.Compare(Uni_2);
       
    78 	test(error==0);
       
    79 	unicode2.Zero();
       
    80 
       
    81 
       
    82 	//testing for legal short name character
       
    83 	TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character
       
    84 	test(result==1);
       
    85 	result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character
       
    86 	test(result==0);
       
    87 	result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character
       
    88 	test(result==0);
       
    89 
       
    90 	lib.Close();
       
    91 	}
       
    92 
       
    93 void OOMTest()
       
    94 	{
       
    95 	test.Next(_L("OOM testing"));
       
    96 	TInt err, tryCount = 0;
       
    97 	do
       
    98 		{
       
    99 			__UHEAP_MARK;
       
   100   		// find out the number of open handles
       
   101 		TInt startProcessHandleCount;
       
   102 		TInt startThreadHandleCount;
       
   103 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   104 
       
   105 			// Setting Heap failure for OOM test
       
   106 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   107 
       
   108 		TRAP(err,Test());
       
   109 
       
   110 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   111 
       
   112 		// check that no handles have leaked
       
   113 		TInt endProcessHandleCount;
       
   114 		TInt endThreadHandleCount;
       
   115 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   116 
       
   117 		test(startProcessHandleCount == endProcessHandleCount);
       
   118 		test(startThreadHandleCount  == endThreadHandleCount);
       
   119 
       
   120 		__UHEAP_MARKEND;
       
   121 		}while (err == KErrNoMemory);
       
   122 
       
   123 	test(err == KErrNone);
       
   124 	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   125 	}
       
   126 
       
   127 
       
   128 LOCAL_C void DoE32MainL()
       
   129 	{
       
   130 	Test();
       
   131 	OOMTest();
       
   132 	}
       
   133 
       
   134 GLDEF_C TInt E32Main()
       
   135 	{
       
   136 	__UHEAP_MARK;
       
   137 
       
   138 	test.Title();
       
   139 	test.Start(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1781 CP1258 test... "));
       
   140 
       
   141 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   142 	TRAPD(error, DoE32MainL());
       
   143 	delete trapCleanup;
       
   144 
       
   145 	test.End();
       
   146 	test.Close();
       
   147 
       
   148 	__UHEAP_MARKEND;
       
   149 	return error;
       
   150 	}