1 /*
2  * Copyright (c) 2022-2024 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 "publisher_listener_proxy_test.h"
17 
18 using namespace testing::ext;
19 
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase()22 void PublisherListenerProxyTest::SetUpTestCase()
23 {
24 }
25 
TearDownTestCase()26 void PublisherListenerProxyTest::TearDownTestCase()
27 {
28 }
29 
SetUp()30 void PublisherListenerProxyTest::SetUp()
31 {
32     sptr<IRemoteObject> object = nullptr;
33     proxy_ = std::make_shared<PublisherListenerProxy>(object);
34 }
35 
TearDown()36 void PublisherListenerProxyTest::TearDown()
37 {
38     proxy_ = nullptr;
39 }
40 
41 /**
42  * @tc.name: OnMessage_001
43  * @tc.desc: Verify the OnMessage function
44  * @tc.type: FUNC
45  * @tc.require: AR000GHSJM
46  */
47 HWTEST_F(PublisherListenerProxyTest, OnMessage_001, TestSize.Level0)
48 {
49     if (proxy_ == nullptr) {
50         return;
51     }
52     uint32_t invalid = 8;
53     DHTopic topic = static_cast<DHTopic>(invalid);
54     std::string message;
55     proxy_->OnMessage(topic, message);
56     EXPECT_EQ(true, message.empty());
57 }
58 
59 /**
60  * @tc.name: OnMessage_002
61  * @tc.desc: Verify the OnMessage function
62  * @tc.type: FUNC
63  * @tc.require: AR000GHSJM
64  */
65 HWTEST_F(PublisherListenerProxyTest, OnMessage_002, TestSize.Level0)
66 {
67     if (proxy_ == nullptr) {
68         return;
69     }
70     DHTopic topic = DHTopic::TOPIC_START_DSCREEN;
71     std::string message;
72     proxy_->OnMessage(topic, message);
73     EXPECT_EQ(true, message.empty());
74 }
75 
76 /**
77  * @tc.name: OnMessage_003
78  * @tc.desc: Verify the OnMessage function
79  * @tc.type: FUNC
80  * @tc.require: AR000GHSJM
81  */
82 HWTEST_F(PublisherListenerProxyTest, OnMessage_003, TestSize.Level0)
83 {
84     if (proxy_ == nullptr) {
85         return;
86     }
87     DHTopic topic = DHTopic::TOPIC_START_DSCREEN;
88     std::string message = "message";
89     proxy_->OnMessage(topic, message);
90     EXPECT_EQ(false, message.empty());
91 }
92 } // namespace DistributedHardware
93 } // namespace OHOS
94