First public contribution.
2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Test code for CTmCode class
27 TVerdict CTTmCodeStep::doTestStepL()
29 SetTestStepResult(EPass);
30 INFO_PRINTF1(_L("TTmCode - Tests CTmCode class"));
31 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TTMCODE-0001 CTmCode tests "));
32 CTmCode* code = new(ELeave) CTmCode;
33 CleanupStack::PushL(code);
35 // Testcase 1 - Append a number, then check retrived number is the same as the one we appended
36 code->CreateBufferL();
38 code->AppendNumberL(num);
39 TTmCodeReader reader(*code, 0, 0x7FFFFFFF);
40 TEST(reader.ReadNumber() == num);
42 // 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
47 TInt pos = code->AppendNumberL(num);
48 sizeDelta = code->Size() - size;
49 TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
51 // Testcase 3 - Append smallest positive number occupying 2 bytes, check correct value read back
54 pos = code->AppendNumberL(num);
55 sizeDelta = code->Size() - size;
56 TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
58 // Testcase 4 - Append largest negative number occupying 1 byte, check correct value read back
61 pos = code->AppendNumberL(num);
62 sizeDelta = code->Size() - size;
63 TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
65 // Testcase 5 - Append smallest negative number occupying 2 bytes, check correct value read back
68 pos = code->AppendNumberL(num);
69 sizeDelta = code->Size() - size;
70 TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
72 // Testcase 6 - Append rect, check same rect returned
74 TRect rect(1, 1, 2, 2);
75 pos = code->AppendRectL(rect);
76 sizeDelta = code->Size() - size;
77 TEST(sizeDelta == 4 && (pos - size) == 4 && reader.ReadRect() == rect);
79 // Testcase 7 - Replace first 2 bytes with 3 different bytes
80 CTmCode* code2 = new(ELeave) CTmCode;
81 CleanupStack::PushL(code2);
82 code2->CreateBufferL();
83 code2->AppendNumberL(1);
84 code2->AppendNumberL(1);
85 code2->AppendNumberL(2);
86 code->ChangeL(0, 1, *code2);
88 TEST(reader.ReadNumber() == 1 && reader.ReadNumber() == 1 && reader.ReadNumber() == 2 && reader.ReadNumber() == 63);
90 // Testcase 8 - Insert 1000 numbers, then read them
93 for (ii = 0; ii < 1000; ii++)
94 code->AppendNumberL(ii);
95 reader.SetCodePos(size);
96 for (ii = 0; ii < 1000; ii++)
97 TEST(reader.ReadNumber() == ii);
99 // Testcase 9 - Insert number at position 42 (1st segment), then reader to 42 and read number
100 code->InsertNumberL(4242, 42);
101 reader.SetCodePos(42);
102 TEST(reader.ReadNumber() == 4242);
104 // Testcase 10 - Insert number so it spans a segment boundary, check it reads back OK
106 code->InsertNumberL(num, 511);
107 reader.SetCodePos(511);
108 TEST(reader.ReadNumber() == num);
110 // Testcase 11 - ChangeL using a range that spans a segment boundary
111 code->InsertByteL(0x11, 515);
113 code2->CreateBufferL();
114 code2->AppendNumberL(0xabababab);
115 code->ChangeL(510, 515, *code2);
116 TTmCodeReader reader2(*code, 0, 0x7FFFFFFF);
117 reader2.SetCodePos(510);
118 TEST(reader2.ReadNumber() == static_cast<TInt32>(0xabababab));
119 TEST(reader2.ReadByte() == static_cast<TUint8>(0x11));
121 CleanupStack::PopAndDestroy(code2);
122 CleanupStack::PopAndDestroy(code);
124 return TestStepResult();