• 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 "netlink_define.h"
19 #include "wrapper_decoder.h"
20 
21 namespace OHOS {
22 namespace nmd {
23 namespace {
24 using namespace testing::ext;
25 } // namespace
26 
27 class WrapperDecoderTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void WrapperDecoderTest::SetUpTestCase() {}
36 
TearDownTestCase()37 void WrapperDecoderTest::TearDownTestCase() {}
38 
SetUp()39 void WrapperDecoderTest::SetUp() {}
40 
TearDown()41 void WrapperDecoderTest::TearDown() {}
42 
43 HWTEST_F(WrapperDecoderTest, DecodeAsciiTest001, TestSize.Level1)
44 {
45     auto msg = std::make_shared<NetsysEventMessage>();
46     std::unique_ptr<WrapperDecoder> decoder = std::make_unique<WrapperDecoder>(msg);
47     std::string buffer = "testMsg@@";
48     auto ret = decoder->DecodeAscii(buffer.data(), buffer.length());
49     EXPECT_FALSE(ret);
50 }
51 
52 HWTEST_F(WrapperDecoderTest, DecodeAsciiTest002, TestSize.Level1)
53 {
54     auto msg = std::make_shared<NetsysEventMessage>();
55     std::unique_ptr<WrapperDecoder> decoder = std::make_unique<WrapperDecoder>(msg);
56     std::string buffer = "@testMsg";
57     auto ret = decoder->DecodeAscii(buffer.data(), 0);
58     EXPECT_FALSE(ret);
59 }
60 
61 HWTEST_F(WrapperDecoderTest, DecodeAsciiTest003, TestSize.Level1)
62 {
63     auto msg = std::make_shared<NetsysEventMessage>();
64     std::unique_ptr<WrapperDecoder> decoder = std::make_unique<WrapperDecoder>(msg);
65     std::string buffer = "@testMsg";
66     auto ret = decoder->DecodeAscii(buffer.data(), buffer.length());
67     EXPECT_FALSE(ret);
68 }
69 
70 HWTEST_F(WrapperDecoderTest, DecodeAsciiTest004, TestSize.Level1)
71 {
72     auto msg = std::make_shared<NetsysEventMessage>();
73     std::unique_ptr<WrapperDecoder> decoder = std::make_unique<WrapperDecoder>(msg);
74     const char *buffer =
75         "action@msg\0ACTION=add\0ACTION=remove\0ACTION=change\0SEQNUM=111\0SEQNUM=\0SUBSYSTEM=net\0SUBSYSTEM="
76         "\0SUBSYSTEM=test\0dfdfcc=ttt\0";
77     auto ret = decoder->DecodeAscii(buffer, sizeof(buffer));
78     EXPECT_TRUE(ret);
79 }
80 
81 HWTEST_F(WrapperDecoderTest, DecodeBinaryTest001, TestSize.Level1)
82 {
83     auto msg = std::make_shared<NetsysEventMessage>();
84     std::unique_ptr<WrapperDecoder> decoder = std::make_unique<WrapperDecoder>(msg);
85     auto ret = decoder->DecodeBinary(nullptr, 0);
86     EXPECT_FALSE(ret);
87 }
88 } // namespace nmd
89 } // namespace OHOS