1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_ENVIRONMENT_TEARDOWN 18 #define ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_ENVIRONMENT_TEARDOWN 19 20 #include <android-base/logging.h> 21 22 namespace android { 23 namespace hardware { 24 namespace audio { 25 namespace common { 26 namespace test { 27 namespace utility { 28 29 namespace doc { 30 namespace detail { getTestName()31const char* getTestName() { 32 return ::testing::UnitTest::GetInstance()->current_test_info()->name(); 33 } 34 } // namespace detail 35 36 /** Document the current test case. 37 * Eg: calling `doc::test("Dump the state of the hal")` in the "debugDump" test 38 * will output: 39 * <testcase name="debugDump" status="run" time="6" 40 * classname="AudioPrimaryHidlTest" 41 description="Dump the state of the hal." /> 42 * see 43 https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#logging-additional-information 44 */ test(const std::string & testCaseDocumentation)45void test(const std::string& testCaseDocumentation) { 46 ::testing::Test::RecordProperty("description", testCaseDocumentation); 47 } 48 49 /** Document why a test was not fully run. Usually due to an optional feature 50 * not implemented. */ partialTest(const std::string & reason)51void partialTest(const std::string& reason) { 52 LOG(INFO) << "Test " << detail::getTestName() << " partially run: " << reason; 53 ::testing::Test::RecordProperty("partialyRunTest", reason); 54 } 55 56 /** Add a note to the test. */ note(const std::string & note)57void note(const std::string& note) { 58 LOG(INFO) << "Test " << detail::getTestName() << " noted: " << note; 59 ::testing::Test::RecordProperty("note", note); 60 } 61 } // namespace doc 62 63 } // namespace utility 64 } // namespace test 65 } // namespace common 66 } // namespace audio 67 } // namespace hardware 68 } // namespace android 69 70 #endif // ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_ENVIRONMENT_TEARDOWN 71