|
29 | 29 | #include <lib/support/CHIPJNIError.h>
|
30 | 30 | #include <lib/support/CodeUtils.h>
|
31 | 31 | #include <lib/support/JniReferences.h>
|
32 |
| -#include <lib/support/UnitTest.h> |
33 |
| -#include <lib/support/UnitTestRegistration.h> |
34 | 32 | #include <platform/CHIPDeviceLayer.h>
|
35 | 33 | #include <platform/android/AndroidChipPlatform-JNI.h>
|
36 | 34 |
|
37 |
| -#include <nlunit-test.h> |
| 35 | +#include "pw_unit_test/framework.h" |
| 36 | +#include "pw_unit_test/googletest_style_event_handler.h" |
| 37 | +#include "pw_unit_test/logging_event_handler.h" |
38 | 38 |
|
39 | 39 | using namespace chip;
|
40 | 40 |
|
@@ -146,57 +146,60 @@ static void onLog(const char * fmt, ...)
|
146 | 146 | VerifyOrReturn(err != CHIP_NO_ERROR, ReportError(env, err, __FUNCTION__));
|
147 | 147 | }
|
148 | 148 |
|
149 |
| -static void jni_log_name(struct _nlTestSuite * inSuite) |
150 |
| -{ |
151 |
| - onLog("[ %s ]\n", inSuite->name); |
152 |
| -} |
| 149 | +namespace pw::unit_test { |
153 | 150 |
|
154 |
| -static void jni_log_initialize(struct _nlTestSuite * inSuite, int inResult, int inWidth) |
| 151 | +class AndroidLoggingEventHandler : public pw::unit_test::LoggingEventHandler |
155 | 152 | {
|
156 |
| - onLog("[ %s : %-*s ] : %s\n", inSuite->name, inWidth, "Initialize", inResult == FAILURE ? "FAILED" : "PASSED"); |
157 |
| -} |
158 |
| -static void jni_log_terminate(struct _nlTestSuite * inSuite, int inResult, int inWidth) |
159 |
| -{ |
160 |
| - onLog("[ %s : %-*s ] : %s\n", inSuite->name, inWidth, "Terminate", inResult == FAILURE ? "FAILED" : "PASSED"); |
161 |
| -} |
| 153 | +public: |
| 154 | + void RunAllTestsStart() override { onLog(PW_UNIT_TEST_GOOGLETEST_RUN_ALL_TESTS_START); } |
162 | 155 |
|
163 |
| -static void jni_log_setup(struct _nlTestSuite * inSuite, int inResult, int inWidth) |
164 |
| -{ |
165 |
| - onLog("[ %s : %-*s ] : %s\n", inSuite->name, inWidth, "Setup", inResult == FAILURE ? "FAILED" : "PASSED"); |
166 |
| -} |
167 |
| - |
168 |
| -static void jni_log_test(struct _nlTestSuite * inSuite, int inWidth, int inIndex) |
169 |
| -{ |
170 |
| - onLog("[ %s : %-*s ] : %s\n", inSuite->name, inWidth, inSuite->tests[inIndex].name, inSuite->flagError ? "FAILED" : "PASSED"); |
171 |
| -} |
172 |
| - |
173 |
| -static void jni_log_teardown(struct _nlTestSuite * inSuite, int inResult, int inWidth) |
174 |
| -{ |
175 |
| - onLog("[ %s : %-*s ] : %s\n", inSuite->name, inWidth, "TearDown", inResult == FAILURE ? "FAILED" : "PASSED"); |
176 |
| -} |
177 |
| - |
178 |
| -static void jni_log_statTest(struct _nlTestSuite * inSuite) |
179 |
| -{ |
180 |
| - onLog("Failed Tests: %d / %d\n", inSuite->failedTests, inSuite->runTests); |
181 |
| -} |
| 156 | + void RunAllTestsEnd(const RunTestsSummary & run_tests_summary) override |
| 157 | + { |
| 158 | + onLog(PW_UNIT_TEST_GOOGLETEST_RUN_ALL_TESTS_END); |
| 159 | + onLog(PW_UNIT_TEST_GOOGLETEST_PASSED_SUMMARY, run_tests_summary.passed_tests); |
| 160 | + if (run_tests_summary.skipped_tests) |
| 161 | + { |
| 162 | + onLog(PW_UNIT_TEST_GOOGLETEST_DISABLED_SUMMARY, run_tests_summary.skipped_tests); |
| 163 | + } |
| 164 | + if (run_tests_summary.failed_tests) |
| 165 | + { |
| 166 | + onLog(PW_UNIT_TEST_GOOGLETEST_FAILED_SUMMARY, run_tests_summary.failed_tests); |
| 167 | + } |
| 168 | + } |
182 | 169 |
|
183 |
| -static void jni_log_statAssert(struct _nlTestSuite * inSuite) |
184 |
| -{ |
185 |
| - onLog("Failed Asserts: %d / %d\n", inSuite->failedAssertions, inSuite->performedAssertions); |
186 |
| -} |
| 170 | + void TestCaseStart(const TestCase & test_case) override |
| 171 | + { |
| 172 | + onLog(PW_UNIT_TEST_GOOGLETEST_CASE_START, test_case.suite_name, test_case.test_name); |
| 173 | + } |
187 | 174 |
|
188 |
| -static nl_test_output_logger_t jni_test_logger = { |
189 |
| - jni_log_name, jni_log_initialize, jni_log_terminate, jni_log_setup, |
190 |
| - jni_log_test, jni_log_teardown, jni_log_statTest, jni_log_statAssert, |
| 175 | + void TestCaseEnd(const TestCase & test_case, TestResult result) override |
| 176 | + { |
| 177 | + // Use a switch with no default to detect changes in the test result enum. |
| 178 | + switch (result) |
| 179 | + { |
| 180 | + case TestResult::kSuccess: |
| 181 | + onLog(PW_UNIT_TEST_GOOGLETEST_CASE_OK, test_case.suite_name, test_case.test_name); |
| 182 | + break; |
| 183 | + case TestResult::kFailure: |
| 184 | + onLog(PW_UNIT_TEST_GOOGLETEST_CASE_FAILED, test_case.suite_name, test_case.test_name); |
| 185 | + break; |
| 186 | + case TestResult::kSkipped: |
| 187 | + onLog(PW_UNIT_TEST_GOOGLETEST_CASE_DISABLED, test_case.suite_name, test_case.test_name); |
| 188 | + break; |
| 189 | + } |
| 190 | + } |
191 | 191 | };
|
| 192 | +}; // namespace pw::unit_test |
192 | 193 |
|
193 | 194 | extern "C" JNIEXPORT jint Java_com_tcl_chip_chiptest_TestEngine_runTest(JNIEnv * env, jclass clazz)
|
194 | 195 | {
|
195 |
| - nlTestSetLogger(&jni_test_logger); |
196 | 196 | chip::DeviceLayer::StackLock lock;
|
197 |
| - // TODO [PW_MIGRATION] Remove NLUnit tests call after migration |
198 |
| - jint ret = RunRegisteredUnitTests(); |
199 |
| - ret += chip::test::RunAllTests(); |
| 197 | + |
| 198 | + // Running Pigweed Tests |
| 199 | + testing::InitGoogleTest(nullptr, static_cast<char **>(nullptr)); |
| 200 | + pw::unit_test::AndroidLoggingEventHandler handler; |
| 201 | + pw::unit_test::RegisterEventHandler(&handler); |
| 202 | + jint ret = RUN_ALL_TESTS(); |
200 | 203 |
|
201 | 204 | return ret;
|
202 | 205 | }
|
0 commit comments