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_key.cpp sl@0: // Overview: sl@0: // Test arrays keys against flat and segmented arrays of characters (8 and 16 bit) and records. sl@0: // API Information: sl@0: // TKeyArrayFix, TKeyArrayVar. sl@0: // Details: sl@0: // - Create flat and segmented array of TText8, TText16, TText. Append some text to the sl@0: // arrays and test the functions of the TKeyArrayFix class using the Find method which sl@0: // calls SetPtr, Set, Compare methods with ECmpNormal8, ECmpFolded8, ECmpCollated8, sl@0: // ECmpNormal16, ECmpFolded16, ECmpCollated16, ECmpNormal, ECmpFolded, ECmpCollated key types. sl@0: // - Test the functions of the TKeyArrayVar class using the Find method which calls SetPtr, Set, sl@0: // Compare methods with ECmpNormal8, ECmpFolded8, ECmpCollated8, ECmpNormal16, ECmpFolded16, sl@0: // ECmpCollated16, ECmpNormal, ECmpFolded, ECmpCollated key types. sl@0: // - Create flat and segmented array of TText, append some structures with different values. sl@0: // - Test the functions of the TKeyArrayFix, TKeyArrayVar classes by searching the values using sl@0: // sequential search technique with ECmpNormal, ECmpTInt32 key type and verifying that it is sl@0: // found at correct position. sl@0: // - For TKeyArrayFix and TKeyArrayVar class, create a flat array of TText, append some structures sl@0: // with different numeric values, sort the array, search the values using ECmpTInt, ECmpTUint, sl@0: // ECmpTint8, ECmpTUint8, ECmpTint16, ECmpTUint16, ECmpTint32, ECmpTUint32 key types and verify sl@0: // that values are found in order 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: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __VC32__ sl@0: #pragma warning (disable:4710) // Function not expanded sl@0: #pragma warning (disable:4702) // Unreachable code sl@0: #endif sl@0: sl@0: const TInt KTestGranularity=0x02; sl@0: sl@0: LOCAL_D RTest test(_L("T_KEY")); sl@0: sl@0: template sl@0: class TArr sl@0: { sl@0: public: sl@0: TArr() {} sl@0: TInt Count() const {return S;} sl@0: T& operator[](TInt anIndex) {return iArr[anIndex];} sl@0: const T& operator[](TInt anIndex) const {return iArr[anIndex];} sl@0: private: sl@0: T iArr[S]; sl@0: }; sl@0: sl@0: //#if defined(_DEBUG) sl@0: struct Record sl@0: { sl@0: TBuf<0x10> name; sl@0: TInt32 age; sl@0: TText8 code; sl@0: }; sl@0: sl@0: struct Record2 sl@0: { sl@0: TInt tint; sl@0: TUint tuint; sl@0: TInt8 tint8; sl@0: TUint8 tuint8; sl@0: TInt16 tint16; sl@0: TUint16 tuint16; sl@0: TInt32 tint32; sl@0: TUint32 tuint32; sl@0: }Rec1, Rec2, Rec3, Rec4; sl@0: sl@0: LOCAL_C void SetRecordData(void) sl@0: { sl@0: Rec1.tint=KMaxTInt; sl@0: Rec2.tint=0; sl@0: Rec3.tint=-KMaxTInt; sl@0: Rec4.tint=KMinTInt; sl@0: Rec1.tint8=KMaxTInt8; sl@0: Rec2.tint8=0; sl@0: Rec3.tint8=-KMaxTInt8; sl@0: Rec4.tint8=(TInt8)KMinTInt8; sl@0: Rec1.tint16=KMaxTInt16; sl@0: Rec2.tint16=0; sl@0: Rec3.tint16=-KMaxTInt16; sl@0: Rec4.tint16=(TInt16)KMinTInt16; sl@0: Rec1.tint32=KMaxTInt32; sl@0: Rec2.tint32=0; sl@0: Rec3.tint32=-KMaxTInt32; sl@0: Rec4.tint32=(TInt32)KMinTInt32; sl@0: Rec1.tuint=0; sl@0: Rec2.tuint=1; sl@0: Rec3.tuint=KMaxTUint-1; sl@0: Rec4.tuint=KMaxTUint; sl@0: Rec1.tuint8=0; sl@0: Rec2.tuint8=1; sl@0: Rec3.tuint8=(TUint8)(KMaxTUint8-1); sl@0: Rec4.tuint8=(TUint8)KMaxTUint8; sl@0: Rec1.tuint16=0; sl@0: Rec2.tuint16=1; sl@0: Rec3.tuint16=(TUint16)(KMaxTUint16-1); sl@0: Rec4.tuint16=(TUint16)KMaxTUint16; sl@0: Rec1.tuint32=0; sl@0: Rec2.tuint32=1; sl@0: Rec3.tuint32=(TUint32)(KMaxTUint32-1); sl@0: Rec4.tuint32=KMaxTUint32; sl@0: } sl@0: sl@0: typedef enum {eEight, eSixteen} TMode; sl@0: sl@0: template // S is TText8, TTExt etc. called S as _TL requires S in e32test.h sl@0: class TestTKey sl@0: { sl@0: public: sl@0: void Test1(TKeyCmpText, TKeyCmpText, TKeyCmpText); sl@0: void Test2(TKeyCmpText, TKeyCmpText, TKeyCmpText); sl@0: void Test3(void); sl@0: void Test4(void); sl@0: void Test5(void); sl@0: void Test6(void); sl@0: }; sl@0: sl@0: template sl@0: GLDEF_C void TestTKey::Test1(TKeyCmpText N, TKeyCmpText F, TKeyCmpText C) sl@0: { sl@0: // This tests the functions of the TKey classes indirectly - mostly using the Find method sl@0: // which calls SetPtr(), Set() (both trivial) and more importantly Compare(), sl@0: sl@0: ArrayType* pArray=new ArrayType(KTestGranularity); sl@0: pArray->AppendL(*(const TArr*)_TL("aa cc")); sl@0: pArray->AppendL(*(const TArr*)_TL("bb bb")); sl@0: pArray->AppendL(*(const TArr*)_TL("cc aa")); sl@0: sl@0: KeyType NormalKey(0,N,5); sl@0: KeyType NormalKeyOffset(sizeof(S)*3,N,2) ; sl@0: KeyType FoldedKey(0,F,5); sl@0: KeyType FoldedKeyOffset(sizeof(S)*3,F,2); sl@0: KeyType CollatedKey(0,C,5); sl@0: KeyType CollatedKeyOffset(sizeof(S)*3,C,2); sl@0: sl@0: TInt pos; sl@0: test(pArray->Find(*(const TArr*)_TL("aa cc"), NormalKey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(const TArr*)_TL("bb bb"), NormalKey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(const TArr*)_TL("cc aa"), NormalKey, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(const TArr*)_TL("BB BB"), NormalKey, pos)!=0); sl@0: sl@0: sl@0: test(pArray->Find(*(const TArr*)_TL("___cc"), NormalKeyOffset, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(const TArr*)_TL("___bb"), NormalKeyOffset, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(const TArr*)_TL("___aa"), NormalKeyOffset, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(const TArr*)_TL("___ax"), NormalKeyOffset, pos)!=0); sl@0: sl@0: sl@0: test(pArray->Find(*(const TArr*)_TL("aa cc"), FoldedKey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(const TArr*)_TL("bb bb"), FoldedKey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(const TArr*)_TL("cc aa"), FoldedKey, pos)==0); sl@0: test(pos==2); sl@0: sl@0: sl@0: test(pArray->Find(*(const TArr*)_TL("___CC"), FoldedKeyOffset, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(const TArr*)_TL("___bB"), FoldedKeyOffset, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(const TArr*)_TL("___Aa"), FoldedKeyOffset, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(const TArr*)_TL("___ax"), FoldedKeyOffset, pos)!=0); sl@0: sl@0: sl@0: test(pArray->Find(*(const TArr*)_TL("aa cc"), CollatedKey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(const TArr*)_TL("bb bb"), CollatedKey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(const TArr*)_TL("cc aa"), CollatedKey, pos)==0); sl@0: test(pos==2); sl@0: sl@0: sl@0: test(pArray->Find(*(const TArr*)_TL("___cc"), CollatedKeyOffset, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(const TArr*)_TL("___bb"), CollatedKeyOffset, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(const TArr*)_TL("___aa"), CollatedKeyOffset, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(const TArr*)_TL("___ax"), CollatedKeyOffset, pos)!=0); sl@0: sl@0: delete pArray; sl@0: } sl@0: sl@0: sl@0: template sl@0: GLDEF_C void TestTKey::Test2(TKeyCmpText N, TKeyCmpText F, TKeyCmpText C) sl@0: { sl@0: // This tests the functions of the TKey classes indirectly - mostly using the Find method sl@0: // which calls SetPtr(), Set() (both trivial) and more importantly Compare(), sl@0: sl@0: ArrayType* pArray=new ArrayType(KTestGranularity); sl@0: pArray->AppendL(*(S(*))_TL("aa cc"), 5*sizeof(S)); sl@0: pArray->AppendL(*(S(*))_TL("bb bbb"), 6*sizeof(S)); sl@0: pArray->AppendL(*(S(*))_TL("cc aaaa"), 7*sizeof(S)); sl@0: sl@0: KeyType NormalKey5(0,N,5); sl@0: KeyType NormalKey6(0,N,6); sl@0: KeyType NormalKey7(0,N,7); sl@0: KeyType NormalKeyOffset(sizeof(S)*3,N,2); sl@0: sl@0: KeyType FoldedKey5(0,F,5); sl@0: KeyType FoldedKey6(0,F,6); sl@0: KeyType FoldedKey7(0,F,7); sl@0: KeyType FoldedKeyOffset(sizeof(S)*3,F,2); sl@0: sl@0: KeyType CollatedKey5(0,C,5); sl@0: KeyType CollatedKey6(0,C,6); sl@0: KeyType CollatedKey7(0,C,7); sl@0: KeyType CollatedKeyOffset(sizeof(S)*3,C,2); sl@0: sl@0: TInt pos; sl@0: test(pArray->Find(*(S(*))_TL("aa cc"), NormalKey5, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(S(*))_TL("bb bbb"), NormalKey6, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(S(*))_TL("cc aaaa"), NormalKey7, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(S(*))_TL("BB BB"), NormalKey5, pos)!=0); sl@0: sl@0: sl@0: test(pArray->Find(*(S(*))_TL("___cc"), NormalKeyOffset, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(S(*))_TL("___bb"), NormalKeyOffset, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(S(*))_TL("___aa"), NormalKeyOffset, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(S(*))_TL("___ax"), NormalKeyOffset, pos)!=0); sl@0: sl@0: sl@0: test(pArray->Find(*(S(*))_TL("aa cc"), FoldedKey5, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(S(*))_TL("bb bbb"), FoldedKey6, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(S(*))_TL("cc aaaa"), FoldedKey7, pos)==0); sl@0: test(pos==2); sl@0: sl@0: sl@0: test(pArray->Find(*(S(*))_TL("___CC"), FoldedKeyOffset, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(S(*))_TL("___bB"), FoldedKeyOffset, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(S(*))_TL("___Aa"), FoldedKeyOffset, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(S(*))_TL("___ax"), FoldedKeyOffset, pos)!=0); sl@0: sl@0: sl@0: test(pArray->Find(*(S(*))_TL("aa cc"), CollatedKey5, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(S(*))_TL("bb bbb"), CollatedKey6, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(S(*))_TL("cc aaaa"), CollatedKey7, pos)==0); sl@0: test(pos==2); sl@0: sl@0: sl@0: test(pArray->Find(*(S(*))_TL("___cc"), CollatedKeyOffset, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(*(S(*))_TL("___bb"), CollatedKeyOffset, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(*(S(*))_TL("___aa"), CollatedKeyOffset, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(*(S(*))_TL("___ax"), CollatedKeyOffset, pos)!=0); sl@0: sl@0: delete pArray; sl@0: } sl@0: sl@0: sl@0: template sl@0: GLDEF_C void TestTKey::Test3(void) sl@0: { sl@0: ArrayType* pArray=new ArrayType(KTestGranularity); sl@0: Record rec1, rec2, rec3; sl@0: sl@0: rec1.name=(_TL("fred")); sl@0: rec1.age=5; sl@0: rec1.code='A'; sl@0: sl@0: rec2.name=(_TL("bill")); sl@0: rec2.age=0x7fffffff; sl@0: rec2.code='Z'; sl@0: sl@0: rec3.name=(_TL("bert")); sl@0: rec3.age=-5; sl@0: rec3.code='X'; sl@0: sl@0: pArray->AppendL(rec1); sl@0: pArray->AppendL(rec2); sl@0: pArray->AppendL(rec3); sl@0: sl@0: TInt pos; sl@0: sl@0: KeyType codekey(_FOFF(Record, code),ECmpNormal,1); sl@0: test(pArray->Find(rec1, codekey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(rec2, codekey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(rec3, codekey, pos)==0); sl@0: test(pos==2); sl@0: sl@0: KeyType agekey(_FOFF(Record, age), ECmpTInt32); sl@0: test(pArray->Find(rec1, agekey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(rec2, agekey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(rec3, agekey, pos)==0); sl@0: test(pos==2); sl@0: sl@0: rec1.age=-50; // march 95 - this isn't allowed , lucky that it works sl@0: test(pArray->Find(rec1, agekey, pos)!=0); sl@0: rec1.age=5; sl@0: sl@0: pArray->Sort(agekey); sl@0: test(pArray->Find(rec1, agekey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(rec2, agekey, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(rec3, agekey, pos)==0); sl@0: test(pos==0); sl@0: sl@0: delete pArray; sl@0: } sl@0: sl@0: template sl@0: GLDEF_C void TestTKey::Test4(void) sl@0: { sl@0: ArrayType* pArray=new ArrayType(KTestGranularity); sl@0: Record rec1, rec2, rec3; sl@0: sl@0: rec1.name=(_TL("fred")); sl@0: rec1.age=5; sl@0: rec1.code='A'; sl@0: rec2.name=(_TL("bill")); sl@0: rec2.age=0x7fffffff; sl@0: rec2.code='Z'; sl@0: rec3.name=(_TL("bert")); sl@0: rec3.age=-5; sl@0: rec3.code='X'; sl@0: sl@0: pArray->AppendL(rec1, sizeof(Record)); sl@0: pArray->AppendL(rec2, sizeof(Record)); sl@0: pArray->AppendL(rec3, sizeof(Record)); sl@0: sl@0: TInt pos; sl@0: KeyType codekey(_FOFF(Record, code),ECmpNormal,1); sl@0: test(pArray->Find(rec1, codekey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(rec2, codekey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(rec3, codekey, pos)==0); sl@0: test(pos==2); sl@0: sl@0: KeyType agekey(_FOFF(Record, age), ECmpTInt32); sl@0: test(pArray->Find(rec1, agekey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(rec2, agekey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(rec3, agekey, pos)==0); sl@0: test(pos==2); sl@0: rec1.age=-50; // march 95 - this isn't allowed - lucky to get away with it sl@0: test(pArray->Find(rec1, agekey, pos)!=0); sl@0: rec1.age=5; sl@0: sl@0: pArray->Sort(agekey); sl@0: test(pArray->Find(rec1, agekey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(rec2, agekey, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(rec3, agekey, pos)==0); sl@0: test(pos==0); sl@0: sl@0: delete pArray; sl@0: } sl@0: sl@0: template sl@0: GLDEF_C void TestTKey::Test5(void) sl@0: { sl@0: // test the numeric enumeration types sl@0: ArrayType* pArray=new ArrayType(KTestGranularity); sl@0: TInt pos; sl@0: sl@0: KeyType TIntKey(_FOFF(Record2, tint), ECmpTInt); sl@0: KeyType TUintKey(_FOFF(Record2, tuint), ECmpTUint); sl@0: KeyType TInt8Key(_FOFF(Record2, tint8), ECmpTInt8); sl@0: KeyType TUint8Key(_FOFF(Record2, tuint8), ECmpTUint8); sl@0: KeyType TInt16Key(_FOFF(Record2, tint16), ECmpTInt16); sl@0: KeyType TUint16Key(_FOFF(Record2, tuint16), ECmpTUint16); sl@0: KeyType TInt32Key(_FOFF(Record2, tint32), ECmpTInt32); sl@0: KeyType TUint32Key(_FOFF(Record2, tuint32), ECmpTUint32); sl@0: sl@0: SetRecordData(); sl@0: sl@0: pArray->AppendL(Rec1); sl@0: pArray->AppendL(Rec2); sl@0: pArray->AppendL(Rec3); sl@0: pArray->AppendL(Rec4); sl@0: sl@0: pArray->Sort(TIntKey); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TIntKey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TIntKey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TIntKey, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TIntKey, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUintKey); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUintKey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUintKey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUintKey, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUintKey, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TInt8Key); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TInt8Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TInt8Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TInt8Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TInt8Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUint8Key); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUint8Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUint8Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUint8Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUint8Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TInt16Key); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TInt16Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TInt16Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TInt16Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TInt16Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUintKey); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUint16Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUint16Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUint16Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUint16Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TInt32Key); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TInt32Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TInt32Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TInt32Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TInt32Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUint32Key); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUint32Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUint32Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUint32Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUint32Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: delete pArray; sl@0: } sl@0: sl@0: template sl@0: GLDEF_C void TestTKey::Test6(void) sl@0: { sl@0: // test the numeric enumeration types sl@0: ArrayType* pArray=new ArrayType(KTestGranularity); sl@0: TInt pos; sl@0: sl@0: KeyType TIntKey(_FOFF(Record2, tint), ECmpTInt); sl@0: KeyType TUintKey(_FOFF(Record2, tuint), ECmpTUint); sl@0: KeyType TInt8Key(_FOFF(Record2, tint8), ECmpTInt8); sl@0: KeyType TUint8Key(_FOFF(Record2, tuint8), ECmpTUint8); sl@0: KeyType TInt16Key(_FOFF(Record2, tint16), ECmpTInt16); sl@0: KeyType TUint16Key(_FOFF(Record2, tuint16), ECmpTUint16); sl@0: KeyType TInt32Key(_FOFF(Record2, tint32), ECmpTInt32); sl@0: KeyType TUint32Key(_FOFF(Record2, tuint32), ECmpTUint32); sl@0: sl@0: SetRecordData(); sl@0: sl@0: pArray->AppendL(Rec1, sizeof(Record2)); sl@0: pArray->AppendL(Rec2, sizeof(Record2)); sl@0: pArray->AppendL(Rec3, sizeof(Record2)); sl@0: pArray->AppendL(Rec4, sizeof(Record2)); sl@0: sl@0: pArray->Sort(TIntKey); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TIntKey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TIntKey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TIntKey, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TIntKey, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUintKey); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUintKey, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUintKey, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUintKey, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUintKey, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TInt8Key); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TInt8Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TInt8Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TInt8Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TInt8Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUint8Key); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUint8Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUint8Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUint8Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUint8Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TInt16Key); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TInt16Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TInt16Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TInt16Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TInt16Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUintKey); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUint16Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUint16Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUint16Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUint16Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TInt32Key); sl@0: // order should be 4,3,2,1 sl@0: test(pArray->Find(Rec4, TInt32Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec3, TInt32Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec2, TInt32Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec1, TInt32Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: pArray->Sort(TUint32Key); sl@0: // order should be 1,2,3,4 sl@0: test(pArray->Find(Rec1, TUint32Key, pos)==0); sl@0: test(pos==0); sl@0: test(pArray->Find(Rec2, TUint32Key, pos)==0); sl@0: test(pos==1); sl@0: test(pArray->Find(Rec3, TUint32Key, pos)==0); sl@0: test(pos==2); sl@0: test(pArray->Find(Rec4, TUint32Key, pos)==0); sl@0: test(pos==3); sl@0: sl@0: delete pArray; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Fixed key class with a flat array of TText8")); sl@0: typedef CArrayFixFlat > aFixedFlatArrayOfTText8; sl@0: TestTKey T1; sl@0: T1.Test1(ECmpNormal8, ECmpFolded8, ECmpCollated8); sl@0: sl@0: test.Next(_L("Fixed key class with a flat array of TText16")); sl@0: typedef CArrayFixFlat > aFixedFlatArrayOfTText16; sl@0: TestTKey T2; sl@0: T2.Test1(ECmpNormal16, ECmpFolded16, ECmpCollated16); sl@0: sl@0: test.Next(_L("Fixed key class with a flat array of TText")); sl@0: typedef CArrayFixFlat > aFixedFlatArrayOfTText; sl@0: TestTKey T3; sl@0: T3.Test1(ECmpNormal, ECmpFolded, ECmpCollated); sl@0: sl@0: test.Next(_L("Fixed key class with a segmented array of TText8")); sl@0: typedef CArrayFixSeg > aFixedSegmentedArrayOfTText8; sl@0: TestTKey T4; sl@0: T4.Test1(ECmpNormal8, ECmpFolded8, ECmpCollated8); sl@0: sl@0: test.Next(_L("Fixed key class with a segmented array of TText16")); sl@0: typedef CArrayFixSeg > aFixedSegmentedArrayOfTText16; sl@0: TestTKey T5; sl@0: T5.Test1(ECmpNormal16, ECmpFolded16, ECmpCollated16); sl@0: sl@0: test.Next(_L("Fixed key class with a segmented array of TText")); sl@0: typedef CArrayFixSeg > aFixedSegmentedArrayOfTText; sl@0: TestTKey T6; sl@0: T6.Test1(ECmpNormal, ECmpFolded, ECmpCollated); sl@0: sl@0: test.Next(_L("Var key with a flat array of TText8")); sl@0: typedef CArrayVarFlat aVarFlatArrayOfTText8; sl@0: TestTKey T7; sl@0: T7.Test2(ECmpNormal8, ECmpFolded8, ECmpCollated8); sl@0: sl@0: test.Next(_L("Var key with a flat array of TText16")); sl@0: typedef CArrayVarFlat aVarFlatArrayOfTText16; sl@0: TestTKey T8; sl@0: T8.Test2(ECmpNormal16, ECmpFolded16, ECmpCollated16); sl@0: sl@0: test.Next(_L("Var key with a flat array of TText")); sl@0: typedef CArrayVarFlat aVarFlatArrayOfTText; sl@0: TestTKey T9; sl@0: T9.Test2(ECmpNormal, ECmpFolded, ECmpCollated); sl@0: sl@0: test.Next(_L("Var key with a segmented array of TText8")); sl@0: typedef CArrayVarSeg aVarSegmentedArrayOfTText8; sl@0: TestTKey T10; sl@0: T10.Test2(ECmpNormal8, ECmpFolded8, ECmpCollated8); sl@0: sl@0: test.Next(_L("Var key with a segmented array of TText16")); sl@0: typedef CArrayVarSeg aVarSegmentedArrayOfTText16; sl@0: TestTKey T11; sl@0: T11.Test2(ECmpNormal16, ECmpFolded16, ECmpCollated16); sl@0: sl@0: test.Next(_L("Var key with a segmented array of TText")); sl@0: typedef CArrayVarSeg aVarSegmentedArrayOfTText; sl@0: TestTKey T12; sl@0: T12.Test2(ECmpNormal, ECmpFolded, ECmpCollated); sl@0: sl@0: test.Next(_L("Fixed key with a flat array of structs")); sl@0: typedef CArrayFixFlat aFixedFlatArrayOfRecord; sl@0: TestTKey T13; sl@0: T13.Test3(); sl@0: sl@0: test.Next(_L("Fixed key with a segmented array of structs")); sl@0: typedef CArrayFixSeg aFixedSegmentedArrayOfRecord; sl@0: TestTKey T14; sl@0: T14.Test3(); sl@0: sl@0: test.Next(_L("Var key with a flat array of structs")); sl@0: typedef CArrayVarFlat aVarFlatArrayOfRecord; sl@0: TestTKey T15; sl@0: T15.Test4(); sl@0: sl@0: test.Next(_L("Var key with a segmented array of structs")); sl@0: typedef CArrayVarSeg aVarSegmentedArrayOfRecord; sl@0: TestTKey T16; sl@0: T16.Test4(); sl@0: sl@0: test.Next(_L("Fixed key with a flat array of structs testing numeric types")); sl@0: typedef CArrayFixFlat aFixedFlatArrayOfRecord2; sl@0: TestTKey T17; sl@0: T17.Test5(); sl@0: sl@0: test.Next(_L("Var key with a flat array of structs testing numeric types")); sl@0: typedef CArrayVarFlat aVarFlatArrayOfRecord2; sl@0: TestTKey T18; sl@0: T18.Test6(); sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /*#else sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Test unavailable in release build. sl@0: // sl@0: { sl@0: sl@0: test.Title(); sl@0: test.Start(_L("No tests for release builds")); sl@0: test.End(); sl@0: return(0); sl@0: } sl@0: #endif sl@0: sl@0: */ sl@0: