|
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 #include "TestImpOOM.h" |
|
17 |
|
18 CTestImpOOM::~CTestImpOOM() |
|
19 /** |
|
20 * Destructor |
|
21 */ |
|
22 { |
|
23 } |
|
24 |
|
25 CTestImpOOM::CTestImpOOM() |
|
26 /** |
|
27 * Constructor |
|
28 */ |
|
29 { |
|
30 // Call base class method to set up the human readable name for logging |
|
31 SetTestStepName(KTestImpOOM); |
|
32 } |
|
33 |
|
34 TVerdict CTestImpOOM::doTestStepPreambleL() |
|
35 /** |
|
36 * @return - TVerdict code |
|
37 * Override of base class virtual |
|
38 */ |
|
39 { |
|
40 INFO_PRINTF1(_L("Start Import of vCards in OOM Test")); |
|
41 |
|
42 iScheduler = new (ELeave) CActiveScheduler; |
|
43 CActiveScheduler::Install(iScheduler); |
|
44 |
|
45 SetTestStepResult(EPass); |
|
46 return TestStepResult(); |
|
47 } |
|
48 |
|
49 TVerdict CTestImpOOM::doTestStepL() |
|
50 /** |
|
51 * @return - TVerdict code |
|
52 * Override of base class pure virtual |
|
53 */ |
|
54 { |
|
55 SetTestStepResult(EPass); |
|
56 TInt tryCount = 1; |
|
57 TInt err = KErrNone; |
|
58 TBool success = EFalse; |
|
59 CArrayPtr<CContactItem>* item = NULL; |
|
60 |
|
61 CContactDatabase *dBase = NULL; |
|
62 _LIT(KTestDbName, "c:importcontact.cdb"); |
|
63 RFs fsSession; |
|
64 RFileReadStream readStream; |
|
65 |
|
66 //replace existing database |
|
67 dBase = CContactDatabase::ReplaceL(KTestDbName); |
|
68 CleanupStack::PushL(dBase); |
|
69 |
|
70 //connect to file system |
|
71 User::LeaveIfError(fsSession.Connect()); |
|
72 CleanupClosePushL(fsSession); |
|
73 |
|
74 TFileName fileName; |
|
75 #ifdef __WINS__ |
|
76 fileName.Append(_L("c:")); |
|
77 #else |
|
78 TFileName processFileName = RProcess().FileName(); |
|
79 TParsePtrC parse(processFileName); |
|
80 fileName.Append(parse.Drive()); |
|
81 #endif |
|
82 fileName.Append(KImportOOM()); |
|
83 |
|
84 //Opens a file containing a stream and prepares the stream for reading |
|
85 User::LeaveIfError(readStream.Open(fsSession, fileName, EFileRead)); |
|
86 CleanupClosePushL(readStream); |
|
87 |
|
88 for ( ;; ) |
|
89 { |
|
90 __UHEAP_SETFAIL(RHeap::EFailNext, tryCount); |
|
91 TRAP(err, item = dBase->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl), readStream, success, CContactDatabase::EDefault)); |
|
92 |
|
93 if ( err == KErrNone ) |
|
94 { |
|
95 __UHEAP_RESET; |
|
96 INFO_PRINTF1(_L("OOM testing of CContactDatabase::ImportContactsL Api is done")); |
|
97 break; |
|
98 } |
|
99 if ( err != KErrNoMemory ) |
|
100 { |
|
101 SetTestStepResult(EFail); |
|
102 break; |
|
103 } |
|
104 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
105 tryCount++; |
|
106 } |
|
107 |
|
108 // item = dBase->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl), readStream, success, CContactDatabase::EDefault); |
|
109 INFO_PRINTF2(_L("TRYCOUNT %d"), tryCount); |
|
110 TInt contactsCount = (*item).Count(); |
|
111 INFO_PRINTF2(_L("Total number of contacts imported is %d "), contactsCount); |
|
112 if (contactsCount == 0) |
|
113 { |
|
114 SetTestStepResult(EFail); |
|
115 } |
|
116 |
|
117 readStream.Close(); |
|
118 |
|
119 // Cleanup |
|
120 item->ResetAndDestroy(); |
|
121 delete item; |
|
122 CleanupStack::PopAndDestroy(&readStream); |
|
123 fsSession.Close(); |
|
124 CleanupStack::PopAndDestroy(&fsSession); |
|
125 CleanupStack::PopAndDestroy(dBase); |
|
126 |
|
127 return TestStepResult(); |
|
128 } |
|
129 |
|
130 TVerdict CTestImpOOM::doTestStepPostambleL() |
|
131 /** |
|
132 * @return - TVerdict code |
|
133 * Override of base class virtual |
|
134 */ |
|
135 { |
|
136 CActiveScheduler::Install(NULL); |
|
137 delete iScheduler; |
|
138 INFO_PRINTF1(_L("Completed Import of vCards in OOM Test")); |
|
139 return TestStepResult(); |
|
140 } |
|
141 |