1 /*
2 * Copyright (c) 2025 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 #include <string>
18 #include <vector>
19 #include <iostream>
20
21 #include "distributed_device_profile_constants.h"
22 #include "distributed_device_profile_log.h"
23 #include "distributed_device_profile_errors.h"
24
25 #include "business_callback_stub.h"
26 #include "distributed_device_profile_client.h"
27 #include "business_event_manager.h"
28
29 using namespace testing::ext;
30 namespace OHOS {
31 namespace DistributedDeviceProfile {
32 using namespace std;
33 namespace {
34 const std::string TAG = "BusinessEventManagerTest";
35 }
36 class BusinessEventManagerTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp();
41 void TearDown();
42 };
43
SetUpTestCase()44 void BusinessEventManagerTest::SetUpTestCase()
45 {}
46
TearDownTestCase()47 void BusinessEventManagerTest::TearDownTestCase()
48 {}
49
SetUp()50 void BusinessEventManagerTest::SetUp()
51 {}
52
TearDown()53 void BusinessEventManagerTest::TearDown()
54 {}
55
56 /*
57 * @tc.name: Init001
58 * @tc.desc: Init
59 * @tc.type: FUNC
60 * @tc.require:
61 */
62 HWTEST_F(BusinessEventManagerTest, Init001, TestSize.Level1)
63 {
64 int32_t result = BusinessEventManager::GetInstance().Init();
65 EXPECT_EQ(result, DP_SUCCESS);
66 }
67
68 /*
69 * @tc.name: PutBusinessEvent001
70 * @tc.desc: Init
71 * @tc.type: FUNC
72 * @tc.require:
73 */
74 HWTEST_F(BusinessEventManagerTest, PutBusinessEvent001, TestSize.Level1)
75 {
76 BusinessEvent businessEvent;
77 businessEvent.SetBusinessKey("");
78 businessEvent.SetBusinessValue("testValue");
79 int32_t result = BusinessEventManager::GetInstance().PutBusinessEvent(businessEvent);
80 EXPECT_EQ(result, DP_INVALID_PARAM);
81 }
82
83 /*
84 * @tc.name: PutBusinessEvent002
85 * @tc.desc: Init
86 * @tc.type: FUNC
87 * @tc.require:
88 */
89 HWTEST_F(BusinessEventManagerTest, PutBusinessEvent002, TestSize.Level1)
90 {
91 BusinessEvent businessEvent;
92 businessEvent.SetBusinessKey("business_id_cast+_reject_event");
93 businessEvent.SetBusinessValue("");
94 int32_t result = BusinessEventManager::GetInstance().PutBusinessEvent(businessEvent);
95 EXPECT_EQ(result, DP_INVALID_PARAM);
96 }
97
98 /*
99 * @tc.name: PutBusinessEvent003
100 * @tc.desc: Init
101 * @tc.type: FUNC
102 * @tc.require:
103 */
104 HWTEST_F(BusinessEventManagerTest, PutBusinessEvent003, TestSize.Level1)
105 {
106 BusinessEvent businessEvent;
107 businessEvent.SetBusinessKey("");
108 businessEvent.SetBusinessValue("");
109 int32_t result = BusinessEventManager::GetInstance().PutBusinessEvent(businessEvent);
110 EXPECT_EQ(result, DP_INVALID_PARAM);
111 }
112
113 /*
114 * @tc.name: PutBusinessEvent004
115 * @tc.desc: Init
116 * @tc.type: FUNC
117 * @tc.require:
118 */
119 HWTEST_F(BusinessEventManagerTest, PutBusinessEvent004, TestSize.Level1)
120 {
121 BusinessEvent businessEvent;
122 businessEvent.SetBusinessKey("businessKey");
123 businessEvent.SetBusinessValue("testValue");
124 int32_t result = BusinessEventManager::GetInstance().PutBusinessEvent(businessEvent);
125 EXPECT_EQ(result, DP_INVALID_PARAM);
126 }
127
128
129 /*
130 * @tc.name: PutBusinessEvent005
131 * @tc.desc: Init
132 * @tc.type: FUNC
133 * @tc.require:
134 */
135 HWTEST_F(BusinessEventManagerTest, PutBusinessEvent005, TestSize.Level1)
136 {
137 BusinessEvent businessEvent;
138 businessEvent.SetBusinessKey("business_id_cast+_disturbance_event");
139 businessEvent.SetBusinessValue("testValue");
140 int32_t result = BusinessEventManager::GetInstance().PutBusinessEvent(businessEvent);
141 EXPECT_EQ(result, DP_SUCCESS);
142 }
143
144 /*
145 * @tc.name: GetBusinessEvent001
146 * @tc.desc: Init
147 * @tc.type: FUNC
148 * @tc.require:
149 */
150 HWTEST_F(BusinessEventManagerTest, GetBusinessEvent001, TestSize.Level1)
151 {
152 BusinessEvent businessEvent;
153 businessEvent.SetBusinessKey("");
154 int32_t result = BusinessEventManager::GetInstance().GetBusinessEvent(businessEvent);
155 EXPECT_EQ(result, DP_INVALID_PARAM);
156 }
157
158 /*
159 * @tc.name: GetBusinessEvent002
160 * @tc.desc: Init
161 * @tc.type: FUNC
162 * @tc.require:
163 */
164 HWTEST_F(BusinessEventManagerTest, GetBusinessEvent002, TestSize.Level1)
165 {
166 BusinessEvent businessEvent;
167 businessEvent.SetBusinessKey("businessKey");
168 int32_t result = BusinessEventManager::GetInstance().GetBusinessEvent(businessEvent);
169 EXPECT_EQ(result, DP_INVALID_PARAM);
170 }
171
172 /*
173 * @tc.name: GetBusinessEvent003
174 * @tc.desc: Init
175 * @tc.type: FUNC
176 * @tc.require:
177 */
178 HWTEST_F(BusinessEventManagerTest, GetBusinessEvent003, TestSize.Level1)
179 {
180 BusinessEvent businessEvent;
181 businessEvent.SetBusinessKey("business_id_cast+_disturbance_event");
182 int32_t result = BusinessEventManager::GetInstance().GetBusinessEvent(businessEvent);
183 EXPECT_EQ(result, DP_SUCCESS);
184 }
185
186 /*
187 * @tc.name: UnInit001
188 * @tc.desc: Init
189 * @tc.type: FUNC
190 * @tc.require:
191 */
192 HWTEST_F(BusinessEventManagerTest, UnInit001, TestSize.Level1)
193 {
194 int32_t result = BusinessEventManager::GetInstance().UnInit();
195 EXPECT_EQ(result, DP_SUCCESS);
196 }
197 } // namespace DistributedDeviceProfile
198 } // namespace OHOS