• 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 "data_receiver.h"
19 #include "netlink_define.h"
20 
21 namespace OHOS {
22 namespace nmd {
23 namespace {
24 constexpr int32_t TEST_SOCKET = 112;
25 constexpr int32_t TEST_FORMAT = NetlinkDefine::NETLINK_FORMAT_BINARY_UNICAST;
26 using namespace testing::ext;
27 } // namespace
28 
29 class DataReceiverTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp();
34     void TearDown();
35     static inline std::shared_ptr<DataReceiver> instance_ = std::make_shared<DataReceiver>(TEST_SOCKET, TEST_FORMAT);
36 };
37 
SetUpTestCase()38 void DataReceiverTest::SetUpTestCase() {}
39 
TearDownTestCase()40 void DataReceiverTest::TearDownTestCase() {}
41 
SetUp()42 void DataReceiverTest::SetUp() {}
43 
TearDown()44 void DataReceiverTest::TearDown() {}
45 
46 HWTEST_F(DataReceiverTest, SocketErrorTest001, TestSize.Level1)
47 {
48     int32_t testSocket = -1;
49     std::unique_ptr<DataReceiver> receiver = std::make_unique<DataReceiver>(testSocket, TEST_FORMAT);
50     ASSERT_NE(receiver, nullptr);
51 }
52 
53 HWTEST_F(DataReceiverTest, FormatErrorTest002, TestSize.Level1)
54 {
55     int32_t testFormat = 6;
56     std::unique_ptr<DataReceiver> receiver = std::make_unique<DataReceiver>(TEST_SOCKET, testFormat);
57     ASSERT_NE(receiver, nullptr);
58 }
59 
60 HWTEST_F(DataReceiverTest, RegisterCallbackTest001, TestSize.Level1)
61 {
__anon025e67e70202(std::shared_ptr<NetsysEventMessage> msg) 62     DataReceiver::EventCallback callback = [](std::shared_ptr<NetsysEventMessage> msg) { (void)msg; };
63     instance_->RegisterCallback(callback);
64 }
65 
66 HWTEST_F(DataReceiverTest, StartTest001, TestSize.Level1)
67 {
68     int32_t ret = instance_->Start();
69     EXPECT_EQ(ret, NetlinkResult::OK);
70 }
71 
72 HWTEST_F(DataReceiverTest, StopTest001, TestSize.Level1)
73 {
74     int32_t ret = instance_->Stop();
75     EXPECT_EQ(ret, NetlinkResult::OK);
76 }
77 
78 } // namespace nmd
79 } // namespace OHOS