1 /*
2  * Copyright (c) 2021-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 "async_common_event_result.h"
17 #include "matching_skills.h"
18 #include "common_event_subscribe_info.h"
19 #undef private
20 #undef protected
21 
22 #include <gtest/gtest.h>
23 
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::EventFwk;
27 using OHOS::Parcel;
28 
29 namespace {
30 const std::string EVENT = "com.ces.test.event";
31 }
32 
33 class CommomEventSubscribeInfoTest : public testing::Test {
34 public:
35     static void SetUpTestCase(void);
36     static void TearDownTestCase(void);
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase(void)41 void CommomEventSubscribeInfoTest::SetUpTestCase(void)
42 {}
43 
TearDownTestCase(void)44 void CommomEventSubscribeInfoTest::TearDownTestCase(void)
45 {}
46 
SetUp(void)47 void CommomEventSubscribeInfoTest::SetUp(void)
48 {}
49 
TearDown(void)50 void CommomEventSubscribeInfoTest::TearDown(void)
51 {}
52 
53 /*
54  * Feature: CommomEventSubscribeInfoTest
55  * Function: SetPriority/GetPriority
56  * SubFunction: NA
57  * FunctionPoints: AddEntity/GetEntity
58  * EnvConditions: NA
59  * CaseDescription: Verify the function when after set priority can get priority
60  */
61 HWTEST_F(CommomEventSubscribeInfoTest, CommomEventSubscribeInfoTest_001, TestSize.Level1)
62 {
63     MatchingSkills matchingSkills;
64     matchingSkills.AddEvent(EVENT);
65     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
66     subscribeInfo.SetPriority(1);
67     EXPECT_EQ(1, subscribeInfo.GetPriority());
68 }
69 
70 /*
71  * Feature: CommomEventSubscribeInfoTest
72  * Function: SetUserId/GetUserId
73  * SubFunction: NA
74  * FunctionPoints: SetUserId/GetUserId
75  * EnvConditions: NA
76  * CaseDescription: Verify the function when after set userId can get userId
77  */
78 HWTEST_F(CommomEventSubscribeInfoTest, CommomEventSubscribeInfoTest_002, TestSize.Level1)
79 {
80     MatchingSkills matchingSkills;
81     matchingSkills.AddEvent(EVENT);
82     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
83     subscribeInfo.SetUserId(1);
84     EXPECT_EQ(1, subscribeInfo.GetUserId());
85 }
86 
87 /*
88  * Feature: CommomEventSubscribeInfoTest
89  * Function: SetPermission/GetPermission
90  * SubFunction: NA
91  * FunctionPoints: SetPermission/GetPermission
92  * EnvConditions: NA
93  * CaseDescription: Verify the function when after set premission can get premission
94  */
95 HWTEST_F(CommomEventSubscribeInfoTest, CommomEventSubscribeInfoTest_003, TestSize.Level1)
96 {
97     MatchingSkills matchingSkills;
98     matchingSkills.AddEvent(EVENT);
99     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
100     subscribeInfo.SetPermission("abc");
101     EXPECT_EQ("abc", subscribeInfo.GetPermission());
102 }
103 
104 /*
105  * Feature: CommomEventSubscribeInfoTest
106  * Function: SetDeviceId/GetDeviceId
107  * SubFunction: NA
108  * FunctionPoints: SetDeviceId/GetDeviceId
109  * EnvConditions: NA
110  * CaseDescription: Verify the function when after set deviceId can get deviceId
111  */
112 HWTEST_F(CommomEventSubscribeInfoTest, CommomEventSubscribeInfoTest_005, TestSize.Level1)
113 {
114     MatchingSkills matchingSkills;
115     matchingSkills.AddEvent(EVENT);
116     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
117     subscribeInfo.SetDeviceId("abc");
118     EXPECT_EQ("abc", subscribeInfo.GetDeviceId());
119 }
120 
121 /*
122  * Feature: CommomEventSubscribeInfoTest
123  * Function: SetPublisherBundleName/GetPublisherBundleName
124  * SubFunction: NA
125  * FunctionPoints: SetPublisherBundleName/GetPublisherBundleName
126  * EnvConditions: NA
127  * CaseDescription: Verify the function when after set publisherBundleName can get publisherBundleName
128  */
129 HWTEST_F(CommomEventSubscribeInfoTest, CommomEventSubscribeInfoTest_007, TestSize.Level1)
130 {
131     MatchingSkills matchingSkills;
132     matchingSkills.AddEvent(EVENT);
133     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
134     subscribeInfo.SetPublisherBundleName("abc");
135     EXPECT_EQ("abc", subscribeInfo.GetPublisherBundleName());
136 }