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 "iservice_registry.h" 39 #include "resource_callback_info.h" 40 #include "singleton.h" 41 #include "transient_task_app_info.h" 42 43 using namespace testing::ext; 44 45 namespace OHOS { 46 extern void BgTaskFwkAbnormalSetWriteRemoteObjectFlag(bool flag); 47 extern void BgTaskFwkAbnormalSetWriteReadRemoteObjectFlag(bool flag); 48 extern void BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(bool flag); 49 extern void BgTaskFwkAbnormalSetReadInterfaceTokenFlag(bool flag); 50 extern void BgTaskFwkAbnormalSetWriteString16Flag(bool flag); 51 extern void BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(bool flag); 52 extern void BgTaskFwkAbnormalSetWriteInt32WithParamFlag(bool flag); 53 extern void BgTaskFwkAbnormalSetWriteParcelableFlag(bool flag); 54 extern void BgTaskFwkAbnormalSetWriteStringFlag(bool flag); 55 extern void BgTaskFwkAbnormalSetWriteUint32Flag(bool flag); 56 extern void BgTaskFwkAbnormalSetReadInt32Flag(bool flag); 57 58 namespace BackgroundTaskMgr { 59 extern void BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(int32_t flag); 60 61 class BgTaskFrameworkAbnormalUnitTest : public testing::Test { 62 public: SetUpTestCase()63 static void SetUpTestCase() {} TearDownTestCase()64 static void TearDownTestCase() {} SetUp()65 void SetUp() override {} TearDown()66 void TearDown() override {} 67 }; 68 69 class TestExpiredCallback : public ExpiredCallback { 70 public: OnExpired()71 void OnExpired() override {} 72 }; 73 74 class TestBackgroundTaskSubscriber : public BackgroundTaskSubscriber {}; 75 76 class TestBackgroundTaskSubscriberStub : public BackgroundTaskSubscriberStub { OnConnected()77 void OnConnected() override {} OnDisconnected()78 void OnDisconnected() override {} OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo> & info)79 void OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo> & info)80 void OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo> & info)81 void OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo> & info)82 void OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override {} OnContinuousTaskStart(const std::shared_ptr<ContinuousTaskCallbackInfo> & continuousTaskCallbackInfo)83 void OnContinuousTaskStart( 84 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override {} OnContinuousTaskStop(const std::shared_ptr<ContinuousTaskCallbackInfo> & continuousTaskCallbackInfo)85 void OnContinuousTaskStop( 86 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override {} OnAppContinuousTaskStop(int32_t uid)87 void OnAppContinuousTaskStop(int32_t uid) override {} OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)88 void OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)89 void OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)90 void OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> & resourceInfo)91 void OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override {} 92 }; 93 94 class TestExpiredCallbackStub : public ExpiredCallbackStub { 95 public: OnExpired()96 void OnExpired() override {} 97 }; 98 99 /** 100 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_001 101 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 102 * @tc.type: FUNC 103 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 104 */ 105 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_001, TestSize.Level1) 106 { 107 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 108 std::shared_ptr<DelaySuspendInfo> delayInfo = std::make_shared<DelaySuspendInfo>(); 109 sptr<TestExpiredCallbackStub> expiredCallbackStub = sptr<TestExpiredCallbackStub>(new TestExpiredCallbackStub()); 110 111 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", nullptr, delayInfo), 112 ERR_CALLBACK_NULL_OR_TYPE_ERR); 113 114 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 115 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 116 ERR_BGTASK_PARCELABLE_FAILED); 117 118 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 119 BgTaskFwkAbnormalSetWriteString16Flag(false); 120 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 121 ERR_BGTASK_PARCELABLE_FAILED); 122 123 BgTaskFwkAbnormalSetWriteString16Flag(true); 124 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 125 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 126 ERR_BGTASK_PARCELABLE_FAILED); 127 128 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 129 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 130 ERR_BGTASK_TRANSACT_FAILED); 131 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 132 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 133 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 134 ERR_BGTASK_PARCELABLE_FAILED); 135 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 136 EXPECT_EQ(backgroundTaskMgrProxy.RequestSuspendDelay(u"reason", expiredCallbackStub, delayInfo), 137 ERR_OK); 138 } 139 140 /** 141 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_002 142 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 143 * @tc.type: FUNC 144 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 145 */ 146 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_002, TestSize.Level1) 147 { 148 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 149 150 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 151 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_PARCELABLE_FAILED); 152 153 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 154 BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 155 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_PARCELABLE_FAILED); 156 157 BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 158 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 159 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_TRANSACT_FAILED); 160 161 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 162 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 163 EXPECT_EQ(backgroundTaskMgrProxy.CancelSuspendDelay(1), ERR_BGTASK_PARCELABLE_FAILED); 164 } 165 166 /** 167 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_003 168 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 169 * @tc.type: FUNC 170 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 171 */ 172 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_003, TestSize.Level1) 173 { 174 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 175 int32_t delayTime; 176 177 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 178 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_PARCELABLE_FAILED); 179 180 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 181 BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 182 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_PARCELABLE_FAILED); 183 184 BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 185 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 186 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_TRANSACT_FAILED); 187 188 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 189 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 190 EXPECT_EQ(backgroundTaskMgrProxy.GetRemainingDelayTime(1, delayTime), ERR_BGTASK_PARCELABLE_FAILED); 191 } 192 193 /** 194 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_004 195 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 196 * @tc.type: FUNC 197 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 198 */ 199 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_004, TestSize.Level1) 200 { 201 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 202 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(nullptr), ERR_BGTASK_INVALID_PARAM); 203 204 sptr<ContinuousTaskParam> taskParam = sptr<ContinuousTaskParam>(new ContinuousTaskParam()); 205 206 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 207 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_PARCELABLE_FAILED); 208 209 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 210 BgTaskFwkAbnormalSetWriteParcelableFlag(false); 211 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_PARCELABLE_FAILED); 212 213 BgTaskFwkAbnormalSetWriteParcelableFlag(true); 214 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 215 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_TRANSACT_FAILED); 216 217 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 218 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 219 EXPECT_EQ(backgroundTaskMgrProxy.StartBackgroundRunning(taskParam), ERR_BGTASK_PARCELABLE_FAILED); 220 } 221 222 /** 223 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_005 224 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 225 * @tc.type: FUNC 226 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 227 */ 228 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_005, TestSize.Level1) 229 { 230 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 231 232 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 233 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr), ERR_BGTASK_PARCELABLE_FAILED); 234 235 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 236 BgTaskFwkAbnormalSetWriteStringFlag(false); 237 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr), ERR_BGTASK_PARCELABLE_FAILED); 238 239 BgTaskFwkAbnormalSetWriteStringFlag(true); 240 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 241 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr), ERR_BGTASK_PARCELABLE_FAILED); 242 243 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 244 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 245 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr), ERR_BGTASK_TRANSACT_FAILED); 246 247 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 248 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 249 EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr), ERR_BGTASK_PARCELABLE_FAILED); 250 } 251 252 /** 253 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_006 254 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 255 * @tc.type: FUNC 256 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 257 */ 258 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_006, TestSize.Level1) 259 { 260 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 261 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(nullptr), ERR_BGTASK_PARCELABLE_FAILED); 262 263 sptr<TestBackgroundTaskSubscriberStub> subscribe = 264 sptr<TestBackgroundTaskSubscriberStub>(new TestBackgroundTaskSubscriberStub()); 265 266 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 267 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 268 269 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 270 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 271 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 272 273 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 274 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 275 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_TRANSACT_FAILED); 276 277 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 278 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 279 EXPECT_EQ(backgroundTaskMgrProxy.SubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 280 } 281 282 /** 283 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_007 284 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 285 * @tc.type: FUNC 286 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 287 */ 288 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_007, TestSize.Level1) 289 { 290 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 291 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(nullptr), ERR_BGTASK_PARCELABLE_FAILED); 292 293 sptr<TestBackgroundTaskSubscriberStub> subscribe = 294 sptr<TestBackgroundTaskSubscriberStub>(new TestBackgroundTaskSubscriberStub()); 295 296 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 297 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 298 299 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 300 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); 301 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 302 303 BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); 304 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 305 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_TRANSACT_FAILED); 306 307 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 308 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 309 EXPECT_EQ(backgroundTaskMgrProxy.UnsubscribeBackgroundTask(subscribe), ERR_BGTASK_PARCELABLE_FAILED); 310 } 311 312 /** 313 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_008 314 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 315 * @tc.type: FUNC 316 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 317 */ 318 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_008, TestSize.Level1) 319 { 320 std::vector<std::shared_ptr<TransientTaskAppInfo>> list; 321 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 322 323 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 324 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_BGTASK_PARCELABLE_FAILED); 325 326 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 327 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 328 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 329 330 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 331 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 332 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_BGTASK_PARCELABLE_FAILED); 333 334 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 335 EXPECT_EQ(backgroundTaskMgrProxy.GetTransientTaskApps(list), ERR_OK); 336 } 337 338 /** 339 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_009 340 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 341 * @tc.type: FUNC 342 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 343 */ 344 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_009, TestSize.Level1) 345 { 346 std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> list; 347 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 348 349 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 350 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_PARCELABLE_FAILED); 351 352 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 353 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 354 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_TRANSACT_FAILED); 355 356 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 357 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 358 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_PARCELABLE_FAILED); 359 360 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 361 EXPECT_EQ(backgroundTaskMgrProxy.GetContinuousTaskApps(list), ERR_BGTASK_PARCELABLE_FAILED); 362 } 363 364 /** 365 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_010 366 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 367 * @tc.type: FUNC 368 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 369 */ 370 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_010, TestSize.Level1) 371 { 372 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 373 374 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 375 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_PARCELABLE_FAILED); 376 377 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 378 BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); 379 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_PARCELABLE_FAILED); 380 381 BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); 382 BgTaskFwkAbnormalSetWriteUint32Flag(false); 383 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_PARCELABLE_FAILED); 384 385 BgTaskFwkAbnormalSetWriteUint32Flag(true); 386 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 387 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_TRANSACT_FAILED); 388 389 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 390 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 391 EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_PARCELABLE_FAILED); 392 } 393 394 /** 395 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_011 396 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 397 * @tc.type: FUNC 398 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 399 */ 400 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_011, TestSize.Level1) 401 { 402 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 403 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(nullptr), ERR_BGTASK_INVALID_PARAM); 404 405 sptr<EfficiencyResourceInfo> resourceInfo = new (std::nothrow) EfficiencyResourceInfo(); 406 407 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 408 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_PARCELABLE_FAILED); 409 410 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 411 BgTaskFwkAbnormalSetWriteParcelableFlag(false); 412 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_PARCELABLE_FAILED); 413 414 BgTaskFwkAbnormalSetWriteParcelableFlag(true); 415 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 416 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_TRANSACT_FAILED); 417 418 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 419 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 420 EXPECT_EQ(backgroundTaskMgrProxy.ApplyEfficiencyResources(resourceInfo), ERR_BGTASK_PARCELABLE_FAILED); 421 } 422 423 /** 424 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_012 425 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 426 * @tc.type: FUNC 427 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 428 */ 429 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_012, TestSize.Level1) 430 { 431 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 432 433 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 434 EXPECT_EQ(backgroundTaskMgrProxy.ResetAllEfficiencyResources(), ERR_BGTASK_PARCELABLE_FAILED); 435 436 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 437 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 438 EXPECT_EQ(backgroundTaskMgrProxy.ResetAllEfficiencyResources(), ERR_BGTASK_TRANSACT_FAILED); 439 440 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 441 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 442 EXPECT_EQ(backgroundTaskMgrProxy.ResetAllEfficiencyResources(), ERR_BGTASK_PARCELABLE_FAILED); 443 } 444 445 /** 446 * @tc.name: BackgroundTaskMgrProxyAbnormalTest_013 447 * @tc.desc: test BackgroundTaskMgrProxy abnormal. 448 * @tc.type: FUNC 449 * @tc.require: issuesI5OD7X issueI5IRJK issueI4QT3W issueI4QU0V 450 */ 451 HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_013, TestSize.Level1) 452 { 453 std::vector<std::shared_ptr<ResourceCallbackInfo>> appList; 454 std::vector<std::shared_ptr<ResourceCallbackInfo>> procList; 455 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); 456 457 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); 458 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_PARCELABLE_FAILED); 459 460 BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); 461 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); 462 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_TRANSACT_FAILED); 463 464 BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); 465 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); 466 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_PARCELABLE_FAILED); 467 468 BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(true); 469 EXPECT_EQ(backgroundTaskMgrProxy.GetEfficiencyResourcesInfos(appList, procList), ERR_BGTASK_PARCELABLE_FAILED); 470 } 471 } 472 } 473