|
1 // Copyright (c) 2006-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 @file |
|
18 @publishedAll |
|
19 @released |
|
20 */ |
|
21 |
|
22 #include <e32panic.h> |
|
23 #include <test/testexecutelog.h> |
|
24 #include <cntfldst.h> |
|
25 #include "ClientServer.h" |
|
26 #include "SimpleViewDefTests.h" |
|
27 |
|
28 _LIT(KTest1,"Testing Inverse behaviour of MI viewdef..."); |
|
29 _LIT(KTest2,"Testing Omission of primary mapping in viewdefs..."); |
|
30 _LIT(KTest3,"Semi-Complex Testing to demonstrate that the primary mapping for all uids are ignored..."); |
|
31 |
|
32 _LIT(KMedium, "MSajkldjKJIlk30aksdjjfeiME"); |
|
33 _LIT(KTimeS,"22000101:235959.999999");// time to use for datetime storage |
|
34 static const TContactItemId KId = 1;//contact id to use for agent storage |
|
35 static const TTime KTime(KTimeS); |
|
36 |
|
37 |
|
38 //Number of contacts |
|
39 CSimpleViewDefTest::CSimpleViewDefTest():CViewDefBase(1) |
|
40 { |
|
41 // Call base class method to set up the human readable name for logging |
|
42 SetTestStepName(SharedConstants::KSimpleViewDefTest); |
|
43 } |
|
44 |
|
45 TVerdict CSimpleViewDefTest::doTestStepL() |
|
46 { |
|
47 __UHEAP_MARK; |
|
48 static const TInt KManyContacts = 3; |
|
49 |
|
50 CContactItemViewDef *viewAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, |
|
51 CContactItemViewDef::EIncludeHiddenFields); |
|
52 viewAll->AddL(KUidContactFieldMatchAll); |
|
53 |
|
54 CContactDatabase *contactsDatabase = CContactDatabase::ReplaceL(); |
|
55 CleanupStack::PushL(contactsDatabase); |
|
56 |
|
57 CContactTemplate* ctemplate = STATIC_CAST( CContactTemplate*, |
|
58 contactsDatabase->ReadContactLC( contactsDatabase->TemplateId(), *viewAll ) ); |
|
59 |
|
60 CContactCard* contact = CContactCard::NewLC(ctemplate); |
|
61 for(TInt i = 0; i< KManyContacts; ++i) |
|
62 { |
|
63 iIterate->AddL( contactsDatabase->AddNewContactL(*contact) ); |
|
64 } |
|
65 CleanupStack::PopAndDestroy(contact); |
|
66 iIterate->Reset(); |
|
67 INFO_PRINTF1(KTest1); |
|
68 MIInverseTestL( iIterate->NextL(), *contactsDatabase, *viewAll ); |
|
69 INFO_PRINTF1(KTest2); |
|
70 PrimayMappingsTestL( iIterate->NextL(), *contactsDatabase, *viewAll ); |
|
71 //this is not really a simple test, using it to confirm that behaviour applies acroos the board |
|
72 INFO_PRINTF1(KTest3); |
|
73 AllPrimayMappingsTestL( iIterate->NextL(), *contactsDatabase, *viewAll ); |
|
74 |
|
75 CleanupStack::PopAndDestroy(ctemplate); |
|
76 CleanupStack::PopAndDestroy(contactsDatabase); |
|
77 CleanupStack::PopAndDestroy(viewAll); |
|
78 iIterate->Close(); |
|
79 __UHEAP_MARKEND; |
|
80 |
|
81 return TestStepResult(); |
|
82 } |
|
83 |
|
84 /*this is for developers to test, doesnt use any memeber variable or such |
|
85 for the sake of simplicity and demonstrability.... This adds one contact to the |
|
86 database and sets all of its fiedls |
|
87 */ |
|
88 void CSimpleViewDefTest::SetupTestL( const TContactItemId aCid, |
|
89 CContactDatabase &aContactsDatabase, |
|
90 const CContactItemViewDef &aViewAll) |
|
91 { |
|
92 TInt length =0; |
|
93 |
|
94 CContactItem *contactItem = NULL; |
|
95 |
|
96 contactItem = aContactsDatabase.OpenContactLX(aCid,aViewAll); |
|
97 CleanupStack::PushL(contactItem); |
|
98 |
|
99 CContactItemFieldSet *fields = &( contactItem->CardFields() ); |
|
100 CContactItemField *field = NULL; |
|
101 length = fields->Count(); |
|
102 |
|
103 for(TInt i = 0; i<length;i++) |
|
104 { |
|
105 field = &((*fields)[i]); |
|
106 switch(field->StorageType()) |
|
107 { |
|
108 case KStorageTypeText: |
|
109 field->TextStorage()->SetTextL(KMedium); |
|
110 break; |
|
111 case KStorageTypeStore: |
|
112 { |
|
113 const TDesC &mstring = KMedium; |
|
114 HBufC8 *buf = HBufC8::NewLC(mstring.Size()); |
|
115 TPtr8 tptr8 = buf->Des(); |
|
116 tptr8.Copy(KMedium); |
|
117 field->StoreStorage()->SetThingL(*buf); |
|
118 CleanupStack::PopAndDestroy(buf); |
|
119 } |
|
120 break; |
|
121 case KStorageTypeContactItemId: |
|
122 field->AgentStorage()->SetAgentId(KId); |
|
123 break; |
|
124 case KStorageTypeDateTime: |
|
125 field->DateTimeStorage()->SetTime(KTime); |
|
126 break; |
|
127 default: |
|
128 User::Panic(KMedium,EInvariantFalse); |
|
129 break; |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 aContactsDatabase.CommitContactL(*contactItem); |
|
135 CleanupStack::PopAndDestroy(contactItem); |
|
136 CleanupStack::Pop();//lock |
|
137 //CleanupStack::Pop(viewMI); |
|
138 contactItem = NULL; |
|
139 fields = NULL; |
|
140 |
|
141 } |
|
142 /*when using mi viewdef to load data no hidden fields have their values restored, |
|
143 i.e. that action of include hidden fields is reveresed to act as exclude*/ |
|
144 void CSimpleViewDefTest::MIInverseTestL( const TContactItemId aCid, |
|
145 CContactDatabase &aContactsDatabase, |
|
146 const CContactItemViewDef &aViewAll) |
|
147 { |
|
148 SetupTestL(aCid,aContactsDatabase,aViewAll); |
|
149 CContactItem *contactItem = NULL; |
|
150 |
|
151 CContactItemViewDef *viewMI = NULL; |
|
152 viewMI = CContactItemViewDef::NewLC(CContactItemViewDef::EMaskFields, |
|
153 CContactItemViewDef::EIncludeHiddenFields); |
|
154 viewMI->AddL(KUidContactFieldMatchAll); |
|
155 |
|
156 aContactsDatabase.SetViewDefinitionL(CContactViewDef::NewL(viewMI)); |
|
157 CleanupStack::Pop(viewMI); |
|
158 contactItem = aContactsDatabase.ReadMinimalContactLC(aCid); |
|
159 |
|
160 CContactItemFieldSet &fields = contactItem->CardFields(); |
|
161 TInt hcount = fields.Count(); |
|
162 |
|
163 INTCOMPARE(hcount, ==, 0, 0, 0);/*there should be three fields in readminimal, all hidden |
|
164 as in instead if including all hidden, they are all excluded*/ |
|
165 |
|
166 CleanupStack::PopAndDestroy(contactItem); |
|
167 contactItem = NULL; |
|
168 } |
|
169 |
|
170 /*when using any viewdef that contains a primary mapping uid to load data, |
|
171 then those fields which use that uid are not excluded/included as necessary*/ |
|
172 void CSimpleViewDefTest::PrimayMappingsTestL( const TContactItemId aCid, |
|
173 CContactDatabase &aContactsDatabase, |
|
174 const CContactItemViewDef &aViewAll) |
|
175 { |
|
176 SetupTestL(aCid,aContactsDatabase,aViewAll); |
|
177 doPrimayMappingsTestL(aCid, aContactsDatabase, aViewAll, KIntContactFieldVCardMapADR); |
|
178 |
|
179 } |
|
180 |
|
181 /*when using any viewdef that contains a primary mapping uid to load data, |
|
182 then those fields which use that uid are not excluded/included as necessary*/ |
|
183 void CSimpleViewDefTest::AllPrimayMappingsTestL( const TContactItemId aCid, |
|
184 CContactDatabase &aContactsDatabase, |
|
185 const CContactItemViewDef &aViewAll) |
|
186 { |
|
187 SetupTestL(aCid,aContactsDatabase,aViewAll); |
|
188 TInt length = iExistingUidsArray->Count(); |
|
189 for(TInt i = 0; i < length; ++i) |
|
190 { |
|
191 doPrimayMappingsTestL(aCid, aContactsDatabase, aViewAll, (*iExistingUidsArray)[i]); |
|
192 } |
|
193 } |
|
194 |
|
195 void CSimpleViewDefTest::doPrimayMappingsTestL( const TContactItemId aCid, |
|
196 CContactDatabase &aContactsDatabase, |
|
197 const CContactItemViewDef &aViewAll, |
|
198 const TInt32 aUid) |
|
199 { |
|
200 CContactItem *contactItem = NULL; |
|
201 TInt fieldsIV = 0;//fields in viewdef |
|
202 TInt primaryFieldsIV = 0; |
|
203 |
|
204 contactItem = aContactsDatabase.ReadContactLC(aCid,aViewAll); |
|
205 CContactItemFieldSet *fields = &( contactItem->CardFields() ); |
|
206 TInt fcount = fields->Count(); |
|
207 TInt ccount = 0; |
|
208 TBool uInArray = EFalse; |
|
209 const CContentType *ctype = NULL; |
|
210 |
|
211 for(TInt i = 0; i < fcount; ++i) |
|
212 { |
|
213 ctype = &( (*fields)[i].ContentType() ); |
|
214 ccount = ctype->FieldTypeCount(); |
|
215 uInArray = EFalse; |
|
216 for(TInt j = 0; j < ccount; ++j) |
|
217 { |
|
218 if( ctype->FieldType(j).iUid == aUid ) //uid stored in standard fieldtype array |
|
219 { |
|
220 ++fieldsIV; |
|
221 uInArray = ETrue; |
|
222 break; |
|
223 } |
|
224 } |
|
225 if( !uInArray && ( ctype->Mapping().iUid == aUid ) )//uid only stored in primary mapping |
|
226 { |
|
227 ++primaryFieldsIV; |
|
228 } |
|
229 } |
|
230 |
|
231 CleanupStack::PopAndDestroy(contactItem); |
|
232 contactItem = NULL; |
|
233 fields = NULL; |
|
234 |
|
235 CContactItemViewDef *viewII = NULL; |
|
236 viewII = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, |
|
237 CContactItemViewDef::EIncludeHiddenFields); |
|
238 viewII->AddL( TUid::Uid(aUid) ); |
|
239 |
|
240 aContactsDatabase.SetViewDefinitionL( CContactViewDef::NewL(viewII) ); |
|
241 CleanupStack::Pop(viewII); |
|
242 contactItem = aContactsDatabase.ReadMinimalContactLC(aCid); |
|
243 fields = &( contactItem->CardFields() ); |
|
244 |
|
245 TInt resCount = 0; |
|
246 resCount = fields->Count(); |
|
247 |
|
248 INTCOMPARE( fcount, >, 0, aUid, 0 ); |
|
249 //primaryFieldsIV is ignored |
|
250 INTCOMPARE( resCount, ==, fieldsIV , aUid, 0 ); |
|
251 |
|
252 CleanupStack::PopAndDestroy(contactItem); |
|
253 contactItem = NULL; |
|
254 fields = NULL; |
|
255 } |
|
256 |