sl@0: /* sl@0: * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "T_CP932.h" sl@0: #include sl@0: sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: sl@0: sl@0: _LIT16(Uni_1, "\x0053\x0059\x004D\x3125\x6349\xAAAA\x9673\x9ED1\x3000\xFF9F"); sl@0: _LIT8(CP932_1, "\x53\x59\x4D\x5F\x91\xA8\x5F\x92\xC2\xEE\xEC\x81\x40\xDF"); sl@0: _LIT16(Uni_2, "\x0032\x0070\xFFFD\xFF61\x8D77\xFFFD\xFFFD"); sl@0: _LIT8(CP932_2, "\x32\x70\x80\xA1\x8B\x4E\xA0\x96\x7F"); sl@0: _LIT16(Uni_3, "\x4E00\x5141\x674F\x95C7\x58F1"); sl@0: _LIT8(CP932_3, "\x88\xEA\x88\xF2\x88\xC7\x88\xC5\x88\xEB"); sl@0: sl@0: _LIT(KName,"CP932"); sl@0: const TUid KPluginUid={0x10206A92}; sl@0: sl@0: sl@0: // Used for supressing warning in OOM tests sl@0: #define __UNUSED_VAR(var) var = var sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1779 sl@0: @SYMTestCaseDesc Tests API behaviours of UnicodeConv class sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for conversions from/to Unicode, using a function pointer sl@0: @SYMTestExpectedResults Test must not fail sl@0: */ sl@0: void CT_CP932::TestL() sl@0: { sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1779 ")); sl@0: RLibrary lib; sl@0: sl@0: const TUidType serverUid(KNullUid,KNullUid,KPluginUid); sl@0: // load the dll sl@0: TInt returnValue = lib.Load(KName,serverUid); sl@0: test(returnValue==0); sl@0: sl@0: // get a pointer to the specified ordinal function and call it sl@0: TLibraryFunction function1 = lib.Lookup(1); sl@0: TLibraryFunction function2 = lib.Lookup(2); sl@0: TLibraryFunction function3 = lib.Lookup(3); sl@0: sl@0: //cast the function pointer f to a function of type void with two arguments sl@0: typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); sl@0: TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast (function1); sl@0: sl@0: typedef void (*TConvertToUnicodeL)(TDes16&, const TDesC8&); sl@0: TConvertToUnicodeL aConvertToUnicodeL = reinterpret_cast (function2); sl@0: sl@0: typedef TBool (*TIsLegalShortNameCharacter)(TUint); sl@0: TIsLegalShortNameCharacter aIsLegalShortNameCharacter = reinterpret_cast (function3); sl@0: sl@0: sl@0: TBuf8<15> foreign1; sl@0: TBuf8<15> foreign3; sl@0: TBuf16<15> unicode2; sl@0: sl@0: const TDesC16& unicode1(Uni_1); sl@0: (*aConvertFromUnicodeL)(foreign1, unicode1); //testing conversion from Unicode sl@0: TInt error = foreign1.Compare(CP932_1); sl@0: test(error==0); sl@0: foreign1.Zero(); sl@0: sl@0: const TDesC16& unicode3(Uni_3); sl@0: (*aConvertFromUnicodeL)(foreign3, unicode3); //testing conversion from Unicode for INC112715 sl@0: error = foreign3.Compare(CP932_3); sl@0: test(error==0); sl@0: foreign3.Zero(); sl@0: sl@0: const TDesC8& foreign2(CP932_2); sl@0: (*aConvertToUnicodeL)(unicode2,foreign2); //testing conversion to Unicode sl@0: error = unicode2.Compare(Uni_2); sl@0: test(error==0); sl@0: unicode2.Zero(); sl@0: sl@0: sl@0: //testing for legal short name character sl@0: TInt result = (*aIsLegalShortNameCharacter)(0x005F); //testing for existent character sl@0: test(result==1); sl@0: result = (*aIsLegalShortNameCharacter)(0x003F); //testing for illegal character sl@0: test(result==0); sl@0: result = (*aIsLegalShortNameCharacter)(0x2999); //testing for non-existent character sl@0: test(result==0); sl@0: result = (*aIsLegalShortNameCharacter)(0xFF61); //testing for a double byte character sl@0: test(result==1); sl@0: sl@0: lib.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-FATCHARSETCONV-CT-1847 sl@0: @SYMTestCaseDesc Tests API behaviours of UnicodeConv class as part of INC090073 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for correct character conversion on certain chinese characters sl@0: @SYMTestExpectedResults Test must not fail sl@0: */ sl@0: void CT_CP932::TestINC090073L() sl@0: { sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FATCHARSETCONV-CT-1847 ")); sl@0: _LIT16(unicode, "\x6DFC\x715C\x9785\x7A37\x61A9\x80B1\x86A3\x7B71\x6615\x6600"); sl@0: _LIT8(CP932Code, "\xED\xE6\xED\xF6\xE8\xD7\xE2\x6C\x8C\x65\x8D\x6E\xE5\x6E\xE2\xAA\xED\xB3\xED\xB2"); sl@0: sl@0: RLibrary lib; sl@0: sl@0: const TUidType serverUid(KNullUid,KNullUid,KPluginUid); sl@0: // load the dll sl@0: TInt returnValue = lib.Load(KName,serverUid); sl@0: test(returnValue==0); sl@0: sl@0: // get a pointer to the specified ordinal function and call it sl@0: TLibraryFunction function1 = lib.Lookup(1); sl@0: sl@0: sl@0: //cast the function pointer f to a function of type void with two arguments sl@0: typedef void (*TConvertFromUnicodeL)(TDes8&, const TDesC16&); sl@0: TConvertFromUnicodeL aConvertFromUnicodeL = reinterpret_cast (function1); sl@0: sl@0: TBuf8<20> foreign1; sl@0: sl@0: const TDesC16& unicode1(unicode); sl@0: (*aConvertFromUnicodeL)(foreign1, unicode1); //testing conversion from Unicode sl@0: TInt error = foreign1.Compare(CP932Code); sl@0: test(error==0); sl@0: foreign1.Zero(); sl@0: sl@0: lib.Close(); sl@0: } sl@0: sl@0: void CT_CP932::OOMTestL() sl@0: { sl@0: INFO_PRINTF1(_L("OOM testing")); sl@0: TInt err, tryCount = 0; sl@0: do sl@0: { sl@0: __UHEAP_MARK; sl@0: // find out the number of open handles sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: // Setting Heap failure for OOM test sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); sl@0: sl@0: TRAP(err,TestL()); sl@0: sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: test(startProcessHandleCount == endProcessHandleCount); sl@0: test(startThreadHandleCount == endThreadHandleCount); sl@0: sl@0: __UHEAP_MARKEND; sl@0: }while (err == KErrNoMemory); sl@0: sl@0: test(err == KErrNone); sl@0: INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"), tryCount); sl@0: } sl@0: sl@0: sl@0: CT_CP932::CT_CP932() sl@0: { sl@0: SetTestStepName(KTestStep_T_CP932); sl@0: } sl@0: sl@0: sl@0: TVerdict CT_CP932::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(error1, TestL()); sl@0: TRAPD(error2, TestINC090073L()); sl@0: TRAPD(error3, OOMTestL()); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if(error1 == KErrNone && error2 == KErrNone && error3 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }