userlibandfileserver/fatfilenameconversionplugins/test/T_CP1254.CPP
branchanywhere
changeset 41 d32f34975bbf
parent 40 04a1b74efd48
parent 37 a9bf1d2c555e
child 48 10816385149a
equal deleted inserted replaced
40:04a1b74efd48 41:d32f34975bbf
     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_CP1254.exe"));
       
    23 
       
    24 _LIT16(Uni_1, "\x0053\x0059\x004D\x0042\x0049\x0041\x004E\xFFFF\x20AC\x00E8\x017B");
       
    25 _LIT8(CP1254_1, "\x53\x59\x4D\x42\x49\x41\x4E\x5F\x80\xE8\x5F");
       
    26 _LIT16(Uni_2, "\x00A1\x02DC\x00AD\xFFFD");
       
    27 _LIT8(CP1254_2, "\xA1\x98\xAD\x90");
       
    28 
       
    29 _LIT(KName,"CP1254");
       
    30 const TUid KPluginUid={0x10206A98};
       
    31 
       
    32 
       
    33 // Used for supressing warning in OOM tests
       
    34 #define __UNUSED_VAR(var) var = var
       
    35 
       
    36 /**
       
    37 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1785
       
    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 	RLibrary lib;
       
    46 
       
    47 	const TUidType serverUid(KNullUid,KNullUid,KPluginUid);
       
    48 	// load the dll
       
    49 	TInt returnValue = lib.Load(KName,serverUid);
       
    50 	test(returnValue==0);
       
    51 
       
    52 	// get a pointer to the specified ordinal function and call it
       
    53 	TLibraryFunction function1 = lib.Lookup(1);
       
    54 	TLibraryFunction function2 = lib.Lookup(2);
       
    55 	TLibraryFunction function3 = lib.Lookup(3);
       
    56 
       
    57 	//cast the function pointer f to a function of type void with two arguments
       
    58 	typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&);
       
    59 	TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast <TConvertFromUnicodeL> (function1);
       
    60 
       
    61 	typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&);
       
    62 	TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast <TConvertToUnicodeL> (function2);
       
    63 
       
    64 	typedef TBool (*TIsLegalShortNameCharacter)(TUint);
       
    65 	TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast <TIsLegalShortNameCharacter> (function3);
       
    66 
       
    67 
       
    68 	TBuf8<15> foreign1;
       
    69 	TBuf16<15> unicode2;
       
    70 
       
    71 	const TDesC16& unicode1(Uni_1);
       
    72 	(*aConvertFromUnicodeL)(foreign1, unicode1); 	//testing conversion from Unicode
       
    73 	TInt error = foreign1.Compare(CP1254_1);
       
    74 	test(error==0);
       
    75 	foreign1.Zero();
       
    76 
       
    77 	const TDesC8& foreign2(CP1254_2);
       
    78 	(*aConvertToUnicodeL)(unicode2,foreign2); 	//testing conversion to Unicode
       
    79 	error = unicode2.Compare(Uni_2);
       
    80 	test(error==0);
       
    81 	unicode2.Zero();
       
    82 
       
    83 
       
    84 	//testing for legal short name character
       
    85 	TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character
       
    86 	test(result==1);
       
    87 	result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character
       
    88 	test(result==0);
       
    89 	result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character
       
    90 	test(result==0);
       
    91 
       
    92 	lib.Close();
       
    93 	}
       
    94 
       
    95 void OOMTest()
       
    96 	{
       
    97 	test.Next(_L("OOM testing"));
       
    98 	TInt err, tryCount = 0;
       
    99 	do
       
   100 		{
       
   101 			__UHEAP_MARK;
       
   102   		// find out the number of open handles
       
   103 		TInt startProcessHandleCount;
       
   104 		TInt startThreadHandleCount;
       
   105 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   106 
       
   107 			// Setting Heap failure for OOM test
       
   108 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   109 
       
   110 		TRAP(err,Test());
       
   111 
       
   112 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   113 
       
   114 		// check that no handles have leaked
       
   115 		TInt endProcessHandleCount;
       
   116 		TInt endThreadHandleCount;
       
   117 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   118 
       
   119 		test(startProcessHandleCount == endProcessHandleCount);
       
   120 		test(startThreadHandleCount  == endThreadHandleCount);
       
   121 
       
   122 		__UHEAP_MARKEND;
       
   123 		}while (err == KErrNoMemory);
       
   124 
       
   125 	test(err == KErrNone);
       
   126 	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   127 	}
       
   128 
       
   129 
       
   130 LOCAL_C void DoE32MainL()
       
   131 	{
       
   132 	Test();
       
   133 	OOMTest();
       
   134 	}
       
   135 
       
   136 
       
   137 GLDEF_C TInt E32Main()
       
   138 	{
       
   139 	__UHEAP_MARK;
       
   140 
       
   141 	test.Title();
       
   142 	test.Start(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1785 CP1254 Tests... "));
       
   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 	}