• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #include "application_info.h"
19 #include "common_event_data.h"
20 #include "common_event_manager.h"
21 #include "common_event_support.h"
22 #include "res_sched_log.h"
23 #include "net_supplier_info.h"
24 #include "want.h"
25 
26 #include "event_controller.h"
27 #include "ressched_utils.h"
28 #include "res_type.h"
29 
30 namespace OHOS {
31 namespace ResourceSchedule {
32 class EventControllerTest : public testing::Test {
33 public:
SetUpTestCase()34     static void SetUpTestCase() {}
TearDownTestCase()35     static void TearDownTestCase() {}
AssertResType(uint32_t & actual,uint32_t & expect)36     static void AssertResType(uint32_t &actual, uint32_t &expect)
37     {
38         EXPECT_TRUE(actual == expect) << "Dispatch resType should be " + std::to_string(expect)
39             + ", actually is " + std::to_string(actual);
40     }
AssertValue(int64_t & actual,int64_t & expect)41     static void AssertValue(int64_t &actual, int64_t &expect)
42     {
43         EXPECT_TRUE(actual == expect) << "Dispatch value should be " + std::to_string(expect)
44             + ", actually is " + std::to_string(actual);
45     }
SetUp()46     void SetUp() {}
TearDown()47     void TearDown() {}
48 };
49 
50 /**
51  * @tc.name: connectivityChange_00100
52  * @tc.desc: test dispatching ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE
53  *           when recieve COMMON_EVENT_CONNECTIVITY_CHANGE.
54  * @tc.type: FUNC
55  * @tc.require: SR000H0H3C AR000HORSU
56  */
57 HWTEST_F(EventControllerTest, connectivityChange_00100, testing::ext::TestSize.Level1)
58 {
59     AAFwk::Want want;
60     EventFwk::CommonEventData data;
61     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE);
62     want.SetParam("NetType", 1);
63     data.SetWant(want);
64     data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTING);
65 
66     EventController::GetInstance().OnReceiveEvent(data);
67     uint32_t expectResType = ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE;
68     int64_t expectValue = 2;
69     EventControllerTest::AssertResType(EventController::GetInstance().resType_, expectResType);
70     EventControllerTest::AssertValue(EventController::GetInstance().value_, expectValue);
71 }
72 
73 /**
74  * @tc.name: connectivityChange_00101
75  * @tc.desc: test dispatching ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE
76  *           when receive COMMON_EVENT_CONNECTIVITY_CHANGE and code is NET_CONN_STATE_CONNECTED.
77  * @tc.type: FUNC
78  * @tc.require: SR000H0H3C AR000HORSU
79  */
80 HWTEST_F(EventControllerTest, connectivityChange_00101, testing::ext::TestSize.Level1)
81 {
82     AAFwk::Want want;
83     EventFwk::CommonEventData data;
84     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE);
85     want.SetParam("NetType", 1);
86     data.SetWant(want);
87     data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED);
88 
89     EventController::GetInstance().OnReceiveEvent(data);
90     uint32_t expectResType = ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE;
91     int64_t expectValue = 3;
92     EventControllerTest::AssertResType(EventController::GetInstance().resType_, expectResType);
93     EventControllerTest::AssertValue(EventController::GetInstance().value_, expectValue);
94 }
95 
96 /**
97  * @tc.name: connectivityChange_00102
98  * @tc.desc: test dispatching ResType::RES_TYPE_APP_INSTALL_UNINSTALL when recieve COMMON_EVENT_PACKAGE_ADDED.
99  * @tc.type: FUNC
100  * @tc.require: SR000H0H3C AR000HORSU
101  */
102 HWTEST_F(EventControllerTest, connectivityChange_00102, testing::ext::TestSize.Level1)
103 {
104     AAFwk::Want want;
105     EventFwk::CommonEventData data;
106     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
107     data.SetWant(want);
108 
109     EventController::GetInstance().OnReceiveEvent(data);
110     uint32_t expectResType = ResType::RES_TYPE_APP_INSTALL_UNINSTALL;
111     int64_t expectValue = 1;
112     EventControllerTest::AssertResType(EventController::GetInstance().resType_, expectResType);
113     EventControllerTest::AssertValue(EventController::GetInstance().value_, expectValue);
114 }
115 
116 /**
117  * @tc.name: connectivityChange_00103
118  * @tc.desc: test dispatching ResType::RES_TYPE_APP_INSTALL_UNINSTALL when recieve COMMON_EVENT_PACKAGE_REMOVED.
119  * @tc.type: FUNC
120  * @tc.require: SR000H0H3C AR000HORSU
121  */
122 HWTEST_F(EventControllerTest, connectivityChange_00103, testing::ext::TestSize.Level1)
123 {
124     AAFwk::Want want;
125     EventFwk::CommonEventData data;
126     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
127     data.SetWant(want);
128 
129     EventController::GetInstance().OnReceiveEvent(data);
130     uint32_t expectResType = ResType::RES_TYPE_APP_INSTALL_UNINSTALL;
131     int64_t expectValue = 0;
132     EventControllerTest::AssertResType(EventController::GetInstance().resType_, expectResType);
133     EventControllerTest::AssertValue(EventController::GetInstance().value_, expectValue);
134 }
135 
136 /**
137  * @tc.name: connectivityChange_00104
138  * @tc.desc: test dispatching ResType::RES_TYPE_SCREEN_STATUS when recieve COMMON_EVENT_SCREEN_ON.
139  * @tc.type: FUNC
140  * @tc.require: SR000H0H3C AR000HORSU
141  */
142 HWTEST_F(EventControllerTest, connectivityChange_00104, testing::ext::TestSize.Level1)
143 {
144     AAFwk::Want want;
145     EventFwk::CommonEventData data;
146     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
147     data.SetWant(want);
148 
149     EventController::GetInstance().OnReceiveEvent(data);
150     uint32_t expectResType = ResType::RES_TYPE_SCREEN_STATUS;
151     int64_t expectValue = 1;
152     EventControllerTest::AssertResType(EventController::GetInstance().resType_, expectResType);
153     EventControllerTest::AssertValue(EventController::GetInstance().value_, expectValue);
154 }
155 
156 /**
157  * @tc.name: connectivityChange_00105
158  * @tc.desc: test dispatching ResType::RES_TYPE_SCREEN_STATUS when recieve COMMON_EVENT_SCREEN_OFF.
159  * @tc.type: FUNC
160  * @tc.require: SR000H0H3C AR000HORSU
161  */
162 HWTEST_F(EventControllerTest, connectivityChange_00105, testing::ext::TestSize.Level1)
163 {
164     AAFwk::Want want;
165     EventFwk::CommonEventData data;
166     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
167     data.SetWant(want);
168 
169     EventController::GetInstance().OnReceiveEvent(data);
170     uint32_t expectResType = ResType::RES_TYPE_SCREEN_STATUS;
171     int64_t expectValue = 0;
172     EventControllerTest::AssertResType(EventController::GetInstance().resType_, expectResType);
173     EventControllerTest::AssertValue(EventController::GetInstance().value_, expectValue);
174 }
175 }
176 }