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