|
1 // Copyright (c) 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 |
|
17 //system include |
|
18 #include <mpbutil.h> |
|
19 //user include |
|
20 #include "testltsyphbkwriteinvalidindex.h" |
|
21 //const define |
|
22 const TUint8 KTypeOfNumber=0x81; |
|
23 |
|
24 CTestLtsyPhbkWriteInvalidIndex::CTestLtsyPhbkWriteInvalidIndex(CTestLtsyModel& aTestModel) |
|
25 : CTestLtsyPhoneStoreBase(aTestModel) |
|
26 { |
|
27 |
|
28 } |
|
29 |
|
30 CTestLtsyPhbkWriteInvalidIndex::~CTestLtsyPhbkWriteInvalidIndex() |
|
31 { |
|
32 } |
|
33 |
|
34 CTestLtsyPhbkWriteInvalidIndex* CTestLtsyPhbkWriteInvalidIndex::NewLC(CTestLtsyModel& aTestModel) |
|
35 { |
|
36 CTestLtsyPhbkWriteInvalidIndex* self = new (ELeave)CTestLtsyPhbkWriteInvalidIndex(aTestModel); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CTestLtsyPhbkWriteInvalidIndex* CTestLtsyPhbkWriteInvalidIndex::NewL(CTestLtsyModel& aTestModel) |
|
43 { |
|
44 CTestLtsyPhbkWriteInvalidIndex* self=CTestLtsyPhbkWriteInvalidIndex::NewLC(aTestModel); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 void CTestLtsyPhbkWriteInvalidIndex::ConstructL() |
|
50 { |
|
51 |
|
52 } |
|
53 |
|
54 TVerdict CTestLtsyPhbkWriteInvalidIndex::doTestStepPreambleL() |
|
55 { |
|
56 INFO_PRINTF1(_L("CTestLtsyPhbkWriteInvalidIndex::doTestStepPreambleL called")); |
|
57 SetTestStepResult(EPass); |
|
58 return TestStepResult(); |
|
59 } |
|
60 |
|
61 TVerdict CTestLtsyPhbkWriteInvalidIndex::doTestStepL() |
|
62 { |
|
63 INFO_PRINTF1(_L("CTestLtsyPhbkWriteInvalidIndex::doTestStepL called")); |
|
64 TInt index = -1; |
|
65 TRAPD(err,WriteEntryL(index)); |
|
66 if(err != KErrNone) |
|
67 { |
|
68 INFO_PRINTF2(_L("The error was returned %d!! when write phonebook"),err); |
|
69 SetTestStepResult(EFail); |
|
70 } |
|
71 |
|
72 index = 0; |
|
73 TRAPD(err1,WriteEntryL(index)); |
|
74 if(err1 != KErrNone) |
|
75 { |
|
76 INFO_PRINTF2(_L("The error was returned %d!! when write phonebook"),err1); |
|
77 SetTestStepResult(EFail); |
|
78 } |
|
79 |
|
80 index = 256; |
|
81 TRAPD(err2,WriteEntryL(index)); |
|
82 if(err2 != KErrNone) |
|
83 { |
|
84 INFO_PRINTF2(_L("The error was returned %d!! when write phonebook"),err2); |
|
85 SetTestStepResult(EFail); |
|
86 } |
|
87 return TestStepResult(); |
|
88 } |
|
89 |
|
90 TVerdict CTestLtsyPhbkWriteInvalidIndex::doTestStepPostambleL() |
|
91 { |
|
92 INFO_PRINTF1(_L("CTestLtsyPhbkWriteInvalidIndex::doTestStepPostambleL called")); |
|
93 return TestStepResult(); |
|
94 } |
|
95 |
|
96 void CTestLtsyPhbkWriteInvalidIndex::WriteEntryL(TInt aIndex) |
|
97 { |
|
98 TRequestStatus status; |
|
99 TBuf8<800> pbData; // Client reserved space for phonebook data |
|
100 TInt ret; |
|
101 |
|
102 _LIT16(KTel,"123456%03d"); |
|
103 _LIT16(KText,"TelNo %03d"); |
|
104 TBuf16<20> text(KTel), number(KText); |
|
105 |
|
106 CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer(); // used to write phonebook data |
|
107 CleanupStack::PushL(pbBuffer); |
|
108 pbBuffer->Set(&pbData); // Set it to point to the Client buffer |
|
109 pbBuffer->AddNewEntryTag(); |
|
110 // convert number into TLV format and append it to allocated buffer |
|
111 TInt index = aIndex; |
|
112 ret = pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex,(TUint16)index); |
|
113 if( ret != KErrNone ) |
|
114 { |
|
115 CleanupStack::PopAndDestroy(); |
|
116 SetTestStepResult(EFail); |
|
117 } |
|
118 number.Format(KTel(), index); |
|
119 ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, number); |
|
120 // ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNewEntry, number); |
|
121 if( ret != KErrNone ) |
|
122 { |
|
123 CleanupStack::PopAndDestroy(); |
|
124 SetTestStepResult(EFail); |
|
125 } |
|
126 // convert number type into TLV format and append it to allocated buffer |
|
127 TUint8 tonNpi=KTypeOfNumber; |
|
128 ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBTonNpi, tonNpi); |
|
129 if(ret!=KErrNone) |
|
130 { |
|
131 CleanupStack::PopAndDestroy(); |
|
132 SetTestStepResult(EFail); |
|
133 } |
|
134 |
|
135 text.Format(KText(), index); |
|
136 // convert text into TLV format and append it to allocated buffer |
|
137 ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText, text); |
|
138 if(ret != KErrNone) |
|
139 { |
|
140 CleanupStack::PopAndDestroy(); |
|
141 SetTestStepResult(EFail); |
|
142 } |
|
143 PhoneBookStore().Write(status, pbData,index); |
|
144 User::WaitForRequest(status); |
|
145 TInt r=status.Int(); |
|
146 INFO_PRINTF2(_L("Write() request status = %d"),r); |
|
147 CleanupStack::PopAndDestroy(); |
|
148 } |
|
149 |
|
150 // end of file |