charconvfw/fatfilenameconversionplugins/test/T_CP1257.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_CP1257.exe"));
       
    23 
       
    24 _LIT16(Uni_1, "\x0053\x0059\x004D\x0042\x0049\x0041\x004E\x3125\x02DB\xFFFF");
       
    25 _LIT8(CP1257_1, "\x53\x59\x4D\x42\x49\x41\x4E\x5F\x9E\x5F");
       
    26 _LIT16(Uni_2, "\x0032\x0070\x20AC\x012E\xFFFD\x00A7");
       
    27 _LIT8(CP1257_2, "\x32\x70\x80\xC1\x81\xA7");
       
    28 
       
    29 _LIT(KName,"CP1257");
       
    30 const TUid KPluginUid={0x10206A95};
       
    31 
       
    32 
       
    33 // Used for supressing warning in OOM tests
       
    34 #define __UNUSED_VAR(var) var = var
       
    35 
       
    36 /**
       
    37 @SYMTestCaseID          SYSLIB-FATCHARSETCONV-CT-1782
       
    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(CP1257_1);
       
    74 	test(error==0);
       
    75 	foreign1.Zero();
       
    76 
       
    77 	const TDesC8& foreign2(CP1257_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-1782 CP1257 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 	}