• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_THREAD_FOR_DATA_OBSERVER_H
17 #define MOCK_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_THREAD_FOR_DATA_OBSERVER_H
18 
19 #include <iostream>
20 #include <memory>
21 
22 #include "gtest/gtest.h"
23 
24 #include "mock_ability_test.h"
25 #include "ohos_application.h"
26 #include "ability_thread.h"
27 #include "event_runner.h"
28 #include "ability_info.h"
29 #include "ability_local_record.h"
30 #include <iostream> //
31 namespace OHOS {
32 namespace AppExecFwk {
MockCreateAbilityThread()33 sptr<AppExecFwk::AbilityThread> MockCreateAbilityThread()
34 {
35     sptr<AppExecFwk::AbilityThread> abilitythread(new (std::nothrow) AppExecFwk::AbilityThread());
36     if (abilitythread == nullptr) {
37         GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock abilityhreadptr is nullptr called";
38         return nullptr;
39     }
40 
41     std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
42     if (application == nullptr) {
43         GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock applicationptr is nullptr called";
44         return nullptr;
45     }
46 
47     std::shared_ptr<AbilityInfo> info = std::make_shared<AbilityInfo>();
48     if (info == nullptr) {
49         GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock AbilityInfo::info is nullptr called";
50         return nullptr;
51     }
52 
53     info->name = std::string("MockAbilityTest");
54     info->type = AbilityType::DATA;
55     info->isNativeAbility = true;
56     std::cout << "info->name : " << (*info).name <<std::endl;
57 
58     sptr<IRemoteObject> token = sptr<IRemoteObject>(new AbilityThread());
59 
60     std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(info, token);
61     std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(info->name);
62 
63     abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
64 
65     return abilitythread;
66 }
67 }  // namespace AppExecFwk
68 }  // namespace OHOS
69 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_THREAD_FOR_DATA_OBSERVER_H
70