sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\buffer\t_sque.cpp sl@0: // Overview: sl@0: // Test single linked list functionality. sl@0: // API Information: sl@0: // TSglQueLink, TSglQueBase. sl@0: // Details: sl@0: // - Create specified number of TSglQueLink objects, then delete them. sl@0: // - Create TSglQueBase object with specified offset and without an offset, sl@0: // add and remove links to the list, check that the list is empty. sl@0: // - Create TSglQueBase object with and without an offset, verify offset, head sl@0: // and last member values are correct. sl@0: // - Create TSglQueBase object, insert links using DoAddFirst and DoAddLast and sl@0: // remove links using DoRemove, check the results are as expected. sl@0: // - Create TSglQueBase object, insert links using DoAddFirst and DoAddLast and sl@0: // verify IsEmpty return the correct value. Set and verify the offset. sl@0: // - Create TSglQue object, insert TSglQueLink link at front and end of list, test sl@0: // whether the links are inserted at specified location, remove some links. sl@0: // - Create TSglQue object, insert links using DoAddFirst and DoAddLast and sl@0: // remove links using DoRemove, check the results are as expected. sl@0: // - Create TSglQue object, insert links using DoAddFirst and DoAddLast and sl@0: // verify IsEmpty return the correct value. Set and verify the offset. sl@0: // - Create TSglQue object with and without an offset, verify offset, head sl@0: // and last member values are correct. sl@0: // - Create TSglQue object, insert links using AddFirst and AddLast and sl@0: // verify results are as expected. sl@0: // - Create TSglQue object, insert links using AddFirst and AddLast and sl@0: // verify results using IsFirst and IsLast are as expected. sl@0: // - Create TSglQue object, insert links using AddFirst and AddLast and sl@0: // verify results using First and Last are as expected. sl@0: // - Create TSglQue object, insert links using AddLast and delete using Remove, sl@0: // verify results are as expected. sl@0: // - Create TSglQueIterBase object, with and without an offset, call the sl@0: // DoCurrent, DoPostInc and SetToFirst methods. sl@0: // - Create TSglQueIterBase object, with and without an offset, and TSglQue sl@0: // with different offsets, verify results are as expected. sl@0: // - Create TSglQueIterBase object, , with and without an offset, use the sl@0: // DoCurrent and DoPostInc methods and verify the results are as expected. sl@0: // - Create TSglQueIterBase object, , with and without an offset, use the sl@0: // DoPostInc and SetToFirst methods and verify the results are as expected. sl@0: // - Create TSglQueIter object, with and without an offset, iterate using sl@0: // the ++ operator and delete the object. sl@0: // - Create TSglQueIter object, with and without an offset, and TSglQue sl@0: // object with different offsets, verify results are as expected. sl@0: // - Create TSglQueIter object, with and without an offset, use the sl@0: // DoCurrent and DoPostInc methods and verify the results are as expected. sl@0: // - Create TSglQueIter object, with and without an offset, use the sl@0: // DoPostInc and SetToFirst methods and verify the results are as expected. sl@0: // - Create TSglQueIter object, with and without an offset, iterate using sl@0: // the ++ operator, use the conversion operator, verify the results are sl@0: // as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // All sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("T_SQUE")); sl@0: sl@0: #define SIZE 10 sl@0: #define MAX_OFFSET 10 sl@0: sl@0: struct Item sl@0: { sl@0: TSglQueLink iLink; sl@0: TInt iSpace[MAX_OFFSET]; // Reserve some space sl@0: }; sl@0: sl@0: struct ItemWithOffset sl@0: { sl@0: TInt iSpace[MAX_OFFSET]; sl@0: TSglQueLink iLink; sl@0: }; sl@0: sl@0: template sl@0: class TestTQueLink sl@0: { sl@0: public: sl@0: void TestQueLink(); // Calls Test: 1 sl@0: void Test1(); sl@0: protected: sl@0: void CreateObjects(TInt aBaseLink); sl@0: void DestroyObjects(); sl@0: private: sl@0: T* iLink[SIZE]; sl@0: }; sl@0: sl@0: template sl@0: void TestTQueLink::CreateObjects(TInt aBaseLink) sl@0: { sl@0: TInt i; sl@0: sl@0: for (i=0;i=0&&aBaseLinkiNext=iLink[aBaseLink]; sl@0: } sl@0: sl@0: template sl@0: void TestTQueLink::DestroyObjects() sl@0: { sl@0: TInt i; sl@0: sl@0: for (i=0;i sl@0: void TestTQueLink::TestQueLink() sl@0: { sl@0: test.Start(_L("Test Enque")); sl@0: Test1(); sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQueLink::Test1() sl@0: { sl@0: test.Start(_L("Create objects")); sl@0: CreateObjects(1); sl@0: test.Next(_L("Destroy objects")); sl@0: DestroyObjects(); sl@0: test.End(); sl@0: } sl@0: sl@0: class VSglQueBase : public TSglQueBase sl@0: { sl@0: public: sl@0: inline VSglQueBase(); sl@0: inline VSglQueBase(TInt anOffset); sl@0: inline void sDoAddFirst(TAny* aPtr) {this->DoAddFirst(aPtr);} sl@0: inline void sDoAddLast(TAny* aPtr) {this->DoAddLast(aPtr);} sl@0: inline void sDoRemove(TAny* aPtr) {this->DoRemove(aPtr);} sl@0: public: sl@0: TSglQueLink** sHead; sl@0: TSglQueLink** sLast; sl@0: TInt* sOffset; sl@0: private: sl@0: void SetMembers(); sl@0: }; sl@0: sl@0: template sl@0: class VSglQue : public TSglQue sl@0: { sl@0: public: sl@0: inline VSglQue(); sl@0: inline VSglQue(TInt anOffset); sl@0: inline void sDoAddFirst(TAny* aPtr) {this->DoAddFirst(aPtr);} sl@0: inline void sDoAddLast(TAny* aPtr) {this->DoAddLast(aPtr);} sl@0: inline void sDoRemove(TAny* aPtr) {this->DoRemove(aPtr);} sl@0: public: sl@0: TSglQueLink** sHead; sl@0: TSglQueLink** sLast; sl@0: TInt* sOffset; sl@0: private: sl@0: void SetMembers(); sl@0: }; sl@0: sl@0: inline VSglQueBase::VSglQueBase() sl@0: { sl@0: SetMembers(); sl@0: } sl@0: sl@0: inline VSglQueBase::VSglQueBase(TInt anOffset) sl@0: :TSglQueBase(anOffset) sl@0: { sl@0: SetMembers(); sl@0: } sl@0: sl@0: void VSglQueBase::SetMembers() sl@0: { sl@0: sHead=&iHead; sl@0: sLast=&iLast; sl@0: sOffset=&iOffset; sl@0: } sl@0: sl@0: template sl@0: VSglQue::VSglQue() sl@0: { sl@0: SetMembers(); sl@0: } sl@0: sl@0: template sl@0: VSglQue::VSglQue(TInt anOffset) sl@0: :TSglQue(anOffset) sl@0: { sl@0: SetMembers(); sl@0: } sl@0: sl@0: template sl@0: void VSglQue::SetMembers() sl@0: { sl@0: sHead=&this->iHead; sl@0: sLast=&this->iLast; sl@0: sOffset=&this->iOffset; sl@0: } sl@0: sl@0: template sl@0: class TestTQue sl@0: { sl@0: public: sl@0: void TestQueBase(); sl@0: void TestSglQue(); sl@0: void Test1(); // All functions //TSglQueBase functions sl@0: void Test2(); // Constructors sl@0: void Test3(); // DoAdd's sl@0: void Test4(); // Public functions sl@0: void Test5(); // All functions //TSglQue sl@0: //void Test6(); // Constructors sl@0: void Test7(); // Add's sl@0: void Test8(); // Is's sl@0: void Test9(); // Get's sl@0: void Test10(); // Add's sl@0: private: sl@0: void CallTest3_4(); sl@0: }; sl@0: sl@0: template sl@0: void TestTQue::CallTest3_4() sl@0: { sl@0: test.Next(_L("Test DoAdd's")); sl@0: Test3(); sl@0: test.Next(_L("Test public functions")); sl@0: Test4(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::TestQueBase() sl@0: { sl@0: test.Start(_L("Test all member functions (simply)")); sl@0: Test1(); sl@0: test.Next(_L("Test Constructors")); sl@0: Test2(); sl@0: CallTest3_4(); sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::TestSglQue() sl@0: { sl@0: test.Start(_L("Test all member functions (simply)")); sl@0: Test5(); sl@0: test.Next(_L("Test Super Class functions")); sl@0: CallTest3_4(); sl@0: test.Next(_L("Test Constructors")); sl@0: Test2(); sl@0: test.Next(_L("Test Add's")); sl@0: Test7(); sl@0: test.Next(_L("Test Is's")); sl@0: Test8(); sl@0: test.Next(_L("Test Get's")); sl@0: Test9(); sl@0: test.Next(_L("Test Remove")); sl@0: Test10(); sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test1() sl@0: { sl@0: T* que; sl@0: TSglQueLink link1,link2; sl@0: TInt offset=4; sl@0: sl@0: test.Start(_L("Constructors")); sl@0: que=new VSglQueBase(offset); sl@0: delete que; sl@0: que=new VSglQueBase; sl@0: //delete que; sl@0: test.Next(_L("DoAdd's")); sl@0: que->sDoAddFirst(&link1); sl@0: que->sDoAddLast(&link2); sl@0: que->sDoRemove(&link1); sl@0: que->sDoRemove(&link2); sl@0: test.Next(_L("Public")); sl@0: que->IsEmpty(); sl@0: que->SetOffset(offset); sl@0: test.Next(_L("Finished")); sl@0: delete que; sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test2() sl@0: { sl@0: T* que; sl@0: TInt offset; sl@0: sl@0: test.Start(_L("Default constructor")); sl@0: que=new T(); sl@0: test(*(que->sOffset)==0); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: delete que; sl@0: test.Next(_L("Offset constructor")); sl@0: for (offset=0;offset<40;offset+=4) sl@0: { sl@0: que=new T(offset); sl@0: test(*(que->sOffset)==offset); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: delete que; sl@0: } sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test3() sl@0: { sl@0: T* que; sl@0: sl@0: { sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Start(_L("AddFirst")); sl@0: que=new T(); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: que->sDoAddFirst(&link1); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: que->sDoAddFirst(&link2); sl@0: test(*(que->sHead)==&link2); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: test(link2.iNext==&link1); sl@0: que->sDoAddFirst(&link3); sl@0: test(*(que->sHead)==&link3); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: test(link2.iNext==&link1); sl@0: test(link3.iNext==&link2); sl@0: que->sDoAddFirst(&link4); sl@0: test(*(que->sHead)==&link4); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: test(link2.iNext==&link1); sl@0: test(link3.iNext==&link2); sl@0: test(link4.iNext==&link3); sl@0: delete que; sl@0: } sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Next(_L("AddLast")); sl@0: que=new T(); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: que->sDoAddLast(&link1); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: que->sDoAddLast(&link2); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link2); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==NULL); sl@0: que->sDoAddLast(&link3); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link3); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==&link3); sl@0: test(link3.iNext==NULL); sl@0: que->sDoAddLast(&link4); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link4); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==&link3); sl@0: test(link3.iNext==&link4); sl@0: test(link4.iNext==NULL); sl@0: test.Next(_L("Remove")); sl@0: que->sDoRemove(&link3); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link4); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==&link4); sl@0: test(link4.iNext==NULL); sl@0: que->sDoRemove(&link4); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link2); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==NULL); sl@0: que->sDoRemove(&link1); sl@0: test(*(que->sHead)==&link2); sl@0: test(*(que->sLast)==&link2); sl@0: test(link2.iNext==NULL); sl@0: que->sDoRemove(&link2); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: delete que; sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test4() sl@0: { sl@0: T* que; sl@0: TInt offset; sl@0: sl@0: test.Start(_L("IsEmpty")); sl@0: que=new T(); sl@0: test(que->IsEmpty()==TRUE); sl@0: TSglQueLink link1,link2; sl@0: que->sDoAddFirst(&link1); sl@0: test(que->IsEmpty()==FALSE); sl@0: que->sDoRemove(&link1); sl@0: test(que->IsEmpty()==TRUE); sl@0: que->sDoAddLast(&link2); sl@0: test(que->IsEmpty()==FALSE); sl@0: que->sDoAddFirst(&link1); sl@0: test(que->IsEmpty()==FALSE); sl@0: que->sDoRemove(&link2); sl@0: test(que->IsEmpty()==FALSE); sl@0: que->sDoRemove(&link1); sl@0: test(que->IsEmpty()==TRUE); sl@0: test.Next(_L("SetOffset")); sl@0: for (offset=0;offset<40;offset+=4) sl@0: { sl@0: que->SetOffset(offset); sl@0: test(*(que->sOffset)==offset); sl@0: } sl@0: test.Next(_L("Finished")); sl@0: delete que; sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test5() sl@0: { sl@0: T* que; sl@0: TSglQueLink link1,link2; sl@0: TInt offset=4; sl@0: sl@0: test.Start(_L("Constructors")); sl@0: que=new VSglQue(offset); sl@0: delete que; sl@0: que=new VSglQue; sl@0: test.Next(_L("Add's")); sl@0: que->AddFirst(link1); sl@0: que->AddLast(link2); sl@0: test.Next(_L("Is's")); sl@0: que->IsFirst(&link1); sl@0: que->IsLast(&link1); sl@0: test.Next(_L("Get's")); sl@0: que->First(); sl@0: que->Last(); sl@0: test.Next(_L("Remove")); sl@0: que->Remove(link1); sl@0: que->Remove(link2); sl@0: test.Next(_L("Finished")); sl@0: delete que; sl@0: test.End(); sl@0: } sl@0: sl@0: /*template sl@0: void TestTQue::Test6() sl@0: { sl@0: T* que; sl@0: TInt offset; sl@0: sl@0: test.Start(_L("Default constructor")); sl@0: que=new VSglQue(); sl@0: test(*(que->sFirstDelta)==NULL); sl@0: delete que; sl@0: test.Next(_L("Offset constructor")); sl@0: for (offset=0;offset<40;offset+=4) sl@0: { sl@0: que=new VDeltaQueBase(offset); sl@0: test(*(que->sOffset)==offset); sl@0: test(*(que->sFirstDelta)==NULL); sl@0: delete que; sl@0: } sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: }*/ sl@0: sl@0: template sl@0: void TestTQue::Test7() sl@0: { sl@0: T* que; sl@0: sl@0: { sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Start(_L("AddFirst")); sl@0: que=new T(); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: que->AddFirst(link1); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: que->AddFirst(link2); sl@0: test(*(que->sHead)==&link2); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: test(link2.iNext==&link1); sl@0: que->AddFirst(link3); sl@0: test(*(que->sHead)==&link3); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: test(link2.iNext==&link1); sl@0: test(link3.iNext==&link2); sl@0: que->AddFirst(link4); sl@0: test(*(que->sHead)==&link4); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: test(link2.iNext==&link1); sl@0: test(link3.iNext==&link2); sl@0: test(link4.iNext==&link3); sl@0: delete que; sl@0: } sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Next(_L("AddLast")); sl@0: que=new T(); sl@0: test.Next(_L("AddLast")); sl@0: que=new T(); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: que->AddLast(link1); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link1); sl@0: test(link1.iNext==NULL); sl@0: que->AddLast(link2); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link2); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==NULL); sl@0: que->AddLast(link3); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link3); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==&link3); sl@0: test(link3.iNext==NULL); sl@0: que->AddLast(link4); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link4); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==&link3); sl@0: test(link3.iNext==&link4); sl@0: test(link4.iNext==NULL); sl@0: delete que; sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test8() sl@0: { sl@0: T* que; sl@0: sl@0: { sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Start(_L("IsFirst")); sl@0: que=new T(); sl@0: test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE); sl@0: que->AddFirst(link1); sl@0: test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sLast))==TRUE); sl@0: test(que->IsFirst(&link1)==TRUE); sl@0: que->AddFirst(link2); sl@0: test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE); sl@0: test(que->IsFirst(&link1)==FALSE); sl@0: test(que->IsFirst(&link2)==TRUE); sl@0: que->AddFirst(link3); sl@0: test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE); sl@0: test(que->IsFirst(&link1)==FALSE); sl@0: test(que->IsFirst(&link2)==FALSE); sl@0: test(que->IsFirst(&link3)==TRUE); sl@0: que->AddFirst(link4); sl@0: test(que->IsFirst((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sHead))==TRUE); sl@0: test(que->IsFirst((TSglQueLink*) *(que->sLast))==FALSE); sl@0: test(que->IsFirst(&link1)==FALSE); sl@0: test(que->IsFirst(&link2)==FALSE); sl@0: test(que->IsFirst(&link3)==FALSE); sl@0: test(que->IsFirst(&link4)==TRUE); sl@0: delete que; sl@0: } sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Next(_L("IsLast")); sl@0: que=new T(); sl@0: test(que->IsLast((TSglQueLink*) que->sHead)==TRUE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE); sl@0: que->AddLast(link1); sl@0: test(que->IsLast((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sHead))==TRUE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE); sl@0: test(que->IsLast(&link1)==TRUE); sl@0: que->AddLast(link2); sl@0: test(que->IsLast((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE); sl@0: test(que->IsLast(&link1)==FALSE); sl@0: test(que->IsLast(&link2)==TRUE); sl@0: que->AddLast(link3); sl@0: test(que->IsLast((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE); sl@0: test(que->IsLast(&link1)==FALSE); sl@0: test(que->IsLast(&link2)==FALSE); sl@0: test(que->IsLast(&link3)==TRUE); sl@0: que->AddLast(link4); sl@0: test(que->IsLast((TSglQueLink*) que->sHead)==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sHead))==FALSE); sl@0: test(que->IsLast((TSglQueLink*) *(que->sLast))==TRUE); sl@0: test(que->IsLast(&link1)==FALSE); sl@0: test(que->IsLast(&link2)==FALSE); sl@0: test(que->IsLast(&link3)==FALSE); sl@0: test(que->IsLast(&link4)==TRUE); sl@0: test.Next(_L("Finished")); sl@0: delete que; sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test9() sl@0: { sl@0: T* que; sl@0: sl@0: { sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Start(_L("First")); sl@0: que=new T(); sl@0: test(que->First()==NULL); sl@0: que->AddFirst(link1); sl@0: test(que->First()==&link1); sl@0: que->AddFirst(link2); sl@0: test(que->First()==&link2); sl@0: que->AddFirst(link3); sl@0: test(que->First()==&link3); sl@0: que->AddFirst(link4); sl@0: test(que->First()==&link4); sl@0: delete que; sl@0: } sl@0: TSglQueLink link1,link2,link3,link4; sl@0: test.Next(_L("Last")); sl@0: que=new T(); sl@0: test(que->Last()==(TSglQueLink*) que->sHead); sl@0: que->AddLast(link1); sl@0: test(que->Last()==&link1); sl@0: que->AddLast(link2); sl@0: test(que->Last()==&link2); sl@0: que->AddLast(link3); sl@0: test(que->Last()==&link3); sl@0: que->AddLast(link4); sl@0: test(que->Last()==&link4); sl@0: test.Next(_L("Finished")); sl@0: delete que; sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQue::Test10() sl@0: { sl@0: T* que; sl@0: TSglQueLink link1,link2,link3,link4; sl@0: sl@0: que=new T(); sl@0: que->AddLast(link1); sl@0: que->AddLast(link2); sl@0: que->AddLast(link3); sl@0: que->AddLast(link4); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link4); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==&link3); sl@0: test(link3.iNext==&link4); sl@0: test(link4.iNext==NULL); sl@0: que->Remove(link3); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link4); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==&link4); sl@0: test(link4.iNext==NULL); sl@0: que->Remove(link4); sl@0: test(*(que->sHead)==&link1); sl@0: test(*(que->sLast)==&link2); sl@0: test(link1.iNext==&link2); sl@0: test(link2.iNext==NULL); sl@0: que->Remove(link1); sl@0: test(*(que->sHead)==&link2); sl@0: test(*(que->sLast)==&link2); sl@0: test(link2.iNext==NULL); sl@0: que->Remove(link2); sl@0: test(*(que->sHead)==NULL); sl@0: test(*(que->sLast)==(TSglQueLink*) que->sHead); sl@0: delete que; sl@0: } sl@0: sl@0: class VSglQueIterBase : public TSglQueIterBase sl@0: { sl@0: public: sl@0: VSglQueIterBase(TSglQueBase& aQue); sl@0: inline TAny* sDoPostInc() {return DoPostInc();} sl@0: inline TAny* sDoCurrent() {return DoCurrent();} sl@0: public: sl@0: TInt* sOffset; sl@0: TSglQueLink** sHead; sl@0: TSglQueLink** sNext; sl@0: private: sl@0: void SetMember(); sl@0: }; sl@0: sl@0: template sl@0: class VSglQueIter : public TSglQueIter sl@0: { sl@0: public: sl@0: VSglQueIter(TSglQue& aQue); sl@0: inline TAny* sDoPostInc() {return this->DoPostInc();} sl@0: inline TAny* sDoCurrent() {return this->DoCurrent();} sl@0: public: sl@0: TInt* sOffset; sl@0: TSglQueLink** sHead; sl@0: TSglQueLink** sNext; sl@0: private: sl@0: void SetMember(); sl@0: }; sl@0: sl@0: VSglQueIterBase::VSglQueIterBase(TSglQueBase& aQue) sl@0: :TSglQueIterBase(aQue) sl@0: { sl@0: SetMember(); sl@0: } sl@0: sl@0: void VSglQueIterBase::SetMember() sl@0: { sl@0: sOffset=&iOffset; sl@0: sHead=&iHead; sl@0: sNext=&iNext; sl@0: } sl@0: sl@0: template sl@0: VSglQueIter::VSglQueIter(TSglQue& aQue) sl@0: :TSglQueIter(aQue) sl@0: { sl@0: SetMember(); sl@0: } sl@0: sl@0: template sl@0: void VSglQueIter::SetMember() sl@0: { sl@0: sOffset=&this->iOffset; sl@0: sHead=&this->iHead; sl@0: sNext=&this->iNext; sl@0: } sl@0: sl@0: template sl@0: class TestTQueIter sl@0: { sl@0: public: sl@0: void TestIterBase(); sl@0: void TestQueIter(); sl@0: void Test1(); //All functions //TSglQueIterBase sl@0: void Test2(); //Constructor sl@0: void Test3(); //Do's sl@0: void Test4(); //Set sl@0: void Test5(); //All functions //TDblQueIter sl@0: //void Test6(); //Constructors //Redundant sl@0: void Test7(); //Iterators sl@0: private: sl@0: void CallTest2_4(); sl@0: }; sl@0: sl@0: template sl@0: void TestTQueIter::CallTest2_4() sl@0: { sl@0: test.Next(_L("Constructors")); sl@0: Test2(); sl@0: test.Next(_L("Do's")); sl@0: Test3(); sl@0: test.Next(_L("Sets")); sl@0: Test4(); sl@0: } sl@0: sl@0: template sl@0: void TestTQueIter::TestIterBase() sl@0: { sl@0: test.Start(_L("All Methods")); sl@0: Test1(); sl@0: CallTest2_4(); sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQueIter::TestQueIter() sl@0: { sl@0: test.Start(_L("All Methods")); sl@0: Test5(); sl@0: CallTest2_4(); sl@0: test.Next(_L("Iterators")); sl@0: Test7(); sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQueIter::Test1() sl@0: { sl@0: T item1,item2; sl@0: TSglQue que(_FOFF(T,iLink)); sl@0: Iter* iter; sl@0: sl@0: que.AddFirst(item2); sl@0: que.AddFirst(item1); sl@0: test.Start(_L("Constructor")); sl@0: iter=new Iter(que); sl@0: test.Next(_L("Do's")); sl@0: iter->sDoCurrent(); sl@0: iter->sDoPostInc(); sl@0: test.Next(_L("Sets")); sl@0: iter->SetToFirst(); sl@0: delete iter; sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQueIter::Test2() sl@0: { sl@0: TSglQue* que; sl@0: TInt offset; sl@0: Iter* iter; sl@0: TSglQueLink* head; sl@0: sl@0: for (offset=0;offset<40;offset+=4) sl@0: { sl@0: que=new TSglQue(offset); sl@0: iter=new Iter(*que); sl@0: test(*(iter->sHead)==PtrAdd((TSglQueLink*) que->Last(),offset)); sl@0: head=*(iter->sHead); sl@0: test(que->IsFirst((T*) PtrSub(*(iter->sNext),offset))); //Need to pass a pointer to a item sl@0: test(*(iter->sOffset)==offset); sl@0: delete iter; sl@0: T item; sl@0: que->AddFirst(item); sl@0: iter=new Iter(*que); sl@0: test(*(iter->sHead)==head); sl@0: test(que->IsFirst((T*) PtrSub(*(iter->sNext),offset))); sl@0: test(*(iter->sOffset)==offset); sl@0: delete iter; sl@0: delete que; sl@0: } sl@0: } sl@0: sl@0: template sl@0: void TestTQueIter::Test3() sl@0: { sl@0: T item1,item2,item3,item4; sl@0: TSglQue que(_FOFF(T,iLink)); sl@0: Iter* iter; sl@0: sl@0: que.AddFirst(item4); sl@0: que.AddFirst(item3); sl@0: que.AddFirst(item2); sl@0: que.AddFirst(item1); sl@0: test.Start(_L("DoPostInc")); sl@0: iter=new Iter(que); sl@0: test(&item1==iter->sDoPostInc()); sl@0: test(&item2.iLink==*(iter->sNext)); sl@0: test(&item2==iter->sDoPostInc()); sl@0: test(&item3.iLink==*(iter->sNext)); sl@0: test(&item3==iter->sDoPostInc()); sl@0: test(&item4.iLink==*(iter->sNext)); sl@0: test(&item4==iter->sDoPostInc()); sl@0: test((Item*) *(iter->sNext)==NULL); sl@0: test(iter->sDoPostInc()==NULL); sl@0: delete iter; sl@0: test.Next(_L("DoCurrent")); sl@0: iter=new Iter(que); sl@0: test(&item1==iter->sDoCurrent()); sl@0: iter->sDoPostInc(); sl@0: test(&item2==iter->sDoCurrent()); sl@0: iter->sDoPostInc(); sl@0: test(&item3==iter->sDoCurrent()); sl@0: iter->sDoPostInc(); sl@0: test(&item4==iter->sDoCurrent()); sl@0: iter->sDoPostInc(); sl@0: test(iter->sDoCurrent()==NULL); sl@0: delete iter; sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: template sl@0: void TestTQueIter::Test4() sl@0: { sl@0: T item1,item2,item3,item4; sl@0: TSglQue que(_FOFF(T,iLink)); sl@0: Iter* iter; sl@0: TInt i,j; sl@0: sl@0: que.AddFirst(item4); sl@0: que.AddFirst(item3); sl@0: que.AddFirst(item2); sl@0: que.AddFirst(item1); sl@0: iter=new Iter(que); sl@0: for(i=0;i<5;i++) sl@0: { sl@0: for(j=0;jsDoPostInc(); sl@0: iter->SetToFirst(); sl@0: test(*(iter->sNext)==&item1.iLink); sl@0: } sl@0: delete iter; sl@0: } sl@0: sl@0: template sl@0: void TestTQueIter::Test5() sl@0: { sl@0: T item1,item2; sl@0: TSglQue que(_FOFF(T,iLink)); sl@0: Iter* iter; sl@0: T* a; sl@0: sl@0: que.AddFirst(item2); sl@0: que.AddFirst(item1); sl@0: test.Start(_L("Constructor")); sl@0: iter=new Iter(que); sl@0: test.Next(_L("Iterators")); sl@0: a=*iter; sl@0: (*iter)++; sl@0: delete iter; sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: /*template //Redundant sl@0: void TestTQueIter::Test6() sl@0: { sl@0: Item item; sl@0: TDblQue* que; sl@0: TInt offset; sl@0: T* iter; sl@0: sl@0: for (offset=0;offset<40;offset+=4) sl@0: { sl@0: que=new TDblQue(offset); sl@0: iter=new T(*que); sl@0: test(que->IsHead((Item*) *(iter->sHead))); sl@0: test(que->IsHead((Item*) *(iter->sNext))); sl@0: test(*(iter->sOffset)==offset); sl@0: delete iter; sl@0: delete que; sl@0: que=new TDblQue(offset); sl@0: que->AddFirst(item); sl@0: iter=new T(*que); sl@0: test(que->IsHead((Item*) *(iter->sHead))); sl@0: test(*(iter->sNext)==&item.iLink); sl@0: test(*(iter->sOffset)==offset); sl@0: delete iter; sl@0: delete que; sl@0: } sl@0: }*/ sl@0: sl@0: template sl@0: void TestTQueIter::Test7() sl@0: { sl@0: T item1,item2,item3,item4; sl@0: TSglQue que(_FOFF(T,iLink)); sl@0: Iter* iter; sl@0: sl@0: que.AddFirst(item4); sl@0: que.AddFirst(item3); sl@0: que.AddFirst(item2); sl@0: que.AddFirst(item1); sl@0: test.Start(_L("PostFix ++")); sl@0: iter=new Iter(que); sl@0: test(&item1==(*iter)++); sl@0: test(&item2.iLink==*(iter->sNext)); sl@0: test(&item2==(*iter)++); sl@0: test(&item3.iLink==*(iter->sNext)); sl@0: test(&item3==(*iter)++); sl@0: test(&item4.iLink==*(iter->sNext)); sl@0: test(&item4==(*iter)++); sl@0: test((Item*) *(iter->sNext)==NULL); sl@0: test((*iter)++==NULL); sl@0: delete iter; sl@0: test.Next(_L("Conversion Operator")); sl@0: iter=new Iter(que); sl@0: test(&item1==*iter); sl@0: (*iter)++; sl@0: test(&item2==*iter); sl@0: (*iter)++; sl@0: test(&item3==*iter); sl@0: (*iter)++; sl@0: test(&item4==*iter); sl@0: (*iter)++; sl@0: test(*iter==NULL); sl@0: delete iter; sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: } sl@0: sl@0: #ifndef _DEBUG sl@0: #pragma warning (disable: 4710) sl@0: #endif sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: TestTQueLink* testSglQueLink; sl@0: TestTQue* testSglQueBase; sl@0: TestTQue >* testSglQue; sl@0: TestTQueIter* testSglQueIterBase; sl@0: TestTQueIter >* testSglQueIter; sl@0: sl@0: TestTQueIter* testSglQueIterBaseOffset; sl@0: TestTQueIter >* testSglQueIterOffset; sl@0: sl@0: test.Title(); sl@0: test.Start(_L("class TSglQueLink")); sl@0: testSglQueLink=new TestTQueLink; sl@0: testSglQueLink->TestQueLink(); sl@0: delete testSglQueLink; sl@0: sl@0: test.Next(_L("class TSglQueBase")); sl@0: testSglQueBase=new TestTQue; sl@0: testSglQueBase->TestQueBase(); sl@0: delete testSglQueBase; sl@0: sl@0: test.Next(_L("class TSlgQue")); sl@0: testSglQue=new TestTQue >; sl@0: testSglQue->TestSglQue(); sl@0: delete testSglQue; sl@0: sl@0: test.Next(_L("class TSglQueIterBase")); sl@0: testSglQueIterBase=new TestTQueIter; sl@0: testSglQueIterBase->TestIterBase(); sl@0: delete testSglQueIterBase; sl@0: sl@0: test.Next(_L("class TSglQueIter")); sl@0: testSglQueIter=new TestTQueIter >; sl@0: testSglQueIter->TestQueIter(); sl@0: delete testSglQueIter; sl@0: sl@0: test.Next(_L("class TSglQueIterBase with Offset")); sl@0: testSglQueIterBaseOffset=new TestTQueIter; sl@0: testSglQueIterBaseOffset->TestIterBase(); sl@0: delete testSglQueIterBaseOffset; sl@0: sl@0: test.Next(_L("class TSglQueIter with Offset")); sl@0: testSglQueIterOffset=new TestTQueIter >; sl@0: testSglQueIterOffset->TestQueIter(); sl@0: delete testSglQueIterOffset; sl@0: sl@0: test.Next(_L("Finished")); sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: #pragma warning (default: 4710) sl@0: sl@0: