summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/testimpexvcard/src/testimpoom.cpp
blob: 71ccb0f3311b5118d44e110953eb135bdee8ec93 (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
/*
* 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: 
*
*/


#include "testimpoom.h"

CTestImpOOM::~CTestImpOOM()
/**
 * Destructor
 */
	{
	}

CTestImpOOM::CTestImpOOM()
/**
 * Constructor
 */
	{
	// Call base class method to set up the human readable name for logging
	SetTestStepName(KTestImpOOM);
	}

TVerdict CTestImpOOM::doTestStepPreambleL()
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
	{
	INFO_PRINTF1(_L("Start Import of vCards in OOM Test"));
	
	iScheduler = new (ELeave) CActiveScheduler;
	CActiveScheduler::Install(iScheduler);
	
	SetTestStepResult(EPass);
	return TestStepResult();
	}

TVerdict CTestImpOOM::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 */
	{
	SetTestStepResult(EPass);
	TInt tryCount = 1;
	TInt err = KErrNone;
	TBool success = EFalse;
	CArrayPtr<CContactItem>* item = NULL;

	CContactDatabase *dBase = NULL;
   	_LIT(KTestDbName, "c:importcontact.cdb");
   	RFs fsSession;
	RFileReadStream readStream;
	
	//replace existing database
	dBase = CContactDatabase::ReplaceL(KTestDbName);
	CleanupStack::PushL(dBase);
	
	//connect to file system
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);
	
	TFileName fileName;
#ifdef __WINS__
	fileName.Append(_L("c:"));
#else
	TFileName processFileName = RProcess().FileName();
	TParsePtrC parse(processFileName);
	fileName.Append(parse.Drive());
#endif
	fileName.Append(KImportOOM());
		
	//Opens a file containing a stream and prepares the stream for reading
	User::LeaveIfError(readStream.Open(fsSession, fileName, EFileRead));
    CleanupClosePushL(readStream);

	for ( ;; )
		{
		__UHEAP_SETFAIL(RHeap::EFailNext, tryCount);
		TRAP(err, item = dBase->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl), readStream, success, CContactDatabase::EDefault));
		 
		if ( err == KErrNone )
			{
			__UHEAP_RESET;
			INFO_PRINTF1(_L("OOM testing of CContactDatabase::ImportContactsL Api is done"));
			break;
			}
		if ( err != KErrNoMemory )
			{
			SetTestStepResult(EFail);
			break;
			}
		__UHEAP_SETFAIL(RHeap::ENone, 0);
		tryCount++;
		}
	 
	// item = dBase->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl), readStream, success, CContactDatabase::EDefault);
	INFO_PRINTF2(_L("TRYCOUNT %d"), tryCount);
	TInt contactsCount = (*item).Count();
	INFO_PRINTF2(_L("Total number of contacts imported is %d "), contactsCount);
	if (contactsCount == 0)
		{
		SetTestStepResult(EFail);
		}

	readStream.Close();
	
	// Cleanup
	item->ResetAndDestroy();
	delete item;
	CleanupStack::PopAndDestroy(&readStream);
	fsSession.Close();
    CleanupStack::PopAndDestroy(&fsSession);
    CleanupStack::PopAndDestroy(dBase);

	return TestStepResult();
	}

TVerdict CTestImpOOM::doTestStepPostambleL()
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
	{
	CActiveScheduler::Install(NULL);
	delete iScheduler;
	INFO_PRINTF1(_L("Completed Import of vCards in OOM Test"));
	return TestStepResult();
	}