• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "wrapper_distributor.h"
19 
20 namespace OHOS {
21 namespace nmd {
22 namespace {
23 using namespace testing::ext;
24 constexpr int32_t TEST_SOCKET = 112;
25 constexpr int32_t TEST_FORMAT = NetlinkDefine::NETLINK_FORMAT_BINARY_UNICAST;
26 } // namespace
27 
28 class WrapperDistributorTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp();
33     void TearDown();
34     static inline std::shared_ptr<WrapperDistributor> instance_ =
35         std::make_shared<WrapperDistributor>(TEST_SOCKET, TEST_FORMAT);
36 };
37 
SetUpTestCase()38 void WrapperDistributorTest::SetUpTestCase() {}
39 
TearDownTestCase()40 void WrapperDistributorTest::TearDownTestCase() {}
41 
SetUp()42 void WrapperDistributorTest::SetUp() {}
43 
TearDown()44 void WrapperDistributorTest::TearDown() {}
45 
46 HWTEST_F(WrapperDistributorTest, SocketErrorTest001, TestSize.Level1)
47 {
48     int32_t testSocket = -1;
49     std::unique_ptr<WrapperDistributor> receiver = std::make_unique<WrapperDistributor>(testSocket, TEST_FORMAT);
50     ASSERT_NE(receiver, nullptr);
51 }
52 
53 HWTEST_F(WrapperDistributorTest, FormatErrorTest001, TestSize.Level1)
54 {
55     int32_t testFormat = 6;
56     std::unique_ptr<WrapperDistributor> distributor = std::make_unique<WrapperDistributor>(TEST_SOCKET, testFormat);
57     ASSERT_NE(distributor, nullptr);
58 }
59 
60 HWTEST_F(WrapperDistributorTest, StartTest001, TestSize.Level1)
61 {
62     int32_t ret = instance_->Start();
63     EXPECT_EQ(ret, NetlinkResult::OK);
64 }
65 
66 HWTEST_F(WrapperDistributorTest, StopTest001, TestSize.Level1)
67 {
68     int32_t ret = instance_->Stop();
69     EXPECT_EQ(ret, NetlinkResult::OK);
70 }
71 
72 HWTEST_F(WrapperDistributorTest, RegisterNetlinkCallbacksTest001, TestSize.Level1)
73 {
74     int32_t ret = instance_->RegisterNetlinkCallbacks(nullptr);
75     EXPECT_EQ(ret, NetlinkResult::ERR_NULL_PTR);
76 }
77 
78 HWTEST_F(WrapperDistributorTest, RegisterNetlinkCallbacksTest002, TestSize.Level1)
79 {
80     auto callbacks_ = std::make_shared<std::vector<sptr<NetsysNative::INotifyCallback>>>();
81     int32_t ret = instance_->RegisterNetlinkCallbacks(callbacks_);
82     EXPECT_EQ(ret, NetlinkResult::OK);
83 }
84 } // namespace nmd
85 } // namespace OHOS