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 <functional> 17 #include <chrono> 18 #include <thread> 19 #include <message_parcel.h> 20 21 #include "gtest/gtest.h" 22 23 #include "background_task_mgr_proxy.h" 24 25 #include "background_task_manager.h" 26 #include "background_task_subscriber.h" 27 #include "background_task_subscriber_stub.h" 28 #include "background_task_subscriber_proxy.h" 29 #include "bgtaskmgr_inner_errors.h" 30 #include "bgtaskmgr_log_wrapper.h" 31 #include "continuous_task_callback_info.h" 32 #include "continuous_task_param.h" 33 #include "delay_suspend_info.h" 34 #include "efficiency_resource_info.h" 35 #include "expired_callback.h" 36 #include "expired_callback_proxy.h" 37 #include "expired_callback_stub.h" 38 #include "mock_background_task_mgr_proxy_helper.h" 39 #include "mock_message_parcel_helper.h" 40 #include "iservice_registry.h" 41 #include "resource_callback_info.h" 42 #include "singleton.h" 43 #include "transient_task_app_info.h" 44 45 using namespace testing::ext; 46 47 namespace OHOS { 48 namespace BackgroundTaskMgr { 49 class BgTaskFrameworkAbnormalUnitTest : public testing::Test { 50 public: SetUpTestCase()51 static void SetUpTestCase() {} TearDownTestCase()52 static void TearDownTestCase() {} SetUp()53 void SetUp() override {} TearDown()54 void TearDown() override {} 55 }; 56 57 class TestExpiredCallback : public ExpiredCallback { 58 public: OnExpired()59 void OnExpired() override {} 60 }; 61 62 class TestBackgroundTaskSubscriber : public BackgroundTaskSubscriber {}; 63 64 class TestBackgroundTaskSubscriberStub : public BackgroundTaskSubscriberStub { OnConnected()65 void OnConnected() override {} OnDisconnected()66 void OnDisconnected() override {} OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo> & info)67 void OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo> & info)68 void OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo> & info)69 void OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo> & info)70 void OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnTransientTaskErr(const std::shared_ptr<TransientTaskAppInfo> & info)71 void OnTransientTaskErr(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnContinuousTaskStart(const std::shared_ptr<ContinuousTaskCallbackInfo> & continuousTaskCallbackInfo)72 void OnContinuousTaskStart( 73 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override {} OnContinuousTaskUpdate(const std::shared_ptr<ContinuousTaskCallbackInfo> & continuousTaskCallbackInfo)74 void OnContinuousTaskUpdate( 75 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override {} OnContinuousTaskStop(const std::shared_ptr<ContinuousTaskCallbackInfo> & continuousTaskCallbackInfo)76 void OnContinuousTaskStop( 77 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override {} OnAppContinuousTaskStop(int32_t uid)78 void OnAppContinuousTaskStop(int32_t uid) override {} OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)79 void OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)80 void OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)81 void OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)82 void OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} 83 }; 84 85 class TestExpiredCallbackStub : public ExpiredCallbackStub { 86 public: OnExpired()87 void OnExpired() override {} 88 }; 89 90 /** 91 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_001 92 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 93 * @tc.type: FUNC 94 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 95 */ 96 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_001, TestSize.Level1) 97 { 98 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 99 std::shared_ptr<DelaySuspendInfo> delayInfo = std::make_shared<DelaySuspendInfo>(); 100 sptr<TestExpiredCallbackStub> expiredCallbackStub = sptr<TestExpiredCallbackStub>(new TestExpiredCallbackStub()); 101 102 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", nullptr, delayInfo), 103 ERR_CALLBACK_NULL_OR_TYPE_ERR); 104 105 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 106 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 107 ERR_BGTASK_PARCELABLE_FAILED); 108 109 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 110 MessageParcelHelper::BgTaskFwkAbnormalSetWriteString16Flag(false); 111 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 112 ERR_BGTASK_PARCELABLE_FAILED); 113 114 MessageParcelHelper::BgTaskFwkAbnormalSetWriteString16Flag(true); 115 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 116 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 117 ERR_BGTASK_PARCELABLE_FAILED); 118 119 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 120 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 121 ERR_BGTASK_TRANSACT_FAILED); 122 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 123 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 124 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 125 ERR_BGTASK_TRANSACT_FAILED); 126 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 127 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 128 ERR_BGTASK_TRANSACT_FAILED); 129 } 130 131 /** 132 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_002 133 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 134 * @tc.type: FUNC 135 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 136 */ 137 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_002, TestSize.Level1) 138 { 139 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 140 141 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 142 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_PARCELABLE_FAILED); 143 144 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 145 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 146 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_PARCELABLE_FAILED); 147 148 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 149 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 150 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_TRANSACT_FAILED); 151 152 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 153 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 154 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_TRANSACT_FAILED); 155 } 156 157 /** 158 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_003 159 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 160 * @tc.type: FUNC 161 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 162 */ 163 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_003, TestSize.Level1) 164 { 165 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 166 int32_t delayTime; 167 168 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 169 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_PARCELABLE_FAILED); 170 171 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 172 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 173 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_PARCELABLE_FAILED); 174 175 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 176 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 177 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_TRANSACT_FAILED); 178 179 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 180 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 181 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_TRANSACT_FAILED); 182 } 183 184 /** 185 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_004 186 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 187 * @tc.type: FUNC 188 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 189 */ 190 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_004, TestSize.Level1) 191 { 192 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 193 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(nullptr), ERR_BGTASK_INVALID_PARAM); 194 195 sptr<ContinuousTaskParam> taskParam = sptr<ContinuousTaskParam>(new ContinuousTaskParam()); 196 197 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 198 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_PARCELABLE_FAILED); 199 200 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 201 MessageParcelHelper::BgTaskFwkAbnormalSetWriteParcelableFlag(false); 202 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_PARCELABLE_FAILED); 203 204 MessageParcelHelper::BgTaskFwkAbnormalSetWriteParcelableFlag(true); 205 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 206 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_TRANSACT_FAILED); 207 208 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 209 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 210 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_TRANSACT_FAILED); 211 } 212 213 /** 214 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_005 215 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 216 * @tc.type: FUNC 217 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V issueI99HSB 218 */ 219 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_005, TestSize.Level1) 220 { 221 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 222 223 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 224 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_BGTASK_PARCELABLE_FAILED); 225 226 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 227 MessageParcelHelper::BgTaskFwkAbnormalSetWriteStringFlag(false); 228 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_BGTASK_TRANSACT_FAILED); 229 230 MessageParcelHelper::BgTaskFwkAbnormalSetWriteStringFlag(true); 231 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 232 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_BGTASK_PARCELABLE_FAILED); 233 234 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 235 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 236 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_BGTASK_PARCELABLE_FAILED); 237 238 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 239 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 240 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_BGTASK_TRANSACT_FAILED); 241 242 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 243 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 244 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_BGTASK_TRANSACT_FAILED); 245 } 246 247 /** 248 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_006 249 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 250 * @tc.type: FUNC 251 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 252 */ 253 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_006, TestSize.Level1) 254 { 255 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 256 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(nullptr), ERR_BGTASK_PARCELABLE_FAILED); 257 258 sptr<TestBackgroundTaskSubscriberStub> subscribe = 259 sptr<TestBackgroundTaskSubscriberStub>(new TestBackgroundTaskSubscriberStub()); 260 261 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 262 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 263 264 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 265 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 266 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 267 268 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 269 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 270 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_TRANSACT_FAILED); 271 272 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 273 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 274 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_TRANSACT_FAILED); 275 } 276 277 /** 278 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_007 279 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 280 * @tc.type: FUNC 281 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 282 */ 283 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_007, TestSize.Level1) 284 { 285 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 286 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(nullptr), ERR_BGTASK_PARCELABLE_FAILED); 287 288 sptr<TestBackgroundTaskSubscriberStub> subscribe = 289 sptr<TestBackgroundTaskSubscriberStub>(new TestBackgroundTaskSubscriberStub()); 290 291 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 292 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 293 294 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 295 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 296 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 297 298 MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 299 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 300 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_TRANSACT_FAILED); 301 302 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 303 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 304 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_TRANSACT_FAILED); 305 } 306 307 /** 308 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_008 309 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 310 * @tc.type: FUNC 311 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 312 */ 313 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_008, TestSize.Level1) 314 { 315 std::vector<std::shared_ptr<TransientTaskAppInfo>> list; 316 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 317 318 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 319 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_BGTASK_PARCELABLE_FAILED); 320 321 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 322 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 323 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 324 325 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 326 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 327 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 328 329 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 330 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 331 } 332 333 /** 334 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_009 335 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 336 * @tc.type: FUNC 337 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 338 */ 339 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_009, TestSize.Level1) 340 { 341 std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> list; 342 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 343 344 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 345 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_PARCELABLE_FAILED); 346 347 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 348 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 349 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 350 351 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 352 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 353 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 354 355 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 356 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 357 } 358 359 /** 360 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_010 361 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 362 * @tc.type: FUNC 363 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 364 */ 365 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_010, TestSize.Level1) 366 { 367 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 368 369 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 370 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_PARCELABLE_FAILED); 371 372 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 373 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 374 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_PARCELABLE_FAILED); 375 376 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 377 MessageParcelHelper::BgTaskFwkAbnormalSetWriteUint32Flag(false); 378 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_PARCELABLE_FAILED); 379 380 MessageParcelHelper::BgTaskFwkAbnormalSetWriteUint32Flag(true); 381 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 382 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_TRANSACT_FAILED); 383 384 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 385 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 386 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_TRANSACT_FAILED); 387 } 388 389 /** 390 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_011 391 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 392 * @tc.type: FUNC 393 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 394 */ 395 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_011, TestSize.Level1) 396 { 397 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 398 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(nullptr), ERR_BGTASK_INVALID_PARAM); 399 400 sptr<EfficiencyResourceInfo> resourceInfo = new (std::nothrow) EfficiencyResourceInfo(); 401 402 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 403 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_PARCELABLE_FAILED); 404 405 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 406 MessageParcelHelper::BgTaskFwkAbnormalSetWriteParcelableFlag(false); 407 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_PARCELABLE_FAILED); 408 409 MessageParcelHelper::BgTaskFwkAbnormalSetWriteParcelableFlag(true); 410 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 411 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_TRANSACT_FAILED); 412 413 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 414 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 415 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_TRANSACT_FAILED); 416 } 417 418 /** 419 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_012 420 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 421 * @tc.type: FUNC 422 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 423 */ 424 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_012, TestSize.Level1) 425 { 426 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 427 428 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 429 EXPECT_EQ(backgroundTaskMgrProxy.ResetAllEfficiencyResources(), ERR_BGTASK_PARCELABLE_FAILED); 430 431 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 432 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 433 EXPECT_EQ(backgroundTaskMgrProxy.ResetAllEfficiencyResources(), ERR_BGTASK_TRANSACT_FAILED); 434 435 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 436 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 437 EXPECT_EQ(backgroundTaskMgrProxy.ResetAllEfficiencyResources(), ERR_BGTASK_TRANSACT_FAILED); 438 } 439 440 /** 441 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_013 442 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 443 * @tc.type: FUNC 444 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 445 */ 446 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_013, TestSize.Level1) 447 { 448 std::vector<std::shared_ptr<ResourceCallbackInfo>> appList; 449 std::vector<std::shared_ptr<ResourceCallbackInfo>> procList; 450 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 451 452 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 453 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_PARCELABLE_FAILED); 454 455 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 456 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 457 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_TRANSACT_FAILED); 458 459 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 460 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 461 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_TRANSACT_FAILED); 462 463 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 464 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_TRANSACT_FAILED); 465 } 466 467 /** 468 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_014 469 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 470 * @tc.type: FUNC 471 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 472 */ 473 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_014, TestSize.Level1) 474 { 475 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 476 EXPECT_EQ(backgroundTaskMgrProxy.RequestBackgroundRunningForInner(nullptr), ERR_BGTASK_INVALID_PARAM); 477 478 sptr<ContinuousTaskParamForInner> taskParam = sptr<ContinuousTaskParamForInner>(new ContinuousTaskParamForInner()); 479 480 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 481 EXPECT_EQ(backgroundTaskMgrProxy.RequestBackgroundRunningForInner(taskParam), ERR_BGTASK_PARCELABLE_FAILED); 482 483 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 484 MessageParcelHelper::BgTaskFwkAbnormalSetWriteParcelableFlag(false); 485 EXPECT_EQ(backgroundTaskMgrProxy.RequestBackgroundRunningForInner(taskParam), ERR_BGTASK_PARCELABLE_FAILED); 486 487 MessageParcelHelper::BgTaskFwkAbnormalSetWriteParcelableFlag(true); 488 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 489 EXPECT_EQ(backgroundTaskMgrProxy.RequestBackgroundRunningForInner(taskParam), ERR_BGTASK_TRANSACT_FAILED); 490 491 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 492 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 493 EXPECT_EQ(backgroundTaskMgrProxy.RequestBackgroundRunningForInner(taskParam), ERR_BGTASK_TRANSACT_FAILED); 494 } 495 496 /** 497 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_015 498 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 499 * @tc.type: FUNC 500 * @tc.require: issuesI936BL 501 */ 502 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_015, TestSize.Level1) 503 { 504 int32_t uid = -1; 505 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 506 507 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 508 EXPECT_NE(backgroundTaskMgrProxy.PauseTransientTaskTimeForInner(uid), 0); 509 510 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 511 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 512 EXPECT_NE(backgroundTaskMgrProxy.PauseTransientTaskTimeForInner(uid), 0); 513 514 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 515 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 516 EXPECT_NE(backgroundTaskMgrProxy.PauseTransientTaskTimeForInner(uid), 0); 517 518 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 519 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 520 EXPECT_NE(backgroundTaskMgrProxy.PauseTransientTaskTimeForInner(uid), 0); 521 } 522 523 /** 524 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_016 525 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 526 * @tc.type: FUNC 527 * @tc.require: issuesI936BL 528 */ 529 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_016, TestSize.Level1) 530 { 531 int32_t uid = -1; 532 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 533 534 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 535 EXPECT_NE(backgroundTaskMgrProxy.StartTransientTaskTimeForInner(uid), 0); 536 537 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 538 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 539 EXPECT_NE(backgroundTaskMgrProxy.StartTransientTaskTimeForInner(uid), 0); 540 541 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 542 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 543 EXPECT_NE(backgroundTaskMgrProxy.StartTransientTaskTimeForInner(uid), 0); 544 545 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 546 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 547 EXPECT_NE(backgroundTaskMgrProxy.StartTransientTaskTimeForInner(uid), 0); 548 } 549 550 /** 551 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_017 552 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 553 * @tc.type: FUNC 554 * @tc.require: issueIAULHW 555 */ 556 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_017, TestSize.Level1) 557 { 558 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 559 560 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 561 EXPECT_NE(backgroundTaskMgrProxy.SetBgTaskConfig("", 1), 0); 562 563 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 564 MessageParcelHelper::BgTaskFwkAbnormalSetWriteStringFlag(false); 565 EXPECT_NE(backgroundTaskMgrProxy.SetBgTaskConfig("", 1), 0); 566 567 MessageParcelHelper::BgTaskFwkAbnormalSetWriteStringFlag(true); 568 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 569 EXPECT_NE(backgroundTaskMgrProxy.SetBgTaskConfig("", 1), 0); 570 571 MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 572 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 573 EXPECT_NE(backgroundTaskMgrProxy.SetBgTaskConfig("", 1), 0); 574 575 BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 576 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 577 EXPECT_NE(backgroundTaskMgrProxy.SetBgTaskConfig("", 1), 0); 578 } 579 } 580 } 581