sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Test code for CTmCode class
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "TAGMA.H"
|
sl@0
|
21 |
#include "TMSTD.H"
|
sl@0
|
22 |
|
sl@0
|
23 |
#include <e32test.h>
|
sl@0
|
24 |
#include <bitdev.h>
|
sl@0
|
25 |
#include "ttmcode.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
TVerdict CTTmCodeStep::doTestStepL()
|
sl@0
|
28 |
{
|
sl@0
|
29 |
SetTestStepResult(EPass);
|
sl@0
|
30 |
INFO_PRINTF1(_L("TTmCode - Tests CTmCode class"));
|
sl@0
|
31 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TTMCODE-0001 CTmCode tests "));
|
sl@0
|
32 |
CTmCode* code = new(ELeave) CTmCode;
|
sl@0
|
33 |
CleanupStack::PushL(code);
|
sl@0
|
34 |
|
sl@0
|
35 |
// Testcase 1 - Append a number, then check retrived number is the same as the one we appended
|
sl@0
|
36 |
code->CreateBufferL();
|
sl@0
|
37 |
TInt num = 42;
|
sl@0
|
38 |
code->AppendNumberL(num);
|
sl@0
|
39 |
TTmCodeReader reader(*code, 0, 0x7FFFFFFF);
|
sl@0
|
40 |
TEST(reader.ReadNumber() == num);
|
sl@0
|
41 |
|
sl@0
|
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
|
sl@0
|
43 |
TInt size;
|
sl@0
|
44 |
TInt sizeDelta;
|
sl@0
|
45 |
size = code->Size();
|
sl@0
|
46 |
num = 63;
|
sl@0
|
47 |
TInt pos = code->AppendNumberL(num);
|
sl@0
|
48 |
sizeDelta = code->Size() - size;
|
sl@0
|
49 |
TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
|
sl@0
|
50 |
|
sl@0
|
51 |
// Testcase 3 - Append smallest positive number occupying 2 bytes, check correct value read back
|
sl@0
|
52 |
size = code->Size();
|
sl@0
|
53 |
num = 64;
|
sl@0
|
54 |
pos = code->AppendNumberL(num);
|
sl@0
|
55 |
sizeDelta = code->Size() - size;
|
sl@0
|
56 |
TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
|
sl@0
|
57 |
|
sl@0
|
58 |
// Testcase 4 - Append largest negative number occupying 1 byte, check correct value read back
|
sl@0
|
59 |
size = code->Size();
|
sl@0
|
60 |
num = -64;
|
sl@0
|
61 |
pos = code->AppendNumberL(num);
|
sl@0
|
62 |
sizeDelta = code->Size() - size;
|
sl@0
|
63 |
TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
|
sl@0
|
64 |
|
sl@0
|
65 |
// Testcase 5 - Append smallest negative number occupying 2 bytes, check correct value read back
|
sl@0
|
66 |
size = code->Size();
|
sl@0
|
67 |
num = -65;
|
sl@0
|
68 |
pos = code->AppendNumberL(num);
|
sl@0
|
69 |
sizeDelta = code->Size() - size;
|
sl@0
|
70 |
TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
|
sl@0
|
71 |
|
sl@0
|
72 |
// Testcase 6 - Append rect, check same rect returned
|
sl@0
|
73 |
size = code->Size();
|
sl@0
|
74 |
TRect rect(1, 1, 2, 2);
|
sl@0
|
75 |
pos = code->AppendRectL(rect);
|
sl@0
|
76 |
sizeDelta = code->Size() - size;
|
sl@0
|
77 |
TEST(sizeDelta == 4 && (pos - size) == 4 && reader.ReadRect() == rect);
|
sl@0
|
78 |
|
sl@0
|
79 |
// Testcase 7 - Replace first 2 bytes with 3 different bytes
|
sl@0
|
80 |
CTmCode* code2 = new(ELeave) CTmCode;
|
sl@0
|
81 |
CleanupStack::PushL(code2);
|
sl@0
|
82 |
code2->CreateBufferL();
|
sl@0
|
83 |
code2->AppendNumberL(1);
|
sl@0
|
84 |
code2->AppendNumberL(1);
|
sl@0
|
85 |
code2->AppendNumberL(2);
|
sl@0
|
86 |
code->ChangeL(0, 1, *code2);
|
sl@0
|
87 |
reader.SetCodePos(0);
|
sl@0
|
88 |
TEST(reader.ReadNumber() == 1 && reader.ReadNumber() == 1 && reader.ReadNumber() == 2 && reader.ReadNumber() == 63);
|
sl@0
|
89 |
|
sl@0
|
90 |
// Testcase 8 - Insert 1000 numbers, then read them
|
sl@0
|
91 |
size = code->Size();
|
sl@0
|
92 |
int ii;
|
sl@0
|
93 |
for (ii = 0; ii < 1000; ii++)
|
sl@0
|
94 |
code->AppendNumberL(ii);
|
sl@0
|
95 |
reader.SetCodePos(size);
|
sl@0
|
96 |
for (ii = 0; ii < 1000; ii++)
|
sl@0
|
97 |
TEST(reader.ReadNumber() == ii);
|
sl@0
|
98 |
|
sl@0
|
99 |
// Testcase 9 - Insert number at position 42 (1st segment), then reader to 42 and read number
|
sl@0
|
100 |
code->InsertNumberL(4242, 42);
|
sl@0
|
101 |
reader.SetCodePos(42);
|
sl@0
|
102 |
TEST(reader.ReadNumber() == 4242);
|
sl@0
|
103 |
|
sl@0
|
104 |
// Testcase 10 - Insert number so it spans a segment boundary, check it reads back OK
|
sl@0
|
105 |
num = -1234567;
|
sl@0
|
106 |
code->InsertNumberL(num, 511);
|
sl@0
|
107 |
reader.SetCodePos(511);
|
sl@0
|
108 |
TEST(reader.ReadNumber() == num);
|
sl@0
|
109 |
|
sl@0
|
110 |
// Testcase 11 - ChangeL using a range that spans a segment boundary
|
sl@0
|
111 |
code->InsertByteL(0x11, 515);
|
sl@0
|
112 |
code2->Reset();
|
sl@0
|
113 |
code2->CreateBufferL();
|
sl@0
|
114 |
code2->AppendNumberL(0xabababab);
|
sl@0
|
115 |
code->ChangeL(510, 515, *code2);
|
sl@0
|
116 |
TTmCodeReader reader2(*code, 0, 0x7FFFFFFF);
|
sl@0
|
117 |
reader2.SetCodePos(510);
|
sl@0
|
118 |
TEST(reader2.ReadNumber() == static_cast<TInt32>(0xabababab));
|
sl@0
|
119 |
TEST(reader2.ReadByte() == static_cast<TUint8>(0x11));
|
sl@0
|
120 |
|
sl@0
|
121 |
CleanupStack::PopAndDestroy(code2);
|
sl@0
|
122 |
CleanupStack::PopAndDestroy(code);
|
sl@0
|
123 |
|
sl@0
|
124 |
return TestStepResult();
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|