1 /*
2 * Copyright (c) 2021-2023 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 "ability_info.h"
23 #include "ability_local_record.h"
24 #include "event_runner.h"
25 #include "fa_ability_thread.h"
26 #include "gtest/gtest.h"
27 #include "mock_ability_test.h"
28 #include "ohos_application.h"
29 namespace OHOS {
30 namespace AppExecFwk {
MockCreateAbilityThread()31 sptr<AppExecFwk::AbilityThread> MockCreateAbilityThread()
32 {
33 sptr<AppExecFwk::AbilityThread> abilitythread(new (std::nothrow) AbilityRuntime::FAAbilityThread());
34 if (abilitythread == nullptr) {
35 GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock abilityhreadptr is nullptr called";
36 return nullptr;
37 }
38
39 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
40 if (application == nullptr) {
41 GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock applicationptr is nullptr called";
42 return nullptr;
43 }
44
45 std::shared_ptr<AbilityInfo> info = std::make_shared<AbilityInfo>();
46 if (info == nullptr) {
47 GTEST_LOG_(INFO) << "mock_ability_thread_for_data_observer:mock AbilityInfo::info is nullptr called";
48 return nullptr;
49 }
50
51 info->name = std::string("MockAbilityTest");
52 info->type = AbilityType::DATA;
53 info->isNativeAbility = true;
54 std::cout << "info->name : " << (*info).name << std::endl;
55
56 sptr<IRemoteObject> token = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
57
58 auto abilityRecord = std::make_shared<AbilityLocalRecord>(info, token, nullptr, 0);
59 std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(info->name);
60
61 abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
62
63 return abilitythread;
64 }
65 } // namespace AppExecFwk
66 } // namespace OHOS
67 #endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_THREAD_FOR_DATA_OBSERVER_H
68