1 /*
2 * Copyright (c) 2022-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 #include <functional>
17 #include <gtest/gtest.h>
18 #define private public
19 #include "ability_handler.h"
20 #include "fa_ability_thread.h"
21 #define protected public
22 #include "sys_mgr_client.h"
23 #include "system_ability_definition.h"
24
25 namespace OHOS {
26 namespace AppExecFwk {
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::AppExecFwk;
30 class CurrentAbilityTest : public Ability {
31 public:
CallRequest()32 sptr<IRemoteObject> CallRequest()
33 {
34 sptr<IRemoteObject> remoteObject =
35 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
36 return remoteObject;
37 }
38 };
39
40 class AbilityThreadCallRequestTest : public testing::Test {
41 public:
AbilityThreadCallRequestTest()42 AbilityThreadCallRequestTest() : abilitythread_(nullptr)
43 {}
~AbilityThreadCallRequestTest()44 ~AbilityThreadCallRequestTest()
45 {
46 abilitythread_ = nullptr;
47 }
48 AbilityThread* abilitythread_;
49 static void SetUpTestCase(void);
50 static void TearDownTestCase(void);
51 void SetUp();
52 void TearDown();
53 };
54
SetUpTestCase(void)55 void AbilityThreadCallRequestTest::SetUpTestCase(void)
56 {}
57
TearDownTestCase(void)58 void AbilityThreadCallRequestTest::TearDownTestCase(void)
59 {}
60
SetUp(void)61 void AbilityThreadCallRequestTest::SetUp(void)
62 {
63 GTEST_LOG_(INFO) << "AbilityThreadCallRequestTest SetUp";
64 }
65
TearDown(void)66 void AbilityThreadCallRequestTest::TearDown(void)
67 {
68 GTEST_LOG_(INFO) << "AbilityThreadCallRequestTest TearDown";
69 }
70
71
72 /**
73 * @tc.number: AaFwk_AbilityThread_CallRequest_0100
74 * @tc.name: CallRequest
75 * @tc.desc: CallRequest success
76 */
77 HWTEST_F(AbilityThreadCallRequestTest, AaFwk_AbilityThread_CallRequest_0100, Function | MediumTest | Level3)
78 {
79 GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CallRequest_0100 start";
80
81 AbilityRuntime::FAAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::FAAbilityThread();
82 EXPECT_NE(abilitythread, nullptr);
83 if (abilitythread != nullptr) {
84 abilitythread->currentAbility_ = std::make_shared<CurrentAbilityTest>();
85 EXPECT_NE(abilitythread->currentAbility_, nullptr);
86 auto runner = EventRunner::Create(true);
87 abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(runner);
88 EXPECT_NE(abilitythread->abilityHandler_, nullptr);
89 abilitythread->CallRequest();
90 }
91 GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CallRequest_0100 end";
92 }
93
94 /**
95 * @tc.number: AaFwk_AbilityThread_CallRequest_0200
96 * @tc.name: CallRequest
97 * @tc.desc: CallRequest success fail because currentAbility_ is null
98 */
99 HWTEST_F(AbilityThreadCallRequestTest, AaFwk_AbilityThread_CallRequest_0200, Function | MediumTest | Level3)
100 {
101 GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CallRequest_0200 start";
102 AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::FAAbilityThread();
103 abilitythread->CallRequest();
104 GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CallRequest_0200 end";
105 }
106
107 /**
108 * @tc.number: AaFwk_AbilityThread_CallRequest_0300
109 * @tc.name: CallRequest
110 * @tc.desc: CallRequest success fail because abilityHandler_ is null
111 */
112 HWTEST_F(AbilityThreadCallRequestTest, AaFwk_AbilityThread_CallRequest_0300, Function | MediumTest | Level3)
113 {
114 GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CallRequest_0300 start";
115
116 AbilityRuntime::FAAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::FAAbilityThread();
117 EXPECT_NE(abilitythread, nullptr);
118 if (abilitythread != nullptr) {
119 abilitythread->currentAbility_ = std::make_shared<CurrentAbilityTest>();
120 EXPECT_NE(abilitythread->currentAbility_, nullptr);
121 abilitythread->CallRequest();
122 }
123 GTEST_LOG_(INFO) << "AaFwk_AbilityThread_CallRequest_0300 end";
124 }
125 } // namespace AppExecFwk
126 } // namespace OHOS
127