blob: c8b30c6266a3ea7e7495e02a70b42a3ac1928422 [file] [log] [blame]
Paul Hu2ca2fc62022-06-22 09:57:43 +00001/*
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
23using ::testing::TestInfo;
24using ::testing::UnitTest;
25
26#define DBG 1
27
28/*
29 * Test base class for net native tests to support common usage.
30 */
31class NetNativeTestBase : public ::testing::Test {
32 public:
33 // TODO: update the logging when gtest supports logging the life cycle on each test.
34 NetNativeTestBase() {
35 if (DBG) LOG(INFO) << getTestCaseLog(true);
36 }
37 ~NetNativeTestBase() {
38 if (DBG) LOG(INFO) << getTestCaseLog(false);
39 }
40
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};