OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This class sets up the environment for running the native tests inside an | 5 // This class sets up the environment for running the native tests inside an |
6 // android application. It outputs (to logcat) markers identifying the | 6 // android application. It outputs (to logcat) markers identifying the |
7 // START/END/CRASH of the test suite, FAILURE/SUCCESS of individual tests etc. | 7 // START/END/CRASH of the test suite, FAILURE/SUCCESS of individual tests etc. |
8 // These markers are read by the test runner script to generate test results. | 8 // These markers are read by the test runner script to generate test results. |
9 // It injects an event listener in gtest to detect various test stages and | 9 // It injects an event listener in gtest to detect various test stages and |
10 // installs signal handlers to detect crashes. | 10 // installs signal handlers to detect crashes. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ::testing::TestEventListeners& listeners = | 127 ::testing::TestEventListeners& listeners = |
128 ::testing::UnitTest::GetInstance()->listeners(); | 128 ::testing::UnitTest::GetInstance()->listeners(); |
129 // Adds a listener to the end. Google Test takes the ownership. | 129 // Adds a listener to the end. Google Test takes the ownership. |
130 listeners.Append(this); | 130 listeners.Append(this); |
131 } | 131 } |
132 | 132 |
133 void AndroidLogPrinter::OnTestProgramStart( | 133 void AndroidLogPrinter::OnTestProgramStart( |
134 const ::testing::UnitTest& unit_test) { | 134 const ::testing::UnitTest& unit_test) { |
135 std::string msg = StringPrintf("[ START ] %d", | 135 std::string msg = StringPrintf("[ START ] %d", |
136 unit_test.test_to_run_count()); | 136 unit_test.test_to_run_count()); |
137 log_write(ANDROID_LOG_VERBOSE, msg.c_str()); | 137 log_write(ANDROID_LOG_ERROR, msg.c_str()); |
138 } | 138 } |
139 | 139 |
140 void AndroidLogPrinter::OnTestStart(const ::testing::TestInfo& test_info) { | 140 void AndroidLogPrinter::OnTestStart(const ::testing::TestInfo& test_info) { |
141 std::string msg = StringPrintf("[ RUN ] %s.%s", | 141 std::string msg = StringPrintf("[ RUN ] %s.%s", |
142 test_info.test_case_name(), test_info.name()); | 142 test_info.test_case_name(), test_info.name()); |
143 log_write(ANDROID_LOG_VERBOSE, msg.c_str()); | 143 log_write(ANDROID_LOG_ERROR, msg.c_str()); |
144 } | 144 } |
145 | 145 |
146 void AndroidLogPrinter::OnTestPartResult( | 146 void AndroidLogPrinter::OnTestPartResult( |
147 const ::testing::TestPartResult& test_part_result) { | 147 const ::testing::TestPartResult& test_part_result) { |
148 std::string msg = StringPrintf( | 148 std::string msg = StringPrintf( |
149 "%s in %s:%d\n%s\n", | 149 "%s in %s:%d\n%s\n", |
150 test_part_result.failed() ? "*** Failure" : "Success", | 150 test_part_result.failed() ? "*** Failure" : "Success", |
151 test_part_result.file_name(), | 151 test_part_result.file_name(), |
152 test_part_result.line_number(), | 152 test_part_result.line_number(), |
153 test_part_result.summary()); | 153 test_part_result.summary()); |
154 log_write(ANDROID_LOG_VERBOSE, msg.c_str()); | 154 log_write(ANDROID_LOG_ERROR, msg.c_str()); |
155 } | 155 } |
156 | 156 |
157 void AndroidLogPrinter::OnTestEnd(const ::testing::TestInfo& test_info) { | 157 void AndroidLogPrinter::OnTestEnd(const ::testing::TestInfo& test_info) { |
158 std::string msg = StringPrintf("%s %s.%s", | 158 std::string msg = StringPrintf("%s %s.%s", |
159 test_info.result()->Failed() ? "[ FAILED ]" : "[ OK ]", | 159 test_info.result()->Failed() ? "[ FAILED ]" : "[ OK ]", |
160 test_info.test_case_name(), test_info.name()); | 160 test_info.test_case_name(), test_info.name()); |
161 log_write(ANDROID_LOG_VERBOSE, msg.c_str()); | 161 log_write(ANDROID_LOG_ERROR, msg.c_str()); |
162 } | 162 } |
163 | 163 |
164 void AndroidLogPrinter::OnTestProgramEnd( | 164 void AndroidLogPrinter::OnTestProgramEnd( |
165 const ::testing::UnitTest& unit_test) { | 165 const ::testing::UnitTest& unit_test) { |
166 std::string msg = StringPrintf("[ END ] %d", | 166 std::string msg = StringPrintf("[ END ] %d", |
167 unit_test.successful_test_count()); | 167 unit_test.successful_test_count()); |
168 log_write(ANDROID_LOG_VERBOSE, msg.c_str()); | 168 log_write(ANDROID_LOG_ERROR, msg.c_str()); |
169 } | 169 } |
170 | 170 |
171 } // namespace | 171 } // namespace |
172 | 172 |
173 // This method is called on a separate java thread so that we won't trigger | 173 // This method is called on a separate java thread so that we won't trigger |
174 // an ANR. | 174 // an ANR. |
175 static void RunTests(JNIEnv* env, | 175 static void RunTests(JNIEnv* env, |
176 jobject obj, | 176 jobject obj, |
177 jstring jfiles_dir, | 177 jstring jfiles_dir, |
178 jobject app_context) { | 178 jobject app_context) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 InstallHandlers(); | 226 InstallHandlers(); |
227 | 227 |
228 base::android::InitVM(vm); | 228 base::android::InitVM(vm); |
229 JNIEnv* env = base::android::AttachCurrentThread(); | 229 JNIEnv* env = base::android::AttachCurrentThread(); |
230 if (!RegisterNativesImpl(env)) { | 230 if (!RegisterNativesImpl(env)) { |
231 return -1; | 231 return -1; |
232 } | 232 } |
233 | 233 |
234 return JNI_VERSION_1_4; | 234 return JNI_VERSION_1_4; |
235 } | 235 } |
OLD | NEW |