os/textandloc/textrendering/textformatting/test/src/TUnique.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * TUnique.cpp test file for UniqueInstance classes
    16 *
    17 */
    18 
    19 
    20 #include "UniqueInstanceImpl.h"
    21 #include <e32test.h>
    22 #include "tunique.h"
    23 
    24 using namespace UniqueInstance;
    25 
    26 #define UNUSED_VAR(a) a = a
    27 
    28 // we will manipulate TInts for simplicity
    29 // some functions that will help us
    30 namespace
    31 {
    32 TInt CompareVoids(void* pl, void* pr)
    33 	{
    34 	TInt l = *reinterpret_cast<TInt*>(pl);
    35 	TInt r = *reinterpret_cast<TInt*>(pr);
    36 	return r - l;
    37 	}
    38 TInt CompareTInts(const TInt* l, const TInt* r) { return *r - *l; }
    39 void* CopyVoidL(void* a, TInt)
    40 	{
    41 	return new(ELeave) TInt(*reinterpret_cast<TInt*>(a));
    42 	}
    43 TInt* CopyTIntL(const TInt* a, TInt) { return new(ELeave) TInt(*a); }
    44 void DeleteVoid(void* a)
    45 	{
    46 	delete reinterpret_cast<TInt*>(a);
    47 	}
    48 void DeleteTInt(TInt* a) { delete a; }
    49 
    50 CTUniqueStep* TestStep;
    51 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
    52 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
    53 }
    54 
    55 /////////////////
    56 //			   //
    57 //	RSkipList  //
    58 //			   //
    59 /////////////////
    60 
    61 namespace
    62 {
    63 TInt TestEmpty(RSkipList& a)
    64 	{
    65 	if (!a.IsEmpty())
    66 		{
    67 		TESTPRINT(_L("RSkipList : unexpectedly has elements"));
    68 		return 1;
    69 		}
    70 	return 0;
    71 	}
    72 TInt TestAddL(RSkipList& a, void* aElt, TInt aExpectedRefCount)
    73 	{
    74 	SElement* e = a.AddExisting(aElt);
    75 	if (!e)
    76 		e = a.AddNewL(aElt);
    77 	if (CompareVoids(e->iObject,aElt))
    78 		{
    79         TESTPRINT(_L("RSkipList : added element does not compare equal to returned value"));
    80 		return 1;
    81 		}
    82 	if (e->iRefCount != aExpectedRefCount)
    83 		{
    84         TESTPRINT(_L("RSkipList : unexpected reference count"));
    85 		return 1;
    86 		}
    87 	return 0;
    88 	}
    89 TInt TestRemove(RSkipList& a, void* aElt)
    90 	{
    91 	if (CompareVoids(a.Remove(aElt), aElt))
    92 		{
    93         TESTPRINT(_L("RSkipList : removed element does not compare equal to returned value"));
    94 		return 1;
    95 		}
    96 	return 0;
    97 	}
    98 void Test(RSkipList& a)
    99 	{
   100 	a.Test();
   101 	}
   102 void TestRSkipListL()
   103 	{
   104 	__UHEAP_MARK;
   105 
   106 	RSkipList s;
   107 	s.Open(CompareVoids, 16);
   108 	Test(s);
   109 
   110 	TInt* n500 = new(ELeave) TInt(-500);
   111 	TInt* n400 = new(ELeave) TInt(-400);
   112 	TInt* n300 = new(ELeave) TInt(-300);
   113 	TInt* n200 = new(ELeave) TInt(-200);
   114 	TInt* n190 = new(ELeave) TInt(-190);
   115 	TInt* n180 = new(ELeave) TInt(-180);
   116 	TInt* n170 = new(ELeave) TInt(-170);
   117 	TInt* n160 = new(ELeave) TInt(-160);
   118 	TInt* n150 = new(ELeave) TInt(-150);
   119 	TInt* n140 = new(ELeave) TInt(-140);
   120 	TInt* n130 = new(ELeave) TInt(-130);
   121 	TInt* n120 = new(ELeave) TInt(-120);
   122 	TInt* n110 = new(ELeave) TInt(-110);
   123 	TInt* n100 = new(ELeave) TInt(-100);
   124 	TInt* n87  = new(ELeave) TInt(-87);
   125 	TInt* n45  = new(ELeave) TInt(-45);
   126 	TInt* n3   = new(ELeave) TInt(-3);
   127 	TInt* p999 = new(ELeave) TInt(999);
   128 	TInt* p998 = new(ELeave) TInt(998);
   129 	TInt* p980 = new(ELeave) TInt(980);
   130 	TInt* p900 = new(ELeave) TInt(900);
   131 	TInt* p800 = new(ELeave) TInt(800);
   132 	TInt* p700 = new(ELeave) TInt(700);
   133 	TInt* p600 = new(ELeave) TInt(600);
   134 	TInt* p500 = new(ELeave) TInt(500);
   135 	TInt* p490 = new(ELeave) TInt(490);
   136 	TInt* p485 = new(ELeave) TInt(485);
   137 	TInt* p480 = new(ELeave) TInt(480);
   138 	TInt* p472 = new(ELeave) TInt(472);
   139 	TInt* p471 = new(ELeave) TInt(471);
   140 	TInt* p470 = new(ELeave) TInt(470);
   141 	TInt* p469 = new(ELeave) TInt(469);
   142 	TInt* p463 = new(ELeave) TInt(463);
   143 	TInt* p460 = new(ELeave) TInt(460);
   144 	TInt* p440 = new(ELeave) TInt(440);
   145 	TInt* p400 = new(ELeave) TInt(400);
   146 	TInt* p350 = new(ELeave) TInt(350);
   147 	TInt* p300 = new(ELeave) TInt(300);
   148 	TInt* p200 = new(ELeave) TInt(200);
   149 	TInt* p101 = new(ELeave) TInt(101);
   150 	TInt* p100 = new(ELeave) TInt(100);
   151 	TInt* p99  = new(ELeave) TInt(99);
   152 	TInt* p45  = new(ELeave) TInt(45);
   153 	TInt* p2   = new(ELeave) TInt(2);
   154 
   155 	// add everything a first time
   156 	TestAddL(s, p999, 1);
   157 	Test(s);
   158 	TestAddL(s, n190, 1);
   159 	Test(s);
   160 	TestAddL(s, n180, 1);
   161 	Test(s);
   162 	TestAddL(s, n160, 1);
   163 	Test(s);
   164 	TestAddL(s, p485, 1);
   165 	Test(s);
   166 	TestAddL(s, n140, 1);
   167 	Test(s);
   168 	TestAddL(s, n200, 1);
   169 	Test(s);
   170 	TestAddL(s, p470, 1);
   171 	Test(s);
   172 	TestAddL(s, n500, 1);
   173 	Test(s);
   174 	TestAddL(s, p980, 1);
   175 	Test(s);
   176 	TestAddL(s, n150, 1);
   177 	Test(s);
   178 	TestAddL(s, n170, 1);
   179 	Test(s);
   180 	TestAddL(s, p490, 1);
   181 	Test(s);
   182 	TestAddL(s, p500, 1);
   183 	Test(s);
   184 	TestAddL(s, p600, 1);
   185 	Test(s);
   186 	TestAddL(s, p440, 1);
   187 	Test(s);
   188 	TestAddL(s, p998, 1);
   189 	Test(s);
   190 	TestAddL(s, p700, 1);
   191 	Test(s);
   192 	TestAddL(s, p463, 1);
   193 	Test(s);
   194 	TestAddL(s, p460, 1);
   195 	Test(s);
   196 	TestAddL(s, p400, 1);
   197 	Test(s);
   198 	TestAddL(s, p800, 1);
   199 	Test(s);
   200 	TestAddL(s, n130, 1);
   201 	Test(s);
   202 	TestAddL(s, n120, 1);
   203 	Test(s);
   204 	TestAddL(s, p471, 1);
   205 	Test(s);
   206 	TestAddL(s, p472, 1);
   207 	Test(s);
   208 	TestAddL(s, p480, 1);
   209 	Test(s);
   210 	TestAddL(s, n400, 1);
   211 	Test(s);
   212 	TestAddL(s, n300, 1);
   213 	Test(s);
   214 	TestAddL(s, p300, 1);
   215 	Test(s);
   216 	TestAddL(s, n110, 1);
   217 	Test(s);
   218 	TestAddL(s, p350, 1);
   219 	Test(s);
   220 	TestAddL(s, p101, 1);
   221 	Test(s);
   222 	TestAddL(s, p200, 1);
   223 	Test(s);
   224 	TestAddL(s, p469, 1);
   225 	Test(s);
   226 	TestAddL(s, p99, 1);
   227 	Test(s);
   228 	TestAddL(s, p100, 1);
   229 	Test(s);
   230 	TestAddL(s, p45, 1);
   231 	Test(s);
   232 	TestAddL(s, p900, 1);
   233 	Test(s);
   234 	TestAddL(s, n100, 1);
   235 	Test(s);
   236 	TestAddL(s, n87, 1);
   237 	Test(s);
   238 	TestAddL(s, n45, 1);
   239 	Test(s);
   240 	TestAddL(s, n3, 1);
   241 	Test(s);
   242 	TestAddL(s, p2, 1);
   243 	Test(s);
   244 
   245 	// remove a few things
   246 	TestRemove(s, p500);
   247 	Test(s);
   248 	TestRemove(s, p900);
   249 	Test(s);
   250 	TestRemove(s, n100);
   251 	Test(s);
   252 	TestRemove(s, n200);
   253 	Test(s);
   254 	TestRemove(s, p800);
   255 	Test(s);
   256 	TestRemove(s, p100);
   257 	Test(s);
   258 	TestRemove(s, n400);
   259 	TestRemove(s, p700);
   260 	TestRemove(s, p200);
   261 	TestRemove(s, p600);
   262 	TestRemove(s, n300);
   263 	TestRemove(s, p300);
   264 	TestRemove(s, p400);
   265 	TestRemove(s, n500);
   266 
   267 	// add everything a second time
   268 	TestAddL(s, p440, 2);
   269 	TestAddL(s, p480, 2);
   270 	TestAddL(s, n180, 2);
   271 	TestAddL(s, n3, 2);
   272 	TestAddL(s, n130, 2);
   273 	TestAddL(s, p470, 2);
   274 	TestAddL(s, n400, 1);
   275 	TestAddL(s, n45, 2);
   276 	TestAddL(s, n190, 2);
   277 	TestAddL(s, p300, 1);
   278 	TestAddL(s, n120, 2);
   279 	TestAddL(s, n150, 2);
   280 	TestAddL(s, p463, 2);
   281 	TestAddL(s, n170, 2);
   282 	TestAddL(s, p469, 2);
   283 	TestAddL(s, p471, 2);
   284 	TestAddL(s, p490, 2);
   285 	TestAddL(s, p200, 1);
   286 	TestAddL(s, p99, 2);
   287 	TestAddL(s, p980, 2);
   288 	TestAddL(s, p101, 2);
   289 	TestAddL(s, p600, 1);
   290 	TestAddL(s, n500, 1);
   291 	TestAddL(s, n110, 2);
   292 	TestAddL(s, p460, 2);
   293 	TestAddL(s, p485, 2);
   294 	TestAddL(s, n160, 2);
   295 	TestAddL(s, n140, 2);
   296 	TestAddL(s, p100, 1);
   297 	TestAddL(s, p472, 2);
   298 	TestAddL(s, p350, 2);
   299 	TestAddL(s, p400, 1);
   300 	TestAddL(s, p999, 2);
   301 	TestAddL(s, n200, 1);
   302 	TestAddL(s, p500, 1);
   303 	TestAddL(s, p998, 2);
   304 	TestAddL(s, n87, 2);
   305 	TestAddL(s, n100, 1);
   306 	TestAddL(s, p45, 2);
   307 	TestAddL(s, p800, 1);
   308 	TestAddL(s, p900, 1);
   309 	TestAddL(s, p700, 1);
   310 	TestAddL(s, n300, 1);
   311 	TestAddL(s, p2, 2);
   312 
   313 	Test(s);
   314 
   315 	// remove everything
   316 	TestRemove(s, p500);
   317 	TestRemove(s, p900);
   318 	TestRemove(s, p980);
   319 	TestRemove(s, p471);
   320 	TestRemove(s, p472);
   321 	TestRemove(s, p480);
   322 	TestRemove(s, p45);
   323 	TestRemove(s, n160);
   324 	TestRemove(s, n100);
   325 	TestRemove(s, n87);
   326 	TestRemove(s, p469);
   327 	TestRemove(s, p490);
   328 	TestRemove(s, n170);
   329 	TestRemove(s, n200);
   330 	TestRemove(s, p460);
   331 	TestRemove(s, p800);
   332 	TestRemove(s, n120);
   333 	TestRemove(s, p485);
   334 	TestRemove(s, p100);
   335 	TestRemove(s, p99);
   336 	TestRemove(s, p101);
   337 	TestRemove(s, n110);
   338 	TestRemove(s, n400);
   339 	TestRemove(s, p463);
   340 	TestRemove(s, n45);
   341 	TestRemove(s, n3);
   342 	TestRemove(s, n190);
   343 	TestRemove(s, p700);
   344 	TestRemove(s, p999);
   345 	TestRemove(s, p200);
   346 	TestRemove(s, p2);
   347 	TestRemove(s, n180);
   348 	TestRemove(s, n150);
   349 	TestRemove(s, p600);
   350 	TestRemove(s, n300);
   351 	TestRemove(s, p300);
   352 	TestRemove(s, p350);
   353 	TestRemove(s, p400);
   354 	TestRemove(s, p440);
   355 	TestRemove(s, p470);
   356 	TestRemove(s, p998);
   357 	TestRemove(s, n140);
   358 	TestRemove(s, n130);
   359 	TestRemove(s, n500);
   360 
   361 	Test(s);
   362 
   363 	// add everything
   364 	TestAddL(s, p999, 1);
   365 	TestAddL(s, n200, 1);
   366 	TestAddL(s, n3, 1);
   367 	TestAddL(s, n110, 1);
   368 	TestAddL(s, p460, 1);
   369 	TestAddL(s, p980, 1);
   370 	TestAddL(s, n500, 1);
   371 	TestAddL(s, p700, 1);
   372 	TestAddL(s, n300, 1);
   373 	TestAddL(s, p2, 1);
   374 	TestAddL(s, p463, 1);
   375 	TestAddL(s, p472, 1);
   376 	TestAddL(s, n100, 1);
   377 	TestAddL(s, p45, 1);
   378 	TestAddL(s, n45, 1);
   379 	TestAddL(s, p469, 1);
   380 	TestAddL(s, n120, 1);
   381 	TestAddL(s, p470, 1);
   382 	TestAddL(s, p400, 1);
   383 	TestAddL(s, n190, 1);
   384 	TestAddL(s, p998, 1);
   385 	TestAddL(s, p490, 1);
   386 	TestAddL(s, n180, 1);
   387 	TestAddL(s, p600, 1);
   388 	TestAddL(s, n160, 1);
   389 	TestAddL(s, p480, 1);
   390 	TestAddL(s, p350, 1);
   391 	TestAddL(s, p200, 1);
   392 	TestAddL(s, n130, 1);
   393 	TestAddL(s, p485, 1);
   394 	TestAddL(s, p500, 1);
   395 	TestAddL(s, p471, 1);
   396 	TestAddL(s, p440, 1);
   397 	TestAddL(s, p800, 1);
   398 	TestAddL(s, n87, 1);
   399 	TestAddL(s, p101, 1);
   400 	TestAddL(s, n140, 1);
   401 	TestAddL(s, p100, 1);
   402 	TestAddL(s, n400, 1);
   403 	TestAddL(s, n170, 1);
   404 	TestAddL(s, p99, 1);
   405 	TestAddL(s, p300, 1);
   406 	TestAddL(s, n150, 1);
   407 	TestAddL(s, p900, 1);
   408 
   409 	Test(s);
   410 
   411 	// remove everything
   412 	TestRemove(s, n120);
   413 	TestRemove(s, p485);
   414 	TestRemove(s, p100);
   415 	TestRemove(s, n500);
   416 	TestRemove(s, n400);
   417 	TestRemove(s, p463);
   418 	TestRemove(s, n150);
   419 	TestRemove(s, p440);
   420 	TestRemove(s, n170);
   421 	TestRemove(s, n3);
   422 	TestRemove(s, p500);
   423 	TestRemove(s, p900);
   424 	TestRemove(s, p980);
   425 	TestRemove(s, p471);
   426 	TestRemove(s, p600);
   427 	TestRemove(s, n300);
   428 	TestRemove(s, p300);
   429 	TestRemove(s, p350);
   430 	TestRemove(s, p700);
   431 	TestRemove(s, n45);
   432 	TestRemove(s, n200);
   433 	TestRemove(s, p2);
   434 	TestRemove(s, p400);
   435 	TestRemove(s, n110);
   436 	TestRemove(s, n190);
   437 	TestRemove(s, p999);
   438 	TestRemove(s, p200);
   439 	TestRemove(s, p99);
   440 	TestRemove(s, p470);
   441 	TestRemove(s, p800);
   442 	TestRemove(s, n180);
   443 	TestRemove(s, p460);
   444 	TestRemove(s, p998);
   445 	TestRemove(s, n140);
   446 	TestRemove(s, p472);
   447 	TestRemove(s, p101);
   448 	TestRemove(s, p480);
   449 	TestRemove(s, n130);
   450 	TestRemove(s, p45);
   451 	TestRemove(s, n160);
   452 	TestRemove(s, n100);
   453 	TestRemove(s, n87);
   454 	TestRemove(s, p469);
   455 	TestRemove(s, p490);
   456 
   457 	TestEmpty(s);
   458 
   459 	delete n500;
   460 	delete n400;
   461 	delete n300;
   462 	delete n200;
   463 	delete n190;
   464 	delete n180;
   465 	delete n170;
   466 	delete n160;
   467 	delete n150;
   468 	delete n140;
   469 	delete n130;
   470 	delete n120;
   471 	delete n110;
   472 	delete n100;
   473 	delete n87;
   474 	delete n45;
   475 	delete n3;
   476 	delete p2;
   477 	delete p45;
   478 	delete p99;
   479 	delete p100;
   480 	delete p101;
   481 	delete p200;
   482 	delete p300;
   483 	delete p350;
   484 	delete p400;
   485 	delete p440;
   486 	delete p460;
   487 	delete p463;
   488 	delete p469;
   489 	delete p470;
   490 	delete p471;
   491 	delete p472;
   492 	delete p480;
   493 	delete p485;
   494 	delete p490;
   495 	delete p500;
   496 	delete p600;
   497 	delete p700;
   498 	delete p800;
   499 	delete p900;
   500 	delete p980;
   501 	delete p998;
   502 	delete p999;
   503 
   504 	s.Close();
   505 
   506 	__UHEAP_MARKENDC(0);
   507 	}
   508 }
   509 
   510 ///////////////////////
   511 //					 //
   512 //  CRepositoryImpl  //
   513 //					 //
   514 ///////////////////////
   515 namespace
   516 {
   517 TInt TestObject(SElement* e, TInt val)
   518 	{
   519 	if (!e->iObject)
   520 		{
   521         TESTPRINT(_L("CRepositoryImpl : object undefined"));
   522 		return 1;
   523 		}
   524 	if (*reinterpret_cast<TInt*>(e->iObject) != val)
   525 		{
   526         TESTPRINT(_L("CRepositoryImpl : object has wrong value"));
   527 		return 1;
   528 		}
   529 	return 0;
   530 	}
   531 void TestCRepositoryImplL()
   532 	{
   533 	__UHEAP_MARK;
   534 
   535 	CRepositoryImpl* rep = new(ELeave) CRepositoryImpl(CompareVoids, DeleteVoid,
   536 		CopyVoidL, sizeof(TInt));
   537 	rep->ConstructL(1);
   538 	TInt* n47	= new(ELeave) TInt(-47);
   539 	TInt* z		= new(ELeave) TInt(0);
   540 	TInt* z2	= new(ELeave) TInt(0);
   541 	TInt* p8765	= new(ELeave) TInt(8765);
   542 
   543 	SElement* z0ui		= rep->IncOrCopyL(z);
   544 
   545 	SElement* zui		= rep->InsertOrIncL(z);
   546 	SElement* n47ui		= rep->InsertOrIncL(n47);
   547 	SElement* p8765ui	= rep->InsertOrIncL(p8765);
   548 	SElement* z2ui		= rep->InsertOrIncL(z2);
   549 
   550 	z = new(ELeave) TInt(0);
   551 	SElement* z3ui		= rep->IncOrCopyL(z);
   552 	delete z;
   553 
   554 	// test equal objects are nullified
   555 	TESTPOINT(zui->iObject == z2ui->iObject);
   556 	TESTPOINT(zui->iObject == z0ui->iObject);
   557 	TESTPOINT(zui->iObject == z3ui->iObject);
   558 
   559 	rep->DeleteOrDec(z0ui);
   560 	rep->DeleteOrDec(z3ui);
   561 
   562 	TestObject(zui, 0);
   563 	TestObject(n47ui, -47);
   564 	TestObject(p8765ui, 8765);
   565 
   566 	rep->DeleteOrDec(n47ui);
   567 
   568 	TestObject(zui, 0);
   569 	TestObject(p8765ui, 8765);
   570 
   571 	z = reinterpret_cast<TInt*>(rep->DetatchOrCopyL(zui));
   572 	z2 = reinterpret_cast<TInt*>(rep->DetatchOrCopyL(z2ui));
   573 	rep->DeleteOrDec(p8765ui);
   574 
   575 	// test that copyable objects are not aliased
   576 	TESTPOINT(z != z2);
   577 	// test that a valid copy is returned
   578 	TESTPOINT(*z == 0);
   579 	TESTPOINT(*z2 == 0);
   580 
   581 	delete z;
   582 	delete z2;
   583 
   584 	delete rep;
   585 
   586 	__UHEAP_MARKENDC(0);
   587 	}
   588 }
   589 
   590 ///////////////////////////////////
   591 //								 //
   592 //  CUniqueInstanceRepository<>  //
   593 //				and				 //
   594 //		 RUniqueInstance<>		 //
   595 //								 //
   596 ///////////////////////////////////
   597 namespace
   598 {
   599 TInt TestNull(const RUniqueInstance<TInt>& a)
   600 	{
   601 	if (a.Peek())
   602 		{
   603         TESTPRINT(_L("RUniqueInstance : null object has value"));
   604 		return 1;
   605 		}
   606 	return 0;
   607 	}
   608 TInt TestValue(const RUniqueInstance<TInt>& a, TInt val)
   609 	{
   610 	if (!a.Peek())
   611 		{
   612         TESTPRINT(_L("RUniqueInstance : unexpected null object"));
   613 		return 1;
   614 		}
   615 	if (*a.Peek() != val)
   616 		{
   617         TESTPRINT(_L("RUniqueInstance : object has wrong value"));
   618 		return 1;
   619 		}
   620 	return 0;
   621 	}
   622 TInt TestRaw(TInt* ob, TInt val)
   623 	{
   624 	if (!ob)
   625 		{
   626         TESTPRINT(_L("RUniqueInstance : object unexpectedly does not own"));
   627 		return 1;
   628 		}
   629 	if (*ob != val)
   630 		{
   631         TESTPRINT(_L("RUniqueInstance : object owns incorrect value"));
   632 		return 1;
   633 		}
   634 	return 0;
   635 	}
   636 void TestRUniqueInstanceL()
   637 	{
   638 	__UHEAP_MARK;
   639 
   640 	CUniqueInstanceRepository<TInt>* intRep =
   641 		CUniqueInstanceRepository<TInt>::NewL(CompareTInts, DeleteTInt, CopyTIntL, 2);
   642 
   643 	RUniqueInstance<TInt> a(*intRep);
   644 	RUniqueInstance<TInt> b(*intRep);
   645 	RUniqueInstance<TInt> c(*intRep);
   646 
   647 	a.TakeL(new(ELeave) TInt(45));
   648 	b.TakeL(new(ELeave) TInt(-6));
   649 	c.TakeL(new(ELeave) TInt(45));
   650 
   651 	// test that equal elements are unified
   652 	TESTPOINT(a.Peek() == c.Peek());
   653 
   654 	TestValue(a, 45);
   655 	TestValue(b, -6);
   656 	TestValue(c, 45);
   657 
   658 	a.CopyTo(c);
   659 
   660 	TestValue(a, 45);
   661 	TestValue(b, -6);
   662 	TestValue(c, 45);
   663 
   664 	b.CopyTo(b);
   665 	b.MoveTo(b);
   666 
   667 	TestValue(a, 45);
   668 	TestValue(b, -6);
   669 	TestValue(c, 45);
   670 
   671 	b.MoveTo(c);
   672 
   673 	TestValue(a, 45);
   674 	TestNull(b);
   675 	TestValue(c, -6);
   676 
   677 	b.MoveTo(c);
   678 
   679 	TestValue(a, 45);
   680 	TestNull(b);
   681 	TestNull(c);
   682 
   683 	c.TakeL(new(ELeave) TInt(87));
   684 	c.CopyTo(b);
   685 	TInt* r = c.DropL();
   686 
   687 	TestRaw(r, 87);
   688 
   689 	delete r;
   690 	r = b.DropL();
   691 
   692 	TestRaw(r, 87);
   693 
   694 	delete r;
   695 
   696 	a.Close();
   697 
   698 	CUniqueInstanceRepository<TInt>* intRep2 =
   699 		CUniqueInstanceRepository<TInt>::NewL(CompareTInts, DeleteTInt, CopyTIntL, 4);
   700 
   701 	RUniqueInstance<TInt> d(*intRep2);
   702 	RUniqueInstance<TInt> e(*intRep2);
   703 	RUniqueInstance<TInt> f(*intRep2);
   704 
   705 	a.TakeL(new(ELeave) TInt(123));
   706 	b.TakeL(new(ELeave) TInt(-445));
   707 	c.TakeL(new(ELeave) TInt(123));
   708 	d.TakeL(new(ELeave) TInt(-7));
   709 	e.TakeL(new(ELeave) TInt(18));
   710 		{
   711 		TInt n0 = -999;
   712 		TInt n1 = 1;
   713 		TInt n2 = 999;
   714 		f.TakeCopyL(&n0);
   715 		TestValue(f, -999);
   716 		f.TakeCopyL(&n1);
   717 		TestValue(f, 1);
   718 		f.TakeCopyL(&n2);
   719 		TestValue(f, 999);
   720 		f.Close();
   721 		}
   722 
   723 	a.MoveTo(d);
   724 	TestNull(a);
   725 	TestValue(d, 123);
   726 	c.CopyTo(d);
   727 	TestValue(d, 123);
   728 	e.MoveTo(a);
   729 	e.TakeL(new(ELeave) TInt(18));
   730 
   731 	// test that equal objects are unified
   732 	TESTPOINT(a.Peek() == e.Peek());
   733 
   734 	d.TakeL(new(ELeave) TInt(-445));
   735 
   736 	// test that equal objects are unified
   737 	TESTPOINT(b.Peek() == d.Peek());
   738 
   739 	a.TakeL(new(ELeave) TInt(-445));
   740 
   741 	// test that objects from different repositories are not unified
   742 	TESTPOINT(a.Peek() != b.Peek());
   743 
   744 	a.Close();
   745 
   746 	// test that destroyed object peeks null
   747 	TESTPOINT(a.Peek() == 0);
   748 
   749 	b.MoveTo(c);
   750 	b.Close();
   751 	c.Close();
   752 	d.Close();
   753 	e.Close();
   754 
   755 	delete intRep2;
   756 	delete intRep;
   757 
   758 	__UHEAP_MARKENDC(0);
   759 	}
   760 }
   761 
   762 
   763 ////////////
   764 //		  //
   765 //  Main  //
   766 //		  //
   767 ////////////
   768 
   769 TVerdict CTUniqueStep::doTestStepL()
   770 	{
   771     SetTestStepResult(EPass);
   772     TestStep = this;
   773     TESTPRINT(_L("TUnique - Unique instance repository tests"));
   774 	TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-UNIQUE-0001 Unique Instance Tests: "));
   775 
   776 	TestRSkipListL();
   777 	TestCRepositoryImplL();
   778 	TestRUniqueInstanceL();
   779 
   780 	return TestStepResult();
   781 	}