|
1 // ciftest.cpp |
|
2 // |
|
3 // Copyright (c) 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include "ciftest.h" |
|
14 #include "fshell.h" |
|
15 #include "command_factory.h" |
|
16 |
|
17 CCommandBase* CCmdCifTest::NewLC() |
|
18 { |
|
19 CCmdCifTest* self = new(ELeave) CCmdCifTest(); |
|
20 CleanupStack::PushL(self); |
|
21 self->BaseConstructL(); |
|
22 return self; |
|
23 } |
|
24 |
|
25 CCmdCifTest::~CCmdCifTest() |
|
26 { |
|
27 delete iCmd; |
|
28 delete iParser; |
|
29 delete iEnvForScript; |
|
30 delete iCurrentCif; |
|
31 iCifFiles.ResetAndDestroy(); |
|
32 } |
|
33 |
|
34 CCmdCifTest::CCmdCifTest() |
|
35 : CCommandBase(EManualComplete | EReportAllErrors) |
|
36 { |
|
37 } |
|
38 |
|
39 const TDesC& CCmdCifTest::Name() const |
|
40 { |
|
41 _LIT(KName, "ciftest"); |
|
42 return KName; |
|
43 } |
|
44 |
|
45 void CCmdCifTest::ArgumentsL(RCommandArgumentList& aArguments) |
|
46 { |
|
47 aArguments.AppendStringL(iCmd, _L("command")); |
|
48 } |
|
49 |
|
50 void CCmdCifTest::OptionsL(RCommandOptionList& aOptions) |
|
51 { |
|
52 aOptions.AppendBoolL(iVerbose, _L("verbose")); |
|
53 aOptions.AppendBoolL(iKeepGoing, _L("keep-going")); |
|
54 } |
|
55 |
|
56 void CCmdCifTest::DoRunL() |
|
57 { |
|
58 if (iCmd) |
|
59 { |
|
60 CCommandInfoFile* cif = CCommandInfoFile::NewL(FsL(), Env(), *iCmd); |
|
61 TestCifL(cif); // Takes ownership |
|
62 } |
|
63 else |
|
64 { |
|
65 _LIT(KCifDir, "y:\\resource\\cif\\fshell\\"); |
|
66 TFindFile find(FsL()); |
|
67 CDir* dir = NULL; |
|
68 TInt found = find.FindWildByDir(_L("*.cif"), KCifDir, dir); |
|
69 while (found == KErrNone) |
|
70 { |
|
71 for (TInt i = 0; i < dir->Count(); i++) |
|
72 { |
|
73 iFileName.Copy(TParsePtrC(find.File()).DriveAndPath()); // The docs for TFindFile state you shouldn't need the extra TParsePtrC::DriveAndPath(). Sigh. |
|
74 iFileName.Append((*dir)[i].iName); |
|
75 iCifFiles.AppendL(iFileName.AllocLC()); |
|
76 CleanupStack::Pop(); |
|
77 } |
|
78 delete dir; |
|
79 dir = NULL; |
|
80 found = find.FindWild(dir); |
|
81 } |
|
82 NextCif(); |
|
83 } |
|
84 } |
|
85 |
|
86 void CCmdCifTest::NextCif() |
|
87 { |
|
88 if (iNextCif == iCifFiles.Count()) |
|
89 { |
|
90 if (iVerbose) |
|
91 { |
|
92 Printf(_L("%d tests run, %d passes %d failures. %d commands have no tests defined.\r\n"), iPasses + iFailures, iPasses, iFailures, iCifFiles.Count() - iPasses - iFailures); |
|
93 } |
|
94 Complete(KErrNone); |
|
95 } |
|
96 else |
|
97 { |
|
98 CCommandInfoFile* cif = NULL; |
|
99 TRAPD(err, cif = CCommandInfoFile::NewL(FsL(), *iCifFiles[iNextCif])); |
|
100 if (!err) |
|
101 { |
|
102 TRAP(err, TestCifL(cif)); |
|
103 if (err) PrintError(err, _L("Error setting up test for CIF %S"), iCifFiles[iNextCif]); |
|
104 } |
|
105 iNextCif++; |
|
106 |
|
107 if (err) |
|
108 { |
|
109 iFailures++; |
|
110 TestCompleted(err); |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 void CCmdCifTest::TestCifL(CCommandInfoFile* aCif) |
|
116 { |
|
117 iCurrentCif = aCif; |
|
118 if (iVerbose) Printf(_L("Checking %S\r\n"), &aCif->CifFileName()); |
|
119 |
|
120 const TDesC& scriptData = aCif->SmokeTest(); |
|
121 if (scriptData.Length() == 0) |
|
122 { |
|
123 if (iVerbose) Printf(_L("Cif has no smoketest section\r\n")); |
|
124 TestCompleted(KErrNone); |
|
125 return; |
|
126 } |
|
127 |
|
128 iEnvForScript = CEnvironment::NewL(Env()); |
|
129 iEnvForScript->SetL(_L("Error"), _L("fshell -e 'echo \"Test failed, env is:\" && env && error'")); |
|
130 iEnvForScript->SetL(_L("Quiet"), _L(">/dev/null")); |
|
131 iEnvForScript->SetL(_L("Silent"), _L("2>&1 >/dev/null")); |
|
132 iEnvForScript->Remove(_L("Verbose")); // In case it's ended up in our parent env |
|
133 if (iVerbose) iEnvForScript->SetL(_L("Verbose"), 1); |
|
134 iFileName.Copy(aCif->CifFileName()); |
|
135 iFileName.Append(_L(":smoke-test")); |
|
136 TParsePtrC parse(iFileName); |
|
137 iEnvForScript->SetL(KScriptName, parse.NameAndExt()); |
|
138 iEnvForScript->SetL(KScriptPath, parse.DriveAndPath()); |
|
139 iEnvForScript->SetL(_L("0"), iFileName); |
|
140 |
|
141 iParser = CParser::NewL(CParser::EExportLineNumbers, scriptData, IoSession(), Stdin(), Stdout(), Stderr(), *iEnvForScript, gShell->CommandFactory(), this, aCif->GetSmokeTestStartingLineNumber()); |
|
142 iParser->Start(); |
|
143 } |
|
144 |
|
145 void CCmdCifTest::HandleParserComplete(CParser& /*aParser*/, const TError& aError) |
|
146 { |
|
147 TInt err = aError.Error(); |
|
148 if (err) |
|
149 { |
|
150 iFailures++; |
|
151 PrintError(err, _L("%S failed at line %d"), &aError.ScriptFileName(), aError.ScriptLineNumber()); |
|
152 } |
|
153 else |
|
154 { |
|
155 if (iVerbose) |
|
156 { |
|
157 Printf(_L("Smoketest for %S completed ok.\r\n"), &iCurrentCif->Name()); |
|
158 } |
|
159 iPasses++; |
|
160 } |
|
161 TestCompleted(err); |
|
162 } |
|
163 |
|
164 void CCmdCifTest::TestCompleted(TInt aError) |
|
165 { |
|
166 // Delete interim data |
|
167 delete iEnvForScript; |
|
168 iEnvForScript = NULL; |
|
169 delete iParser; |
|
170 iParser = NULL; |
|
171 delete iCurrentCif; |
|
172 iCurrentCif = NULL; |
|
173 |
|
174 if (aError == KErrNone || iKeepGoing) |
|
175 { |
|
176 // Async call NextCif() |
|
177 TRequestStatus* stat = &iStatus; |
|
178 User::RequestComplete(stat, KErrNone); |
|
179 SetActive(); |
|
180 } |
|
181 else |
|
182 { |
|
183 Complete(aError); |
|
184 } |
|
185 } |
|
186 |
|
187 void CCmdCifTest::RunL() |
|
188 { |
|
189 NextCif(); |
|
190 } |