persistentstorage/store/TCONT/t_storset.cpp
changeset 51 7d4490026038
parent 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
40:b8bdbc8f59c7 51:7d4490026038
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    33 @SYMTestExpectedResults Test must not fail
    33 @SYMTestExpectedResults Test must not fail
    34 @SYMREQ                 REQ0000
    34 @SYMREQ                 REQ0000
    35 */
    35 */
    36 LOCAL_C void test1L()
    36 LOCAL_C void test1L()
    37 	{
    37 	{
       
    38 	test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1121 Insertion & Deletion "));
       
    39 	
    38 	const TInt KEntryCount=200;
    40 	const TInt KEntryCount=200;
    39 
       
    40 	TPagedSet<TInt32> set;
    41 	TPagedSet<TInt32> set;
    41 	set.Connect(CMemPagePool::NewLC());
    42 	set.Connect(CMemPagePool::NewLC());
    42 	test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1121 Insertion & Deletion "));
    43 	//IsIntact() and IsDirty() test
       
    44 	TBool rc = set.IsIntact();
       
    45 	test(rc);
       
    46 	rc = set.IsDirty();
       
    47 	test(!rc);
       
    48 	set.MarkDirty();
       
    49 	rc = set.IsDirty();
       
    50 	test(rc);
       
    51 	//IsBroken() test
       
    52 	rc = set.IsBroken();
       
    53 	test(!rc);
       
    54 	set.MarkBroken();
       
    55 	rc = set.IsBroken();
       
    56 	test(!rc);//Empty tree - cannot be marked as broken
       
    57 	TInt yy = 10;
       
    58 	set.InsertL(yy);
       
    59 	set.MarkBroken();
       
    60 	rc = set.IsBroken();
       
    61 	test(rc);
       
    62 	set.RepairL();
       
    63 	rc = set.IsBroken();
       
    64 	test(!rc);
       
    65 	set.ClearL();
       
    66 	rc = set.IsBroken();
       
    67 	test(!rc);
    43 
    68 
    44 	TInt32 it=0;
    69 	TInt32 it=0;
    45 //*	test(set.InsertL(it));
    70 //*	test(set.InsertL(it));
    46 	set.InsertL(it);
    71 	set.InsertL(it);
    47 	test(set.Count()==1);
    72 	test(set.Count()==1);
   129 	test.Next(_L("Iterate over items"));
   154 	test.Next(_L("Iterate over items"));
   130 	TUint8 *checkMap=(TUint8*)User::AllocLC(KEntryCount);
   155 	TUint8 *checkMap=(TUint8*)User::AllocLC(KEntryCount);
   131 	Mem::FillZ(checkMap,KEntryCount);
   156 	Mem::FillZ(checkMap,KEntryCount);
   132 	TPagedSetIter<TUint32> iter(set);
   157 	TPagedSetIter<TUint32> iter(set);
   133 	if (iter.ResetL())
   158 	if (iter.ResetL())
   134 		do	++checkMap[iter.AtL()]; while (iter.NextL());
   159 		{
       
   160 		do	
       
   161 			{
       
   162 			TUint32 data1 = iter.AtL();
       
   163 			++checkMap[data1];
       
   164 			TUint32 data2;
       
   165 			iter.ExtractAtL(data2);
       
   166 			test(data1 == data2);
       
   167 			}while(iter.NextL());
       
   168 		}
   135 	for (ii=0;ii<KEntryCount;++ii)
   169 	for (ii=0;ii<KEntryCount;++ii)
   136 		test(checkMap[ii]==1);
   170 		test(checkMap[ii]==1);
   137 	CleanupStack::PopAndDestroy();
   171 	CleanupStack::PopAndDestroy();
   138 
   172 
   139 	test.Next(_L("Delete items"));
   173 	test.Next(_L("Delete items"));
   171 	test.Next(_L("Check contents"));
   205 	test.Next(_L("Check contents"));
   172 	jj=(jj+17)%KEntryCount;
   206 	jj=(jj+17)%KEntryCount;
   173 	TPagedSetBiIter<TUint32> biter(set);
   207 	TPagedSetBiIter<TUint32> biter(set);
   174 	test(biter.FirstL());
   208 	test(biter.FirstL());
   175 	test(biter.AtL()==jj);
   209 	test(biter.AtL()==jj);
       
   210 	TUint32 data; 
       
   211 	biter.ExtractAtL(data);
       
   212 	test(data == jj);
   176 	test(!biter.NextL());
   213 	test(!biter.NextL());
   177 	test(biter.LastL());
   214 	test(biter.LastL());
   178 	test(biter.AtL()==jj);
   215 	test(biter.AtL()==jj);
   179 	test(!biter.PreviousL());
   216 	test(!biter.PreviousL());
   180 	TPagedSetRIter<TUint32> riter(set);
   217 	TPagedSetRIter<TUint32> riter(set);
   181 	test(riter.ResetL());
   218 	test(riter.ResetL());
   182 	test(riter.AtL()==jj);
   219 	test(riter.AtL()==jj);
       
   220 	riter.ExtractAtL(data);
       
   221 	test(data == jj);
   183 	test(!riter.NextL());
   222 	test(!riter.NextL());
   184 
   223 
   185 //*	test(set.DeleteL(jj));
   224 //*	test(set.DeleteL(jj));
   186 	set.DeleteL(jj);
   225 	set.DeleteL(jj);
   187 	test(!iter.ResetL());
   226 	test(!iter.ResetL());
   307 		{
   346 		{
   308 		TRAP(err, set.InsertL(it));
   347 		TRAP(err, set.InsertL(it));
   309 		test(err==KErrNone);
   348 		test(err==KErrNone);
   310 		}
   349 		}
   311 	test(set.Count()==KEntryCount);
   350 	test(set.Count()==KEntryCount);
       
   351 	TBool rc = set.IsEmpty();
       
   352 	test(!rc);
       
   353 	set.MarkDirty();
       
   354 	set.MarkCurrent();
   312 	TRAP(err, set.ContainsL(it));
   355 	TRAP(err, set.ContainsL(it));
   313 	test(err==KErrNone);
   356 	test(err==KErrNone);
   314 	TRAP(err, set.InsertL(it));
   357 	TRAP(err, set.InsertL(it));
   315 	test(err==KErrNone);
   358 	test(err==KErrNone);
   316 		
   359 		
   354 	wts.Close();
   397 	wts.Close();
   355 	buf->Des().Append(_L8("Ala ma kota a kot ma futro. Futro jest dobre by chronic przed zimnem."));
   398 	buf->Des().Append(_L8("Ala ma kota a kot ma futro. Futro jest dobre by chronic przed zimnem."));
   356 	RDesReadStream rts;
   399 	RDesReadStream rts;
   357 	ptr.Set(buf->Des());
   400 	ptr.Set(buf->Des());
   358 	rts.Open(ptr);
   401 	rts.Open(ptr);
   359 		
   402 
   360 	CEmbeddedStore* estor = CEmbeddedStore::FromLC(rts);
   403 	CEmbeddedStore* estor = CEmbeddedStore::FromLC(rts);
   361 	RStoreReadStream rstream;
   404 	RStoreReadStream rstream;
   362 	rstream.OpenL(*estor, id);
   405 	rstream.OpenL(*estor, id);
   363 	TStreamPos pos = rstream.Source()->SeekL(MStreamBuf::ERead, 5);
   406 	TStreamPos pos = rstream.Source()->SeekL(MStreamBuf::ERead, 5);
   364 	test(pos.Offset() == 5);
   407 	test(pos.Offset() == 5);
   377 	
   420 	
   378 	test.End();
   421 	test.End();
   379 	CleanupStack::PopAndDestroy();
   422 	CleanupStack::PopAndDestroy();
   380 	}
   423 	}
   381 
   424 
       
   425 /**
       
   426 @SYMTestCaseID          PDS-STORE-CT-4065
       
   427 @SYMTestCaseDesc        TStreamPos tests.
       
   428 @SYMTestActions         Tests operations provided by TStreamPos class. 
       
   429 @SYMTestPriority        High
       
   430 @SYMTestExpectedResults Test must not fail
       
   431 */
       
   432 void StreamPosTest()
       
   433 	{
       
   434 	TStreamPos pos1;
       
   435 	TStreamPos pos2(5);
       
   436 	pos1 = pos2;
       
   437 	test(pos1 == pos2);
       
   438 	
       
   439 	pos1 = 5 + pos2;
       
   440 	test(pos1 > pos2);
       
   441 	test(pos2 < pos1);
       
   442 	test(pos2 <= pos1);
       
   443 	test(pos1 != pos2);
       
   444 	pos1 = pos1 - 5;
       
   445 	test(pos1 == pos2);
       
   446 	
       
   447 	pos2 += 0;
       
   448 	test(pos1 == pos2);
       
   449 	pos2 -= 0;
       
   450 	test(pos1 == pos2);
       
   451 	}
       
   452 
       
   453 struct TTestEntry
       
   454 	{
       
   455 	inline TTestEntry() :
       
   456 		iKey(-1),
       
   457 		iData(-1)
       
   458 		{
       
   459 		}
       
   460 	inline TTestEntry(TInt aKey, TInt aData) :
       
   461 		iKey(aKey),
       
   462 		iData(aData)
       
   463 		{
       
   464 		}
       
   465 	TInt	iKey;
       
   466 	TInt	iData;
       
   467 	};
       
   468 
       
   469 /**
       
   470 @SYMTestCaseID          PDS-STORE-CT-4066
       
   471 @SYMTestCaseDesc        TBtreeFix tests.
       
   472 @SYMTestActions         Tests operations provided by TBtreeFix class. 
       
   473 @SYMTestPriority        High
       
   474 @SYMTestExpectedResults Test must not fail
       
   475 */
       
   476 void BTreeFixTestL()
       
   477 	{
       
   478 	CMemPagePool* pool = CMemPagePool::NewLC();
       
   479 		
       
   480 	TBtreeToken token(TBtreeToken::EEmpty);
       
   481 	TBool rc = token.IsEmpty();
       
   482 	test(rc);
       
   483 	rc = token.IsIntact();
       
   484 	test(rc);
       
   485 	
       
   486 	TBtreeFix<TTestEntry, TInt> bentry(token, EBtreeSecure);
       
   487 	TBtreeKey bkey(sizeof(TInt));
       
   488 	bentry.Connect(pool, &bkey);
       
   489 	
       
   490 	TBtreePos bpos;
       
   491 	rc = bentry.FindL(bpos, 1);
       
   492 	test(!rc);
       
   493 	rc = bentry.InsertL(bpos, TTestEntry(1, 101));
       
   494 	test(rc);
       
   495 	rc = bentry.FindL(bpos, 1);
       
   496 	test(rc);
       
   497 	TTestEntry entry1 = bentry.AtL(bpos);
       
   498 	test(entry1.iKey == 1 && entry1.iData == 101);
       
   499 	const void* key = bkey.Key(&entry1);
       
   500 	TInt keyVal = *((const TInt*)key);
       
   501 	test.Printf(_L("keyVal=%d\n"), keyVal);
       
   502 	
       
   503 	rc = bentry.InsertL(bpos, TTestEntry(3, 103));
       
   504 	test(rc);
       
   505 	rc = bentry.InsertL(bpos, TTestEntry(2, 102));
       
   506 	test(rc);
       
   507 	
       
   508 	rc = bentry.FindL(bpos, 2);
       
   509 	test(rc);
       
   510 	TTestEntry entry2;
       
   511 	bentry.ExtractAtL(bpos, entry2);
       
   512 	test(entry2.iKey == 2 && entry2.iData == 102);
       
   513 
       
   514 	rc = bentry.FindL(bpos, 3);
       
   515 	test(rc);
       
   516 	TTestEntry entry3;
       
   517 	bentry.ExtractAtL(bpos, entry3);
       
   518 	test(entry3.iKey == 3 && entry3.iData == 103);
       
   519 
       
   520 	//==============================================
       
   521 	
       
   522 	TBtreeMark bmark;
       
   523 	if(bentry.ResetL(bmark))
       
   524 		{
       
   525 		do
       
   526 			{
       
   527 			TTestEntry entry = bentry.AtL(bmark);
       
   528 			test.Printf(_L("AtL(): entry.iKey=%d, entry.iData=%d\n"), entry.iKey, entry.iData);
       
   529 			bentry.ExtractAtL(bmark, entry);
       
   530 			test.Printf(_L("ExtractAtL(): entry.iKey=%d, entry.iData=%d\n"), entry.iKey, entry.iData);
       
   531 			}while(bentry.NextL(bmark));
       
   532 		}
       
   533 
       
   534 	rc = bentry.NextL(bmark);
       
   535 	test(!rc);
       
   536 
       
   537 	//==============================================
       
   538 
       
   539 	rc = bentry.DeleteL(2);
       
   540 	test(rc);
       
   541 	rc = bentry.FindL(bpos, 2);
       
   542 	test(!rc);
       
   543 	rc = bentry.FindL(bpos, 3);
       
   544 	test(rc);
       
   545 	TRAPD(err, bentry.DeleteAtL(bpos));
       
   546 	test(err == KErrNone);
       
   547 	rc = bentry.FindL(bpos, 3);
       
   548 	test(!rc);
       
   549 	
       
   550 	bentry.MarkDirty();
       
   551 	rc = bentry.IsDirty();
       
   552 	test(rc);
       
   553 	bentry.MarkCurrent();
       
   554 	rc = bentry.IsDirty();
       
   555 	test(!rc);
       
   556 	
       
   557 	bentry.ClearL();
       
   558 	CleanupStack::PopAndDestroy(pool);
       
   559 	}
       
   560 
   382 LOCAL_C void doMainL()
   561 LOCAL_C void doMainL()
   383 	{
   562 	{
   384 	test.Start(_L("Basic operations"));
   563 	test.Start(_L("Basic operations"));
   385 	test1L();
   564 	test1L();
   386 	test.Next(_L("Large set TUint32"));
   565 	test.Next(_L("Large set TUint32"));
   387 	test2L();
   566 	test2L();
   388 	test.Next(_L("Tokens and streaming"));
   567 	test.Next(_L("Tokens and streaming"));
   389 	test3L();
   568 	test3L();
   390 	test.Next(_L("Forgotten API"));
   569 	test.Next(_L("Forgotten API"));
   391 	test4L();
   570 	test4L();
       
   571 	test.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4065: TStreamPos test"));
       
   572 	StreamPosTest();
       
   573 	test.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4066: TBtreeFix test"));
       
   574 	BTreeFixTestL();
   392 	test.End();
   575 	test.End();
   393 	}
   576 	}
   394 
   577 
   395 LOCAL_C void setupCleanup()
   578 LOCAL_C void setupCleanup()
   396 //
   579 //