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 "distributed_hardware_stub_test.h"
17
18 #include <memory>
19
20 #include "iremote_stub.h"
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace DistributedHardware {
SetUpTestCase(void)25 void DistributedHardwareStubTest::SetUpTestCase(void) {}
26
TearDownTestCase(void)27 void DistributedHardwareStubTest::TearDownTestCase(void) {}
28
SetUp()29 void DistributedHardwareStubTest::SetUp()
30 {
31 stubTest_ = std::make_shared<MockDistributedHardwareStub>();
32 }
33
TearDown()34 void DistributedHardwareStubTest::TearDown()
35 {
36 stubTest_ = nullptr;
37 }
38
39 /**
40 * @tc.name: OnRemoteRequest_001
41 * @tc.desc: Verify the OnRemoteRequest function
42 * @tc.type: FUNC
43 * @tc.require: AR000GHSJM
44 */
45 HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_001, TestSize.Level0)
46 {
47 uint32_t code = 0;
48 MessageParcel data;
49 MessageParcel reply;
50 MessageOption option;
51 EXPECT_NE(DH_FWK_SUCCESS, stubTest_->OnRemoteRequest(code, data, reply, option));
52 }
53
54 /**
55 * @tc.name: OnRemoteRequest_002
56 * @tc.desc: Verify the OnRemoteRequest function
57 * @tc.type: FUNC
58 * @tc.require: AR000GHSJM
59 */
60 HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_002, TestSize.Level0)
61 {
62 uint32_t code = 0;
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option;
66 EXPECT_EQ(ERR_INVALID_DATA, stubTest_->OnRemoteRequest(code, data, reply, option));
67 }
68
69 /**
70 * @tc.name: RegisterPublisherListenerInner_001
71 * @tc.desc: Verify the RegisterPublisherListenerInner function
72 * @tc.type: FUNC
73 * @tc.require: AR000GHSJM
74 */
75 HWTEST_F(DistributedHardwareStubTest, RegisterPublisherListenerInner_001, TestSize.Level0)
76 {
77 MessageParcel data;
78 MessageParcel reply;
79 EXPECT_NE(DH_FWK_SUCCESS, stubTest_->RegisterPublisherListenerInner(data, reply));
80 }
81
82 /**
83 * @tc.name: UnregisterPublisherListenerInner_001
84 * @tc.desc: Verify the UnregisterPublisherListenerInner function
85 * @tc.type: FUNC
86 * @tc.require: AR000GHSJM
87 */
88 HWTEST_F(DistributedHardwareStubTest, UnregisterPublisherListenerInner_001, TestSize.Level0)
89 {
90 MessageParcel data;
91 MessageParcel reply;
92 EXPECT_NE(DH_FWK_SUCCESS, stubTest_->UnregisterPublisherListenerInner(data, reply));
93 }
94
95 /**
96 * @tc.name: PublishMessageInner_001
97 * @tc.desc: Verify the PublishMessageInner function
98 * @tc.type: FUNC
99 * @tc.require: AR000GHSJM
100 */
101 HWTEST_F(DistributedHardwareStubTest, PublishMessageInner_001, TestSize.Level0)
102 {
103 MessageParcel data;
104 MessageParcel reply;
105 EXPECT_NE(DH_FWK_SUCCESS, stubTest_->PublishMessageInner(data, reply));
106 }
107
108 /**
109 * @tc.name: ValidTopic_001
110 * @tc.desc: Verify the ValidTopic function
111 * @tc.type: FUNC
112 * @tc.require: AR000GHSJM
113 */
114 HWTEST_F(DistributedHardwareStubTest, ValidTopic_001, TestSize.Level0)
115 {
116 uint32_t topic = static_cast<uint32_t>(DHTopic::TOPIC_MIN);
117 EXPECT_EQ(false, stubTest_->ValidTopic(topic));
118
119 uint32_t topic1 = static_cast<uint32_t>(DHTopic::TOPIC_MAX);
120 EXPECT_EQ(false, stubTest_->ValidTopic(topic1));
121
122 uint32_t topic2 = static_cast<uint32_t>(DHTopic::TOPIC_START_DSCREEN);
123 EXPECT_EQ(true, stubTest_->ValidTopic(topic2));
124 }
125 } // namespace DistributedHardware
126 } // namespace OHOS
127