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 "netsys_event_message.h"
19 
20 namespace OHOS {
21 namespace nmd {
22 namespace {
23 using namespace testing::ext;
24 constexpr const char *TEST_DATA = "TEST_DATA";
25 } // namespace
26 
27 class NetsysEventMessageTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33     static inline std::shared_ptr<NetsysEventMessage> instance_ = std::make_shared<NetsysEventMessage>();
34 };
35 
SetUpTestCase()36 void NetsysEventMessageTest::SetUpTestCase()
37 {
38     instance_->PushMessage(NetsysEventMessage::Type::ADDRESS, TEST_DATA);
39 }
40 
TearDownTestCase()41 void NetsysEventMessageTest::TearDownTestCase() {}
42 
SetUp()43 void NetsysEventMessageTest::SetUp() {}
44 
TearDown()45 void NetsysEventMessageTest::TearDown() {}
46 
47 HWTEST_F(NetsysEventMessageTest, GetMessageTest001, TestSize.Level1)
48 {
49     std::string result = instance_->GetMessage(NetsysEventMessage::Type::ADDRESS);
50     ASSERT_EQ(result, std::string(TEST_DATA));
51 }
52 
53 HWTEST_F(NetsysEventMessageTest, GetMessageTest002, TestSize.Level1)
54 {
55     instance_->DumpMessage();
56 
57     std::string result = instance_->GetMessage(NetsysEventMessage::Type::GATEWAY);
58     ASSERT_TRUE(result.empty());
59 }
60 } // namespace nmd
61 } // namespace OHOS