1 /*
2 * Copyright (c) 2022 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 <memory>
17
18 #include <gtest/gtest.h>
19
20 #include "net_manager_constants.h"
21 #include "net_mgr_log_wrapper.h"
22 #include "netmanager_base_common_utils.h"
23 #include "net_stats_database_defines.h"
24 #include "net_stats_history.h"
25
26 namespace OHOS {
27 namespace NetManagerStandard {
28 using namespace NetStatsDatabaseDefines;
29 namespace {
30 constexpr uint64_t TIME_CYCLE = 60;
31 } // namespace
32
33 using namespace testing::ext;
34 class NetStatsHistoryTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase()42 void NetStatsHistoryTest::SetUpTestCase() {}
43
TearDownTestCase()44 void NetStatsHistoryTest::TearDownTestCase() {}
45
SetUp()46 void NetStatsHistoryTest::SetUp() {}
47
TearDown()48 void NetStatsHistoryTest::TearDown() {}
49
50 HWTEST_F(NetStatsHistoryTest, HistoryTest001, TestSize.Level1)
51 {
52 auto history = std::make_unique<NetStatsHistory>();
53 std::vector<NetStatsInfo> infos;
54 int32_t ret = history->GetHistory(infos);
__anoncb0edaf10202(const auto &info) 55 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
56 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
57 }
58
59 HWTEST_F(NetStatsHistoryTest, HistoryTest002, TestSize.Level1)
60 {
61 auto history = std::make_unique<NetStatsHistory>();
62 std::vector<NetStatsInfo> infos;
63 uint64_t currentTime = CommonUtils::GetCurrentSecond();
64 int32_t ret = history->GetHistory(infos, currentTime - TIME_CYCLE, currentTime + TIME_CYCLE);
__anoncb0edaf10302(const auto &info) 65 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
66 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
67 }
68
69 HWTEST_F(NetStatsHistoryTest, HistoryTest003, TestSize.Level1)
70 {
71 auto history = std::make_unique<NetStatsHistory>();
72 std::vector<NetStatsInfo> infos;
73 int32_t ret = history->GetHistory(infos, 1152, 0, LONG_MAX);
__anoncb0edaf10402(const auto &info) 74 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
75 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
76 }
77
78 HWTEST_F(NetStatsHistoryTest, HistoryTest004, TestSize.Level1)
79 {
80 auto history = std::make_unique<NetStatsHistory>();
81 std::vector<NetStatsInfo> infos;
82 uint64_t currentTime = CommonUtils::GetCurrentSecond();
83 int32_t ret = history->GetHistory(infos, 1152, currentTime - TIME_CYCLE, currentTime + TIME_CYCLE);
__anoncb0edaf10502(const auto &info) 84 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
85 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
86 }
87
88 HWTEST_F(NetStatsHistoryTest, HistoryTest005, TestSize.Level1)
89 {
90 auto history = std::make_unique<NetStatsHistory>();
91 std::vector<NetStatsInfo> infos;
92 int32_t ret = history->GetHistory(infos, "wlan0");
__anoncb0edaf10602(const auto &info) 93 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
94 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
95 }
96
97 HWTEST_F(NetStatsHistoryTest, HistoryTest006, TestSize.Level1)
98 {
99 auto history = std::make_unique<NetStatsHistory>();
100 std::vector<NetStatsInfo> infos;
101 uint64_t currentTime = CommonUtils::GetCurrentSecond();
102 int32_t ret = history->GetHistory(infos, "wlan0", currentTime - TIME_CYCLE, currentTime + TIME_CYCLE);
__anoncb0edaf10702(const auto &info) 103 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
104 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
105 }
106
107 HWTEST_F(NetStatsHistoryTest, HistoryTest007, TestSize.Level1)
108 {
109 auto history = std::make_unique<NetStatsHistory>();
110 std::vector<NetStatsInfo> infos;
111 int32_t ret = history->GetHistory(infos, "wlan0", 1152, 0, LONG_MAX);
__anoncb0edaf10802(const auto &info) 112 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
113 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
114 }
115
116 HWTEST_F(NetStatsHistoryTest, HistoryTest008, TestSize.Level1)
117 {
118 auto history = std::make_unique<NetStatsHistory>();
119 std::vector<NetStatsInfo> infos;
120 uint64_t currentTime = CommonUtils::GetCurrentSecond();
121 int32_t ret = history->GetHistory(infos, "wlan0", 1152, currentTime - TIME_CYCLE, currentTime + TIME_CYCLE);
__anoncb0edaf10902(const auto &info) 122 std::for_each(infos.begin(), infos.end(), [](const auto &info) { std::cout << info.UidData() << std::endl; });
123 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
124 }
125 } // namespace NetManagerStandard
126 } // namespace OHOS