symport/e32test/buffer/t_sque.cpp
changeset 1 0a7b44b10206
child 2 806186ab5e14
equal deleted inserted replaced
0:c55016431358 1:0a7b44b10206
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\buffer\t_sque.cpp
       
    15 // Overview:
       
    16 // Test single linked list functionality.
       
    17 // API Information:
       
    18 // TSglQueLink, TSglQueBase.
       
    19 // Details:
       
    20 // - Create specified number of TSglQueLink objects, then delete them. 
       
    21 // - Create TSglQueBase object with specified offset and without an offset,
       
    22 // add and remove links to the list, check that the list is empty.
       
    23 // - Create TSglQueBase object with and without an offset, verify offset, head 
       
    24 // and last member values are correct.
       
    25 // - Create TSglQueBase object, insert links using DoAddFirst and DoAddLast and
       
    26 // remove links using DoRemove, check the results are as expected.
       
    27 // - Create TSglQueBase object, insert links using DoAddFirst and DoAddLast and
       
    28 // verify IsEmpty return the correct value. Set and verify the offset.
       
    29 // - Create TSglQue object, insert TSglQueLink link at front and end of list, test 
       
    30 // whether the links are inserted at specified location, remove some links.
       
    31 // - Create TSglQue object, insert links using DoAddFirst and DoAddLast and
       
    32 // remove links using DoRemove, check the results are as expected.
       
    33 // - Create TSglQue object, insert links using DoAddFirst and DoAddLast and
       
    34 // verify IsEmpty return the correct value. Set and verify the offset.
       
    35 // - Create TSglQue object with and without an offset, verify offset, head 
       
    36 // and last member values are correct.
       
    37 // - Create TSglQue object, insert links using AddFirst and AddLast and
       
    38 // verify results are as expected.
       
    39 // - Create TSglQue object, insert links using AddFirst and AddLast and
       
    40 // verify results using IsFirst and IsLast are as expected.
       
    41 // - Create TSglQue object, insert links using AddFirst and AddLast and
       
    42 // verify results using First and Last are as expected.
       
    43 // - Create TSglQue object, insert links using AddLast and delete using Remove,
       
    44 // verify results are as expected.
       
    45 // - Create TSglQueIterBase object, with and without an offset, call the 
       
    46 // DoCurrent, DoPostInc and SetToFirst methods.
       
    47 // - Create TSglQueIterBase object, with and without an offset, and TSglQue 
       
    48 // with different offsets, verify results are as expected.
       
    49 // - Create TSglQueIterBase object, , with and without an offset, use the 
       
    50 // DoCurrent and DoPostInc methods and verify the results are as expected.
       
    51 // - Create TSglQueIterBase object, , with and without an offset, use the 
       
    52 // DoPostInc and SetToFirst methods and verify the results are as expected.
       
    53 // - Create TSglQueIter object, with and without an offset, iterate using 
       
    54 // the ++ operator and delete the object.
       
    55 // - Create TSglQueIter object, with and without an offset, and TSglQue 
       
    56 // object with different offsets, verify results are as expected.
       
    57 // - Create TSglQueIter object, with and without an offset, use the 
       
    58 // DoCurrent and DoPostInc methods and verify the results are as expected.
       
    59 // - Create TSglQueIter object, with and without an offset, use the 
       
    60 // DoPostInc and SetToFirst methods and verify the results are as expected.
       
    61 // - Create TSglQueIter object, with and without an offset, iterate using 
       
    62 // the ++ operator, use the conversion operator, verify the results are 
       
    63 // as expected.
       
    64 // Platforms/Drives/Compatibility:
       
    65 // All 
       
    66 // Assumptions/Requirement/Pre-requisites:
       
    67 // Failures and causes:
       
    68 // Base Port information:
       
    69 // 
       
    70 //
       
    71 
       
    72 #include <e32base.h>
       
    73 #include <e32test.h>
       
    74 
       
    75 LOCAL_D RTest test(_L("T_SQUE"));
       
    76 
       
    77 #define SIZE 10
       
    78 #define MAX_OFFSET 10
       
    79 
       
    80 struct Item
       
    81 	{
       
    82 	TSglQueLink iLink;
       
    83 	TInt iSpace[MAX_OFFSET]; // Reserve some space
       
    84 	};
       
    85 
       
    86 struct ItemWithOffset
       
    87 	{
       
    88 	TInt iSpace[MAX_OFFSET];
       
    89 	TSglQueLink iLink;
       
    90 	};
       
    91 
       
    92 template<class T>
       
    93 class TestTQueLink
       
    94 	{
       
    95 public:
       
    96 	void TestQueLink();	// Calls Test: 1
       
    97 	void Test1();
       
    98 protected:
       
    99 	void CreateObjects(TInt aBaseLink);
       
   100 	void DestroyObjects();
       
   101 private:
       
   102 	T* iLink[SIZE];
       
   103 	};
       
   104 
       
   105 template<class T>
       
   106 void TestTQueLink<T>::CreateObjects(TInt aBaseLink)
       
   107 	{
       
   108 	TInt i;
       
   109 
       
   110 	for (i=0;i<SIZE;i++)
       
   111 		iLink[i]=new T;
       
   112 	if (aBaseLink>=0&&aBaseLink<SIZE)
       
   113 		(iLink[aBaseLink])->iNext=iLink[aBaseLink];
       
   114 	}
       
   115 
       
   116 template<class T>
       
   117 void TestTQueLink<T>::DestroyObjects()
       
   118 	{
       
   119 	TInt i;
       
   120 
       
   121 	for (i=0;i<SIZE;i++)
       
   122 		delete iLink[i];
       
   123 	}
       
   124 
       
   125 template <class T>
       
   126 void TestTQueLink<T>::TestQueLink()
       
   127 	{
       
   128 	test.Start(_L("Test Enque"));
       
   129 	Test1();
       
   130 	test.Next(_L("Finished"));
       
   131 	test.End();
       
   132 	}
       
   133 
       
   134 template<class T>
       
   135 void TestTQueLink<T>::Test1()
       
   136 	{
       
   137 	test.Start(_L("Create objects"));
       
   138 	CreateObjects(1);
       
   139 	test.Next(_L("Destroy objects"));
       
   140 	DestroyObjects();
       
   141 	test.End();
       
   142 	}
       
   143 
       
   144 class VSglQueBase : public TSglQueBase
       
   145 	{
       
   146 public:
       
   147 	inline VSglQueBase();
       
   148 	inline VSglQueBase(TInt anOffset);
       
   149 	inline void sDoAddFirst(TAny* aPtr) {this->DoAddFirst(aPtr);}
       
   150 	inline void sDoAddLast(TAny* aPtr) {this->DoAddLast(aPtr);}
       
   151 	inline void sDoRemove(TAny* aPtr) {this->DoRemove(aPtr);}
       
   152 public:
       
   153 	TSglQueLink** sHead;
       
   154 	TSglQueLink** sLast;
       
   155 	TInt* sOffset;
       
   156 private:
       
   157 	void SetMembers();
       
   158 	};
       
   159 
       
   160 template <class T>
       
   161 class VSglQue : public TSglQue<T>
       
   162 	{
       
   163 public:
       
   164 	inline VSglQue();
       
   165 	inline VSglQue(TInt anOffset);
       
   166 	inline void sDoAddFirst(TAny* aPtr) {this->DoAddFirst(aPtr);}
       
   167 	inline void sDoAddLast(TAny* aPtr) {this->DoAddLast(aPtr);}
       
   168 	inline void sDoRemove(TAny* aPtr) {this->DoRemove(aPtr);}
       
   169 public:
       
   170 	TSglQueLink** sHead;
       
   171 	TSglQueLink** sLast;
       
   172 	TInt* sOffset;
       
   173 private:
       
   174 	void SetMembers();
       
   175 	};
       
   176 
       
   177 inline VSglQueBase::VSglQueBase()
       
   178 	{
       
   179 	SetMembers();
       
   180 	}
       
   181 
       
   182 inline VSglQueBase::VSglQueBase(TInt anOffset)
       
   183 	:TSglQueBase(anOffset)
       
   184 	{
       
   185 	SetMembers();
       
   186 	}
       
   187 
       
   188 void VSglQueBase::SetMembers()
       
   189 	{
       
   190 	sHead=&iHead;
       
   191 	sLast=&iLast;
       
   192 	sOffset=&iOffset;
       
   193 	}
       
   194 
       
   195 template <class T>
       
   196 VSglQue<T>::VSglQue()
       
   197 	{
       
   198 	SetMembers();
       
   199 	}
       
   200 
       
   201 template <class T>
       
   202 VSglQue<T>::VSglQue(TInt anOffset)
       
   203 	:TSglQue<T>(anOffset)
       
   204 	{
       
   205 	SetMembers();
       
   206 	}
       
   207 
       
   208 template <class T>
       
   209 void VSglQue<T>::SetMembers()
       
   210 	{
       
   211 	sHead=&this->iHead;
       
   212 	sLast=&this->iLast;
       
   213 	sOffset=&this->iOffset;
       
   214 	}
       
   215 
       
   216 template<class T>
       
   217 class TestTQue
       
   218 	{
       
   219 public:
       
   220 	void TestQueBase();
       
   221 	void TestSglQue();
       
   222 	void Test1();	// All functions		//TSglQueBase functions
       
   223 	void Test2();	// Constructors
       
   224 	void Test3();	// DoAdd's
       
   225 	void Test4();	// Public functions
       
   226 	void Test5();	// All functions		//TSglQue
       
   227 	//void Test6();	// Constructors
       
   228 	void Test7();	// Add's
       
   229 	void Test8();	// Is's
       
   230 	void Test9();	// Get's
       
   231 	void Test10();	// Add's
       
   232 private:
       
   233 	void CallTest3_4();	
       
   234 	};
       
   235 
       
   236 template<class T>
       
   237 void TestTQue<T>::CallTest3_4()
       
   238 	{
       
   239 	test.Next(_L("Test DoAdd's"));
       
   240 	Test3();
       
   241 	test.Next(_L("Test public functions"));
       
   242 	Test4();
       
   243 	}
       
   244 
       
   245 template<class T>
       
   246 void TestTQue<T>::TestQueBase()
       
   247 	{
       
   248 	test.Start(_L("Test all member functions (simply)"));
       
   249 	Test1();						 
       
   250 	test.Next(_L("Test Constructors"));
       
   251 	Test2();
       
   252 	CallTest3_4();
       
   253 	test.Next(_L("Finished"));
       
   254 	test.End();
       
   255 	}
       
   256 
       
   257 template<class T>
       
   258 void TestTQue<T>::TestSglQue()
       
   259 	{
       
   260 	test.Start(_L("Test all member functions (simply)"));
       
   261 	Test5();
       
   262 	test.Next(_L("Test Super Class functions"));
       
   263 	CallTest3_4();
       
   264 	test.Next(_L("Test Constructors"));
       
   265 	Test2();
       
   266 	test.Next(_L("Test Add's"));
       
   267 	Test7();
       
   268 	test.Next(_L("Test Is's"));
       
   269 	Test8();
       
   270 	test.Next(_L("Test Get's"));
       
   271 	Test9();
       
   272 	test.Next(_L("Test Remove"));
       
   273 	Test10();
       
   274 	test.Next(_L("Finished"));
       
   275 	test.End();
       
   276 	}
       
   277 
       
   278 template<class T>
       
   279 void TestTQue<T>::Test1()
       
   280 	{
       
   281 	T* que;
       
   282 	TSglQueLink link1,link2;
       
   283 	TInt offset=4;
       
   284 
       
   285 	test.Start(_L("Constructors"));
       
   286 	que=new VSglQueBase(offset);
       
   287 	delete que;
       
   288 	que=new VSglQueBase;
       
   289 	//delete que;
       
   290 	test.Next(_L("DoAdd's"));
       
   291 	que->sDoAddFirst(&link1);
       
   292 	que->sDoAddLast(&link2);
       
   293 	que->sDoRemove(&link1);
       
   294 	que->sDoRemove(&link2);
       
   295 	test.Next(_L("Public"));
       
   296 	que->IsEmpty();
       
   297 	que->SetOffset(offset);
       
   298 	test.Next(_L("Finished"));
       
   299 	delete que;
       
   300 	test.End();
       
   301 	}
       
   302 
       
   303 template<class T>
       
   304 void TestTQue<T>::Test2()
       
   305 	{
       
   306 	T* que;
       
   307 	TInt offset;
       
   308 
       
   309 	test.Start(_L("Default constructor"));
       
   310 	que=new T();
       
   311 	test(*(que->sOffset)==0);
       
   312 	test(*(que->sHead)==NULL);
       
   313 	test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   314 	delete que;
       
   315 	test.Next(_L("Offset constructor"));
       
   316 	for (offset=0;offset<40;offset+=4)
       
   317 		{
       
   318 		que=new T(offset);
       
   319 		test(*(que->sOffset)==offset);
       
   320 		test(*(que->sHead)==NULL);
       
   321 		test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   322 		delete que;
       
   323 		}
       
   324 	test.Next(_L("Finished"));
       
   325 	test.End();
       
   326 	}
       
   327 
       
   328 template<class T>
       
   329 void TestTQue<T>::Test3()
       
   330 	{
       
   331 	T* que;
       
   332 
       
   333 		{
       
   334 		TSglQueLink link1,link2,link3,link4;
       
   335 		test.Start(_L("AddFirst"));
       
   336 		que=new T();
       
   337 		test(*(que->sHead)==NULL);
       
   338 		test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   339 		que->sDoAddFirst(&link1);
       
   340 		test(*(que->sHead)==&link1);
       
   341 		test(*(que->sLast)==&link1);
       
   342 		test(link1.iNext==NULL);
       
   343 		que->sDoAddFirst(&link2);
       
   344 		test(*(que->sHead)==&link2);
       
   345 		test(*(que->sLast)==&link1);
       
   346 		test(link1.iNext==NULL);
       
   347 		test(link2.iNext==&link1);
       
   348 		que->sDoAddFirst(&link3);
       
   349 		test(*(que->sHead)==&link3);
       
   350 		test(*(que->sLast)==&link1);
       
   351 		test(link1.iNext==NULL);
       
   352 		test(link2.iNext==&link1);
       
   353 		test(link3.iNext==&link2);
       
   354 		que->sDoAddFirst(&link4);
       
   355 		test(*(que->sHead)==&link4);
       
   356 		test(*(que->sLast)==&link1);
       
   357 		test(link1.iNext==NULL);
       
   358 		test(link2.iNext==&link1);
       
   359 		test(link3.iNext==&link2);
       
   360 		test(link4.iNext==&link3);
       
   361 		delete que;
       
   362 		}
       
   363 	TSglQueLink link1,link2,link3,link4;
       
   364 	test.Next(_L("AddLast"));
       
   365 	que=new T();
       
   366 	test(*(que->sHead)==NULL);
       
   367 	test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   368 	que->sDoAddLast(&link1);
       
   369 	test(*(que->sHead)==&link1);
       
   370 	test(*(que->sLast)==&link1);
       
   371 	test(link1.iNext==NULL);
       
   372 	que->sDoAddLast(&link2);
       
   373 	test(*(que->sHead)==&link1);
       
   374 	test(*(que->sLast)==&link2);
       
   375 	test(link1.iNext==&link2);
       
   376 	test(link2.iNext==NULL);
       
   377 	que->sDoAddLast(&link3);
       
   378 	test(*(que->sHead)==&link1);
       
   379 	test(*(que->sLast)==&link3);
       
   380 	test(link1.iNext==&link2);
       
   381 	test(link2.iNext==&link3);
       
   382 	test(link3.iNext==NULL);
       
   383 	que->sDoAddLast(&link4);
       
   384 	test(*(que->sHead)==&link1);
       
   385 	test(*(que->sLast)==&link4);
       
   386 	test(link1.iNext==&link2);
       
   387 	test(link2.iNext==&link3);
       
   388 	test(link3.iNext==&link4);
       
   389 	test(link4.iNext==NULL);
       
   390 	test.Next(_L("Remove"));
       
   391 	que->sDoRemove(&link3);
       
   392 	test(*(que->sHead)==&link1);
       
   393 	test(*(que->sLast)==&link4);
       
   394 	test(link1.iNext==&link2);
       
   395 	test(link2.iNext==&link4);
       
   396 	test(link4.iNext==NULL);
       
   397 	que->sDoRemove(&link4);
       
   398 	test(*(que->sHead)==&link1);
       
   399 	test(*(que->sLast)==&link2);
       
   400 	test(link1.iNext==&link2);
       
   401 	test(link2.iNext==NULL);
       
   402 	que->sDoRemove(&link1);
       
   403 	test(*(que->sHead)==&link2);
       
   404 	test(*(que->sLast)==&link2);
       
   405 	test(link2.iNext==NULL);
       
   406 	que->sDoRemove(&link2);
       
   407 	test(*(que->sHead)==NULL);
       
   408 	test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   409  	delete que;
       
   410 	test.Next(_L("Finished"));
       
   411 	test.End();
       
   412 	}
       
   413 
       
   414 template<class T>
       
   415 void TestTQue<T>::Test4()
       
   416 	{
       
   417 	T* que;
       
   418 	TInt offset;
       
   419 
       
   420 	test.Start(_L("IsEmpty"));
       
   421 	que=new T();
       
   422 	test(que->IsEmpty()==TRUE);
       
   423 	TSglQueLink link1,link2;
       
   424 	que->sDoAddFirst(&link1);
       
   425 	test(que->IsEmpty()==FALSE);
       
   426 	que->sDoRemove(&link1);
       
   427 	test(que->IsEmpty()==TRUE);
       
   428 	que->sDoAddLast(&link2);
       
   429 	test(que->IsEmpty()==FALSE);
       
   430 	que->sDoAddFirst(&link1);
       
   431 	test(que->IsEmpty()==FALSE);
       
   432 	que->sDoRemove(&link2);
       
   433 	test(que->IsEmpty()==FALSE);
       
   434 	que->sDoRemove(&link1);
       
   435 	test(que->IsEmpty()==TRUE);
       
   436 	test.Next(_L("SetOffset"));
       
   437 	for (offset=0;offset<40;offset+=4)
       
   438 		{
       
   439 		que->SetOffset(offset);
       
   440 		test(*(que->sOffset)==offset);
       
   441 		}
       
   442 	test.Next(_L("Finished"));
       
   443  	delete que;
       
   444 	test.End();
       
   445 	}
       
   446 
       
   447 template<class T>
       
   448 void TestTQue<T>::Test5()
       
   449 	{
       
   450 	T* que;
       
   451 	TSglQueLink link1,link2;
       
   452 	TInt offset=4;
       
   453 
       
   454 	test.Start(_L("Constructors"));
       
   455 	que=new VSglQue<TSglQueLink>(offset);
       
   456 	delete que;
       
   457 	que=new VSglQue<TSglQueLink>;
       
   458 	test.Next(_L("Add's"));
       
   459 	que->AddFirst(link1);
       
   460 	que->AddLast(link2);
       
   461 	test.Next(_L("Is's"));
       
   462 	que->IsFirst(&link1);
       
   463 	que->IsLast(&link1);
       
   464 	test.Next(_L("Get's"));
       
   465 	que->First();
       
   466 	que->Last();
       
   467 	test.Next(_L("Remove"));
       
   468 	que->Remove(link1);
       
   469 	que->Remove(link2);
       
   470 	test.Next(_L("Finished"));
       
   471 	delete que;
       
   472 	test.End();
       
   473 	}
       
   474 
       
   475 /*template<class T>
       
   476 void TestTQue<T>::Test6()
       
   477 	{
       
   478 	T* que;
       
   479 	TInt offset;
       
   480 
       
   481 	test.Start(_L("Default constructor"));
       
   482 	que=new VSglQue<TSglQueBase>();
       
   483 	test(*(que->sFirstDelta)==NULL);
       
   484 	delete que;
       
   485 	test.Next(_L("Offset constructor"));
       
   486 	for (offset=0;offset<40;offset+=4)
       
   487 		{
       
   488 		que=new VDeltaQueBase(offset);
       
   489 		test(*(que->sOffset)==offset);
       
   490 		test(*(que->sFirstDelta)==NULL);
       
   491 		delete que;
       
   492 		}
       
   493 	test.Next(_L("Finished"));
       
   494 	test.End();
       
   495 	}*/
       
   496 
       
   497 template<class T>
       
   498 void TestTQue<T>::Test7()
       
   499 	{
       
   500 	T* que;
       
   501 
       
   502 		{
       
   503 		TSglQueLink link1,link2,link3,link4;
       
   504 		test.Start(_L("AddFirst"));
       
   505 		que=new T();
       
   506 		test(*(que->sHead)==NULL);
       
   507 		test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   508 		que->AddFirst(link1);
       
   509 		test(*(que->sHead)==&link1);
       
   510 		test(*(que->sLast)==&link1);
       
   511 		test(link1.iNext==NULL);
       
   512 		que->AddFirst(link2);
       
   513 		test(*(que->sHead)==&link2);
       
   514 		test(*(que->sLast)==&link1);
       
   515 		test(link1.iNext==NULL);
       
   516 		test(link2.iNext==&link1);
       
   517 		que->AddFirst(link3);
       
   518 		test(*(que->sHead)==&link3);
       
   519 		test(*(que->sLast)==&link1);
       
   520 		test(link1.iNext==NULL);
       
   521 		test(link2.iNext==&link1);
       
   522 		test(link3.iNext==&link2);
       
   523 		que->AddFirst(link4);
       
   524 		test(*(que->sHead)==&link4);
       
   525 		test(*(que->sLast)==&link1);
       
   526 		test(link1.iNext==NULL);
       
   527 		test(link2.iNext==&link1);
       
   528 		test(link3.iNext==&link2);
       
   529 		test(link4.iNext==&link3);
       
   530 		delete que;
       
   531 		}
       
   532 	TSglQueLink link1,link2,link3,link4;
       
   533 	test.Next(_L("AddLast"));
       
   534 	que=new T();
       
   535 	test.Next(_L("AddLast"));
       
   536 	que=new T();
       
   537 	test(*(que->sHead)==NULL);
       
   538 	test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   539 	que->AddLast(link1);
       
   540 	test(*(que->sHead)==&link1);
       
   541 	test(*(que->sLast)==&link1);
       
   542 	test(link1.iNext==NULL);
       
   543 	que->AddLast(link2);
       
   544 	test(*(que->sHead)==&link1);
       
   545 	test(*(que->sLast)==&link2);
       
   546 	test(link1.iNext==&link2);
       
   547 	test(link2.iNext==NULL);
       
   548 	que->AddLast(link3);
       
   549 	test(*(que->sHead)==&link1);
       
   550 	test(*(que->sLast)==&link3);
       
   551 	test(link1.iNext==&link2);
       
   552 	test(link2.iNext==&link3);
       
   553 	test(link3.iNext==NULL);
       
   554 	que->AddLast(link4);
       
   555 	test(*(que->sHead)==&link1);
       
   556 	test(*(que->sLast)==&link4);
       
   557 	test(link1.iNext==&link2);
       
   558 	test(link2.iNext==&link3);
       
   559 	test(link3.iNext==&link4);
       
   560 	test(link4.iNext==NULL);
       
   561 	delete que;
       
   562 	test.Next(_L("Finished"));
       
   563 	test.End();
       
   564 	}
       
   565 
       
   566 template<class T>
       
   567 void TestTQue<T>::Test8()
       
   568 	{
       
   569 	T* que;
       
   570 
       
   571 		{
       
   572 		TSglQueLink link1,link2,link3,link4;
       
   573 		test.Start(_L("IsFirst"));
       
   574 		que=new T();
       
   575 		test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE);
       
   576 		test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE);
       
   577 		test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE);
       
   578 		que->AddFirst(link1);
       
   579 		test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE);
       
   580 		test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE);
       
   581 		test(que->IsFirst((TSglQueLink*) *(que->sLast))==TRUE);
       
   582 		test(que->IsFirst(&link1)==TRUE);
       
   583 		que->AddFirst(link2);
       
   584 		test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE);
       
   585 		test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE);
       
   586 		test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE);
       
   587 		test(que->IsFirst(&link1)==FALSE);
       
   588 		test(que->IsFirst(&link2)==TRUE);
       
   589 		que->AddFirst(link3);
       
   590 		test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE);
       
   591 		test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE);
       
   592 		test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE);
       
   593 		test(que->IsFirst(&link1)==FALSE);
       
   594 		test(que->IsFirst(&link2)==FALSE);
       
   595 		test(que->IsFirst(&link3)==TRUE);
       
   596 		que->AddFirst(link4);
       
   597 		test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE);
       
   598 		test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE);
       
   599 		test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE);
       
   600 		test(que->IsFirst(&link1)==FALSE);
       
   601 		test(que->IsFirst(&link2)==FALSE);
       
   602 		test(que->IsFirst(&link3)==FALSE);
       
   603 		test(que->IsFirst(&link4)==TRUE);
       
   604 		delete que;
       
   605 		}
       
   606 	TSglQueLink link1,link2,link3,link4;
       
   607 	test.Next(_L("IsLast"));
       
   608 	que=new T();
       
   609 	test(que->IsLast((TSglQueLink*) que->sHead)==TRUE);
       
   610 	test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE);
       
   611 	test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE);
       
   612 	que->AddLast(link1);
       
   613 	test(que->IsLast((TSglQueLink*) que->sHead)==FALSE);
       
   614 	test(que->IsLast((TSglQueLink*) *(que->sHead))==TRUE);
       
   615 	test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE);
       
   616 	test(que->IsLast(&link1)==TRUE);
       
   617 	que->AddLast(link2);
       
   618 	test(que->IsLast((TSglQueLink*) que->sHead)==FALSE);
       
   619 	test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE);
       
   620 	test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE);
       
   621 	test(que->IsLast(&link1)==FALSE);
       
   622 	test(que->IsLast(&link2)==TRUE);
       
   623 	que->AddLast(link3);
       
   624 	test(que->IsLast((TSglQueLink*) que->sHead)==FALSE);
       
   625 	test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE);
       
   626 	test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE);
       
   627 	test(que->IsLast(&link1)==FALSE);
       
   628 	test(que->IsLast(&link2)==FALSE);
       
   629 	test(que->IsLast(&link3)==TRUE);
       
   630 	que->AddLast(link4);
       
   631 	test(que->IsLast((TSglQueLink*) que->sHead)==FALSE);
       
   632 	test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE);
       
   633 	test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE);
       
   634 	test(que->IsLast(&link1)==FALSE);
       
   635 	test(que->IsLast(&link2)==FALSE);
       
   636 	test(que->IsLast(&link3)==FALSE);
       
   637 	test(que->IsLast(&link4)==TRUE);
       
   638 	test.Next(_L("Finished"));
       
   639 	delete que;
       
   640 	test.End();
       
   641 	}
       
   642 
       
   643 template<class T>
       
   644 void TestTQue<T>::Test9()
       
   645 	{
       
   646 	T* que;
       
   647 
       
   648 		{
       
   649 		TSglQueLink link1,link2,link3,link4;
       
   650 		test.Start(_L("First"));
       
   651 		que=new T();
       
   652 		test(que->First()==NULL);
       
   653 		que->AddFirst(link1);
       
   654 		test(que->First()==&link1);
       
   655 	 	que->AddFirst(link2);
       
   656 		test(que->First()==&link2);
       
   657 	 	que->AddFirst(link3);
       
   658 		test(que->First()==&link3);
       
   659 	  	que->AddFirst(link4);
       
   660 		test(que->First()==&link4);
       
   661 	 	delete que;
       
   662 		}
       
   663 	TSglQueLink link1,link2,link3,link4;
       
   664 	test.Next(_L("Last"));
       
   665 	que=new T();
       
   666 	test(que->Last()==(TSglQueLink*) que->sHead);
       
   667 	que->AddLast(link1);
       
   668 	test(que->Last()==&link1);
       
   669  	que->AddLast(link2);
       
   670 	test(que->Last()==&link2);
       
   671  	que->AddLast(link3);
       
   672 	test(que->Last()==&link3);
       
   673   	que->AddLast(link4);
       
   674 	test(que->Last()==&link4);
       
   675 	test.Next(_L("Finished"));
       
   676  	delete que;
       
   677 	test.End();
       
   678 	}
       
   679 
       
   680 template<class T>
       
   681 void TestTQue<T>::Test10()
       
   682 	{
       
   683 	T* que;
       
   684 	TSglQueLink link1,link2,link3,link4;
       
   685 
       
   686 	que=new T();
       
   687 	que->AddLast(link1);
       
   688 	que->AddLast(link2);
       
   689 	que->AddLast(link3);
       
   690 	que->AddLast(link4);
       
   691 	test(*(que->sHead)==&link1);
       
   692 	test(*(que->sLast)==&link4);
       
   693 	test(link1.iNext==&link2);
       
   694 	test(link2.iNext==&link3);
       
   695 	test(link3.iNext==&link4);
       
   696 	test(link4.iNext==NULL);
       
   697 	que->Remove(link3);
       
   698 	test(*(que->sHead)==&link1);
       
   699 	test(*(que->sLast)==&link4);
       
   700 	test(link1.iNext==&link2);
       
   701 	test(link2.iNext==&link4);
       
   702 	test(link4.iNext==NULL);
       
   703 	que->Remove(link4);
       
   704 	test(*(que->sHead)==&link1);
       
   705 	test(*(que->sLast)==&link2);
       
   706 	test(link1.iNext==&link2);
       
   707 	test(link2.iNext==NULL);
       
   708 	que->Remove(link1);
       
   709 	test(*(que->sHead)==&link2);
       
   710 	test(*(que->sLast)==&link2);
       
   711 	test(link2.iNext==NULL);
       
   712 	que->Remove(link2);
       
   713 	test(*(que->sHead)==NULL);
       
   714 	test(*(que->sLast)==(TSglQueLink*) que->sHead);
       
   715  	delete que;
       
   716 	}
       
   717 
       
   718 class VSglQueIterBase : public TSglQueIterBase
       
   719 	{
       
   720 public:
       
   721 	VSglQueIterBase(TSglQueBase& aQue);
       
   722 	inline TAny* sDoPostInc() {return DoPostInc();}
       
   723 	inline TAny* sDoCurrent() {return DoCurrent();}
       
   724 public:
       
   725 	TInt* sOffset;
       
   726 	TSglQueLink** sHead;
       
   727 	TSglQueLink** sNext;
       
   728 private:
       
   729 	void SetMember();
       
   730 	};
       
   731 
       
   732 template <class T>
       
   733 class VSglQueIter : public TSglQueIter<T>
       
   734 	{
       
   735 public:
       
   736 	VSglQueIter(TSglQue<T>& aQue);
       
   737 	inline TAny* sDoPostInc() {return this->DoPostInc();}
       
   738 	inline TAny* sDoCurrent() {return this->DoCurrent();}
       
   739 public:
       
   740 	TInt* sOffset;
       
   741 	TSglQueLink** sHead;
       
   742 	TSglQueLink** sNext;
       
   743 private:
       
   744 	void SetMember();
       
   745 	};
       
   746 
       
   747 VSglQueIterBase::VSglQueIterBase(TSglQueBase& aQue)
       
   748 	:TSglQueIterBase(aQue)
       
   749 	{
       
   750 	SetMember();
       
   751 	}
       
   752 
       
   753 void VSglQueIterBase::SetMember()
       
   754 	{
       
   755 	sOffset=&iOffset;
       
   756 	sHead=&iHead;
       
   757 	sNext=&iNext;
       
   758 	}
       
   759 
       
   760 template <class T>
       
   761 VSglQueIter<T>::VSglQueIter(TSglQue<T>& aQue)
       
   762 	:TSglQueIter<T>(aQue)
       
   763 	{
       
   764 	SetMember();
       
   765 	}
       
   766 
       
   767 template <class T>
       
   768 void VSglQueIter<T>::SetMember()
       
   769 	{
       
   770 	sOffset=&this->iOffset;
       
   771 	sHead=&this->iHead;
       
   772 	sNext=&this->iNext;
       
   773 	}
       
   774 	
       
   775 template<class T,class Iter>
       
   776 class TestTQueIter
       
   777 	{
       
   778 public:
       
   779 	void TestIterBase();
       
   780 	void TestQueIter();
       
   781 	void Test1();	//All functions			//TSglQueIterBase
       
   782 	void Test2();	//Constructor
       
   783 	void Test3();	//Do's
       
   784 	void Test4();	//Set
       
   785 	void Test5();	//All functions			//TDblQueIter
       
   786 	//void Test6();	//Constructors									//Redundant
       
   787 	void Test7();	//Iterators
       
   788 private:
       
   789 	void CallTest2_4();
       
   790 	};
       
   791 
       
   792 template<class T,class Iter>
       
   793 void TestTQueIter<T,Iter>::CallTest2_4()
       
   794 	{
       
   795 	test.Next(_L("Constructors"));
       
   796 	Test2();
       
   797 	test.Next(_L("Do's"));
       
   798 	Test3();
       
   799 	test.Next(_L("Sets"));
       
   800 	Test4();
       
   801 	}
       
   802 
       
   803 template<class T,class Iter>
       
   804 void TestTQueIter<T,Iter>::TestIterBase()
       
   805 	{
       
   806 	test.Start(_L("All Methods"));
       
   807 	Test1();
       
   808 	CallTest2_4();
       
   809 	test.Next(_L("Finished"));
       
   810 	test.End();
       
   811 	}
       
   812 
       
   813 template<class T,class Iter>
       
   814 void TestTQueIter<T,Iter>::TestQueIter()
       
   815 	{
       
   816 	test.Start(_L("All Methods"));
       
   817 	Test5();
       
   818 	CallTest2_4();
       
   819 	test.Next(_L("Iterators"));
       
   820 	Test7();
       
   821 	test.Next(_L("Finished"));
       
   822 	test.End();
       
   823 	}
       
   824 
       
   825 template<class T,class Iter>
       
   826 void TestTQueIter<T,Iter>::Test1()
       
   827 	{
       
   828 	T item1,item2;
       
   829 	TSglQue<T> que(_FOFF(T,iLink));
       
   830 	Iter* iter;
       
   831 
       
   832 	que.AddFirst(item2);
       
   833 	que.AddFirst(item1);
       
   834 	test.Start(_L("Constructor"));
       
   835 	iter=new Iter(que);
       
   836 	test.Next(_L("Do's"));
       
   837 	iter->sDoCurrent();
       
   838 	iter->sDoPostInc();
       
   839 	test.Next(_L("Sets"));
       
   840 	iter->SetToFirst();
       
   841 	delete iter;
       
   842 	test.Next(_L("Finished"));
       
   843 	test.End();
       
   844 	}
       
   845 
       
   846 template<class T,class Iter>
       
   847 void TestTQueIter<T,Iter>::Test2()
       
   848 	{
       
   849 	TSglQue<T>* que;
       
   850 	TInt offset;
       
   851  	Iter* iter;
       
   852 	TSglQueLink* head;
       
   853 
       
   854 	for (offset=0;offset<40;offset+=4)
       
   855 		{
       
   856 		que=new TSglQue<T>(offset);
       
   857 		iter=new Iter(*que);
       
   858 		test(*(iter->sHead)==PtrAdd((TSglQueLink*) que->Last(),offset));
       
   859 		head=*(iter->sHead);
       
   860 		test(que->IsFirst((T*) PtrSub(*(iter->sNext),offset)));		//Need to pass a pointer to a item
       
   861 		test(*(iter->sOffset)==offset);
       
   862 		delete iter;
       
   863 		T item;
       
   864 		que->AddFirst(item);
       
   865 		iter=new Iter(*que);
       
   866 		test(*(iter->sHead)==head);
       
   867 		test(que->IsFirst((T*) PtrSub(*(iter->sNext),offset)));
       
   868 		test(*(iter->sOffset)==offset);
       
   869 		delete iter;
       
   870 		delete que;
       
   871 		}
       
   872 	}
       
   873 
       
   874 template<class T,class Iter>
       
   875 void TestTQueIter<T,Iter>::Test3()
       
   876 	{
       
   877 	T item1,item2,item3,item4;
       
   878 	TSglQue<T> que(_FOFF(T,iLink));
       
   879  	Iter* iter;
       
   880 				  
       
   881 	que.AddFirst(item4);
       
   882 	que.AddFirst(item3);
       
   883 	que.AddFirst(item2);
       
   884 	que.AddFirst(item1);
       
   885 	test.Start(_L("DoPostInc"));
       
   886 	iter=new Iter(que);
       
   887 	test(&item1==iter->sDoPostInc());
       
   888 	test(&item2.iLink==*(iter->sNext));
       
   889 	test(&item2==iter->sDoPostInc());
       
   890 	test(&item3.iLink==*(iter->sNext));
       
   891 	test(&item3==iter->sDoPostInc());
       
   892 	test(&item4.iLink==*(iter->sNext));
       
   893 	test(&item4==iter->sDoPostInc());
       
   894 	test((Item*) *(iter->sNext)==NULL);
       
   895 	test(iter->sDoPostInc()==NULL);
       
   896 	delete iter;
       
   897 	test.Next(_L("DoCurrent"));
       
   898 	iter=new Iter(que);
       
   899 	test(&item1==iter->sDoCurrent());
       
   900 	iter->sDoPostInc();
       
   901 	test(&item2==iter->sDoCurrent());
       
   902 	iter->sDoPostInc();
       
   903 	test(&item3==iter->sDoCurrent());
       
   904 	iter->sDoPostInc();
       
   905 	test(&item4==iter->sDoCurrent());
       
   906 	iter->sDoPostInc();
       
   907 	test(iter->sDoCurrent()==NULL);
       
   908 	delete iter;
       
   909 	test.Next(_L("Finished"));
       
   910 	test.End();
       
   911 	}
       
   912 
       
   913 template<class T,class Iter>
       
   914 void TestTQueIter<T,Iter>::Test4()
       
   915 	{
       
   916 	T item1,item2,item3,item4;
       
   917 	TSglQue<T> que(_FOFF(T,iLink));
       
   918  	Iter* iter;
       
   919 	TInt i,j;
       
   920 
       
   921 	que.AddFirst(item4);
       
   922 	que.AddFirst(item3);
       
   923 	que.AddFirst(item2);
       
   924 	que.AddFirst(item1);
       
   925 	iter=new Iter(que);
       
   926 	for(i=0;i<5;i++)
       
   927 		{
       
   928 		for(j=0;j<i;j++)
       
   929 			iter->sDoPostInc();
       
   930 		iter->SetToFirst();
       
   931 		test(*(iter->sNext)==&item1.iLink);
       
   932 		}
       
   933 	delete iter;
       
   934 	}
       
   935 
       
   936 template<class T,class Iter>
       
   937 void TestTQueIter<T,Iter>::Test5()
       
   938 	{
       
   939 	T item1,item2;
       
   940 	TSglQue<T> que(_FOFF(T,iLink));
       
   941 	Iter* iter;
       
   942 	T* a;
       
   943 
       
   944 	que.AddFirst(item2);
       
   945 	que.AddFirst(item1);
       
   946 	test.Start(_L("Constructor"));
       
   947 	iter=new Iter(que);
       
   948 	test.Next(_L("Iterators"));
       
   949 	a=*iter;
       
   950 	(*iter)++;
       
   951 	delete iter;
       
   952 	test.Next(_L("Finished"));
       
   953 	test.End();
       
   954 	}
       
   955 
       
   956 /*template<class T>											//Redundant
       
   957 void TestTQueIter<T>::Test6()
       
   958 	{
       
   959 	Item item;
       
   960 	TDblQue<Item>* que;
       
   961 	TInt offset;
       
   962  	T* iter;
       
   963 
       
   964 	for (offset=0;offset<40;offset+=4)
       
   965 		{
       
   966 		que=new TDblQue<Item>(offset);
       
   967 		iter=new T(*que);
       
   968 		test(que->IsHead((Item*) *(iter->sHead)));
       
   969 		test(que->IsHead((Item*) *(iter->sNext)));
       
   970 		test(*(iter->sOffset)==offset);
       
   971 		delete iter;
       
   972 		delete que;
       
   973 		que=new TDblQue<Item>(offset);
       
   974 		que->AddFirst(item);
       
   975 		iter=new T(*que);
       
   976 		test(que->IsHead((Item*) *(iter->sHead)));
       
   977 		test(*(iter->sNext)==&item.iLink);
       
   978 		test(*(iter->sOffset)==offset);
       
   979 		delete iter;
       
   980 		delete que;
       
   981 		}
       
   982 	}*/
       
   983 
       
   984 template<class T,class Iter>
       
   985 void TestTQueIter<T,Iter>::Test7()
       
   986 	{
       
   987 	T item1,item2,item3,item4;
       
   988 	TSglQue<T> que(_FOFF(T,iLink));
       
   989  	Iter* iter;
       
   990 				  
       
   991 	que.AddFirst(item4);
       
   992 	que.AddFirst(item3);
       
   993 	que.AddFirst(item2);
       
   994 	que.AddFirst(item1);
       
   995 	test.Start(_L("PostFix ++"));
       
   996 	iter=new Iter(que);
       
   997 	test(&item1==(*iter)++);
       
   998 	test(&item2.iLink==*(iter->sNext));
       
   999 	test(&item2==(*iter)++);
       
  1000 	test(&item3.iLink==*(iter->sNext));
       
  1001 	test(&item3==(*iter)++);
       
  1002 	test(&item4.iLink==*(iter->sNext));
       
  1003 	test(&item4==(*iter)++);
       
  1004 	test((Item*) *(iter->sNext)==NULL);
       
  1005 	test((*iter)++==NULL);
       
  1006 	delete iter;
       
  1007 	test.Next(_L("Conversion Operator"));
       
  1008 	iter=new Iter(que);
       
  1009 	test(&item1==*iter);
       
  1010 	(*iter)++;
       
  1011 	test(&item2==*iter);
       
  1012 	(*iter)++;
       
  1013 	test(&item3==*iter);
       
  1014 	(*iter)++;
       
  1015 	test(&item4==*iter);
       
  1016 	(*iter)++;
       
  1017 	test(*iter==NULL);
       
  1018 	delete iter;
       
  1019 	test.Next(_L("Finished"));
       
  1020 	test.End();
       
  1021 	}
       
  1022 	
       
  1023 #ifndef _DEBUG
       
  1024 #pragma warning (disable: 4710)
       
  1025 #endif
       
  1026 
       
  1027 GLDEF_C TInt E32Main()
       
  1028     {
       
  1029 
       
  1030 	TestTQueLink<TSglQueLink>* testSglQueLink;
       
  1031 	TestTQue<VSglQueBase>* testSglQueBase;
       
  1032 	TestTQue<VSglQue<TSglQueLink> >* testSglQue;
       
  1033 	TestTQueIter<Item,VSglQueIterBase>* testSglQueIterBase;
       
  1034 	TestTQueIter<Item,VSglQueIter<Item> >* testSglQueIter;
       
  1035 
       
  1036 	TestTQueIter<ItemWithOffset,VSglQueIterBase>* testSglQueIterBaseOffset;
       
  1037 	TestTQueIter<ItemWithOffset,VSglQueIter<ItemWithOffset> >* testSglQueIterOffset;
       
  1038  
       
  1039 	test.Title();
       
  1040 	test.Start(_L("class TSglQueLink"));
       
  1041 	testSglQueLink=new TestTQueLink<TSglQueLink>;
       
  1042 	testSglQueLink->TestQueLink();
       
  1043 	delete testSglQueLink;
       
  1044 
       
  1045 	test.Next(_L("class TSglQueBase"));
       
  1046 	testSglQueBase=new TestTQue<VSglQueBase>;
       
  1047 	testSglQueBase->TestQueBase();
       
  1048  	delete testSglQueBase;
       
  1049 
       
  1050 	test.Next(_L("class TSlgQue"));
       
  1051 	testSglQue=new TestTQue<VSglQue<TSglQueLink> >;
       
  1052 	testSglQue->TestSglQue();
       
  1053  	delete testSglQue;
       
  1054 
       
  1055 	test.Next(_L("class TSglQueIterBase"));
       
  1056 	testSglQueIterBase=new TestTQueIter<Item,VSglQueIterBase>;
       
  1057 	testSglQueIterBase->TestIterBase();
       
  1058  	delete testSglQueIterBase;
       
  1059 
       
  1060 	test.Next(_L("class TSglQueIter"));
       
  1061 	testSglQueIter=new TestTQueIter<Item,VSglQueIter<Item> >;
       
  1062 	testSglQueIter->TestQueIter();
       
  1063  	delete testSglQueIter;
       
  1064 
       
  1065 	test.Next(_L("class TSglQueIterBase with Offset"));
       
  1066 	testSglQueIterBaseOffset=new TestTQueIter<ItemWithOffset,VSglQueIterBase>;
       
  1067 	testSglQueIterBaseOffset->TestIterBase();
       
  1068  	delete testSglQueIterBaseOffset;
       
  1069 
       
  1070 	test.Next(_L("class TSglQueIter with Offset"));
       
  1071 	testSglQueIterOffset=new TestTQueIter<ItemWithOffset,VSglQueIter<ItemWithOffset> >;
       
  1072 	testSglQueIterOffset->TestQueIter();
       
  1073  	delete testSglQueIterOffset;
       
  1074 
       
  1075 	test.Next(_L("Finished"));
       
  1076 	test.End();
       
  1077 	return(KErrNone);
       
  1078     }
       
  1079 #pragma warning (default: 4710)
       
  1080 
       
  1081