|
1 /* |
|
2 * Copyright (c) 2010 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: Main program for the Unit test process |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <memory> |
|
19 #include <unistd.h> |
|
20 |
|
21 #include "logger.h" |
|
22 #include "exceptionbase.h" |
|
23 #include "runtimeexception.h" |
|
24 #include "javacommonutils.h" |
|
25 #include "runtimestarterutils.h" |
|
26 #include "jvmstarter.h" |
|
27 |
|
28 using namespace java::runtime; |
|
29 using namespace java::util; |
|
30 |
|
31 int startJvm(int argc, char *argv[]); |
|
32 const wchar_t* const UNIT_TEST_RUNNER_MAIN_CLASS = L"com.nokia.mj.impl.rt.test.UnitTestRunner"; |
|
33 void findMidlet(); |
|
34 |
|
35 int main(int argc, char *argv[]) |
|
36 { |
|
37 LOG(EJavaRuntime, EInfo, "UNIT TEST RUNNER main()"); |
|
38 |
|
39 int result = -1; |
|
40 try |
|
41 { |
|
42 result = startJvm(argc, argv); |
|
43 } |
|
44 catch (RuntimeException& e) |
|
45 { |
|
46 ELOG1(EJavaRuntime, "UNIT TEST RUNNER main() RuntimeException caught: %s ", |
|
47 e.toString().c_str()); |
|
48 } |
|
49 |
|
50 catch (ExceptionBase& e) |
|
51 { |
|
52 ELOG1(EJavaRuntime, "UNIT TEST RUNNER main() ExceptionBase caught: %s ", |
|
53 e.toString().c_str()); |
|
54 } |
|
55 |
|
56 catch (std::exception& e) |
|
57 { |
|
58 ELOG1(EJavaRuntime, "UNIT TEST RUNNER main() Exception %s caught", e.what()); |
|
59 } |
|
60 |
|
61 LOG1(EJavaRuntime, EInfo, "UNIT TEST RUNNER EXIT = %d", result); |
|
62 return result; |
|
63 } |
|
64 |
|
65 int startJvm(int argc, char *argv[]) |
|
66 { |
|
67 JELOG2(EJavaRuntime); |
|
68 |
|
69 // Create instance of RuntimeStarterUtils for thread supervisioning. |
|
70 std::auto_ptr<RuntimeStarterUtils> starterUtils(new RuntimeStarterUtils()); |
|
71 starterUtils->startThreadSupervisor(); |
|
72 |
|
73 JvmStarter::Configuration config = JvmStarter::CLDC; |
|
74 int argInd = 1; |
|
75 if (argc > 2) |
|
76 { |
|
77 if (strncmp(argv[1], "-conf", 5) == 0) |
|
78 { |
|
79 argInd = 2; |
|
80 if (strcmp(argv[1]+5, "=cdc") == 0) |
|
81 { |
|
82 config = JvmStarter::CDC; |
|
83 } |
|
84 else if (strcmp(argv[1]+5, "=foundation") == 0) |
|
85 { |
|
86 config = JvmStarter::FOUNDATION; |
|
87 } |
|
88 } |
|
89 } |
|
90 // Create starter for starting the JVM |
|
91 std::auto_ptr<JvmStarter> |
|
92 jvm(JvmStarter::getJvmStarterInstance(config, |
|
93 L"Unit_test_runner")); |
|
94 |
|
95 // starterUtils->enableDevelopmentFeatures(*jvm.get()); |
|
96 jvm->enableThreadDumping(); |
|
97 |
|
98 jvm->appendSystemProperty(L"-Dcom.nokia.rt.port=unittestrunner"); |
|
99 |
|
100 jvm->setMainClass(UNIT_TEST_RUNNER_MAIN_CLASS); |
|
101 |
|
102 for (; argInd < argc; ++argInd) |
|
103 { |
|
104 jvm->appendApplicationArgument( |
|
105 JavaCommonUtils::utf8ToWstring(argv[argInd])); |
|
106 } |
|
107 |
|
108 // Start the JVM. |
|
109 return jvm->startJvm(); |
|
110 } |