summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/cntperftest/src/simpleviewdeftest.cpp
blob: 318bab981c410d7ae5d738ccd2631e18f3ae96d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


/**
 @file
 @publishedAll
 @released
*/

#include <e32panic.h>
#include <test/testexecutelog.h>
#include <cntfldst.h>
#include "clientserver.h"
#include "simpleviewdeftests.h"

_LIT(KTest1,"Testing Inverse behaviour of MI viewdef...");
_LIT(KTest2,"Testing Omission of primary mapping in viewdefs...");
_LIT(KTest3,"Semi-Complex Testing to demonstrate that the primary mapping for all uids are ignored...");

_LIT(KMedium, "MSajkldjKJIlk30aksdjjfeiME");
_LIT(KTimeS,"22000101:235959.999999");// time to use for datetime storage
static const TContactItemId KId = 1;//contact id to use for agent storage
static const TTime KTime(KTimeS);


//Number of contacts
CSimpleViewDefTest::CSimpleViewDefTest():CViewDefBase(1)
	{
	// Call base class method to set up the human readable name for logging
	SetTestStepName(SharedConstants::KSimpleViewDefTest);
	}

TVerdict CSimpleViewDefTest::doTestStepL()
	{
	__UHEAP_MARK;
	static const TInt KManyContacts = 3;
	
	CContactItemViewDef *viewAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,
	CContactItemViewDef::EIncludeHiddenFields);
	viewAll->AddL(KUidContactFieldMatchAll);

	CContactDatabase *contactsDatabase = CContactDatabase::ReplaceL();
	CleanupStack::PushL(contactsDatabase);		
			
	CContactTemplate* ctemplate = STATIC_CAST( CContactTemplate*, 
	contactsDatabase->ReadContactLC( contactsDatabase->TemplateId(), *viewAll ) );
	
	CContactCard* contact = CContactCard::NewLC(ctemplate);
	for(TInt i = 0; i< KManyContacts; ++i)
		{
		iIterate->AddL( contactsDatabase->AddNewContactL(*contact) );
		}
	CleanupStack::PopAndDestroy(contact);
	iIterate->Reset();
	INFO_PRINTF1(KTest1);
	MIInverseTestL( iIterate->NextL(), *contactsDatabase, *viewAll );
	INFO_PRINTF1(KTest2);
	PrimayMappingsTestL( iIterate->NextL(), *contactsDatabase, *viewAll );
	//this is not really a simple test, using it to confirm that behaviour applies acroos the board
	INFO_PRINTF1(KTest3);
	AllPrimayMappingsTestL( iIterate->NextL(), *contactsDatabase, *viewAll );
	
	CleanupStack::PopAndDestroy(ctemplate);
	CleanupStack::PopAndDestroy(contactsDatabase);
	CleanupStack::PopAndDestroy(viewAll);
	iIterate->Close();
	__UHEAP_MARKEND;
	
	return TestStepResult();
	}

/*this is for developers to test, doesnt use any memeber variable or such
for the sake of simplicity and demonstrability.... This adds one contact to the
database and sets all of its fiedls
*/
void CSimpleViewDefTest::SetupTestL(	const TContactItemId aCid, 
										CContactDatabase &aContactsDatabase,
										const CContactItemViewDef &aViewAll)
	{
	TInt length =0;
	
	CContactItem *contactItem = NULL;
	
	contactItem = aContactsDatabase.OpenContactLX(aCid,aViewAll);
	CleanupStack::PushL(contactItem);
	
	CContactItemFieldSet *fields = &( contactItem->CardFields() );
	CContactItemField *field = NULL;
	length = fields->Count();
	
	for(TInt i = 0; i<length;i++)
		{
		field = &((*fields)[i]);
		switch(field->StorageType())
			{
			case KStorageTypeText:
				field->TextStorage()->SetTextL(KMedium);
			break;
			case KStorageTypeStore:
				{
				const TDesC &mstring = KMedium;
				HBufC8 *buf = HBufC8::NewLC(mstring.Size());
				TPtr8 tptr8 = buf->Des();
				tptr8.Copy(KMedium);
				field->StoreStorage()->SetThingL(*buf);
				CleanupStack::PopAndDestroy(buf);
				}
			break;
			case KStorageTypeContactItemId:
				field->AgentStorage()->SetAgentId(KId);
			break;
			case KStorageTypeDateTime:
				field->DateTimeStorage()->SetTime(KTime);
			break;
			default:
				User::Panic(KMedium,EInvariantFalse);
			break;
			}
		}

	
	aContactsDatabase.CommitContactL(*contactItem);
	CleanupStack::PopAndDestroy(contactItem);
	CleanupStack::Pop();//lock
	//CleanupStack::Pop(viewMI);
	contactItem = NULL;
	fields = NULL;
	
	}
/*when using mi viewdef to load data no hidden fields have their values restored,
i.e. that action of include hidden fields is reveresed to act as exclude*/	
void CSimpleViewDefTest::MIInverseTestL(	const TContactItemId aCid, 
											CContactDatabase &aContactsDatabase,
											const CContactItemViewDef &aViewAll)
	{
	SetupTestL(aCid,aContactsDatabase,aViewAll);
	CContactItem *contactItem = NULL;
	
	CContactItemViewDef *viewMI = NULL;
	viewMI = CContactItemViewDef::NewLC(CContactItemViewDef::EMaskFields,
	CContactItemViewDef::EIncludeHiddenFields);
	viewMI->AddL(KUidContactFieldMatchAll);
	
	aContactsDatabase.SetViewDefinitionL(CContactViewDef::NewL(viewMI));
	CleanupStack::Pop(viewMI);
	contactItem = aContactsDatabase.ReadMinimalContactLC(aCid);
	
	CContactItemFieldSet &fields = contactItem->CardFields();
	TInt hcount = fields.Count();
	
	INTCOMPARE(hcount, ==, 0, 0, 0);/*there should be three fields in readminimal, all hidden
						as in instead if including all hidden, they are all excluded*/

	CleanupStack::PopAndDestroy(contactItem);
	contactItem = NULL;
	}
	
/*when using any viewdef that contains a primary mapping uid to load data,
then those fields which use that uid are not excluded/included as necessary*/	
void CSimpleViewDefTest::PrimayMappingsTestL(	const TContactItemId aCid, 
												CContactDatabase &aContactsDatabase,
												const CContactItemViewDef &aViewAll)
	{
	SetupTestL(aCid,aContactsDatabase,aViewAll);
	doPrimayMappingsTestL(aCid, aContactsDatabase, aViewAll, KIntContactFieldVCardMapADR);
	
	}
	
/*when using any viewdef that contains a primary mapping uid to load data,
then those fields which use that uid are not excluded/included as necessary*/	
void CSimpleViewDefTest::AllPrimayMappingsTestL(	const TContactItemId aCid, 
													CContactDatabase &aContactsDatabase,
													const CContactItemViewDef &aViewAll)
	{
	SetupTestL(aCid,aContactsDatabase,aViewAll);
	TInt length = iExistingUidsArray->Count();
	for(TInt i = 0; i < length; ++i)
		{
		doPrimayMappingsTestL(aCid, aContactsDatabase, aViewAll, (*iExistingUidsArray)[i]);
		}
	}

void CSimpleViewDefTest::doPrimayMappingsTestL(	const TContactItemId aCid, 
													CContactDatabase &aContactsDatabase,
													const CContactItemViewDef &aViewAll,
													const TInt32 aUid)
	{
	CContactItem *contactItem = NULL;
	TInt fieldsIV = 0;//fields in viewdef
	TInt primaryFieldsIV = 0;
		
	contactItem = aContactsDatabase.ReadContactLC(aCid,aViewAll);
	CContactItemFieldSet *fields = &( contactItem->CardFields() );
	TInt fcount = fields->Count();
	TInt ccount = 0;
	TBool uInArray = EFalse;
	const CContentType *ctype = NULL;
	
	for(TInt i = 0; i < fcount; ++i)
		{
		ctype = &( (*fields)[i].ContentType() );
		ccount = ctype->FieldTypeCount();
		uInArray = EFalse;
		for(TInt j = 0; j < ccount; ++j)
			{
			if( ctype->FieldType(j).iUid == aUid ) //uid stored in standard fieldtype array
				{
				++fieldsIV;
				uInArray = ETrue;
				break;
				}
			}
		if( !uInArray && ( ctype->Mapping().iUid == aUid ) )//uid only stored in primary mapping
			{
			++primaryFieldsIV;
			}
		}
		
	CleanupStack::PopAndDestroy(contactItem);
	contactItem = NULL;
	fields = NULL;
	
	CContactItemViewDef *viewII = NULL;
	viewII = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,
	CContactItemViewDef::EIncludeHiddenFields);
	viewII->AddL( TUid::Uid(aUid) );
	
	aContactsDatabase.SetViewDefinitionL( CContactViewDef::NewL(viewII) );
	CleanupStack::Pop(viewII);
	contactItem = aContactsDatabase.ReadMinimalContactLC(aCid);
	fields = &( contactItem->CardFields() );
	
	TInt resCount = 0;
	resCount = fields->Count();
	
	INTCOMPARE( fcount, >, 0, aUid, 0 );
	//primaryFieldsIV is ignored
	INTCOMPARE(  resCount, ==, fieldsIV , aUid, 0 );
		
	CleanupStack::PopAndDestroy(contactItem);
	contactItem = NULL;
	fields = NULL;
	}