1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #include <android-base/format.h>
20 #include <android-base/logging.h>
21 #include "gtest/gtest.h"
22 
23 using ::testing::TestInfo;
24 using ::testing::UnitTest;
25 
26 #define DBG 1
27 
28 /*
29  * Test base class for net native tests to support common usage.
30  */
31 class NetNativeTestBase : public ::testing::Test {
32   public:
33     // TODO: update the logging when gtest supports logging the life cycle on each test.
NetNativeTestBase()34     NetNativeTestBase() {
35         if (DBG) LOG(INFO) << getTestCaseLog(true);
36     }
~NetNativeTestBase()37     ~NetNativeTestBase() {
38         if (DBG) LOG(INFO) << getTestCaseLog(false);
39     }
40 
getTestCaseLog(bool running)41     std::string getTestCaseLog(bool running) {
42         const TestInfo* const test_info = UnitTest::GetInstance()->current_test_info();
43         return fmt::format("{}: {}#{}", (running ? "started" : "finished"),
44                            test_info->test_suite_name(), test_info->name());
45     }
46 };
47