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 #include "gtest/gtest-message.h"
19 #include "gtest/gtest-test-part.h"
20 #include "gtest/hwext/gtest-ext.h"
21 #include "gtest/hwext/gtest-tag.h"
22
23 #define private public
24 #include "ethernet_configuration.h"
25
26 namespace OHOS {
27 namespace NetManagerStandard {
28 namespace {
29 using namespace testing::ext;
30 constexpr const char *IFACE = "iface0";
31 std::string IFACE_NAME = "iface0";
32 constexpr const char *FILE_PATH = "./BUILD.gn";
33 constexpr const char *DIR_PATH = "./BUILD.gn";
34 std::string REAL_PATH = "./BUILD.gn";
35 std::string FILE_CONTENT = "./BUILD.gn";
36 } // namespace
37
38 class EthernetConfigurationTest : public testing::Test {
39 public:
40 static void SetUpTestCase();
41 static void TearDownTestCase();
42 void SetUp();
43 void TearDown();
44 };
45
SetUpTestCase()46 void EthernetConfigurationTest::SetUpTestCase() {}
47
TearDownTestCase()48 void EthernetConfigurationTest::TearDownTestCase() {}
49
SetUp()50 void EthernetConfigurationTest::SetUp() {}
51
TearDown()52 void EthernetConfigurationTest::TearDown() {}
53
54 HWTEST_F(EthernetConfigurationTest, EthernetConfiguration001, TestSize.Level1)
55 {
56 EthernetConfiguration ethernetConfiguration;
57 std::map<std::string, std::set<NetCap>> devCaps;
58 std::map<std::string, sptr<InterfaceConfiguration>> devCfgs;
59 bool ret = ethernetConfiguration.ReadSystemConfiguration(devCaps, devCfgs);
60 EXPECT_TRUE(ret);
61 ret = ethernetConfiguration.ReadUserConfiguration(devCfgs);
62 EXPECT_TRUE(ret);
63 sptr<InterfaceConfiguration> cfg = (std::make_unique<InterfaceConfiguration>()).release();
64 ret = ethernetConfiguration.WriteUserConfiguration(IFACE, cfg);
65 EXPECT_TRUE(ret);
66 ret = ethernetConfiguration.ClearAllUserConfiguration();
67 EXPECT_TRUE(ret);
68 EthernetDhcpCallback::DhcpResult dhcpResult;
69 sptr<StaticConfiguration> config = (std::make_unique<StaticConfiguration>()).release();
70 ret = ethernetConfiguration.ConvertToConfiguration(dhcpResult, config);
71 EXPECT_FALSE(ret);
72 std::string strRet = ethernetConfiguration.ReadJsonFile(FILE_PATH);
73 ret = ethernetConfiguration.IsDirExist(DIR_PATH);
74 ret = ethernetConfiguration.CreateDir(DIR_PATH);
75 ret = ethernetConfiguration.DelDir(DIR_PATH);
76 ret = ethernetConfiguration.IsFileExist(FILE_PATH, REAL_PATH);
77 EXPECT_FALSE(ret);
78 ret = ethernetConfiguration.ReadFile(FILE_PATH, FILE_CONTENT);
79 EXPECT_FALSE(ret);
80 ret = ethernetConfiguration.WriteFile(FILE_PATH, FILE_CONTENT);
81 EXPECT_TRUE(ret);
82 ethernetConfiguration.ParserFileConfig(FILE_CONTENT, IFACE_NAME, cfg);
83 ethernetConfiguration.GenCfgContent(IFACE, cfg, FILE_CONTENT);
84 sptr<InterfaceConfiguration> cfg2 = nullptr;
85 ret = ethernetConfiguration.WriteUserConfiguration(IFACE, cfg2);
86 EXPECT_FALSE(ret);
87 }
88 } // namespace NetManagerStandard
89 } // namespace OHOS