|
1 // Copyright (c) 2004-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 // Test Help Model module to check the PlatSec search order. |
|
15 // Note: Use could be made of drive A: on the emulator and not on the hardware |
|
16 // by using the Macro __WINS__ |
|
17 // |
|
18 // |
|
19 |
|
20 // System includes |
|
21 #include <e32std.h> |
|
22 #include <e32def.h> |
|
23 |
|
24 #include <e32test.h> |
|
25 #include <f32file.h> |
|
26 |
|
27 // User includes |
|
28 #include <bautils.h> |
|
29 #include "HLPMODEL.H" |
|
30 #include <coreappstest/testserver.h> |
|
31 |
|
32 |
|
33 #include "SearchOrderTest.h" |
|
34 |
|
35 |
|
36 // These defines and the Local method DrivesOfMediaTypeL should be moved to the |
|
37 // Agenda Test Library (agntestlibrary) |
|
38 _LIT(KMediaNotPresent, "MediaNotPresent"); |
|
39 _LIT(KMediaUnknown, "MediaUnknown"); |
|
40 _LIT(KMediaFloppy, "MediaFloppy"); |
|
41 _LIT(KMediaHardDisk, "MediaHardDisk"); |
|
42 _LIT(KMediaCdRom, "MediaCdRom"); |
|
43 _LIT(KMediaRam, "MediaRam"); |
|
44 _LIT(KMediaFlash, "MediaFlash"); |
|
45 _LIT(KMediaRom, "MediaRom"); |
|
46 _LIT(KMediaRemote, "MediaRemote"); |
|
47 _LIT(KMediaNANDFlash, "MediaNANDFlash"); |
|
48 TPtrC MediaTypes[] = |
|
49 { KMediaNotPresent(),KMediaUnknown(),KMediaFloppy(),KMediaHardDisk(),KMediaCdRom(), |
|
50 KMediaRam(),KMediaFlash(),KMediaRom(),KMediaRemote(),KMediaNANDFlash()}; |
|
51 |
|
52 CSearchOrderTest::CSearchOrderTest(RTest& aTest):iTest(aTest) |
|
53 {} |
|
54 |
|
55 |
|
56 CSearchOrderTest::~CSearchOrderTest() |
|
57 { |
|
58 iFsSession.Close(); |
|
59 } |
|
60 |
|
61 CSearchOrderTest* CSearchOrderTest::NewL( RTest& aTest) |
|
62 { |
|
63 CSearchOrderTest* self = new (ELeave) CSearchOrderTest(aTest); |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 CArrayFix<TInt>* CSearchOrderTest::DrivesOfMediaTypeL( TMediaType aMedia, RFs& aFs, TBool aStopAtFirst ) |
|
71 { |
|
72 TDriveInfo info; |
|
73 TInt error = KErrNone; |
|
74 TDriveList driveList; |
|
75 CArrayFix<TInt>* array = new (ELeave) CArrayFixFlat<TInt>(10); |
|
76 CleanupStack::PushL( array ); |
|
77 User::LeaveIfError(aFs.DriveList(driveList)); |
|
78 for(TInt drive=EDriveA;drive<=EDriveZ;drive++) |
|
79 { |
|
80 if( driveList[drive] ) |
|
81 { |
|
82 error = aFs.Drive(info, drive); |
|
83 if (error != KErrNone) |
|
84 { |
|
85 continue; |
|
86 } |
|
87 if ( info.iType == aMedia ) |
|
88 { |
|
89 array->AppendL( drive ); |
|
90 if( aStopAtFirst ) |
|
91 { // return if only the first drive of the required type. |
|
92 break; |
|
93 } |
|
94 } |
|
95 } |
|
96 } |
|
97 CleanupStack::Pop( array ); |
|
98 return array; |
|
99 } |
|
100 |
|
101 /** |
|
102 MMCDriveL |
|
103 |
|
104 Determines a list of drives of type EMediaHardDisk. |
|
105 The first drive in this list is returned and used |
|
106 by the rest of the test. |
|
107 */ |
|
108 TDriveUnit CSearchOrderTest::MMCDriveL() |
|
109 { |
|
110 CArrayFix<TInt>* drives = DrivesOfMediaTypeL(EMediaHardDisk,iFsSession,EFalse); |
|
111 CleanupStack::PushL(drives); |
|
112 TInt drivesTInt = drives->Count(); |
|
113 if( drivesTInt ) |
|
114 { |
|
115 iTest.Printf(_L("Found the following drives of type %S\n"),&MediaTypes[EMediaHardDisk]); |
|
116 for(TInt i=0;i<drivesTInt;i++) |
|
117 { |
|
118 TDriveUnit drv(drives->At(i)); |
|
119 TPtrC drvPtr(drv.Name()); |
|
120 iTest.Printf(_L("%S\n"),&drvPtr); |
|
121 } |
|
122 } |
|
123 else |
|
124 { |
|
125 iTest.Printf( _L("No drives found of type %S\n"),&MediaTypes[EMediaHardDisk]); |
|
126 User::LeaveIfError(KErrHardwareNotAvailable); |
|
127 } |
|
128 TDriveUnit mmcDrive(drives->At(0)); |
|
129 CleanupStack::PopAndDestroy(drives); |
|
130 // Use the first drive in the list for the rest of the test. |
|
131 return mmcDrive; |
|
132 } |
|
133 |
|
134 void CSearchOrderTest::ConstructL() |
|
135 { |
|
136 User::LeaveIfError(iFsSession.Connect()); |
|
137 iMMCDrive = MMCDriveL().Name(); |
|
138 iTest.Printf(_L("%S Chosen for the test.\n"), &iMMCDrive); |
|
139 iHelpPathFileMMC.Copy(iMMCDrive); |
|
140 iHelpPathFileMMC.Append(KHelpPathFileMMC); |
|
141 } |
|
142 |
|
143 |
|
144 /** |
|
145 MoveHelpFileL |
|
146 Deletes and Moves the help files from the anticipated destination drive, |
|
147 dependent upon the Operation defined. |
|
148 */ |
|
149 void CSearchOrderTest::MoveHelpFileL( TInt aOperation ) |
|
150 { |
|
151 switch( aOperation ) |
|
152 { |
|
153 case EInitial_DeleteAll: |
|
154 iTest.Printf(_L("Removing file PlatSecSearchTest.hlp from drives\n")); |
|
155 DeleteAllHelpFilesL(); |
|
156 break; |
|
157 /* Commented out because not supported on the hardware. |
|
158 case EMoveToA: |
|
159 iTest.Printf(_L("Copying SearchTest.hlp to drives A:")); |
|
160 CopyHlpFile( KHelpPathFileAOnZ, KHelpPathFileA ); |
|
161 break; |
|
162 */ |
|
163 case EMoveToC: |
|
164 iTest.Printf(_L("Copying PlatSecSearchTest.hlp to drives C:\n")); |
|
165 CopyHlpFileL( KHelpPathFileCOnZ, KHelpPathFileC ); |
|
166 break; |
|
167 |
|
168 case EMoveToMMC: |
|
169 iTest.Printf(_L("Copying PlatSecSearchTest.hlp to MMC drive\n")); |
|
170 CopyHlpFileL( KHelpPathFileFOnZ, iHelpPathFileMMC ); |
|
171 break; |
|
172 |
|
173 case EFinal_DeleteAll: |
|
174 iTest.Printf(_L("Removing file PlatSecSearchTest.hlp from drives\n")); |
|
175 DeleteAllHelpFilesL(); |
|
176 break; |
|
177 |
|
178 default: |
|
179 // Error condition so leave |
|
180 User::Leave(KErrNotFound); |
|
181 } |
|
182 |
|
183 return; |
|
184 } |
|
185 |
|
186 /** |
|
187 DeleteAllHelpFiles |
|
188 Removes help files from A, C & MMC, Z help file will be exported in the |
|
189 build process. |
|
190 */ |
|
191 void CSearchOrderTest::DeleteAllHelpFilesL() |
|
192 { |
|
193 // The help file for Z should be exported in the build process. |
|
194 |
|
195 RPIMTestServer serv; |
|
196 User::LeaveIfError(serv.Connect()); |
|
197 // TRAPD( err, serv.DeleteFileL( KHelpPathFileA )); |
|
198 TRAPD( err, serv.DeleteFileL( KHelpPathFileC )); |
|
199 TRAP( err, serv.DeleteFileL( iHelpPathFileMMC )); |
|
200 serv.Close(); |
|
201 } |
|
202 |
|
203 void CSearchOrderTest::CopyHlpFileL(const TDesC& aFileName, const TDesC& aToFileName) |
|
204 { |
|
205 RPIMTestServer serv; |
|
206 User::LeaveIfError(serv.Connect()); |
|
207 serv.CopyFileL(aFileName, aToFileName); |
|
208 serv.Close(); |
|
209 } |
|
210 |
|
211 TBool CSearchOrderTest::CheckCategoryListL(TInt aOperation, CDesCArray* aCatList ) const |
|
212 { |
|
213 TInt mxCount = aCatList->Count(); |
|
214 iTest.Printf(_L("Category List: \n")); |
|
215 for(TInt index=0;index<mxCount;index++) |
|
216 { |
|
217 TPtrC cat(aCatList->MdcaPoint(index)); |
|
218 iTest.Printf(_L("%S\n"),&cat); |
|
219 } |
|
220 |
|
221 TInt pntr = 0; |
|
222 switch(aOperation) |
|
223 { |
|
224 case EInitial_DeleteAll: |
|
225 |
|
226 iTest.Next(_L("Looking for category 'Drive Z:' in search order.\n")); |
|
227 // Check that we Find Drive Z: last in search order. |
|
228 return ((aCatList->Find( KDriveZ, pntr ) == 0) && |
|
229 !(aCatList->Find( KDriveC, pntr ) == 0) && |
|
230 !(aCatList->Find( KDriveF, pntr ) == 0)); |
|
231 /* Commented out because not supported on the hardware. |
|
232 case EMoveToA: |
|
233 |
|
234 iTest.Next(_L("Looking for Drive A: in search order.\n")); |
|
235 // Check that we Find Drive A: last in search order. |
|
236 return (aCatList->Find( KDriveA, pntr ) == 0); |
|
237 */ |
|
238 case EMoveToC: |
|
239 |
|
240 iTest.Next(_L("Looking for category 'Drive C:' in search order.\n")); |
|
241 // Check that we Find Drive C: last in search order. |
|
242 return ((aCatList->Find( KDriveC, pntr ) == 0) && |
|
243 !(aCatList->Find( KDriveZ, pntr ) == 0) && |
|
244 !(aCatList->Find( KDriveF, pntr ) == 0)); |
|
245 |
|
246 case EMoveToMMC: |
|
247 |
|
248 iTest.Next(_L("Looking for category 'Drive F:' in search order.\n")); |
|
249 // Check that we Find Drive F: last in search order. |
|
250 return ((aCatList->Find( KDriveF, pntr ) == 0) && |
|
251 !(aCatList->Find( KDriveC, pntr ) == 0) && |
|
252 !(aCatList->Find( KDriveZ, pntr ) == 0)); |
|
253 |
|
254 case EFinal_DeleteAll: |
|
255 |
|
256 iTest.Next(_L("Looking for category 'Drive Z:' in search order.\n")); |
|
257 // Check that we Find Drive Z: last in search order. |
|
258 return ((aCatList->Find( KDriveZ, pntr ) == 0) && |
|
259 !(aCatList->Find( KDriveC, pntr ) == 0) && |
|
260 !(aCatList->Find( KDriveF, pntr ) == 0)); |
|
261 |
|
262 default: |
|
263 // Error condition so leave |
|
264 User::Leave(KErrNotFound); |
|
265 } |
|
266 |
|
267 return EFalse; |
|
268 } |
|
269 |