1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <ctime>
17 #include <thread>
18 #include <vector>
19
20 #include <gtest/gtest.h>
21
22 #ifdef GTEST_API_
23 #define private public
24 #define protected public
25 #endif
26
27 #include "net_manager_center.h"
28 #include "net_stats_callback_test.h"
29 #include "net_stats_constants.h"
30 #include "net_stats_service.h"
31 #include "common/net_stats_service_common.h"
32
33 namespace OHOS {
34 namespace NetManagerStandard {
35 namespace {
36 #define DTEST_LOG std::cout << __func__ << ":" << __LINE__ << ":"
37 } // namespace
38
39 using namespace testing::ext;
40 class NetStatsServiceCommonTest : public testing::Test {
41 public:
42 static void SetUpTestCase();
43 static void TearDownTestCase();
44 void SetUp();
45 void TearDown();
46 static inline std::shared_ptr<NetStatsServiceCommon> instance_ = nullptr;
47 };
48
SetUpTestCase()49 void NetStatsServiceCommonTest::SetUpTestCase()
50 {
51 instance_ = std::make_shared<NetStatsServiceCommon>();
52 }
53
TearDownTestCase()54 void NetStatsServiceCommonTest::TearDownTestCase()
55 {
56 instance_ = nullptr;
57 }
58
SetUp()59 void NetStatsServiceCommonTest::SetUp() {}
60
TearDown()61 void NetStatsServiceCommonTest::TearDown() {}
62
63 HWTEST_F(NetStatsServiceCommonTest, GetDumpMessageTest001, TestSize.Level1)
64 {
65 std::string iface = "wlan0";
66 uint64_t start = 1000;
67 uint64_t end = 2000;
68 NetStatsInfo info;
69 auto res = instance_->GetIfaceStatsDetail(iface, start, end, info);
70 EXPECT_NE(res, NETMANAGER_SUCCESS);
71 }
72
73 HWTEST_F(NetStatsServiceCommonTest, GetIfaceStatsDetailTest002, TestSize.Level1)
74 {
75 std::string iface = "eth0";
76 uint64_t start = 1000;
77 uint64_t end = 2000;
78 NetStatsInfo info;
79 auto res = instance_->GetIfaceStatsDetail(iface, start, end, info);
80 EXPECT_NE(res, NETMANAGER_SUCCESS);
81 }
82
83 HWTEST_F(NetStatsServiceCommonTest, GetIfaceStatsDetailTest003, TestSize.Level1)
84 {
85 std::string iface = "usb0";
86 uint64_t start = 1000;
87 uint64_t end = 2000;
88 NetStatsInfo info;
89 auto res = instance_->GetIfaceStatsDetail(iface, start, end, info);
90 EXPECT_NE(res, NETMANAGER_SUCCESS);
91 }
92
93 HWTEST_F(NetStatsServiceCommonTest, ResetStatsFactoryTest001, TestSize.Level1)
94 {
95 auto result = instance_->ResetStatsFactory();
96 EXPECT_EQ(result, 0);
97 }
98 } // namespace NetManagerStandard
99 } // namespace OHOS
100