• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <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 "vnic_manager.h"
26 
27 namespace OHOS {
28 namespace NetManagerStandard {
29 namespace {
30 using namespace testing::ext;
31 } // namespace
32 
33 class VnicManagerTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase()41 void VnicManagerTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void VnicManagerTest::TearDownTestCase() {}
44 
SetUp()45 void VnicManagerTest::SetUp() {}
46 
TearDown()47 void VnicManagerTest::TearDown() {}
48 
49 HWTEST_F(VnicManagerTest, CreateVnicInterface001, TestSize.Level1)
50 {
51     auto result = VnicManager::GetInstance().CreateVnicInterface();
52     EXPECT_EQ(result, NETMANAGER_SUCCESS);
53 
54     VnicManager::GetInstance().DestroyVnicInterface();
55 }
56 
57 HWTEST_F(VnicManagerTest, SetVnicMtu001, TestSize.Level1)
58 {
59     std::string ifName = "";
60     int32_t testNumber = 0;
61     auto result = VnicManager::GetInstance().SetVnicMtu(ifName, testNumber);
62     EXPECT_EQ(result, NETMANAGER_ERROR);
63 
64     testNumber = 1;
65     result = VnicManager::GetInstance().SetVnicMtu(ifName, testNumber);
66     EXPECT_EQ(result, NETMANAGER_SUCCESS);
67 }
68 
69 HWTEST_F(VnicManagerTest, SetVnicAddress001, TestSize.Level1)
70 {
71     std::string ifName = "";
72     std::string tunAddr = "";
73     int32_t testNumber = 0;
74     auto result = VnicManager::GetInstance().SetVnicAddress(ifName, tunAddr, testNumber);
75     EXPECT_EQ(result, NETMANAGER_ERROR);
76 }
77 
78 HWTEST_F(VnicManagerTest, SetVnicUp001, TestSize.Level1)
79 {
80     auto result = VnicManager::GetInstance().SetVnicUp();
81     EXPECT_EQ(result, NETMANAGER_SUCCESS);
82 }
83 
84 HWTEST_F(VnicManagerTest, SetVnicDown001, TestSize.Level1)
85 {
86     auto result = VnicManager::GetInstance().SetVnicDown();
87     EXPECT_EQ(result, NETMANAGER_SUCCESS);
88 }
89 
90 HWTEST_F(VnicManagerTest, InitIfreq001, TestSize.Level1)
91 {
92     ifreq ifr;
93     std::string cardName = "";
94     auto result = VnicManager::GetInstance().InitIfreq(ifr, cardName);
95     EXPECT_EQ(result, NETMANAGER_SUCCESS);
96 }
97 } // namespace NetManagerStandard
98 } // namespace OHOS
99