|
1 // Copyright (c) 2004-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 // EtelPacketTestAuthenticationAndDNS.cpp |
|
15 // This is the cpp file for Packet Data Context Data Structure |
|
16 // File created 03-11-2004 |
|
17 // |
|
18 // |
|
19 |
|
20 // Symbian OS includes |
|
21 #include <e32base.h> |
|
22 #include <etelpckt.h> |
|
23 #include <etelutils.h> |
|
24 #include <pcktcs.h> |
|
25 |
|
26 |
|
27 #include "Te_EtelPacketTestStepBase.h" |
|
28 #include "testdef.h" |
|
29 #include "Te_etelpckt_defs.h" |
|
30 #include "Te_EtelPacketTestPCO_IE.h" |
|
31 |
|
32 |
|
33 CEtelPacketTestPCO_IE::CEtelPacketTestPCO_IE() |
|
34 { |
|
35 // store the name of this test case |
|
36 SetTestStepName(_L("PCO_IE")); |
|
37 } |
|
38 |
|
39 // destructor |
|
40 CEtelPacketTestPCO_IE::~CEtelPacketTestPCO_IE() |
|
41 { |
|
42 } |
|
43 |
|
44 enum TVerdict CEtelPacketTestPCO_IE::doTestStepL( void ) |
|
45 /** |
|
46 * Test step AuthorizationData |
|
47 * |
|
48 */ |
|
49 { |
|
50 TInt ret; |
|
51 |
|
52 // --------------------------------------------------- |
|
53 // TEST CASE 1 - Construction |
|
54 // --------------------------------------------------- |
|
55 const TInt KZero=0; |
|
56 const TInt KMinimumBufferSize = 1; |
|
57 const TInt KSmallBuffer=20; |
|
58 |
|
59 // Create Item |
|
60 const TUint16 XId=1; |
|
61 const TUint16 YId=10; |
|
62 |
|
63 RPacketContext::TPcoId pcoIdX(XId); |
|
64 RPacketContext::TPcoId pcoIdY(YId); |
|
65 |
|
66 // Create Item Buffers |
|
67 const TInt KAppendableBufferSize=3; |
|
68 |
|
69 // BufferX |
|
70 TBuf8<KAppendableBufferSize> appendableBufferX(_L8("xxx")); |
|
71 appendableBufferX.SetLength(KAppendableBufferSize); |
|
72 TPtr8 appendablePtrX(const_cast<TUint8*>(appendableBufferX.Ptr()),appendableBufferX.Length(),appendableBufferX.Length()); |
|
73 |
|
74 // BufferY |
|
75 TBuf8<KAppendableBufferSize> appendableBufferY(_L8("yyy")); |
|
76 appendableBufferY.SetLength(KAppendableBufferSize); |
|
77 TPtr8 appendablePtrY(const_cast<TUint8*>(appendableBufferY.Ptr()),appendableBufferY.Length(),appendableBufferY.Length()); |
|
78 |
|
79 // Create Buffer for TLV struct |
|
80 TBuf8<KSmallBuffer> smallBuffer; // MaxLength = 20 |
|
81 smallBuffer.SetLength(smallBuffer.MaxLength()); |
|
82 smallBuffer.FillZ(); |
|
83 TPtr8 smallPtr(smallBuffer.LeftTPtr(smallBuffer.MaxLength())); |
|
84 smallPtr.SetLength(0); |
|
85 |
|
86 // Create Zero length buffer |
|
87 TPtr8 zeroSizePtr=smallPtr.LeftTPtr(KZero); |
|
88 TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> zeroTLV(zeroSizePtr,KZero); |
|
89 |
|
90 // Create TLV struct with size=20 |
|
91 TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> smallTLV(smallPtr,KZero); |
|
92 |
|
93 // --------------------------------------------------- |
|
94 // TEST CASE 2 - AppendItemL |
|
95 // --------------------------------------------------- |
|
96 |
|
97 // Append an Item to zero length Tlv |
|
98 ret=zeroTLV.AppendItemL(pcoIdX,appendablePtrX); |
|
99 TEST(ret==KErrOverflow); |
|
100 |
|
101 // Append a larger buffer |
|
102 const TInt KLargeBuffer=30; |
|
103 TBuf8<KLargeBuffer> largeBuffer(_L8("xxxxxxxxx")); |
|
104 largeBuffer.SetLength(KLargeBuffer); |
|
105 TPtr8 largePtr(const_cast<TUint8*>(largeBuffer.Ptr()),largeBuffer.Length(),largeBuffer.Length()); |
|
106 |
|
107 // Append |
|
108 ret=smallTLV.AppendItemL(pcoIdX,largePtr); |
|
109 TEST(ret==KErrOverflow); |
|
110 |
|
111 // Append 3 Items - X + Y + X |
|
112 ret=smallTLV.AppendItemL(pcoIdX,appendablePtrX); |
|
113 TEST(ret==KErrNone); |
|
114 |
|
115 ret=smallTLV.AppendItemL(pcoIdY,appendablePtrY); |
|
116 TEST(ret==KErrNone); |
|
117 |
|
118 ret=smallTLV.AppendItemL(pcoIdX,appendablePtrX); |
|
119 TEST(ret==KErrNone); |
|
120 |
|
121 // Overflow the buffer |
|
122 ret=smallTLV.AppendItemL(pcoIdY,appendablePtrY); |
|
123 TEST(ret==KErrOverflow); |
|
124 |
|
125 // --------------------------------------------------- |
|
126 // TEST CASE 3 - NextItemL |
|
127 // Buffer contains = XYX |
|
128 // --------------------------------------------------- |
|
129 // Construct TPtr8 buffers for retrieval |
|
130 // Buffer large enough to handle data |
|
131 const TInt KBigEnoughBuf=5; |
|
132 TBuf8<KBigEnoughBuf> bigEnoughBuf; |
|
133 bigEnoughBuf.SetLength(0); |
|
134 TPtr8 bigEnoughPtr(const_cast<TUint8*>(bigEnoughBuf.Ptr()),bigEnoughBuf.Length(),bigEnoughBuf.MaxLength()); |
|
135 |
|
136 // Buffer too small to hold data |
|
137 const TInt KTooSmallBuf=2; |
|
138 TBuf8<KTooSmallBuf> tooSmallBuf; |
|
139 tooSmallBuf.SetLength(0); |
|
140 TPtr8 tooSmallPtr(const_cast<TUint8*>(tooSmallBuf.Ptr()),tooSmallBuf.Length(),tooSmallBuf.MaxLength()); |
|
141 |
|
142 // Get Next Item from zero length TLV |
|
143 ret=zeroTLV.NextItemL(pcoIdY,bigEnoughPtr); |
|
144 TEST(ret==KErrNotFound); |
|
145 |
|
146 // Create Item Z |
|
147 smallTLV.ResetCursorPos(); |
|
148 const TUint16 ZId=2; |
|
149 RPacketContext::TPcoId pcoIdZ(ZId); |
|
150 |
|
151 // Get a non existant item |
|
152 TInt err(KErrNone); |
|
153 TInt leaveErr(KErrNone); |
|
154 TRAP(leaveErr,err=smallTLV.NextItemL(pcoIdZ,bigEnoughPtr)); |
|
155 TEST(leaveErr==KErrNone && err==KErrNotFound); |
|
156 |
|
157 |
|
158 // Get an existing item in bigEnoughBuffer |
|
159 ret=smallTLV.NextItemL(pcoIdX,bigEnoughPtr); |
|
160 TEST(ret==KErrNone); |
|
161 TEST(bigEnoughPtr==appendablePtrX); |
|
162 |
|
163 // Get last item |
|
164 ret=smallTLV.NextItemL(pcoIdX,bigEnoughPtr); |
|
165 TEST(ret==KErrNone); |
|
166 TEST(bigEnoughPtr==appendablePtrX); |
|
167 |
|
168 // Cursor should be at end, try to get item before cursor |
|
169 ret=smallTLV.NextItemL(pcoIdY,bigEnoughPtr); |
|
170 TEST(ret==KErrNotFound); |
|
171 |
|
172 // reset cursor |
|
173 smallTLV.ResetCursorPos(); |
|
174 |
|
175 // get item |
|
176 ret=smallTLV.NextItemL(pcoIdY,bigEnoughPtr); |
|
177 TEST(ret==KErrNone); |
|
178 TEST(bigEnoughPtr==appendablePtrY); |
|
179 |
|
180 |
|
181 // --------------------------------------------------- |
|
182 // TEST CASE 4 - RemoveNextItemL |
|
183 // Buffer contains = XYX |
|
184 // --------------------------------------------------- |
|
185 // remove item form zero length TLV |
|
186 ret=zeroTLV.RemoveNextItemL(pcoIdX); |
|
187 TEST(ret==KErrNotFound); |
|
188 |
|
189 // reset cursor |
|
190 smallTLV.ResetCursorPos(); |
|
191 |
|
192 // remove pcoIdX |
|
193 ret=smallTLV.RemoveNextItemL(pcoIdX); |
|
194 TEST(ret==KErrNone); |
|
195 |
|
196 // remove pcoIdX |
|
197 ret=smallTLV.RemoveNextItemL(pcoIdX); |
|
198 TEST(ret==KErrNone); |
|
199 |
|
200 ret=smallTLV.AppendItemL(pcoIdZ,appendablePtrX); |
|
201 TEST(ret==KErrNone); |
|
202 ret=smallTLV.AnyNextItemL(pcoIdY,bigEnoughPtr); |
|
203 TEST(ret==KErrNone); |
|
204 TEST(pcoIdY.Id()==YId); |
|
205 TEST(bigEnoughPtr==appendablePtrY); |
|
206 |
|
207 ret=smallTLV.AnyNextItemL(pcoIdZ,bigEnoughPtr); |
|
208 TEST(ret==KErrNone); |
|
209 TEST(pcoIdZ.Id()==ZId); |
|
210 TEST(bigEnoughPtr==appendablePtrX); |
|
211 |
|
212 // remove pcoIdY |
|
213 ret=smallTLV.RemoveNextItemL(pcoIdY); |
|
214 TEST(ret==KErrNotFound); |
|
215 |
|
216 // reset cursor |
|
217 smallTLV.ResetCursorPos(); |
|
218 ret=smallTLV.RemoveNextItemL(pcoIdX); |
|
219 TEST(ret==KErrNotFound); |
|
220 ret=smallTLV.RemoveNextItemL(pcoIdY); |
|
221 TEST(ret==KErrNone); |
|
222 ret=smallTLV.RemoveNextItemL(pcoIdZ); |
|
223 TEST(ret==KErrNone); |
|
224 |
|
225 |
|
226 // --------------------------------------------------- |
|
227 // TEST CASE 4 - AnyNextItemL |
|
228 // Buffer is Empty |
|
229 // --------------------------------------------------- |
|
230 // Get any next item from zero length TLV |
|
231 ret=zeroTLV.AnyNextItemL(pcoIdY,bigEnoughPtr); |
|
232 TEST(ret==KErrNotFound); |
|
233 |
|
234 ret=smallTLV.AnyNextItemL(pcoIdY,tooSmallPtr); |
|
235 TEST(ret==KErrNotFound); |
|
236 |
|
237 // Append Item |
|
238 ret=smallTLV.AppendItemL(pcoIdX,appendablePtrX); |
|
239 TEST(ret==KErrNone); |
|
240 |
|
241 // Get item after appending an existing item |
|
242 ret=smallTLV.NextItemL(pcoIdX,bigEnoughPtr); |
|
243 TEST(ret==KErrNone); |
|
244 TEST(bigEnoughPtr==appendablePtrX); |
|
245 |
|
246 ret=smallTLV.AppendItemL(pcoIdY,appendablePtrY); |
|
247 TEST(ret==KErrNone); |
|
248 ret=smallTLV.AppendItemL(pcoIdX,appendablePtrX); |
|
249 TEST(ret==KErrNone); |
|
250 |
|
251 // Searching for item while cursor at end of buffer |
|
252 ret=smallTLV.AnyNextItemL(pcoIdY,bigEnoughPtr); |
|
253 TEST(ret==KErrNone); |
|
254 TEST(pcoIdY.Id()==YId); |
|
255 TEST(bigEnoughPtr==appendablePtrY); |
|
256 |
|
257 // Reset cursor |
|
258 smallTLV.ResetCursorPos(); |
|
259 |
|
260 // Get item into tooSmallbuf |
|
261 ret=smallTLV.AnyNextItemL(pcoIdX,tooSmallPtr); |
|
262 TEST(ret==KErrNone); |
|
263 |
|
264 // Reset cursor |
|
265 smallTLV.ResetCursorPos(); |
|
266 |
|
267 // Get 3 items |
|
268 ret=smallTLV.AnyNextItemL(pcoIdX,bigEnoughPtr); |
|
269 TEST(ret==KErrNone); |
|
270 TEST(pcoIdX.Id()==XId); |
|
271 TEST(bigEnoughPtr==appendablePtrX); |
|
272 |
|
273 // second item |
|
274 ret=smallTLV.AnyNextItemL(pcoIdY,bigEnoughPtr); |
|
275 TEST(ret==KErrNone); |
|
276 TEST(pcoIdY.Id()==YId); |
|
277 TEST(bigEnoughPtr==appendablePtrY); |
|
278 |
|
279 // third item |
|
280 ret=smallTLV.AnyNextItemL(pcoIdX,bigEnoughPtr); |
|
281 TEST(ret==KErrNone); |
|
282 TEST(pcoIdX.Id()==XId); |
|
283 TEST(bigEnoughPtr==appendablePtrX); |
|
284 |
|
285 // try get item at end of buffer |
|
286 ret=smallTLV.AnyNextItemL(pcoIdY,bigEnoughPtr); |
|
287 TEST(ret==KErrNotFound); |
|
288 |
|
289 // --------------------------------------------------- |
|
290 // TEST CASE 5 - Random pattern of calls |
|
291 // Buffer contains XYX |
|
292 // --------------------------------------------------- |
|
293 // Clear Buffer |
|
294 // reset cursor |
|
295 smallTLV.ResetCursorPos(); |
|
296 // remove pcoIdX |
|
297 |
|
298 ret=smallTLV.RemoveNextItemL(pcoIdX); |
|
299 TEST(ret== KErrNone); |
|
300 |
|
301 // remove pcoIdY |
|
302 ret=smallTLV.RemoveNextItemL(pcoIdY); |
|
303 TEST(ret== KErrNone); |
|
304 |
|
305 // remove pcoIdX |
|
306 ret=smallTLV.RemoveNextItemL(pcoIdX); |
|
307 TEST(ret== KErrNone); |
|
308 |
|
309 // Buffer is Empty |
|
310 // Append Item |
|
311 ret=smallTLV.AppendItemL(pcoIdX,appendablePtrX); |
|
312 TEST(ret==KErrNone); |
|
313 |
|
314 // remove pcoIdX after appending pcoIdX |
|
315 ret=smallTLV.RemoveNextItemL(pcoIdX); |
|
316 TEST(ret==KErrNone); |
|
317 |
|
318 // Append Item |
|
319 ret=smallTLV.AppendItemL(pcoIdY,appendablePtrY); |
|
320 TEST(ret==KErrNone); |
|
321 |
|
322 // try get any item after adding pcoIdY |
|
323 ret=smallTLV.AnyNextItemL(pcoIdY,bigEnoughPtr); |
|
324 TEST(ret==KErrNone); |
|
325 TEST(pcoIdY.Id()==YId); |
|
326 TEST(bigEnoughPtr==appendablePtrY); |
|
327 |
|
328 // reset cursor |
|
329 // Buffer contains Y |
|
330 smallTLV.ResetCursorPos(); |
|
331 |
|
332 // get item |
|
333 ret=smallTLV.AnyNextItemL(pcoIdY,bigEnoughPtr); |
|
334 TEST(ret==KErrNone); |
|
335 TEST(pcoIdY.Id()==YId); |
|
336 |
|
337 // Get item pcoIdY |
|
338 ret=smallTLV.NextItemL(pcoIdY,bigEnoughPtr); |
|
339 TEST(ret==KErrNotFound); |
|
340 |
|
341 // remove pcoIdX |
|
342 ret=smallTLV.RemoveNextItemL(pcoIdX); |
|
343 TEST(ret==KErrNotFound); |
|
344 |
|
345 |
|
346 // --------------------------------------------------- |
|
347 // Test CASE 6 - TPcoId |
|
348 // --------------------------------------------------- |
|
349 const TUint16 KFirstPcoId=257; |
|
350 const TUint16 KSecondPcoId=0x103; |
|
351 const TUint16 KSecondPcoIdFlipped=0x301; |
|
352 const TInt KTwoByte=0xFFFE; |
|
353 const TInt KTwoByteFlipped=0xFEFF; |
|
354 const TInt16 KIDSize=sizeof(TUint16); |
|
355 |
|
356 // Create PCO_ID's |
|
357 RPacketContext::TPcoId firstId(KFirstPcoId); |
|
358 |
|
359 // --------------------------------------------------- |
|
360 // -- ExternalizeL |
|
361 // --------------------------------------------------- |
|
362 // -- to buffer large enough to hold value |
|
363 // -- Memory to contain ID - 4 bytes |
|
364 TInt bigExternalizedBuff(KZero); |
|
365 |
|
366 // Create TPtr to the first byte |
|
367 TPtr8 bigExternalizedPtr(reinterpret_cast<TUint8*>(&bigExternalizedBuff),sizeof(TInt),sizeof(TInt)); |
|
368 |
|
369 firstId.ExternalizeL(bigExternalizedPtr); |
|
370 TEST(bigExternalizedBuff==KFirstPcoId); |
|
371 |
|
372 // -- to buffer to small to hold value |
|
373 // -- Memory to contain ID - 1 byte |
|
374 TUint8 smallExternalizedBuff(KZero); |
|
375 // Create TPtr to the first byte |
|
376 TPtr8 smallExternalizedPtr(static_cast<TUint8*>(&smallExternalizedBuff),sizeof(TUint8),sizeof(TUint8)); |
|
377 |
|
378 // Externalize to a pointer with size less than needed. |
|
379 TRAP(err,firstId.ExternalizeL(smallExternalizedPtr)); |
|
380 TEST(err==KErrOverflow); |
|
381 |
|
382 // -- InternalizeL |
|
383 // -- Try internalize a |
|
384 TRAP(err,firstId.InternalizeL(smallExternalizedPtr)); |
|
385 TEST(err==KErrUnderflow); |
|
386 |
|
387 bigExternalizedBuff=KTwoByte; |
|
388 firstId.InternalizeL(bigExternalizedPtr); |
|
389 TEST(firstId.Id()== KTwoByteFlipped); |
|
390 |
|
391 // -- SerializedLength |
|
392 TUint16 size=firstId.SerializedLength(); |
|
393 TEST(size==KIDSize); |
|
394 |
|
395 // -- SetId |
|
396 RPacketContext::TPcoId secondId(0); |
|
397 secondId.SetId(KSecondPcoId); |
|
398 TEST(secondId.Id()==KSecondPcoId); |
|
399 |
|
400 // Check with Externalize |
|
401 secondId.ExternalizeL(bigExternalizedPtr); |
|
402 TEST(bigExternalizedBuff==KSecondPcoIdFlipped); |
|
403 |
|
404 // -- IsEqual |
|
405 firstId.SetId(KSecondPcoId); |
|
406 secondId.SetId(KSecondPcoId); |
|
407 TBool result=firstId.IsEqual(secondId); |
|
408 TEST(result); |
|
409 |
|
410 secondId.SetId(KFirstPcoId); |
|
411 result=firstId.IsEqual(secondId); |
|
412 TEST(!result); |
|
413 |
|
414 // --------------------------------------------------- |
|
415 // Test CASE 7 - NextItemL and RemoveNextItemL using a |
|
416 // 0 length item |
|
417 // Buffer is empty |
|
418 // --------------------------------------------------- |
|
419 |
|
420 // Create Buffer A with 0 length |
|
421 const TUint16 AId=3; |
|
422 RPacketContext::TPcoId pcoIdA(AId); |
|
423 TBuf8<KMinimumBufferSize> appendableBufferA; |
|
424 appendableBufferA.SetLength(KZero); |
|
425 TPtr8 appendablePtrA(const_cast<TUint8*>(appendableBufferA.Ptr()),appendableBufferA.Length(),appendableBufferA.Length()); |
|
426 |
|
427 // reset cursor |
|
428 smallTLV.ResetCursorPos(); |
|
429 |
|
430 // Append 0 length item to TLV struct |
|
431 ret=smallTLV.AppendItemL(pcoIdA, appendablePtrA); |
|
432 TEST(ret==KErrNone); |
|
433 |
|
434 // Try to read back 0 length item |
|
435 // Will fail with KErrNotFound if unsuccessful |
|
436 ret=smallTLV.NextItemL(pcoIdA, bigEnoughPtr); |
|
437 TEST(ret==KErrNone); |
|
438 TEST(bigEnoughPtr==appendablePtrA); |
|
439 |
|
440 // reset cursor |
|
441 smallTLV.ResetCursorPos(); |
|
442 |
|
443 // Finally remove item with 0 length |
|
444 // Will fail with KErrNotFound if unsuccessful |
|
445 ret=smallTLV.RemoveNextItemL(pcoIdA); |
|
446 TEST(ret==KErrNone); |
|
447 |
|
448 return TestStepResult(); |
|
449 } |
|
450 |
|
451 |