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