• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 <gtest/gtest.h>
17 
18 #include "iservice_registry.h"
19 #include "system_ability_definition.h"
20 
21 #ifdef GTEST_API_
22 #define private public
23 #endif
24 
25 #include "clat_constants.h"
26 #include "clat_manager.h"
27 #include "net_conn_manager_test_util.h"
28 #include "net_manager_constants.h"
29 #include "netnative_log_wrapper.h"
30 #include "netsys_native_service_proxy.h"
31 #include "network_permission.h"
32 #include "physical_network.h"
33 
34 namespace OHOS {
35 namespace NetsysNative {
36 using namespace testing::ext;
37 using namespace NetManagerStandard;
38 using namespace NetConnManagerTestUtil;
39 
40 class ClatManagerTest : 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<ClatManager> instance_ = nullptr;
47 };
48 
SetUpTestCase()49 void ClatManagerTest::SetUpTestCase()
50 {
51     instance_ = std::make_shared<ClatManager>();
52 }
53 
TearDownTestCase()54 void ClatManagerTest::TearDownTestCase()
55 {
56     instance_ = nullptr;
57 }
58 
SetUp()59 void ClatManagerTest::SetUp() {}
60 
TearDown()61 void ClatManagerTest::TearDown() {}
62 
63 /**
64  * @tc.name: ClatStartTest001
65  * @tc.desc: Test ConnManager ClatStart.
66  * @tc.type: FUNC
67  */
68 HWTEST_F(ClatManagerTest, ClatStartTest001, TestSize.Level1)
69 {
70     const std::string v6Iface = "";
71     int32_t netId = 1;
72     const std::string nat64PrefixStr;
73     NetManagerNative *netsysService = nullptr;
74 
75     int32_t ret = instance_->ClatStart(v6Iface, netId, nat64PrefixStr, netsysService);
76     EXPECT_EQ(ret, NETMANAGER_ERR_INVALID_PARAMETER);
77 
78     netsysService = new NetManagerNative();
79     ret = instance_->ClatStart(v6Iface, netId, nat64PrefixStr, netsysService);
80     EXPECT_EQ(ret, NETMANAGER_ERR_INVALID_PARAMETER);
81 }
82 
83 /**
84  * @tc.name: ClatStopTest001
85  * @tc.desc: Test ConnManager ClatStop.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(ClatManagerTest, ClatStopTest001, TestSize.Level1)
89 {
90     const std::string v6Iface = "";
91 
92     int32_t ret = instance_->ClatStop(v6Iface);
93     EXPECT_EQ(ret, NETMANAGER_ERR_OPERATION_FAILED);
94 }
95 
96 /**
97  * @tc.name: GenerateClatSrcAddrTest001
98  * @tc.desc: Test ConnManager GenerateClatSrcAddr.
99  * @tc.type: FUNC
100  */
101 HWTEST_F(ClatManagerTest, GenerateClatSrcAddrTest001, TestSize.Level1)
102 {
103     const std::string v6Iface = "";
104     const std::string nat64PrefixStr = "";
105     uint32_t fwmark = 1;
106     INetAddr v4Addr;
107     INetAddr v6Addr;
108 
109     int32_t ret = instance_->GenerateClatSrcAddr(v6Iface, fwmark, nat64PrefixStr, v4Addr, v6Addr);
110     EXPECT_EQ(ret, NETMANAGER_ERR_INVALID_PARAMETER);
111 }
112 
113 /**
114  * @tc.name: CreateAndConfigureTunIfaceTest001
115  * @tc.desc: Test ConnManager CreateAndConfigureTunIface.
116  * @tc.type: FUNC
117  */
118 HWTEST_F(ClatManagerTest, CreateAndConfigureTunIfaceTest001, TestSize.Level1)
119 {
120     const std::string v6Iface = "";
121     const std::string tunIface = "";
122     INetAddr v4Addr;
123     NetManagerNative *netsysService = nullptr;
124     int tunFd = 1;
125 
126     int32_t ret = instance_->CreateAndConfigureTunIface(v6Iface, tunIface, v4Addr, netsysService, tunFd);
127     EXPECT_EQ(ret, NETMANAGER_ERR_OPERATION_FAILED);
128 }
129 
130 /**
131  * @tc.name: CreateAndConfigureClatSocketTest001
132  * @tc.desc: Test ConnManager CreateAndConfigureClatSocket.
133  * @tc.type: FUNC
134  */
135 HWTEST_F(ClatManagerTest, CreateAndConfigureClatSocketTest001, TestSize.Level1)
136 {
137     const std::string v6Iface = "";
138     uint32_t fwmark = 1;
139     INetAddr v6Addr;
140     int readSock6 = 1;
141     int writeSock6 = 1;
142 
143     int32_t ret = instance_->CreateAndConfigureClatSocket(v6Iface, v6Addr, fwmark, readSock6, writeSock6);
144     EXPECT_EQ(ret, NETMANAGER_ERR_OPERATION_FAILED);
145 }
146 } // namespace NetsysNative
147 } // namespace OHOS