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_CP1257.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\x0042\x0049\x0041\x004E\x3125\x02DB\xFFFF"); sl@0: _LIT8(CP1257_1, "\x53\x59\x4D\x42\x49\x41\x4E\x5F\x9E\x5F"); sl@0: _LIT16(Uni_2, "\x0032\x0070\x20AC\x012E\xFFFD\x00A7"); sl@0: _LIT8(CP1257_2, "\x32\x70\x80\xC1\x81\xA7"); sl@0: sl@0: _LIT(KName,"CP1257"); sl@0: const TUid KPluginUid={0x10206A95}; 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-1782 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_CP1257::TestL() 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: 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: 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(CP1257_1); sl@0: test(error==0); sl@0: foreign1.Zero(); sl@0: sl@0: const TDesC8& foreign2(CP1257_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: sl@0: lib.Close(); sl@0: } sl@0: sl@0: void CT_CP1257::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_CP1257::CT_CP1257() sl@0: { sl@0: SetTestStepName(KTestStep_T_CP1257); sl@0: } sl@0: sl@0: sl@0: TVerdict CT_CP1257::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(error1, TestL()); sl@0: TRAPD(error2, OOMTestL()); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if(error1 == KErrNone && error2 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }