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 <gtest/gtest.h>
17
18 #include "net_conn_service_iface.h"
19 #include "net_conn_constants.h"
20 #include "net_manager_constants.h"
21 #include "net_factoryreset_callback_stub.h"
22
23 namespace OHOS {
24 namespace NetManagerStandard {
25 namespace {
26 using namespace testing::ext;
27 constexpr const char *TEST_IDENT = "test_ident";
28 uint32_t g_supplierId = 0;
29 } // namespace
30
31 class NetConnServiceIfaceTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 static inline NetConnServiceIface instance_;
38 };
39
SetUpTestCase()40 void NetConnServiceIfaceTest::SetUpTestCase() {}
41
TearDownTestCase()42 void NetConnServiceIfaceTest::TearDownTestCase() {}
43
SetUp()44 void NetConnServiceIfaceTest::SetUp() {}
45
TearDown()46 void NetConnServiceIfaceTest::TearDown() {}
47
48 HWTEST_F(NetConnServiceIfaceTest, GetIfaceNamesTest001, TestSize.Level1)
49 {
50 std::list<std::string> ifaceNames;
51 int32_t ret = instance_.GetIfaceNames(NetBearType::BEARER_ETHERNET, ifaceNames);
52 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
53 }
54
55 HWTEST_F(NetConnServiceIfaceTest, GetIfaceNameByTypeTest001, TestSize.Level1)
56 {
57 std::string ifaceName;
58 int32_t ret = instance_.GetIfaceNameByType(NetBearType::BEARER_ETHERNET, TEST_IDENT, ifaceName);
59 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
60 }
61
62 HWTEST_F(NetConnServiceIfaceTest, RegisterNetSupplierTest001, TestSize.Level1)
63 {
64 uint32_t supplierId = 0;
65 std::set<NetCap> netCaps{NET_CAPABILITY_INTERNET};
66 int32_t ret = instance_.RegisterNetSupplier(NetBearType::BEARER_CELLULAR, "", netCaps, supplierId);
67 EXPECT_EQ(ret, NETMANAGER_ERROR);
68 ret = instance_.UnregisterNetSupplier(supplierId);
69 EXPECT_EQ(ret, NETMANAGER_ERROR);
70 }
71
72 HWTEST_F(NetConnServiceIfaceTest, UpdateNetLinkInfoTest001, TestSize.Level1)
73 {
74 sptr<NetLinkInfo> netLinkInfo = new (std::nothrow) NetLinkInfo();
75 ASSERT_NE(netLinkInfo, nullptr);
76 auto ret = instance_.UpdateNetLinkInfo(g_supplierId, netLinkInfo);
77 EXPECT_EQ(ret, NETMANAGER_ERROR);
78 }
79
80 HWTEST_F(NetConnServiceIfaceTest, UpdateNetSupplierInfoTest001, TestSize.Level1)
81 {
82 sptr<NetSupplierInfo> netSupplierInfo = new (std::nothrow) NetSupplierInfo();
83 ASSERT_NE(netSupplierInfo, nullptr);
84 auto ret = instance_.UpdateNetSupplierInfo(g_supplierId, netSupplierInfo);
85 EXPECT_EQ(ret, NETMANAGER_ERROR);
86 }
87
88 HWTEST_F(NetConnServiceIfaceTest, RestrictBackgroundChangedTest001, TestSize.Level1)
89 {
90 int32_t ret = instance_.RestrictBackgroundChanged(false);
91 EXPECT_EQ(ret, NETMANAGER_ERROR);
92 }
93
94 HWTEST_F(NetConnServiceIfaceTest, RegisterNetFactoryResetCallbackTest001, TestSize.Level1)
95 {
96 sptr<INetFactoryResetCallback> callback = nullptr;
97 auto ret = instance_.RegisterNetFactoryResetCallback(callback);
98 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
99
100 callback = new (std::nothrow) NetFactoryResetCallbackStub();
101 ret = instance_.RegisterNetFactoryResetCallback(callback);
102 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
103 }
104 } // namespace NetManagerStandard
105 } // namespace OHOS
106