24
|
1 |
// Copyright (c) 1997-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 "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 |
//
|
|
15 |
|
|
16 |
#include <e32test.h>
|
|
17 |
|
|
18 |
#include "TE_EtelMMTestStepBase.h"
|
|
19 |
#include "TE_mmphonebookstoreutils.h"
|
|
20 |
#include "testdef.h"
|
|
21 |
|
|
22 |
CTestPhonebookStoreUtils::CTestPhonebookStoreUtils()
|
|
23 |
/** Each test step initialises it's own name
|
|
24 |
*/
|
|
25 |
{
|
|
26 |
// store the name of this test case
|
|
27 |
// this is the name that is used by the script file
|
|
28 |
SetTestStepName(_L("TestPhonebookStoreU"));
|
|
29 |
}
|
|
30 |
|
|
31 |
enum TVerdict CTestPhonebookStoreUtils::doTestStepL()
|
|
32 |
{
|
|
33 |
//
|
|
34 |
// Create a buffer
|
|
35 |
//
|
|
36 |
TBuf8<200> buf;
|
|
37 |
CPhoneBookBuffer* phonebookBuffer=new(ELeave) CPhoneBookBuffer();
|
|
38 |
|
|
39 |
//
|
|
40 |
// Setup the phonebook buffer class
|
|
41 |
//
|
|
42 |
phonebookBuffer->Set(&buf);
|
|
43 |
|
|
44 |
//
|
|
45 |
// Write first entry
|
|
46 |
//
|
|
47 |
// A tag is 1 byte, each string requires a 16 bit length value and
|
|
48 |
// all other values are as sized. Unicode strings must be word aligned
|
|
49 |
// on a 4 byte boundary.
|
|
50 |
//
|
|
51 |
// Add new entry tag to the phonebook buffer
|
|
52 |
//
|
|
53 |
TInt bufferLength = 0;
|
|
54 |
TInt result;
|
|
55 |
|
|
56 |
result = phonebookBuffer->AddNewEntryTag();
|
|
57 |
TEST(result == KErrNone);
|
|
58 |
bufferLength += 1; // Tag equals 1 byte
|
|
59 |
|
|
60 |
// Add a tag and integer to the phonebook buffer
|
|
61 |
TUint16 index1=1;
|
|
62 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex,index1);
|
|
63 |
TEST(result == KErrNone);
|
|
64 |
bufferLength += 1; // Tag equals 1 byte
|
|
65 |
bufferLength += 2; // 16 bit value is 2 bytes
|
|
66 |
|
|
67 |
// Add a tag and a descriptor to the phonebook buffer
|
|
68 |
_LIT16(KName,"First Name");
|
|
69 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText,KName);
|
|
70 |
TEST(result == KErrNone);
|
|
71 |
bufferLength += 1; // Tag equals 1 byte
|
|
72 |
bufferLength += 2; // 16 bit length value is 2 bytes
|
|
73 |
bufferLength += (4 - (bufferLength % 4)) %4; // Word align Unicode strings
|
|
74 |
bufferLength += (KName.iTypeLength * 2); // Unicode sting
|
|
75 |
|
|
76 |
_LIT16(KNumber,"01632960000");
|
|
77 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber,KNumber);
|
|
78 |
TEST(result == KErrNone);
|
|
79 |
bufferLength += 1; // Tag equals 1 byte
|
|
80 |
bufferLength += 2; // 16 bit length value is 2 bytes
|
|
81 |
bufferLength += (4 - (bufferLength % 4)) %4; // Word align Unicode strings
|
|
82 |
bufferLength += (KNumber.iTypeLength * 2); // Unicode sting
|
|
83 |
|
|
84 |
TUint8 tonNpi=0x91; // international TON/NPI
|
|
85 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBTonNpi,tonNpi);
|
|
86 |
TEST(result == KErrNone);
|
|
87 |
bufferLength += 1; // Tag equals 1 byte
|
|
88 |
bufferLength += 1; // 8 bit length value is 1 byte
|
|
89 |
|
|
90 |
// Try adding some invalid tags...
|
|
91 |
_LIT8(KText8Tag, "8 bit text");
|
|
92 |
_LIT16(KText16Tag, "16 bit text");
|
|
93 |
TUint8 uint8Tag(10);
|
|
94 |
TUint16 uint16Tag(55555);
|
|
95 |
TUint32 uint32Tag(10203040);
|
|
96 |
|
|
97 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText, KText8Tag);
|
|
98 |
TEST(result == KErrArgument);
|
|
99 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBTonNpi, KText16Tag);
|
|
100 |
TEST(result == KErrArgument);
|
|
101 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex, uint8Tag);
|
|
102 |
TEST(result == KErrArgument);
|
|
103 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText, uint16Tag);
|
|
104 |
TEST(result == KErrArgument);
|
|
105 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex, uint32Tag);
|
|
106 |
TEST(result == KErrArgument);
|
|
107 |
|
|
108 |
//
|
|
109 |
// Write second entry
|
|
110 |
//
|
|
111 |
// Add new entry tag to the phonebook buffer
|
|
112 |
//
|
|
113 |
result = phonebookBuffer->AddNewEntryTag();
|
|
114 |
TEST(result == KErrNone);
|
|
115 |
bufferLength += 1; // Tag equals 1 byte
|
|
116 |
|
|
117 |
// Add a tag and integer to the phonebook buffer
|
|
118 |
TUint16 index2=2;
|
|
119 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex,index2);
|
|
120 |
TEST(result == KErrNone);
|
|
121 |
bufferLength += 1; // Tag equals 1 byte
|
|
122 |
bufferLength += 2; // 16 bit value is 2 bytes
|
|
123 |
|
|
124 |
// Add a tag and a descriptor to the phonebook buffer
|
|
125 |
_LIT16(KName2,"Second Name");
|
|
126 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText,KName2);
|
|
127 |
TEST(result == KErrNone);
|
|
128 |
bufferLength += 1; // Tag equals 1 byte
|
|
129 |
bufferLength += 2; // 16 bit length value is 2 bytes
|
|
130 |
bufferLength += (4 - (bufferLength % 4)) %4; // Word align Unicode strings
|
|
131 |
bufferLength += (KName2.iTypeLength * 2); // Unicode sting
|
|
132 |
|
|
133 |
_LIT16(KNumber2,"01632960000");
|
|
134 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber,KNumber2);
|
|
135 |
TEST(result == KErrNone);
|
|
136 |
bufferLength += 1; // Tag equals 1 byte
|
|
137 |
bufferLength += 2; // 16 bit length value is 2 bytes
|
|
138 |
bufferLength += (4 - (bufferLength % 4)) %4; // Word align Unicode strings
|
|
139 |
bufferLength += (KNumber2.iTypeLength * 2); // Unicode sting
|
|
140 |
|
|
141 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBTonNpi,tonNpi);
|
|
142 |
TEST(result == KErrNone);
|
|
143 |
bufferLength += 1; // Tag equals 1 byte
|
|
144 |
bufferLength += 1; // 8 bit length value is 1 byte
|
|
145 |
|
|
146 |
//
|
|
147 |
// Write a partial third entry
|
|
148 |
//
|
|
149 |
// Add new entry tag to the phonebook buffer
|
|
150 |
//
|
|
151 |
result = phonebookBuffer->AddNewEntryTag();
|
|
152 |
TEST(result == KErrNone);
|
|
153 |
|
|
154 |
// Add a tag and integer to the phonebook buffer
|
|
155 |
TUint16 index3=3;
|
|
156 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex,index3);
|
|
157 |
TEST(result == KErrNone);
|
|
158 |
|
|
159 |
// Add a tag and a descriptor to the phonebook buffer
|
|
160 |
_LIT16(KName3,"Third Name");
|
|
161 |
result = phonebookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText,KName3);
|
|
162 |
TEST(result == KErrNone);
|
|
163 |
|
|
164 |
//
|
|
165 |
// Now remove third entry from the buffer - this is just to test removing mechanism
|
|
166 |
//
|
|
167 |
result = phonebookBuffer->RemovePartialEntry();
|
|
168 |
TEST(result == KErrNone);
|
|
169 |
|
|
170 |
//
|
|
171 |
// Start reading the buffer
|
|
172 |
//
|
|
173 |
phonebookBuffer->StartRead();
|
|
174 |
|
|
175 |
//
|
|
176 |
// Get buffer length
|
|
177 |
//
|
|
178 |
TInt phonebookBufferLen = phonebookBuffer->BufferLength();
|
|
179 |
TEST(phonebookBufferLen == bufferLength);
|
|
180 |
|
|
181 |
//
|
|
182 |
// First Entry
|
|
183 |
// Read Tag Value and Data Type
|
|
184 |
//
|
|
185 |
TUint8 tag;
|
|
186 |
CPhoneBookBuffer::TPhBkTagType dataType;
|
|
187 |
|
|
188 |
result = phonebookBuffer->GetTagAndType(tag, dataType); // new entry tag
|
|
189 |
TEST(result == KErrNone);
|
|
190 |
TEST(tag==RMobilePhoneBookStore::ETagPBNewEntry);
|
|
191 |
|
|
192 |
// Read and Validate the integer
|
|
193 |
result = phonebookBuffer->GetTagAndType(tag, dataType); // data tag
|
|
194 |
TEST(result == KErrNone);
|
|
195 |
TEST(tag==RMobilePhoneBookStore::ETagPBAdnIndex);
|
|
196 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeInt16);
|
|
197 |
|
|
198 |
TUint16 readIndex1;
|
|
199 |
result = phonebookBuffer->GetValue(readIndex1);
|
|
200 |
TEST(result == KErrNone);
|
|
201 |
TEST(readIndex1==index1);
|
|
202 |
|
|
203 |
// Read and Validate the descriptor
|
|
204 |
result = phonebookBuffer->GetTagAndType(tag, dataType);
|
|
205 |
TEST(result == KErrNone);
|
|
206 |
TEST(tag==RMobilePhoneBookStore::ETagPBText);
|
|
207 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeDes16);
|
|
208 |
|
|
209 |
TBuf16<100> readBuf;
|
|
210 |
TPtrC16 readBufPtr(readBuf);
|
|
211 |
result = phonebookBuffer->GetValue(readBufPtr);
|
|
212 |
TEST(result == KErrNone);
|
|
213 |
TEST(readBufPtr.Compare(KName)==0);
|
|
214 |
|
|
215 |
// Read and Validate the next descriptor
|
|
216 |
result = phonebookBuffer->GetTagAndType(tag, dataType);
|
|
217 |
TEST(result == KErrNone);
|
|
218 |
TEST(tag==RMobilePhoneBookStore::ETagPBNumber);
|
|
219 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeDes16);
|
|
220 |
|
|
221 |
result = phonebookBuffer->GetValue(readBufPtr);
|
|
222 |
TEST(result == KErrNone);
|
|
223 |
TEST(readBufPtr.Compare(KNumber)==0);
|
|
224 |
|
|
225 |
// Read and Validate the byte
|
|
226 |
result = phonebookBuffer->GetTagAndType(tag, dataType); // data tag
|
|
227 |
TEST(result == KErrNone);
|
|
228 |
TEST(tag==RMobilePhoneBookStore::ETagPBTonNpi);
|
|
229 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeInt8);
|
|
230 |
|
|
231 |
TUint8 readTonNpi;
|
|
232 |
result = phonebookBuffer->GetValue(readTonNpi);
|
|
233 |
TEST(result == KErrNone);
|
|
234 |
TEST(readTonNpi==tonNpi);
|
|
235 |
|
|
236 |
//
|
|
237 |
// Second Entry
|
|
238 |
//
|
|
239 |
result = phonebookBuffer->GetTagAndType(tag, dataType); // new entry tag
|
|
240 |
TEST(result == KErrNone);
|
|
241 |
TEST(tag==RMobilePhoneBookStore::ETagPBNewEntry);
|
|
242 |
|
|
243 |
// Read and Validate the integer
|
|
244 |
result = phonebookBuffer->GetTagAndType(tag, dataType); // data tag
|
|
245 |
TEST(result == KErrNone);
|
|
246 |
TEST(tag==RMobilePhoneBookStore::ETagPBAdnIndex);
|
|
247 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeInt16);
|
|
248 |
|
|
249 |
TUint16 readIndex2;
|
|
250 |
result = phonebookBuffer->GetValue(readIndex2);
|
|
251 |
TEST(result == KErrNone);
|
|
252 |
TEST(readIndex2==index2);
|
|
253 |
|
|
254 |
// Read and Validate the descriptor
|
|
255 |
result = phonebookBuffer->GetTagAndType(tag, dataType);
|
|
256 |
TEST(result == KErrNone);
|
|
257 |
TEST(tag==RMobilePhoneBookStore::ETagPBText);
|
|
258 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeDes16);
|
|
259 |
|
|
260 |
result = phonebookBuffer->GetValue(readBufPtr);
|
|
261 |
TEST(result == KErrNone);
|
|
262 |
TEST(readBufPtr.Compare(KName2)==0);
|
|
263 |
|
|
264 |
// Read and Validate the next descriptor
|
|
265 |
result = phonebookBuffer->GetTagAndType(tag, dataType);
|
|
266 |
TEST(result == KErrNone);
|
|
267 |
TEST(tag==RMobilePhoneBookStore::ETagPBNumber);
|
|
268 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeDes16);
|
|
269 |
|
|
270 |
result = phonebookBuffer->GetValue(readBufPtr);
|
|
271 |
TEST(result == KErrNone);
|
|
272 |
TEST(readBufPtr.Compare(KNumber2)==0);
|
|
273 |
|
|
274 |
// Read and Validate the byte
|
|
275 |
result = phonebookBuffer->GetTagAndType(tag, dataType); // data tag
|
|
276 |
TEST(result == KErrNone);
|
|
277 |
TEST(tag==RMobilePhoneBookStore::ETagPBTonNpi);
|
|
278 |
TEST(dataType==CPhoneBookBuffer::EPhBkTypeInt8);
|
|
279 |
|
|
280 |
result = phonebookBuffer->GetValue(readTonNpi);
|
|
281 |
TEST(result == KErrNone);
|
|
282 |
TEST(readTonNpi==tonNpi);
|
|
283 |
|
|
284 |
//
|
|
285 |
// Check that buffer is now finished
|
|
286 |
//
|
|
287 |
result = phonebookBuffer->GetTagAndType(tag, dataType); // data tag
|
|
288 |
TEST(result==KErrNotFound);
|
|
289 |
|
|
290 |
delete phonebookBuffer;
|
|
291 |
|
|
292 |
return TestStepResult();
|
|
293 |
}
|
|
294 |
|
|
295 |
|