|
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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <f32file.h> |
|
18 |
|
19 #include <msvapi.h> |
|
20 |
|
21 _LIT(KMsvServerPattern, "!MsvServer*"); |
|
22 RTest test(_L("AutoRun")); |
|
23 |
|
24 // |
|
25 |
|
26 |
|
27 LOCAL_C void WaitForServerClose() |
|
28 { |
|
29 // Wait 10 seconds for server to exit |
|
30 TInt count = 10; |
|
31 while(count--) |
|
32 { |
|
33 TFullName name; |
|
34 TFindProcess find(KMsvServerPattern); |
|
35 if (find.Next(name) != KErrNone) |
|
36 return; |
|
37 else if (count <= 0) |
|
38 { |
|
39 RProcess process; |
|
40 process.Open(find); |
|
41 process.Terminate(KErrGeneral); |
|
42 process.Close(); |
|
43 } |
|
44 User::After(1000000); |
|
45 } |
|
46 } |
|
47 |
|
48 LOCAL_C void LaunchAndWaitL(const TDesC& file) |
|
49 { |
|
50 RProcess p; |
|
51 test(p.Create(file, KNullDesC) == KErrNone); |
|
52 |
|
53 TRequestStatus status = KRequestPending; |
|
54 p.Logon(status); |
|
55 p.Resume(); |
|
56 User::WaitForRequest(status); |
|
57 p.Close(); |
|
58 |
|
59 WaitForServerClose(); |
|
60 } |
|
61 |
|
62 LOCAL_C void ScanDirL(RFs& aFs, const TDesC& aDir) |
|
63 { |
|
64 User::After(1000000); |
|
65 |
|
66 TParse parse; |
|
67 parse.Set(_L("t_*.exe"), &aDir, NULL); |
|
68 TPtrC spec(parse.FullName()); |
|
69 |
|
70 test.Start(parse.DriveAndPath()); |
|
71 TFindFile find(aFs); |
|
72 CDir* dir; |
|
73 |
|
74 if (!find.FindWildByPath(parse.FullName(), NULL, dir)) |
|
75 { |
|
76 CleanupStack::PushL(dir); |
|
77 |
|
78 for(int i = 0; i < dir->Count(); i++) |
|
79 { |
|
80 parse.Set((*dir)[i].iName, &spec, NULL); |
|
81 |
|
82 if (i == 0) |
|
83 test.Start(parse.FullName()); |
|
84 else |
|
85 test.Next(parse.FullName()); |
|
86 |
|
87 LaunchAndWaitL(parse.FullName()); |
|
88 } |
|
89 |
|
90 CleanupStack::PopAndDestroy(); // dir |
|
91 } |
|
92 test.End(); |
|
93 } |
|
94 |
|
95 LOCAL_C void ScanStartL(RFs aFs, const TDesC& aPath) |
|
96 { |
|
97 // Scan the top-level directory for test executables |
|
98 ScanDirL(aFs, aPath); |
|
99 |
|
100 // Setup directory scan |
|
101 CDirScan* scan = CDirScan::NewLC(aFs); |
|
102 scan->SetScanDataL(aPath, KEntryAttDir|KEntryAttMatchExclusive, ESortNone, CDirScan::EScanUpTree); |
|
103 |
|
104 // Iterate through all the directories |
|
105 FOREVER |
|
106 { |
|
107 // Get next directory list |
|
108 CDir* dir = NULL; |
|
109 TRAPD(error, scan->NextL(dir)); |
|
110 if (error || !dir) |
|
111 break; |
|
112 |
|
113 delete dir; |
|
114 ScanDirL(aFs, scan->FullPath()); |
|
115 }; |
|
116 CleanupStack::PopAndDestroy(); // scan |
|
117 } |
|
118 |
|
119 LOCAL_C void doMainL() |
|
120 { |
|
121 CActiveScheduler::Install(new(ELeave)CActiveScheduler); |
|
122 |
|
123 RFs fs; |
|
124 User::LeaveIfError(fs.Connect()); |
|
125 CleanupClosePushL(fs); |
|
126 |
|
127 ScanStartL(fs, RProcess().FileName()); |
|
128 CleanupStack::PopAndDestroy(); // fs |
|
129 |
|
130 delete CActiveScheduler::Current(); |
|
131 } |
|
132 |
|
133 |
|
134 GLDEF_C TInt E32Main() |
|
135 { |
|
136 __UHEAP_MARK; |
|
137 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
138 __ASSERT_ALWAYS(cleanup, User::Invariant()); |
|
139 TRAPD(ret,doMainL()); |
|
140 test(ret == KErrNone); |
|
141 test.Close(); |
|
142 delete cleanup; |
|
143 __UHEAP_MARKEND; |
|
144 return(KErrNone); |
|
145 } |
|
146 |
|
147 |
|
148 |