1 /*
2 * Copyright (c) 2023 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 <gtest/gtest.h>
17
18 #ifdef GTEST_API_
19 #define private public
20 #define protected public
21 #endif
22
23 #include "net_manager_constants.h"
24 #include "netnative_log_wrapper.h"
25 #include "virtual_network.h"
26
27 namespace OHOS {
28 namespace nmd {
29 namespace {
30 using namespace testing::ext;
31 constexpr int32_t TEST_NET_ID = 1001;
32 } // namespace
33 class VirtualNetWorkTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp();
38 void TearDown();
39 static inline std::shared_ptr<VirtualNetwork> instance_ = nullptr;
40 };
41
SetUpTestCase()42 void VirtualNetWorkTest::SetUpTestCase()
43 {
44 instance_ = std::make_shared<VirtualNetwork>(TEST_NET_ID, false);
45 }
46
TearDownTestCase()47 void VirtualNetWorkTest::TearDownTestCase() {}
48
SetUp()49 void VirtualNetWorkTest::SetUp() {}
50
TearDown()51 void VirtualNetWorkTest::TearDown() {}
52
53 HWTEST_F(VirtualNetWorkTest, GetHasDns001, TestSize.Level1)
54 {
55 auto result = instance_->GetHasDns();
56 EXPECT_FALSE(result);
57 }
58
59 HWTEST_F(VirtualNetWorkTest, AddUids001, TestSize.Level1)
60 {
61 std::vector<UidRange> uidVec;
62 auto result = instance_->AddUids(uidVec);
63 EXPECT_EQ(result, NETMANAGER_SUCCESS);
64 }
65
66 HWTEST_F(VirtualNetWorkTest, RemoveUids001, TestSize.Level1)
67 {
68 std::vector<UidRange> uidVec;
69 auto result = instance_->RemoveUids(uidVec);
70 EXPECT_EQ(result, NETMANAGER_SUCCESS);
71 }
72
73 HWTEST_F(VirtualNetWorkTest, AddInterface001, TestSize.Level1)
74 {
75 std::string iface = "wlan0";
76 auto result = instance_->AddInterface(iface);
77 EXPECT_EQ(result, NETMANAGER_SUCCESS);
78 }
79
80 HWTEST_F(VirtualNetWorkTest, RemoveInterface001, TestSize.Level1)
81 {
82 std::string iface = "wlan0";
83 auto result = instance_->RemoveInterface(iface);
84 EXPECT_NE(result, NETMANAGER_SUCCESS);
85 }
86 } // namespace nmd
87 } // namespace OHOS