|
1 // Copyright (c) 2000-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 // BioTest.h |
|
15 // |
|
16 |
|
17 #ifndef __BIOTEST_H__ |
|
18 #define __BIOTEST_H__ |
|
19 |
|
20 #include <e32test.h> |
|
21 #include "msvtestutilsbase.h" |
|
22 #include "BIODB.H" |
|
23 #include <bautils.h> |
|
24 #include <bifchangeobserver.h> |
|
25 |
|
26 // Constants |
|
27 _LIT(KBifFolderV2, "\\resource\\messaging\\Bif\\"); |
|
28 |
|
29 |
|
30 // The following must be defined by the test exe |
|
31 GLREF_D RTest test; |
|
32 LOCAL_C void doTestsL(); |
|
33 |
|
34 // Globals |
|
35 TInt TestNum = 0; |
|
36 class CBioTestUtils; |
|
37 CBioTestUtils* theUtils = NULL; |
|
38 |
|
39 //********************************** |
|
40 // CBioTestUtils |
|
41 //********************************** |
|
42 |
|
43 class CBioTestUtils : public CTestUtils |
|
44 { |
|
45 public: |
|
46 static CBioTestUtils* NewL(RTest& aTest); |
|
47 CBioTestUtils(RTest& aTest); |
|
48 void Panic(TInt aPanic); |
|
49 // |
|
50 public: |
|
51 void Start(const TDesC& aDes); |
|
52 void Complete(); |
|
53 void End(TInt aRet); |
|
54 // |
|
55 void ClearBifFoldersL(); |
|
56 void ClearBifFolderL(TInt aDrive); |
|
57 TBool BifInstalledL(CBIODatabase& aDatabase, TUid aId); |
|
58 TBool FindFileL(TParse& aParse, const TDesC& aDir, const TDesC& aName); |
|
59 // |
|
60 private: |
|
61 void ConstructL(); |
|
62 TBool DoFindFileL(TParse& aParse, TInt aDrive, const TDesC& aDir, const TDesC& aName); |
|
63 // |
|
64 private: |
|
65 TInt iTestNum; |
|
66 }; |
|
67 |
|
68 |
|
69 CBioTestUtils* CBioTestUtils::NewL(RTest& aTest) |
|
70 { |
|
71 CBioTestUtils* self = new(ELeave)CBioTestUtils(aTest); |
|
72 CleanupStack::PushL(self); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop(); // self |
|
75 return self; |
|
76 } |
|
77 |
|
78 CBioTestUtils::CBioTestUtils(RTest& aTest) |
|
79 : CTestUtils(aTest) |
|
80 { |
|
81 } |
|
82 |
|
83 void CBioTestUtils::ConstructL() |
|
84 { |
|
85 CTestUtils::ConstructL(); |
|
86 |
|
87 // Is there a D-drive? |
|
88 TVolumeInfo info; |
|
89 Test()(FileSession().Volume(info, EDriveD) == KErrNone); |
|
90 } |
|
91 |
|
92 void CBioTestUtils::Panic(TInt) |
|
93 { |
|
94 Test()(EFalse); |
|
95 } |
|
96 |
|
97 void CBioTestUtils::Start(const TDesC& aDes) |
|
98 { |
|
99 if (iTestNum == 0) |
|
100 Test().Start(aDes); |
|
101 else |
|
102 Test().Next(aDes); |
|
103 |
|
104 TestStart(++iTestNum, aDes); |
|
105 } |
|
106 |
|
107 void CBioTestUtils::Complete() |
|
108 { |
|
109 TestFinish(iTestNum, KErrNone); |
|
110 } |
|
111 |
|
112 void CBioTestUtils::End(TInt aRet) |
|
113 { |
|
114 if (!aRet) |
|
115 TestHarnessCompleted(); |
|
116 else |
|
117 TestHarnessFailed(aRet); |
|
118 |
|
119 Test()(aRet == KErrNone); |
|
120 |
|
121 if (iTestNum > 0) |
|
122 Test().End(); |
|
123 |
|
124 Test().Close(); |
|
125 } |
|
126 |
|
127 void CBioTestUtils::ClearBifFoldersL() |
|
128 { |
|
129 ClearBifFolderL(EDriveC); |
|
130 ClearBifFolderL(EDriveD); |
|
131 } |
|
132 |
|
133 void CBioTestUtils::ClearBifFolderL(TInt aDrive) |
|
134 { |
|
135 CFileMan* fileMan = CFileMan::NewL(FileSession()); |
|
136 CleanupStack::PushL(fileMan); |
|
137 |
|
138 // Get drive name |
|
139 TDriveUnit unit(aDrive); |
|
140 TPtrC drive(unit.Name()); |
|
141 |
|
142 // Generate path |
|
143 TParse parse; |
|
144 TInt error; |
|
145 |
|
146 User::LeaveIfError(parse.Set(KBifFolderV2(), &drive, NULL)); |
|
147 |
|
148 // Delete the folder |
|
149 error = fileMan->RmDir(parse.DriveAndPath()); |
|
150 if (error != KErrNotFound && error != KErrPathNotFound) |
|
151 User::LeaveIfError(error); |
|
152 |
|
153 CleanupStack::PopAndDestroy(); // fileMan |
|
154 } |
|
155 |
|
156 TBool CBioTestUtils::BifInstalledL(CBIODatabase& aDatabase, TUid aId) |
|
157 { |
|
158 TInt index; |
|
159 TRAPD(error, aDatabase.GetBioIndexWithMsgIDL(aId, index)); |
|
160 return !error; |
|
161 } |
|
162 |
|
163 TBool CBioTestUtils::FindFileL(TParse& aParse, const TDesC& aDir, const TDesC& aName) |
|
164 { |
|
165 // Check rom |
|
166 if (DoFindFileL(aParse, EDriveZ, aDir, aName)) |
|
167 return ETrue; |
|
168 |
|
169 // Check alternate drive |
|
170 if (DoFindFileL(aParse, EDriveD, aDir, aName)) |
|
171 return ETrue; |
|
172 |
|
173 // Check internal disk |
|
174 if (DoFindFileL(aParse, EDriveC, aDir, aName)) |
|
175 return ETrue; |
|
176 |
|
177 // File not found |
|
178 return EFalse; |
|
179 } |
|
180 |
|
181 TBool CBioTestUtils::DoFindFileL(TParse& aParse, TInt aDrive, const TDesC& aDir, const TDesC& aName) |
|
182 { |
|
183 // Generate drive name |
|
184 TDriveUnit unit(aDrive); |
|
185 TPtrC drive(unit.Name()); |
|
186 |
|
187 // Generate path and see if file exists |
|
188 User::LeaveIfError(aParse.Set(drive, &aDir, &aName)); |
|
189 return BaflUtils::FileExists(FileSession(), aParse.FullName()); |
|
190 } |
|
191 |
|
192 //********************************** |
|
193 // Global |
|
194 //********************************** |
|
195 |
|
196 LOCAL_C void SetupL() |
|
197 { |
|
198 CActiveScheduler::Install(new(ELeave)CActiveScheduler); |
|
199 |
|
200 // Create test class |
|
201 theUtils = CBioTestUtils::NewL(test); |
|
202 } |
|
203 |
|
204 LOCAL_C void Close(TInt aRet) |
|
205 { |
|
206 if (theUtils) |
|
207 { |
|
208 theUtils->End(aRet); |
|
209 delete theUtils; |
|
210 } |
|
211 |
|
212 delete CActiveScheduler::Current(); |
|
213 } |
|
214 |
|
215 LOCAL_C void doMainL() |
|
216 { |
|
217 SetupL(); |
|
218 doTestsL(); |
|
219 } |
|
220 |
|
221 GLDEF_C TInt E32Main() |
|
222 { |
|
223 __UHEAP_MARK; |
|
224 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
225 __ASSERT_ALWAYS(cleanup, User::Invariant()); |
|
226 TRAPD(ret,doMainL()); |
|
227 Close(ret); |
|
228 delete cleanup; |
|
229 __UHEAP_MARKEND; |
|
230 return KErrNone; |
|
231 } |
|
232 |
|
233 #endif |