sl@0: // Copyright (c) 2004-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: // RPermanentFileStoreIter functionality tests sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("t_storiter")); sl@0: LOCAL_D CTrapCleanup *TheTrapCleanup; sl@0: LOCAL_D RFs TheFs; sl@0: sl@0: // This is a path specification and should not be used as is sl@0: _LIT(KFileLocationSpec, "Z:\\T_ITER1.DAT"); sl@0: const TInt KMaxTestStreamIds = 512; sl@0: LOCAL_D TStreamId StreamIds[KMaxTestStreamIds];//Test stream IDs - used in test functions sl@0: sl@0: //aCount - there should be aCount valid stream IDs in StreamIds array. sl@0: //The function aborts program's execution if aStreamId is not in StreamIds array. sl@0: LOCAL_C void AssertStreamId(TInt aCount, TStreamId aStreamId) sl@0: { sl@0: __ASSERT_DEBUG(aCount >= 0 && aCount < KMaxTestStreamIds, User::Invariant()); sl@0: TInt i = 0; sl@0: for(;(i= 0 && aCount < KMaxTestStreamIds, User::Invariant()); sl@0: TStreamId storeStreamIds[KMaxTestStreamIds]; sl@0: Mem::FillZ(storeStreamIds, sizeof(storeStreamIds)); sl@0: RPermanentFileStoreIter iter; sl@0: ::CleanupClosePushL(iter); sl@0: TInt count = 0; sl@0: iter.ResetL(aStore); sl@0: TStreamId id; sl@0: while((id = iter.NextL()) != KNullStreamIdValue) sl@0: { sl@0: //verifying that it is a valid stream ID sl@0: ::AssertValidStreamIdL(id, aStore); sl@0: //Save stream ID in storeStreamIds array sl@0: storeStreamIds[count++] = id; sl@0: //Assert stream ID sl@0: ::AssertStreamId(aCount, id); sl@0: } sl@0: test(count == aCount); sl@0: //Assert duplications sl@0: ::AssertStreamIdDuplication(storeStreamIds, count); sl@0: CleanupStack::PopAndDestroy(&iter); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1219 sl@0: @SYMTestCaseDesc CPermanentFileStore-StreamId iteration tests sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests by creating file store instance with stream count to zero. sl@0: Assert if StreamIds items and count don't match sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void Test1L() sl@0: { sl@0: test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1219 CPermanentFileStore-StreamId iteration tests - 1 ")); sl@0: //Create CPermanentFileStore instance. Stream count should be 0 sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: sl@0: RFile file; sl@0: test(file.Create(::TheFs, parse.FullName(), EFileWrite| EFileRead) == KErrNone); sl@0: CPermanentFileStore* store = CPermanentFileStore::NewLC(file); sl@0: store->SetTypeL(KPermanentFileStoreLayoutUid); sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 0); sl@0: //Create 1 stream. Stream count: 1 sl@0: RStoreWriteStream out; sl@0: ::StreamIds[0] = out.CreateLC(*store); sl@0: out.CommitL(); sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 1); sl@0: //Create 2 new streams. Stream count: 1 + 2 sl@0: RStoreWriteStream out2; sl@0: ::StreamIds[1] = out2.CreateLC(*store); sl@0: out2.CommitL(); sl@0: RStoreWriteStream out3; sl@0: ::StreamIds[2] = out3.CreateLC(*store); sl@0: out3.CommitL(); sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 3); sl@0: //Close 1 stream. Stream count: 3 sl@0: CleanupStack::PopAndDestroy(&out3); sl@0: ::AssertStreamIdsL(*store, 3); sl@0: //Delete 1 stream. Stream count: 2 sl@0: store->DeleteL(::StreamIds[2]); sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 2); sl@0: //Cleanup sl@0: CleanupStack::PopAndDestroy(&out2); sl@0: CleanupStack::PopAndDestroy(&out); sl@0: CleanupStack::PopAndDestroy(store); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1220 sl@0: @SYMTestCaseDesc CPermanentFileStore-StreamId iteration tests sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test by creating file store instance with stream count to two. sl@0: Assert if StreamIds items and count don't match sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void Test2L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1220 CPermanentFileStore-StreamId iteration tests - 2 ")); sl@0: sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: sl@0: //Create CPermanentFileStore instance with an existing store file . Stream count: 2 sl@0: CPermanentFileStore* store = CPermanentFileStore::OpenLC(::TheFs, parse.FullName(), EFileWrite | EFileRead); sl@0: store->SetTypeL(KPermanentFileStoreLayoutUid); sl@0: ::AssertStreamIdsL(*store, 2); sl@0: //Create new stream. Stream count: 3 sl@0: RStoreWriteStream out; sl@0: ::StreamIds[2] = out.CreateLC(*store); sl@0: out.CommitL(); sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 3); sl@0: //Create 2 new streams. Stream count: 3 + 2 sl@0: RStoreWriteStream out2; sl@0: ::StreamIds[3] = out2.CreateLC(*store); sl@0: out2.CommitL(); sl@0: RStoreWriteStream out3; sl@0: ::StreamIds[4] = out3.CreateLC(*store); sl@0: out3.CommitL(); sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 5); sl@0: //Cleanup sl@0: CleanupStack::PopAndDestroy(&out3); sl@0: CleanupStack::PopAndDestroy(&out2); sl@0: CleanupStack::PopAndDestroy(&out); sl@0: CleanupStack::PopAndDestroy(store); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1221 sl@0: @SYMTestCaseDesc CPermanentFileStore-StreamId iteration tests sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test by creating file store instance with stream count to five. sl@0: Assert if StreamIds items and count don't match.Read and test data from the streams sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void Test3L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1221 CPermanentFileStore-StreamId iteration tests - 3 ")); sl@0: sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: sl@0: //Create CPermanentFileStore instance with an existing store file . Stream count: 5 sl@0: CPermanentFileStore* store = CPermanentFileStore::OpenLC(::TheFs, parse.FullName(), EFileWrite | EFileRead); sl@0: store->SetTypeL(KPermanentFileStoreLayoutUid); sl@0: ::AssertStreamIdsL(*store, 5); sl@0: //Save some data to the streams. Stream count: 5 sl@0: RPermanentFileStoreIter iter; sl@0: iter.ResetLC(*store); sl@0: TStreamId id; sl@0: TInt i = 0; sl@0: while((id = iter.NextL()) != KNullStreamIdValue) sl@0: { sl@0: RStoreWriteStream out; sl@0: out.ReplaceLC(*store, id); sl@0: out << TInt32(++i); sl@0: out.CommitL(); sl@0: CleanupStack::PopAndDestroy(&out); sl@0: } sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 5); sl@0: CleanupStack::PopAndDestroy(&iter); sl@0: //Read and test data from the streams. Stream count: 5 sl@0: i = 0; sl@0: iter.ResetLC(*store); sl@0: while((id = iter.NextL()) != KNullStreamIdValue) sl@0: { sl@0: RStoreReadStream in; sl@0: in.OpenLC(*store, id); sl@0: TInt32 v = 0; sl@0: in >> v; sl@0: test(v == ++i); sl@0: CleanupStack::PopAndDestroy(&in); sl@0: } sl@0: //Cleanup sl@0: CleanupStack::PopAndDestroy(&iter); sl@0: CleanupStack::PopAndDestroy(store); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1222 sl@0: @SYMTestCaseDesc CPermanentFileStore-StreamId iteration tests sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test by creating file store instance with stream count to five and delete all the streams. sl@0: Assert if StreamIds items and count don't match sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void Test4L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1222 CPermanentFileStore-StreamId iteration tests - 4 ")); sl@0: sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: sl@0: //Create CPermanentFileStore instance with an existing store file . Stream count: 5 sl@0: CPermanentFileStore* store = CPermanentFileStore::OpenLC(::TheFs, parse.FullName(), EFileWrite | EFileRead); sl@0: store->SetTypeL(KPermanentFileStoreLayoutUid); sl@0: ::AssertStreamIdsL(*store, 5); sl@0: TInt i; sl@0: //Delete all streams sl@0: for(i=0;i<5;i++) sl@0: { sl@0: store->DeleteL(::StreamIds[i]); sl@0: } sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, 0); sl@0: //Create KMaxTestStreamIds/4 streams sl@0: for(i=0;i<(KMaxTestStreamIds/4);i++) sl@0: { sl@0: RStoreWriteStream out; sl@0: ::StreamIds[i] = out.CreateLC(*store); sl@0: out.CommitL(); sl@0: CleanupStack::PopAndDestroy(&out); sl@0: } sl@0: store->CommitL(); sl@0: ::AssertStreamIdsL(*store, KMaxTestStreamIds / 4); sl@0: //Delete last KMaxTestStreamIds/8 streams sl@0: for(i=(KMaxTestStreamIds/8);i<(KMaxTestStreamIds/4);i++) sl@0: { sl@0: store->DeleteL(::StreamIds[i]); sl@0: } sl@0: store->CommitL(); sl@0: //There are KMaxTestStreamIds/8 streams in store sl@0: ::AssertStreamIdsL(*store, KMaxTestStreamIds / 8); sl@0: //Create KMaxTestStreamIds/2 streams sl@0: for(i=(KMaxTestStreamIds/8);i<(KMaxTestStreamIds/8+KMaxTestStreamIds/2);i++) sl@0: { sl@0: RStoreWriteStream out; sl@0: ::StreamIds[i] = out.CreateLC(*store); sl@0: out.CommitL(); sl@0: CleanupStack::PopAndDestroy(&out); sl@0: } sl@0: store->CommitL(); sl@0: //There are KMaxTestStreamIds / 2 + KMaxTestStreamIds / 8 streams in store sl@0: ::AssertStreamIdsL(*store, KMaxTestStreamIds / 2 + KMaxTestStreamIds / 8); sl@0: //Delete first KMaxTestStreamIds/4 streams sl@0: for(i=0;i<(KMaxTestStreamIds/4);i++) sl@0: { sl@0: store->DeleteL(::StreamIds[i]); sl@0: } sl@0: store->CommitL(); sl@0: //There are KMaxTestStreamIds / 8 + KMaxTestStreamIds / 4 streams in store sl@0: Mem::Move(::StreamIds, &::StreamIds[KMaxTestStreamIds / 4], sizeof(TStreamId) * (KMaxTestStreamIds / 8 + KMaxTestStreamIds / 4)); sl@0: ::AssertStreamIdsL(*store, KMaxTestStreamIds / 8 + KMaxTestStreamIds / 4); sl@0: CleanupStack::PopAndDestroy(store); sl@0: } sl@0: sl@0: //Run tests sl@0: LOCAL_C void MainL() sl@0: { sl@0: ::Test1L(); sl@0: ::Test2L(); sl@0: ::Test3L(); sl@0: ::Test4L(); sl@0: test.End(); sl@0: } sl@0: sl@0: //Delete created/used store files. sl@0: LOCAL_C void Cleanup() sl@0: { sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: ::TheFs.Delete(parse.FullName()); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: ::TheTrapCleanup = CTrapCleanup::New(); sl@0: sl@0: __UHEAP_MARK; sl@0: test(::TheFs.Connect() == KErrNone); sl@0: sl@0: ::Cleanup(); sl@0: TRAPD(err, ::MainL()); sl@0: test(err == KErrNone); sl@0: test.Close(); sl@0: ::Cleanup(); sl@0: sl@0: ::TheFs.Close(); sl@0: __UHEAP_MARKEND; sl@0: delete ::TheTrapCleanup; sl@0: return 0; sl@0: } sl@0: