2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "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 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
// Include Files
|
|
18 |
#include "stf.h"
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <e32std.h>
|
|
21 |
#include <e32cons.h> // Console
|
|
22 |
#include "executor.h"
|
|
23 |
#include "cmdparser.h"
|
|
24 |
#include "helper.h"
|
|
25 |
|
|
26 |
_LIT(KTextFailed, " failed, leave code = %d");
|
|
27 |
_LIT(KTextPressAnyKey, " [press any key to exit.]\n");
|
|
28 |
|
|
29 |
LOCAL_D CConsoleBase* console;
|
|
30 |
LOCAL_D TBool isPrompt = ETrue;
|
|
31 |
|
|
32 |
|
|
33 |
LOCAL_C TInt Execute()
|
|
34 |
{
|
|
35 |
|
|
36 |
//parse the command line
|
|
37 |
CCmdParser* parser = NULL;
|
|
38 |
TRAPD(err, parser = CCmdParser::NewL());
|
|
39 |
if (err != KErrNone)
|
|
40 |
{
|
|
41 |
#ifdef _DEBUG
|
|
42 |
RDebug::Print(_L("Command parser construction failed %d: "), err);
|
|
43 |
#endif
|
|
44 |
return err;
|
|
45 |
}
|
|
46 |
|
|
47 |
const TInt length = User().CommandLineLength();
|
|
48 |
HBufC* cmdLine = NULL;
|
|
49 |
TRAPD(err1 , cmdLine = HBufC::NewL(length));
|
|
50 |
if (err1 != KErrNone)
|
|
51 |
{
|
|
52 |
#ifdef _DEBUG
|
|
53 |
RDebug::Print(_L("Command line buffer construction failed %d: "), err1);
|
|
54 |
#endif
|
|
55 |
delete parser;
|
|
56 |
return err1;
|
|
57 |
}
|
|
58 |
|
|
59 |
TPtr ptr = cmdLine->Des();
|
|
60 |
User().CommandLine(ptr);
|
|
61 |
ptr.TrimAll();
|
|
62 |
TBool rst = parser->Parse(ptr);
|
|
63 |
delete cmdLine;
|
|
64 |
//end parse the command line.
|
|
65 |
|
|
66 |
isPrompt = parser->IsPrompt();
|
|
67 |
if (parser->IsHelp() || parser->IsVersion())
|
|
68 |
{
|
|
69 |
//only show help or version info.
|
|
70 |
isPrompt = ETrue;
|
|
71 |
CHelper* helper = NULL;
|
|
72 |
TRAPD( err, helper = CHelper::NewL(console));
|
|
73 |
if (err != KErrNone)
|
|
74 |
{
|
|
75 |
#ifdef _DEBUG
|
|
76 |
RDebug::Print(_L("helper construction failed %d: "), err);
|
|
77 |
#endif
|
|
78 |
delete parser;
|
|
79 |
return err;
|
|
80 |
}
|
|
81 |
if(parser->IsHelp())
|
|
82 |
{
|
|
83 |
helper->ShowHelp();
|
|
84 |
}
|
|
85 |
else
|
|
86 |
{
|
|
87 |
helper->ShowVersion();
|
|
88 |
}
|
|
89 |
delete helper;
|
|
90 |
}
|
|
91 |
else
|
|
92 |
{
|
|
93 |
if (!rst)
|
|
94 |
{
|
|
95 |
#ifdef _DEBUG
|
|
96 |
RDebug::Print(_L("arguments error."));
|
|
97 |
#endif
|
|
98 |
delete parser;
|
|
99 |
return KErrArgument;
|
|
100 |
}
|
|
101 |
|
|
102 |
// Construct the test client
|
|
103 |
CExecutor* executor = NULL;
|
|
104 |
TRAPD( err, executor = CExecutor::NewL(parser,console) );
|
|
105 |
if (err != KErrNone)
|
|
106 |
{
|
|
107 |
#ifdef _DEBUG
|
|
108 |
RDebug::Print(_L("STF executor construction failed %d: \n"), err);
|
|
109 |
#endif
|
|
110 |
delete parser;
|
|
111 |
return err;
|
|
112 |
}
|
|
113 |
|
|
114 |
// Run tests
|
|
115 |
TRAP( err, executor->RunTestsL() );
|
|
116 |
if (err != KErrNone)
|
|
117 |
{
|
|
118 |
console->Printf(_L("STF execution failed with: %d \n"),err);
|
|
119 |
|
|
120 |
#ifdef _DEBUG
|
|
121 |
RDebug::Print(_L("RunTestsL left with %d: "), err);
|
|
122 |
#endif
|
|
123 |
}
|
|
124 |
|
|
125 |
// Deallocate resources
|
|
126 |
delete executor;
|
|
127 |
}
|
|
128 |
|
|
129 |
delete parser;
|
|
130 |
return KErrNone;
|
|
131 |
}
|
|
132 |
|
|
133 |
LOCAL_C void DoStartL()
|
|
134 |
{
|
|
135 |
// Create active scheduler (to run active objects)
|
|
136 |
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
|
|
137 |
CleanupStack::PushL(scheduler);
|
|
138 |
CActiveScheduler::Install(scheduler);
|
|
139 |
TInt err = Execute();
|
|
140 |
if(err != KErrNone)
|
|
141 |
{
|
|
142 |
console->Printf(_L("STF Get Error: %d."), err);
|
|
143 |
if(err == KErrArgument)
|
|
144 |
{
|
|
145 |
console->Printf(_L("Arguments error.\n"));
|
|
146 |
}
|
|
147 |
else if(err == KErrNoMemory)
|
|
148 |
{
|
|
149 |
console->Printf(_L("No enough memory.\n"));
|
|
150 |
}
|
|
151 |
else if(err == KErrNotFound)
|
|
152 |
{
|
|
153 |
console->Printf(_L("Required resouce not found.\n"));
|
|
154 |
}
|
|
155 |
else if(err == KErrNotSupported)
|
|
156 |
{
|
|
157 |
console->Printf(_L("Operation not supported in this version.\n"));
|
|
158 |
}
|
|
159 |
else
|
|
160 |
{
|
|
161 |
console->Printf(_L("Other unknow error.\n"));
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
// Delete active scheduler
|
|
167 |
CleanupStack::PopAndDestroy(scheduler);
|
|
168 |
}
|
|
169 |
|
|
170 |
// Global Variables
|
|
171 |
GLDEF_C TInt E32Main()
|
|
172 |
{
|
|
173 |
|
|
174 |
TInt processHandleCountBefore;
|
|
175 |
TInt threadHandleCountBefore;
|
|
176 |
RThread().HandleCount(processHandleCountBefore, threadHandleCountBefore);
|
|
177 |
TInt reqsBefore = RThread().RequestCount();
|
|
178 |
|
|
179 |
TInt processHandleCountAfter;
|
|
180 |
TInt threadHandleCountAfter;
|
|
181 |
TInt reqsAfter;
|
|
182 |
|
|
183 |
__UHEAP_MARK;
|
|
184 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
185 |
TRAPD(createError, console = Console::NewL(_L("STF"), TSize(
|
|
186 |
KConsFullScreen, KConsFullScreen)));
|
|
187 |
if(createError)
|
|
188 |
{
|
|
189 |
return createError;
|
|
190 |
}
|
|
191 |
|
|
192 |
TRAPD(mainError, DoStartL());
|
|
193 |
if(mainError)
|
|
194 |
{
|
|
195 |
console->Printf(KTextFailed, mainError);
|
|
196 |
}
|
|
197 |
if(isPrompt)
|
|
198 |
{
|
|
199 |
console->Printf(KTextPressAnyKey);
|
|
200 |
console->Getch();
|
|
201 |
}
|
|
202 |
reqsAfter = RThread().RequestCount();
|
|
203 |
RThread().HandleCount(processHandleCountAfter, threadHandleCountAfter);
|
|
204 |
|
|
205 |
if (reqsAfter != reqsBefore)
|
|
206 |
{
|
|
207 |
#ifdef _DEBUG
|
|
208 |
RDebug::Print(_L("Request count not matching! %d vs. %d: "),
|
|
209 |
reqsBefore, reqsAfter);
|
|
210 |
#endif
|
|
211 |
}
|
|
212 |
if (threadHandleCountAfter != threadHandleCountBefore)
|
|
213 |
{
|
|
214 |
#ifdef _DEBUG
|
|
215 |
RDebug::Print(_L("Handle count not matching! %d vs. %d: "),
|
|
216 |
threadHandleCountBefore, threadHandleCountAfter);
|
|
217 |
#endif
|
|
218 |
}
|
|
219 |
delete console;
|
|
220 |
delete cleanup;
|
|
221 |
__UHEAP_MARKEND;
|
|
222 |
return KErrNone;
|
|
223 |
}
|