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 "netlink_define.h"
19 #include "wrapper_listener.h"
20
21 namespace OHOS {
22 namespace nmd {
23 namespace {
24 using namespace testing::ext;
25 constexpr int32_t TEST_SOCKET = 56;
__anon71c76e770202(int32_t socket) 26 WrapperListener::RecvFunc g_func = [](int32_t socket) { std::cout << "Socket :" << socket << std::endl; };
27 } // namespace
28
29 class WrapperListenerTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp();
34 void TearDown();
35 std::shared_ptr<WrapperListener> instance_ = std::make_shared<WrapperListener>(TEST_SOCKET, g_func);
36 };
37
SetUpTestCase()38 void WrapperListenerTest::SetUpTestCase() {}
39
TearDownTestCase()40 void WrapperListenerTest::TearDownTestCase() {}
41
SetUp()42 void WrapperListenerTest::SetUp() {}
43
TearDown()44 void WrapperListenerTest::TearDown() {}
45
46 HWTEST_F(WrapperListenerTest, StartTest001, TestSize.Level1)
47 {
48 int32_t testSocket = -2;
49 std::unique_ptr<WrapperListener> listener = std::make_unique<WrapperListener>(testSocket, g_func);
50 auto ret = listener->Start();
51 EXPECT_EQ(ret, NetlinkResult::ERROR);
52 ret = listener->Stop();
53 EXPECT_EQ(ret, NetlinkResult::ERROR);
54 }
55
56 HWTEST_F(WrapperListenerTest, StartTest002, TestSize.Level1)
57 {
58 auto ret = instance_->Start();
59 EXPECT_EQ(ret, NetlinkResult::OK);
60 ret = instance_->Stop();
61 EXPECT_EQ(ret, NetlinkResult::OK);
62 }
63 } // namespace nmd
64 } // namespace OHOS