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, RegisterNetSupplierTest001, TestSize.Level1)
49 {
50 uint32_t supplierId = 0;
51 std::set<NetCap> netCaps{NET_CAPABILITY_INTERNET};
52 int32_t ret = instance_.RegisterNetSupplier(NetBearType::BEARER_CELLULAR, "", netCaps, supplierId);
53 EXPECT_EQ(ret, NETMANAGER_ERROR);
54 ret = instance_.UnregisterNetSupplier(supplierId);
55 EXPECT_EQ(ret, NETMANAGER_ERROR);
56 }
57
58 HWTEST_F(NetConnServiceIfaceTest, UpdateNetLinkInfoTest001, TestSize.Level1)
59 {
60 sptr<NetLinkInfo> netLinkInfo = new (std::nothrow) NetLinkInfo();
61 ASSERT_NE(netLinkInfo, nullptr);
62 auto ret = instance_.UpdateNetLinkInfo(g_supplierId, netLinkInfo);
63 EXPECT_EQ(ret, NETMANAGER_ERROR);
64 }
65
66 HWTEST_F(NetConnServiceIfaceTest, UpdateNetSupplierInfoTest001, TestSize.Level1)
67 {
68 sptr<NetSupplierInfo> netSupplierInfo = new (std::nothrow) NetSupplierInfo();
69 ASSERT_NE(netSupplierInfo, nullptr);
70 auto ret = instance_.UpdateNetSupplierInfo(g_supplierId, netSupplierInfo);
71 EXPECT_EQ(ret, NETMANAGER_ERROR);
72 }
73
74 HWTEST_F(NetConnServiceIfaceTest, RestrictBackgroundChangedTest001, TestSize.Level1)
75 {
76 int32_t ret = instance_.RestrictBackgroundChanged(false);
77 EXPECT_EQ(ret, NETMANAGER_ERROR);
78 }
79
80 HWTEST_F(NetConnServiceIfaceTest, RegisterNetFactoryResetCallbackTest001, TestSize.Level1)
81 {
82 sptr<INetFactoryResetCallback> callback = nullptr;
83 auto ret = instance_.RegisterNetFactoryResetCallback(callback);
84 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
85
86 callback = new (std::nothrow) NetFactoryResetCallbackStub();
87 ret = instance_.RegisterNetFactoryResetCallback(callback);
88 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
89 }
90 } // namespace NetManagerStandard
91 } // namespace OHOS
92