1 /*
2 * Copyright (c) 2025-2026 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 "common_event_publish_info.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21 using namespace OHOS;
22 using namespace OHOS::EventFwk;
23 namespace {
24 const int32_t SUBSCRIBER_UIDS_MAX_NUM = 3;
25 }
26
27 class CommonEventPublishInfoTest : public ::testing::Test {
28 protected:
SetUp()29 void SetUp() override {}
TearDown()30 void TearDown() override {}
31 };
32
33
34 /**
35 * @tc.name : SetSubscriberUid_ShouldSetCorrectly_WhenUidsLessThanMax
36 * @tc.number: CommonEventPublishInfoTest_001
37 * @tc.desc : Test SetSubscriberUid method when the size of subscriberUids is less than the maximum limit
38 */
39 HWTEST_F(CommonEventPublishInfoTest, SetSubscriberUid_ShouldSetCorrectly_WhenUidsLessThanMax, TestSize.Level1)
40 {
41 CommonEventPublishInfo commonEventPublishInfo;
42 std::vector<int32_t> subscriberUids = {1, 2, 3};
43 commonEventPublishInfo.SetSubscriberUid(subscriberUids);
44 EXPECT_EQ(commonEventPublishInfo.GetSubscriberUid(), subscriberUids);
45 }
46
47 /**
48 * @tc.name : SetSubscriberUid_ShouldSetCorrectly_WhenUidsMoreThanMax
49 * @tc.number: CommonEventPublishInfoTest_002
50 * @tc.desc : Test SetSubscriberUid method when the size of subscriberUids is more than the maximum limit
51 */
52 HWTEST_F(CommonEventPublishInfoTest, SetSubscriberUid_ShouldSetCorrectly_WhenUidsMoreThanMax, TestSize.Level1)
53 {
54 CommonEventPublishInfo commonEventPublishInfo;
55 std::vector<int32_t> subscriberUids(SUBSCRIBER_UIDS_MAX_NUM + 1, 1);
56 commonEventPublishInfo.SetSubscriberUid(subscriberUids);
57 std::vector<int32_t> expectedUids(subscriberUids.begin(), subscriberUids.begin() + SUBSCRIBER_UIDS_MAX_NUM);
58 EXPECT_EQ(commonEventPublishInfo.GetSubscriberUid(), expectedUids);
59 }
60
61 /**
62 * @tc.name : SetSubscriberUid_ShouldSetEmpty_WhenUidsIsEmpty
63 * @tc.number: CommonEventPublishInfoTest_003
64 * @tc.desc : Test SetSubscriberUid method when the subscriberUids is empty
65 */
66 HWTEST_F(CommonEventPublishInfoTest, SetSubscriberUid_ShouldSetEmpty_WhenUidsIsEmpty, TestSize.Level1)
67 {
68 CommonEventPublishInfo commonEventPublishInfo;
69 std::vector<int32_t> subscriberUids;
70 commonEventPublishInfo.SetSubscriberUid(subscriberUids);
71 EXPECT_TRUE(commonEventPublishInfo.GetSubscriberUid().empty());
72 }