summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/t_platsec.cpp
blob: 33f79ed96461b7566ae8675672bae0ad9aa4f017 (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
/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* 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: 
* Tests Contacts Database can be opened and read with only ReadUserData capability
*
*/


#include <e32std.h>
#include <e32test.h>
#include <cntdb.h>
#include <cntitem.h>
#include <cntfldst.h>
#include "t_utils2.h"
#include "t_utils.h"
#include <coreappstest/testserver.h>
#include "t_platsec.h"

//
// Configuration.
//


//
// Constants.
//

_LIT(KTestName,"t_platsec");

#ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__
//_LIT(KDbFileName58920,"c:SQLite__Contacts58920.cdb");
_LIT(KDbFileName58920,"c:Contacts58920.cdb");
_LIT(KSourceDbFileName58920,"z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\SQLite__Contacts58920.cdb");
_LIT(KDestDbFileName58920,"SQLite__Contacts58920.cdb");
#else //__SYMBIAN_CNTMODEL_USE_SQLITE__
_LIT(KDbFileName58920,"c:contacts58920.cdb");
_LIT(KSourceDbFileName58920,"z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\contacts58920.cdb");
_LIT(KDestDbFileName58920,"contacts58920.cdb");
#endif //__SYMBIAN_CNTMODEL_USE_SQLITE__

_LIT(KLogFileName,"t_platsec.log");


//
// CPlatSecTest.
//

CPlatSecTest* CPlatSecTest::NewLC(RTest& aTest)
	{
	CPlatSecTest* self = new CPlatSecTest(aTest);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

CPlatSecTest::CPlatSecTest(RTest& aTest) : iTest(aTest)
	{
	}

CPlatSecTest::~CPlatSecTest()
	{
	if (iTestServer.Handle() != 0)
		{ // cleanup temp database
		HBufC* fullDbName = GetFullDbName(KDestDbFileName58920);
		if(fullDbName)
		    {
    		TRAP_IGNORE(iTestServer.DeleteFileL(*fullDbName));
    		delete fullDbName;
		    }
		iTestServer.Close();
		}
	delete iDb;
	delete iLog;
	iFs.Close();
	iTest.Close();
	}

void CPlatSecTest::ConstructL()
	{
	User::LeaveIfError(iFs.Connect());
	User::LeaveIfError(iTestServer.Connect());

	// Copy test contacts database
	HBufC* fullDbName = GetFullDbName(KDestDbFileName58920);
	User::LeaveIfNull(fullDbName);

    CleanupStack::PushL(fullDbName);
	iTestServer.CopyFileL(KSourceDbFileName58920, *fullDbName);
    CleanupStack::PopAndDestroy(fullDbName);

	iLogFileName=KLogFileName;
	iDbFileName=KDbFileName58920;
	iLog=CLog::NewL(iTest,iLogFileName);
	}

void CPlatSecTest::IdleFindCallback()
	{
	}

void CPlatSecTest::DoTestL()
	{

	TPtrC match;

	// Test for DEF58920 (Contacts not usable if only ReadUserData capabilitiy)
	// Note absence of WriteUserData in .mmp file


	iLog->LogLine(_L("Open database with ReadUserData capability only"));
	// Prior to bug fix used to get the following when doing an open
	// *PlatSec* ERROR - Capability check failed
    // - A Message (function number=0x464000f1) from Thread
    // T_PLATSEC.EXE[00000000]0001::Main, sent to Server
    // !DBMS server, was checked by Thread EDBSRV.EXE[100012a5]0001::!DBMS
    // server and was found to be missing the capabilities: WriteUserData .
    // t_platsec finishes with -46 error
	iDb=CContactDatabase::OpenL(iDbFileName);


	iLog->LogLine(_L("DatabaseDrive()"));
	TDriveUnit driveUnit;
	TBool bHasBeenSet = iDb->DatabaseDrive(driveUnit);

	iLog->LogLine(_L("GetCurrentDatabase()"));
	TFileName currentDb;
	iDb->GetCurrentDatabase(currentDb);

	iLog->LogLine(_L("CountL()"));
    TInt numberContacts = iDb->CountL();

	iLog->LogLine(_L("SortedItemsL()"));
    CContactIdArray* idList=CContactIdArray::NewLC(iDb->SortedItemsL());
	const TInt index=(*idList)[0];

	iLog->LogLine(_L("ReadContactLC()"));
	CContactItem* item= iDb->ReadContactLC(index);

	CContactItemFieldSet& fields=item->CardFields();
	const TInt fieldCount=fields.Count();

	CContactItemField &field1 = fields[1];
	TPtrC fieldText1=field1.TextStorage()->Text();

	// check that can read out of database
	iTest.Next(_L("Reading Contact field"));

#ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__
  	iTest(fieldText1 == _L("Name1"));
#else //__SYMBIAN_CNTMODEL_USE_SQLITE__
  	iTest(fieldText1 == _L("9AB24C76BmQAte[POqjm_PoyFam\\\\cKq"));
#endif //__SYMBIAN_CNTMODEL_USE_SQLITE__

    CleanupStack::PopAndDestroy(item);
    CleanupStack::PopAndDestroy(idList);

	//
	}

void RunTestsL(RTest& aTest)
	{
	CPlatSecTest* platSecTest=CPlatSecTest::NewLC(aTest);

	platSecTest->DoTestL();

	CleanupStack::PopAndDestroy(platSecTest);
	}


//
// Main.
//

/**

@SYMTestCaseID     PIM-T-PLATSEC-0001

*/

GLDEF_C TInt E32Main()
	{
	RDebug::Print(_L("t_platsec started"));
	__UHEAP_MARK;
#ifndef __SECURE_API__
	RProcess process;
	TBuf<256> commandLine;
	process.CommandLine(commandLine);
#else
	TBuf<256> commandLine;
	User::CommandLine(commandLine);
#endif
	TInt result(KErrNone);
	CActiveScheduler* scheduler=new CActiveScheduler;
	if (scheduler)
		{
		CActiveScheduler::Install(scheduler);
		CTrapCleanup* cleanup=CTrapCleanup::New();
		if (cleanup)
			{
			RTest test(KTestName);

			test.Start(_L("@SYMTESTCaseID:PIM-T-PLATSEC-0001 Test for DEF58920"));


			TRAP(result,RunTestsL(test));
			test(result == KErrNone);

			// test SUCCESS
			test.End();
			test.Close();
			delete cleanup;
			}

		delete scheduler;
		}
	__UHEAP_MARKEND;
	return result;
    }