sl@0: // Copyright (c) 2002-2009 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: // This file contains the test steps for Unit Test Suite 03 : Filename.cpp sl@0: // sl@0: // sl@0: sl@0: // EPOC includes sl@0: #include sl@0: sl@0: // Test system includes sl@0: #include sl@0: sl@0: // Specific includes for this test suite sl@0: #include "TSU_MmTsthStep03.h" sl@0: #include "TSU_MmTsthSuite03.h" sl@0: sl@0: // Specific includes for these test steps sl@0: #include "TSU_MmTsth03.h" sl@0: #include "TestFramework/Filename.h" sl@0: sl@0: // -------------------------------------------- sl@0: sl@0: // Unit Test Suite 03 : Filename.cpp sl@0: // Depends on : none sl@0: sl@0: // Tests :- sl@0: // 1. Allocate and deallocate an object sl@0: // 2. Test assignment overloads sl@0: // 3. Test copy overloads sl@0: // 4. Test locate sl@0: // 5. Test slicing (Left) sl@0: // 11. Test data scope sl@0: sl@0: // --------------------- sl@0: // RTestMmTsthU0301 sl@0: sl@0: RTestMmTsthU0301* RTestMmTsthU0301::NewL() sl@0: { sl@0: RTestMmTsthU0301* self = new(ELeave) RTestMmTsthU0301; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU0301::RTestMmTsthU0301() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-0301"); sl@0: } sl@0: sl@0: // preamble sl@0: TVerdict RTestMmTsthU0301::OpenL() sl@0: { sl@0: // stub - to avoid calling RTestStep_MM_TSTH_U_03::OpenL() which sl@0: // initialises iFileName sl@0: return iTestStepResult = EPass; sl@0: } sl@0: sl@0: // postamble sl@0: void RTestMmTsthU0301::Close() sl@0: { sl@0: } sl@0: sl@0: // do the test step. sl@0: TVerdict RTestMmTsthU0301::DoTestStepL() sl@0: { sl@0: // NB this test is the test for NewL() therefore it uses sl@0: // a stubbed preamble / postamble sl@0: sl@0: INFO_PRINTF1(_L("Create a CFileName")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: // create a CFileName with NewL sl@0: CFileName* theFileName = NULL; sl@0: TRAPD(err, theFileName = CFileName::NewL()); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CFileName::NewL left with code %d"), err); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: INFO_PRINTF1(_L("CFileName::NewL succeeded")); sl@0: delete theFileName; sl@0: sl@0: // create a CFileName with NewLC sl@0: CFileName* theLCFileName = NULL; sl@0: TRAPD(err2, theLCFileName = CFileName::NewLC(); sl@0: CleanupStack::Pop(theLCFileName) ); sl@0: if(err2 != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CFileName::NewLC left with code %d"), err2); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("CFileName::NewLC succeeded")); sl@0: delete theLCFileName; sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // ------------------------ sl@0: // RTestMmTsthU0302 sl@0: RTestMmTsthU0302* RTestMmTsthU0302::NewL() sl@0: { sl@0: RTestMmTsthU0302* self = new(ELeave) RTestMmTsthU0302; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU0302::RTestMmTsthU0302() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-0302"); sl@0: } sl@0: sl@0: // do the test step. sl@0: TVerdict RTestMmTsthU0302::DoTestStepL() sl@0: { sl@0: const TInt KTestBufSize = 48; // allocate enough space for test strings sl@0: sl@0: INFO_PRINTF1(_L("Test CFileName assign overloads")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: // test against TPtrC sl@0: TPtrC testTPtrCStr = _L("Test TPtrC String"); sl@0: *iFileName = testTPtrCStr; sl@0: if(testTPtrCStr != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // test against TDesC sl@0: TBufC testTDesCStr = _L("Test TDesC String"); sl@0: *iFileName = testTDesCStr; sl@0: if(testTDesCStr != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::operator=(const TDesC&) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // test against TFileName sl@0: TFileName testTFileNameStr = _L("Test TFileName String"); sl@0: *iFileName = testTFileNameStr; sl@0: if(testTFileNameStr != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::operator=(const TFileName&) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // test against TText* sl@0: const TText* testTTextStr = _S("Test TText String\0"); sl@0: *iFileName = testTTextStr; sl@0: // convert testTTextStr for comparison purposes sl@0: TBuf testCompTTextStr(testTTextStr); sl@0: if(testCompTTextStr != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::operator=(const TText*) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // test against self sl@0: CFileName* testCFileName = CFileName::NewL(); sl@0: *testCFileName = _L("Test CFileName String"); sl@0: *iFileName = *testCFileName; sl@0: if(testCFileName->FileName() != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::operator=(const CFileName&) failed")); sl@0: delete testCFileName; sl@0: return iTestStepResult = EFail; sl@0: } sl@0: delete testCFileName; sl@0: sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: sl@0: } sl@0: sl@0: // ------------------------ sl@0: // RTestMmTsthU0303 sl@0: sl@0: RTestMmTsthU0303* RTestMmTsthU0303::NewL() sl@0: { sl@0: RTestMmTsthU0303* self = new(ELeave) RTestMmTsthU0303; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU0303::RTestMmTsthU0303() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-0303"); sl@0: } sl@0: sl@0: // do the test step. sl@0: TVerdict RTestMmTsthU0303::DoTestStepL() sl@0: { sl@0: const TInt KTestBufSize = 48; // allocate enough space for test strings sl@0: sl@0: INFO_PRINTF1(_L("Test CFileName::Copy")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: // test against TDesC8 sl@0: TBufC8 testTDesC8Str = _L8("Test TDesC8 String"); sl@0: iFileName->Copy(testTDesC8Str); sl@0: // convert testTDesC8Str for comparison purposes sl@0: TBuf16 testCompTDesC8Str = _L16("Test TDesC8 String"); sl@0: if(testCompTDesC8Str != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::Copy(const TDesC8&) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // test against TDesC16 sl@0: TBufC16 testTDesC16Str = _L16("Test TDesC16 String"); sl@0: iFileName->Copy(testTDesC16Str); sl@0: if(testTDesC16Str != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::Copy(const TDesC16&) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // test against TUint16* with length sl@0: const TUint16* testTUint16Str = _S16("Test TUint16 String"); sl@0: // convert testTUint16Str for comparison purposes sl@0: TBuf16 testCompTUint16Str(testTUint16Str); sl@0: iFileName->Copy(testTUint16Str, testCompTUint16Str.Length()); sl@0: const TDesC& iFileNameLeft = iFileName->FileName().Left(testCompTUint16Str.Length()); sl@0: if(testCompTUint16Str != iFileNameLeft) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::Copy(const TUint16*, int) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // test against TUint16* zero terminated sl@0: const TUint16* testTUint16ZStr = _S16("Test TUint16Z String\0"); sl@0: iFileName->Copy(testTUint16ZStr); sl@0: // convert testTUint16Str for comparison purposes sl@0: TBuf16 testCompTUint16ZStr(testTUint16ZStr); sl@0: if(testCompTUint16ZStr != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::Copy(const TUint16*) failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: sl@0: } sl@0: sl@0: // ------------------------ sl@0: // RTestMmTsthU0304 sl@0: RTestMmTsthU0304* RTestMmTsthU0304::NewL() sl@0: { sl@0: RTestMmTsthU0304* self = new(ELeave) RTestMmTsthU0304; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU0304::RTestMmTsthU0304() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-0304"); sl@0: } sl@0: sl@0: // Do the test step. sl@0: TVerdict RTestMmTsthU0304::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Test CFileName::Locate")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: // test is inconclusive if the assignment fails sl@0: TPtrC testLocateStr = _L("ABCDEFG"); sl@0: *iFileName = testLocateStr; sl@0: if(testLocateStr != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test")); sl@0: return iTestStepResult = EInconclusive; sl@0: } sl@0: TInt rc = iFileName->Locate('C'); sl@0: if(rc != 2) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::Locate() failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: rc = iFileName->Locate('Z'); sl@0: if(rc != KErrNotFound) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::Locate() failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // ------------------------ sl@0: // RTestMmTsthU0305 sl@0: sl@0: RTestMmTsthU0305* RTestMmTsthU0305::NewL() sl@0: { sl@0: RTestMmTsthU0305* self = new(ELeave) RTestMmTsthU0305; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU0305::RTestMmTsthU0305() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-0305"); sl@0: } sl@0: sl@0: // Do the test step. sl@0: TVerdict RTestMmTsthU0305::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Test CFileName::Left")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: // test is inconclusive if the assignment fails sl@0: TPtrC testLocateStr = _L("ABCDEFG"); sl@0: *iFileName = testLocateStr; sl@0: if(testLocateStr != iFileName->FileName()) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::operator=(const TPtrC&) failed in Locate Test")); sl@0: return iTestStepResult = EInconclusive; sl@0: } sl@0: const TFileName& iFileNameLeft = iFileName->Left(3); sl@0: TPtrC testLeftStr = _L("ABC"); sl@0: sl@0: if(testLeftStr != iFileNameLeft) sl@0: { sl@0: ERR_PRINTF1(_L("CFileName::Left() failed")); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: sl@0: } sl@0: sl@0: // ------------------------ sl@0: // RTestMmTsthU0311 sl@0: RTestMmTsthU0311* RTestMmTsthU0311::NewL() sl@0: { sl@0: RTestMmTsthU0311* self = new(ELeave) RTestMmTsthU0311; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU0311::RTestMmTsthU0311() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-0311"); sl@0: } sl@0: sl@0: // Do the test step. sl@0: TVerdict RTestMmTsthU0311::DoTestStepL() sl@0: { sl@0: const TInt KTestBufSize = 48; // allocate enough space for test strings sl@0: sl@0: INFO_PRINTF1(_L("Test CFileName memory scope")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: // send original copied string out of scope, to prove that CFileName sl@0: // is using its own data space sl@0: TPtr16 testDynTDesCStr(REINTERPRET_CAST(TUint16*,User::AllocLC(KTestBufSize*2)), 0, KTestBufSize); sl@0: testDynTDesCStr = _L("Test TDesC String"); sl@0: *iFileName = testDynTDesCStr; sl@0: sl@0: CleanupStack::PopAndDestroy(); // testDynTDesCStr sl@0: sl@0: // if iFileName->FileName() is out of scope, this will panic with USER 7. If it doesn't, we've passed sl@0: TPtrC resStr = iFileName->FileName(); sl@0: INFO_PRINTF2(_L("CFileName::FileName() is '%S'"), &resStr); sl@0: sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: sl@0: }