sl@0: /* sl@0: * Copyright (c) 2002-2010 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 "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: * Test code for CTmCode class sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "TAGMA.H" sl@0: #include "TMSTD.H" sl@0: sl@0: #include sl@0: #include sl@0: #include "ttmcode.h" sl@0: sl@0: TVerdict CTTmCodeStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EPass); sl@0: INFO_PRINTF1(_L("TTmCode - Tests CTmCode class")); sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TTMCODE-0001 CTmCode tests ")); sl@0: CTmCode* code = new(ELeave) CTmCode; sl@0: CleanupStack::PushL(code); sl@0: sl@0: // Testcase 1 - Append a number, then check retrived number is the same as the one we appended sl@0: code->CreateBufferL(); sl@0: TInt num = 42; sl@0: code->AppendNumberL(num); sl@0: TTmCodeReader reader(*code, 0, 0x7FFFFFFF); sl@0: TEST(reader.ReadNumber() == num); sl@0: sl@0: // Testcase 2 - Append largest positive number occupying 1 byte (where a byte is 7 bits in the case of CTmCode), check correct value read back sl@0: TInt size; sl@0: TInt sizeDelta; sl@0: size = code->Size(); sl@0: num = 63; sl@0: TInt pos = code->AppendNumberL(num); sl@0: sizeDelta = code->Size() - size; sl@0: TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num); sl@0: sl@0: // Testcase 3 - Append smallest positive number occupying 2 bytes, check correct value read back sl@0: size = code->Size(); sl@0: num = 64; sl@0: pos = code->AppendNumberL(num); sl@0: sizeDelta = code->Size() - size; sl@0: TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num); sl@0: sl@0: // Testcase 4 - Append largest negative number occupying 1 byte, check correct value read back sl@0: size = code->Size(); sl@0: num = -64; sl@0: pos = code->AppendNumberL(num); sl@0: sizeDelta = code->Size() - size; sl@0: TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num); sl@0: sl@0: // Testcase 5 - Append smallest negative number occupying 2 bytes, check correct value read back sl@0: size = code->Size(); sl@0: num = -65; sl@0: pos = code->AppendNumberL(num); sl@0: sizeDelta = code->Size() - size; sl@0: TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num); sl@0: sl@0: // Testcase 6 - Append rect, check same rect returned sl@0: size = code->Size(); sl@0: TRect rect(1, 1, 2, 2); sl@0: pos = code->AppendRectL(rect); sl@0: sizeDelta = code->Size() - size; sl@0: TEST(sizeDelta == 4 && (pos - size) == 4 && reader.ReadRect() == rect); sl@0: sl@0: // Testcase 7 - Replace first 2 bytes with 3 different bytes sl@0: CTmCode* code2 = new(ELeave) CTmCode; sl@0: CleanupStack::PushL(code2); sl@0: code2->CreateBufferL(); sl@0: code2->AppendNumberL(1); sl@0: code2->AppendNumberL(1); sl@0: code2->AppendNumberL(2); sl@0: code->ChangeL(0, 1, *code2); sl@0: reader.SetCodePos(0); sl@0: TEST(reader.ReadNumber() == 1 && reader.ReadNumber() == 1 && reader.ReadNumber() == 2 && reader.ReadNumber() == 63); sl@0: sl@0: // Testcase 8 - Insert 1000 numbers, then read them sl@0: size = code->Size(); sl@0: int ii; sl@0: for (ii = 0; ii < 1000; ii++) sl@0: code->AppendNumberL(ii); sl@0: reader.SetCodePos(size); sl@0: for (ii = 0; ii < 1000; ii++) sl@0: TEST(reader.ReadNumber() == ii); sl@0: sl@0: // Testcase 9 - Insert number at position 42 (1st segment), then reader to 42 and read number sl@0: code->InsertNumberL(4242, 42); sl@0: reader.SetCodePos(42); sl@0: TEST(reader.ReadNumber() == 4242); sl@0: sl@0: // Testcase 10 - Insert number so it spans a segment boundary, check it reads back OK sl@0: num = -1234567; sl@0: code->InsertNumberL(num, 511); sl@0: reader.SetCodePos(511); sl@0: TEST(reader.ReadNumber() == num); sl@0: sl@0: // Testcase 11 - ChangeL using a range that spans a segment boundary sl@0: code->InsertByteL(0x11, 515); sl@0: code2->Reset(); sl@0: code2->CreateBufferL(); sl@0: code2->AppendNumberL(0xabababab); sl@0: code->ChangeL(510, 515, *code2); sl@0: TTmCodeReader reader2(*code, 0, 0x7FFFFFFF); sl@0: reader2.SetCodePos(510); sl@0: TEST(reader2.ReadNumber() == static_cast(0xabababab)); sl@0: TEST(reader2.ReadByte() == static_cast(0x11)); sl@0: sl@0: CleanupStack::PopAndDestroy(code2); sl@0: CleanupStack::PopAndDestroy(code); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: