sl@0: // Copyright (c) 1998-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: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "U32STD.H" sl@0: sl@0: const TInt KTestCleanupStack=0x20; sl@0: sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup; sl@0: LOCAL_D RTest test(_L("t_storset")); sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1121 sl@0: @SYMTestCaseDesc TPagedSet class functionality test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests insert/delete/contains without duplicates. sl@0: Tests for emptying the set 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-1121 Insertion & Deletion ")); sl@0: sl@0: const TInt KEntryCount=200; sl@0: TPagedSet set; sl@0: set.Connect(CMemPagePool::NewLC()); sl@0: //IsIntact() and IsDirty() test sl@0: TBool rc = set.IsIntact(); sl@0: test(rc); sl@0: rc = set.IsDirty(); sl@0: test(!rc); sl@0: set.MarkDirty(); sl@0: rc = set.IsDirty(); sl@0: test(rc); sl@0: //IsBroken() test sl@0: rc = set.IsBroken(); sl@0: test(!rc); sl@0: set.MarkBroken(); sl@0: rc = set.IsBroken(); sl@0: test(!rc);//Empty tree - cannot be marked as broken sl@0: TInt yy = 10; sl@0: set.InsertL(yy); sl@0: set.MarkBroken(); sl@0: rc = set.IsBroken(); sl@0: test(rc); sl@0: set.RepairL(); sl@0: rc = set.IsBroken(); sl@0: test(!rc); sl@0: set.ClearL(); sl@0: rc = set.IsBroken(); sl@0: test(!rc); sl@0: sl@0: TInt32 it=0; sl@0: //* test(set.InsertL(it)); sl@0: set.InsertL(it); sl@0: test(set.Count()==1); sl@0: //* test(!set.InsertL(it)); sl@0: test(set.Count()==1); sl@0: test(set.ContainsL(it)); sl@0: //* test(set.DeleteL(it)); sl@0: set.DeleteL(it); sl@0: test(set.Count()==0); sl@0: //* test(!set.DeleteL(it)); sl@0: //* test(set.Count()==0); sl@0: test(!set.ContainsL(it)); sl@0: sl@0: //* test.Next(_L("Duplicates")); sl@0: TInt ii; sl@0: //* for (ii=0;ii set; sl@0: //* set.Connect(CMemPagePool::NewLC(),TBtree::EQosFastest); sl@0: set.Connect(CMemPagePool::NewLC()); sl@0: sl@0: test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1122 Add items ")); sl@0: TUint32 jj=0; sl@0: TInt32 ii; sl@0: for (ii=KEntryCount;ii>0;--ii) sl@0: { sl@0: jj=(jj+17)%KEntryCount; sl@0: //* test(set.InsertL(jj)); sl@0: set.InsertL(jj); sl@0: } sl@0: test(set.Count()==KEntryCount); sl@0: sl@0: test.Next(_L("Check contents")); sl@0: for (ii=0;ii iter(set); sl@0: if (iter.ResetL()) sl@0: { sl@0: do sl@0: { sl@0: TUint32 data1 = iter.AtL(); sl@0: ++checkMap[data1]; sl@0: TUint32 data2; sl@0: iter.ExtractAtL(data2); sl@0: test(data1 == data2); sl@0: }while(iter.NextL()); sl@0: } sl@0: for (ii=0;iiKEntryCount/2;--ii) sl@0: { sl@0: jj=(jj+17)%KEntryCount; sl@0: //* test(set.DeleteL(jj)); sl@0: set.DeleteL(jj); sl@0: } sl@0: test(set.Count()==KEntryCount/2); sl@0: sl@0: test.Next(_L("Check contents")); sl@0: for (;ii>0;--ii) sl@0: { sl@0: jj=(jj+17)%KEntryCount; sl@0: test(set.ContainsL(jj)); sl@0: } sl@0: jj=0; sl@0: for (ii=KEntryCount;ii>KEntryCount/2;--ii) sl@0: { sl@0: jj=(jj+17)%KEntryCount; sl@0: test(!set.ContainsL(jj)); sl@0: } sl@0: sl@0: test.Next(_L("Delete items")); sl@0: for (;ii>1;--ii) sl@0: { sl@0: jj=(jj+17)%KEntryCount; sl@0: //* test(set.DeleteL(jj)); sl@0: set.DeleteL(jj); sl@0: } sl@0: test(set.Count()==1); sl@0: sl@0: test.Next(_L("Check contents")); sl@0: jj=(jj+17)%KEntryCount; sl@0: TPagedSetBiIter biter(set); sl@0: test(biter.FirstL()); sl@0: test(biter.AtL()==jj); sl@0: TUint32 data; sl@0: biter.ExtractAtL(data); sl@0: test(data == jj); sl@0: test(!biter.NextL()); sl@0: test(biter.LastL()); sl@0: test(biter.AtL()==jj); sl@0: test(!biter.PreviousL()); sl@0: TPagedSetRIter riter(set); sl@0: test(riter.ResetL()); sl@0: test(riter.AtL()==jj); sl@0: riter.ExtractAtL(data); sl@0: test(data == jj); sl@0: test(!riter.NextL()); sl@0: sl@0: //* test(set.DeleteL(jj)); sl@0: set.DeleteL(jj); sl@0: test(!iter.ResetL()); sl@0: test(set.Count()==0); sl@0: sl@0: test.End(); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1123 sl@0: @SYMTestCaseDesc Stream set out test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Build set and stream out sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void test3aL(RWriteStream& aStream,MPagePool *aPool,TInt aCount) sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1123 ")); sl@0: TPagedSet set; sl@0: //* set.Connect(aPool,TBtree::EQosFastest); sl@0: set.Connect(aPool); sl@0: sl@0: for (TInt ii=0;ii>token; sl@0: TPagedSet set(token); sl@0: //* set.Connect(aPool,TBtree::EQosFastest); sl@0: set.Connect(aPool); sl@0: sl@0: test(set.Count()==aCount); sl@0: for (TInt ii=0;ii set; sl@0: set.Connect(CMemPagePool::NewLC()); sl@0: test.Next(_L("Duplicates")); sl@0: TInt ii, err; sl@0: for (ii=0;iiAcquireL(); sl@0: test(&nopFunc != NULL); sl@0: TAny* any = mpp->AllocL(); sl@0: TPageRef pref; sl@0: pref = mpp->AssignL(any, EPageReclaimable); sl@0: mpp->MPagePool::Delete(pref); sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: test.Next(_L("CPersistentStore DoSetRootL")); sl@0: CPersistentStoreHelper* ps = new (ELeave) CPersistentStoreHelper(); sl@0: CleanupStack::PushL(ps); sl@0: ps->SetRootL(KNullStreamId); sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: test.Next(_L("HDirectStoreBuf::DoSeekL calls")); sl@0: HBufC8* buf = HBufC8::NewLC(1024); sl@0: RDesWriteStream wts; sl@0: sl@0: TPtr8 ptr(buf->Des()); sl@0: wts.Open(ptr); sl@0: TStreamId id(5); sl@0: wts << id; sl@0: wts.CommitL(); sl@0: wts.Close(); sl@0: buf->Des().Append(_L8("Ala ma kota a kot ma futro. Futro jest dobre by chronic przed zimnem.")); sl@0: RDesReadStream rts; sl@0: ptr.Set(buf->Des()); sl@0: rts.Open(ptr); sl@0: sl@0: CEmbeddedStore* estor = CEmbeddedStore::FromLC(rts); sl@0: RStoreReadStream rstream; sl@0: rstream.OpenL(*estor, id); sl@0: TStreamPos pos = rstream.Source()->SeekL(MStreamBuf::ERead, 5); sl@0: test(pos.Offset() == 5); sl@0: rts.Close(); sl@0: rstream.Close(); sl@0: CleanupStack::PopAndDestroy(2); sl@0: sl@0: test.Next(_L("Calling TEmpty Constructor")); sl@0: TPagedSetToken set2(TBtreeToken::EEmpty); sl@0: test( set2.Count() == 0); sl@0: sl@0: test.Next(_L("Set function")); sl@0: set.Set(set2); sl@0: const TPagedSetToken& pst = set.Token(); sl@0: test(pst.Count() == set2.Count()); sl@0: sl@0: test.End(); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-STORE-CT-4065 sl@0: @SYMTestCaseDesc TStreamPos tests. sl@0: @SYMTestActions Tests operations provided by TStreamPos class. sl@0: @SYMTestPriority High sl@0: @SYMTestExpectedResults Test must not fail sl@0: */ sl@0: void StreamPosTest() sl@0: { sl@0: TStreamPos pos1; sl@0: TStreamPos pos2(5); sl@0: pos1 = pos2; sl@0: test(pos1 == pos2); sl@0: sl@0: pos1 = 5 + pos2; sl@0: test(pos1 > pos2); sl@0: test(pos2 < pos1); sl@0: test(pos2 <= pos1); sl@0: test(pos1 != pos2); sl@0: pos1 = pos1 - 5; sl@0: test(pos1 == pos2); sl@0: sl@0: pos2 += 0; sl@0: test(pos1 == pos2); sl@0: pos2 -= 0; sl@0: test(pos1 == pos2); sl@0: } sl@0: sl@0: struct TTestEntry sl@0: { sl@0: inline TTestEntry() : sl@0: iKey(-1), sl@0: iData(-1) sl@0: { sl@0: } sl@0: inline TTestEntry(TInt aKey, TInt aData) : sl@0: iKey(aKey), sl@0: iData(aData) sl@0: { sl@0: } sl@0: TInt iKey; sl@0: TInt iData; sl@0: }; sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-STORE-CT-4066 sl@0: @SYMTestCaseDesc TBtreeFix tests. sl@0: @SYMTestActions Tests operations provided by TBtreeFix class. sl@0: @SYMTestPriority High sl@0: @SYMTestExpectedResults Test must not fail sl@0: */ sl@0: void BTreeFixTestL() sl@0: { sl@0: CMemPagePool* pool = CMemPagePool::NewLC(); sl@0: sl@0: TBtreeToken token(TBtreeToken::EEmpty); sl@0: TBool rc = token.IsEmpty(); sl@0: test(rc); sl@0: rc = token.IsIntact(); sl@0: test(rc); sl@0: sl@0: TBtreeFix bentry(token, EBtreeSecure); sl@0: TBtreeKey bkey(sizeof(TInt)); sl@0: bentry.Connect(pool, &bkey); sl@0: sl@0: TBtreePos bpos; sl@0: rc = bentry.FindL(bpos, 1); sl@0: test(!rc); sl@0: rc = bentry.InsertL(bpos, TTestEntry(1, 101)); sl@0: test(rc); sl@0: rc = bentry.FindL(bpos, 1); sl@0: test(rc); sl@0: TTestEntry entry1 = bentry.AtL(bpos); sl@0: test(entry1.iKey == 1 && entry1.iData == 101); sl@0: const void* key = bkey.Key(&entry1); sl@0: TInt keyVal = *((const TInt*)key); sl@0: test.Printf(_L("keyVal=%d\n"), keyVal); sl@0: sl@0: rc = bentry.InsertL(bpos, TTestEntry(3, 103)); sl@0: test(rc); sl@0: rc = bentry.InsertL(bpos, TTestEntry(2, 102)); sl@0: test(rc); sl@0: sl@0: rc = bentry.FindL(bpos, 2); sl@0: test(rc); sl@0: TTestEntry entry2; sl@0: bentry.ExtractAtL(bpos, entry2); sl@0: test(entry2.iKey == 2 && entry2.iData == 102); sl@0: sl@0: rc = bentry.FindL(bpos, 3); sl@0: test(rc); sl@0: TTestEntry entry3; sl@0: bentry.ExtractAtL(bpos, entry3); sl@0: test(entry3.iKey == 3 && entry3.iData == 103); sl@0: sl@0: //============================================== sl@0: sl@0: TBtreeMark bmark; sl@0: if(bentry.ResetL(bmark)) sl@0: { sl@0: do sl@0: { sl@0: TTestEntry entry = bentry.AtL(bmark); sl@0: test.Printf(_L("AtL(): entry.iKey=%d, entry.iData=%d\n"), entry.iKey, entry.iData); sl@0: bentry.ExtractAtL(bmark, entry); sl@0: test.Printf(_L("ExtractAtL(): entry.iKey=%d, entry.iData=%d\n"), entry.iKey, entry.iData); sl@0: }while(bentry.NextL(bmark)); sl@0: } sl@0: sl@0: rc = bentry.NextL(bmark); sl@0: test(!rc); sl@0: sl@0: //============================================== sl@0: sl@0: rc = bentry.DeleteL(2); sl@0: test(rc); sl@0: rc = bentry.FindL(bpos, 2); sl@0: test(!rc); sl@0: rc = bentry.FindL(bpos, 3); sl@0: test(rc); sl@0: TRAPD(err, bentry.DeleteAtL(bpos)); sl@0: test(err == KErrNone); sl@0: rc = bentry.FindL(bpos, 3); sl@0: test(!rc); sl@0: sl@0: bentry.MarkDirty(); sl@0: rc = bentry.IsDirty(); sl@0: test(rc); sl@0: bentry.MarkCurrent(); sl@0: rc = bentry.IsDirty(); sl@0: test(!rc); sl@0: sl@0: bentry.ClearL(); sl@0: CleanupStack::PopAndDestroy(pool); sl@0: } sl@0: sl@0: LOCAL_C void doMainL() sl@0: { sl@0: test.Start(_L("Basic operations")); sl@0: test1L(); sl@0: test.Next(_L("Large set TUint32")); sl@0: test2L(); sl@0: test.Next(_L("Tokens and streaming")); sl@0: test3L(); sl@0: test.Next(_L("Forgotten API")); sl@0: test4L(); sl@0: test.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4065: TStreamPos test")); sl@0: StreamPosTest(); sl@0: test.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4066: TBtreeFix test")); sl@0: BTreeFixTestL(); sl@0: test.End(); sl@0: } sl@0: sl@0: LOCAL_C void setupCleanup() sl@0: // sl@0: // Initialise the cleanup stack. sl@0: // sl@0: { sl@0: TheTrapCleanup=CTrapCleanup::New(); sl@0: test(TheTrapCleanup!=NULL); sl@0: TRAPD(r,\ sl@0: {\ sl@0: for (TInt i=KTestCleanupStack;i>0;i--)\ sl@0: CleanupStack::PushL((TAny*)1);\ sl@0: test(r==KErrNone);\ sl@0: CleanupStack::Pop(KTestCleanupStack);\ sl@0: }); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: setupCleanup(); sl@0: __UHEAP_MARK; sl@0: // sl@0: TRAPD(r,doMainL()); sl@0: test(r==KErrNone); sl@0: // sl@0: __UHEAP_MARKEND; sl@0: delete TheTrapCleanup; sl@0: test.Close(); sl@0: return 0; sl@0: } sl@0: