author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32test\buffer\t_bflat.cpp |
|
15 |
// Overview: |
|
16 |
// Test all aspects of the CBufFlat class. |
|
17 |
// API Information: |
|
18 |
// CBufFlat. |
|
19 |
// Details: |
|
20 |
// - Test all the operations of the class and see if methods are implemented -- |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
21 |
// including NewL, Reset, Size, Set Reserve, InsertL, Delete, Ptr, Read, ResizeL, Write and Compress. |
0 | 22 |
// - Test CBufFlat constructor is as expected. |
23 |
// - Insert data into the flat storage dynamic buffer and verify that InsertL method |
|
24 |
// is as expected. |
|
25 |
// - Delete all data in buffer using Reset() method and check size is zero. |
|
26 |
// - Test Ptr, Free, Size, Backptr and SetReserveL methods work as expected. |
|
27 |
// - Insert data into the buffer, delete some data from the beginning, middle, end and |
|
28 |
// check for data is as expected. |
|
29 |
// - Verify the data in the buffer before and after Compress and Read methods is as expected. |
|
30 |
// Platforms/Drives/Compatibility: |
|
31 |
// All |
|
32 |
// Assumptions/Requirement/Pre-requisites: |
|
33 |
// Failures and causes: |
|
34 |
// Base Port information: |
|
35 |
// |
|
36 |
// |
|
37 |
||
38 |
#include <e32test.h> |
|
39 |
||
40 |
LOCAL_D RTest test(_L("T_BFLAT")); |
|
41 |
||
42 |
class TestCBufFlat |
|
43 |
{ |
|
44 |
public: |
|
45 |
void Test1(); // Tests all operations of the class. |
|
46 |
void Test2(); // Test public methods of class. |
|
47 |
}; |
|
48 |
||
49 |
class TestCBufSeg |
|
50 |
{ |
|
51 |
public: |
|
52 |
void Test1(); // Test all operations of the class. |
|
53 |
}; |
|
54 |
||
55 |
GLDEF_C void TestCBufFlat::Test1() |
|
56 |
// |
|
57 |
// Tests all operations of the class. |
|
58 |
// |
|
59 |
{ |
|
60 |
TText* tp; |
|
61 |
test.Start(_L("Test all operations of CBufFlat")); |
|
62 |
CBufFlat* bf=(CBufFlat*)CBufFlat::NewL(100); |
|
63 |
bf->Reset(); |
|
64 |
bf->Size(); |
|
65 |
bf->SetReserveL(50); // Panics if 50 < iSize |
|
66 |
bf->InsertL(0,TPtrC8((TText8*)"Hello World")); |
|
67 |
bf->Delete(0,5); |
|
68 |
tp=(TText*)bf->Ptr(3).Ptr(); |
|
69 |
tp=(TText*)bf->BackPtr(3).Ptr(); |
|
70 |
bf->Read(2,tp,2); |
|
71 |
bf->Write(2,tp,2); |
|
72 |
bf->Compress(); |
|
73 |
test.End(); |
|
74 |
} |
|
75 |
||
76 |
GLDEF_C void TestCBufFlat::Test2() |
|
77 |
// |
|
78 |
// Test all the methods of the class |
|
79 |
// |
|
80 |
{ |
|
81 |
||
82 |
test.Start(_L("Test constructor of CBufFlat")); |
|
83 |
CBufFlat* bf1=(CBufFlat*)CBufFlat::NewL(20); |
|
84 |
test(bf1->Size()==0); |
|
85 |
test(bf1->Ptr(0).Length()==0); |
|
86 |
||
87 |
test.Next(_L("Insert, Reset, Ptr, Free, Size")); |
|
88 |
TBuf8<0x40> tb1=(TText8*)"Hello World"; |
|
89 |
TBuf8<0x40> tb2=(TText8*)"This string is greater than twenty characters long"; |
|
90 |
TBuf8<0x40> tb3; |
|
91 |
bf1->InsertL(0,tb1); // Insert - no expand |
|
92 |
test(bf1->Ptr(0)==tb1); |
|
93 |
test(bf1->Size()==tb1.Size()); |
|
94 |
test(bf1->Ptr(0).Length()==tb1.Size()); |
|
95 |
bf1->InsertL(bf1->Size(),tb2); // Insert and expand |
|
96 |
test(bf1->Size()==(tb1.Size()+tb2.Size())); |
|
97 |
test(bf1->Ptr(0).Left(tb1.Length())==tb1); |
|
98 |
test(bf1->Ptr(tb1.Length())==tb2); |
|
99 |
bf1->InsertL(bf1->Size(),tb3); // Insert a null string |
|
100 |
test(bf1->Size()==(tb1.Size()+tb2.Size())); |
|
101 |
test(bf1->Ptr(0).Left(tb1.Length())==tb1); |
|
102 |
test(bf1->Ptr(tb1.Length())==tb2); |
|
103 |
bf1->Reset(); // Reset |
|
104 |
test(bf1->Size()==0); |
|
105 |
bf1->InsertL(0,tb1); // Insert into a string |
|
106 |
bf1->InsertL(5,tb1); |
|
107 |
bf1->Delete(16,bf1->Size()-16); |
|
108 |
test(bf1->Ptr(0)==TPtrC8((TText8*)"HelloHello World")); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
bf1->InsertL(10,tb1,5); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
test(bf1->Ptr(0)==TPtrC8((TText8*)"HelloHelloHello World")); |
0 | 111 |
// |
112 |
test.Next(_L("SetReserve")); |
|
113 |
bf1->SetReserveL(50); // SetReserve > 0 |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
test(bf1->Size()==21); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
test(bf1->Ptr(0).Length()==21); |
0 | 116 |
bf1->Reset(); |
117 |
bf1->SetReserveL(0); // SetReserve = 0 |
|
118 |
test(bf1->Size()==0); |
|
119 |
test(bf1->Ptr(0).Length()==0); |
|
120 |
// |
|
121 |
test.Next(_L("Delete, BackPtr")); |
|
122 |
bf1->InsertL(0,tb1); |
|
123 |
bf1->Delete(6,1); // Delete Middle |
|
124 |
test(bf1->Ptr(0)==TPtrC8((TText8*)"Hello orld")); |
|
125 |
test(bf1->Size()==10); |
|
126 |
bf1->Delete(9,1); // Delete End |
|
127 |
test(bf1->Ptr(bf1->Size()).Length()==0); |
|
128 |
bf1->InsertL(bf1->Size(),tb3); |
|
129 |
test(bf1->Ptr(0)==TPtrC8((TText8*)"Hello orl")); |
|
130 |
bf1->Delete(0,2); // Delete Start / BackPtr |
|
131 |
test(bf1->BackPtr(5)==TPtrC8((TText8*)"llo o")); |
|
132 |
test(bf1->Size()==7); |
|
133 |
// |
|
134 |
test.Next(_L("Write, Compress")); |
|
135 |
bf1->Write(1,tb1,5); |
|
136 |
test(bf1->Ptr(0)==TPtrC8((TText8*)"lHellol")); |
|
137 |
test(bf1->Size()==7); |
|
138 |
bf1->Compress(); // Compress |
|
139 |
test(bf1->Size()==7); |
|
140 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
test.Next(_L("Read, Resize")); |
0 | 142 |
bf1->Read(4,tb1,bf1->Size()-4); |
143 |
test(tb1.Size()==3); |
|
144 |
test(tb1==TPtrC8((TText8*)"lol")); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
TBuf8<0x10> tb4=(TText8*)"Hello Hello Sun ";; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
TBuf8<0x10> tb5; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
test(bf1->Size()==7); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
bf1->ResizeL(64); // ResizeL |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
test(bf1->Size()==64); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
bf1->Write(0,tb4,16); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
bf1->Write(16,tb4,16); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
bf1->Write(32,tb4,16); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
bf1->Write(48,tb4,16); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
bf1->Read(0,tb5); //Reads maxlength of tb5 that is 16 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
bf1->Read(0,tb3); //Reads maxlength of tb3 that is 64 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
test(tb5==TPtrC8((TText8*)"Hello Hello Sun ")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
test(tb3==TPtrC8((TText8*)"Hello Hello Sun Hello Hello Sun Hello Hello Sun Hello Hello Sun ")); |
0 | 158 |
// |
159 |
test.End(); |
|
160 |
} |
|
161 |
||
162 |
LOCAL_C void test_CBufFlat() |
|
163 |
// |
|
164 |
// Test the BufFlat class. |
|
165 |
// |
|
166 |
{ |
|
167 |
TestCBufFlat b; |
|
168 |
||
169 |
test.Start(_L("All operations")); |
|
170 |
b.Test1(); |
|
171 |
test.Next(_L("All methods")); |
|
172 |
b.Test2(); |
|
173 |
// |
|
174 |
test.End(); |
|
175 |
} |
|
176 |
||
177 |
GLDEF_C TInt E32Main() |
|
178 |
// |
|
179 |
// Test the ADT Varray types. |
|
180 |
// |
|
181 |
{ |
|
182 |
test.Title(); |
|
183 |
test.Start(_L("class CBufFlat")); |
|
184 |
test_CBufFlat(); |
|
185 |
test.End(); |
|
186 |
return(0); |
|
187 |
} |
|
188 |