1 /*
2 * Copyright (c) 2024-2024 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 #define private public
18 #define protected public
19 #include "ability_interceptor_executer.h"
20 #undef private
21 #undef protected
22
23 #include "interceptor/crowd_test_interceptor.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27 using namespace OHOS::AppExecFwk;
28
29 namespace OHOS {
30 namespace AAFwk {
31 class AbilityInterceptorThirdTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37
38 public:
39 };
40
SetUpTestCase()41 void AbilityInterceptorThirdTest::SetUpTestCase()
42 {}
43
TearDownTestCase()44 void AbilityInterceptorThirdTest::TearDownTestCase()
45 {}
46
SetUp()47 void AbilityInterceptorThirdTest::SetUp()
48 {}
49
TearDown()50 void AbilityInterceptorThirdTest::TearDown()
51 {}
52
53 /**
54 * @tc.name: AbilityInterceptorThirdTest_RemoveInterceptor_001
55 * @tc.desc: CrowdTestInterceptor
56 * @tc.type: FUNC
57 * @tc.require: No
58 */
59 HWTEST_F(AbilityInterceptorThirdTest, RemoveInterceptor_001, TestSize.Level1)
60 {
61 std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
62 executer->AddInterceptor("CrowdTest", std::make_shared<CrowdTestInterceptor>());
63 auto resMap = executer->GetInterceptorMapCopy();
64 EXPECT_EQ(resMap.size(), 1);
65 executer->RemoveInterceptor("CrowdTest");
66 auto resMap2 = executer->GetInterceptorMapCopy();
67 EXPECT_EQ(resMap2.size(), 0);
68 }
69
70 /**
71 * @tc.name: AbilityInterceptorThirdTest_SetTaskHandler_001
72 * @tc.desc: SetTaskHandler
73 * @tc.type: FUNC
74 * @tc.require: No
75 */
76 HWTEST_F(AbilityInterceptorThirdTest, SetTaskHandler_001, TestSize.Level1)
77 {
78 std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
79 std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler = AAFwk::TaskHandlerWrap::CreateQueueHandler("SetTaskHandler");
80 executer->AddInterceptor("CrowdTest", std::make_shared<CrowdTestInterceptor>());
81 executer->SetTaskHandler(taskHandler);
82 auto resMap2 = executer->GetInterceptorMapCopy();
83 EXPECT_EQ(resMap2.size(), 1);
84 }
85
86 } // namespace AAFwk
87 } // namespace OHOS
88