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