• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "ecological_rule/ability_ecological_rule_mgr_service_param.h"
18 #include "interceptor/ecological_rule_interceptor.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 using namespace OHOS::AppExecFwk;
23 using ErmsCallerInfo = OHOS::EcologicalRuleMgrService::AbilityCallerInfo;
24 
25 namespace OHOS {
26 namespace AAFwk {
27 class EcologicalRuleInterceptorTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void EcologicalRuleInterceptorTest::SetUpTestCase()
36 {}
37 
TearDownTestCase()38 void EcologicalRuleInterceptorTest::TearDownTestCase()
39 {}
40 
SetUp()41 void EcologicalRuleInterceptorTest::SetUp()
42 {}
43 
TearDown()44 void EcologicalRuleInterceptorTest::TearDown()
45 {}
46 
47 /**
48  * @tc.name: EcologicalRuleInterceptorTest_GetAppTypeByBundleType_001
49  * @tc.desc: GetAppTypeByBundleType
50  * @tc.type: FUNC
51  * @tc.require: No
52  */
53 HWTEST_F(EcologicalRuleInterceptorTest, EcologicalRuleInterceptorTest_GetAppTypeByBundleType_001, TestSize.Level1)
54 {
55     int32_t bundleType = static_cast<int32_t>(AppExecFwk::BundleType::ATOMIC_SERVICE);
56     auto result = EcologicalRuleInterceptor::GetAppTypeByBundleType(bundleType);
57     EXPECT_EQ(result, ErmsCallerInfo::TYPE_ATOM_SERVICE);
58 }
59 
60 /**
61  * @tc.name: EcologicalRuleInterceptorTest_GetAppTypeByBundleType_002
62  * @tc.desc: GetAppTypeByBundleType
63  * @tc.type: FUNC
64  * @tc.require: No
65  */
66 HWTEST_F(EcologicalRuleInterceptorTest, EcologicalRuleInterceptorTest_GetAppTypeByBundleType_002, TestSize.Level1)
67 {
68     int32_t bundleType = static_cast<int32_t>(AppExecFwk::BundleType::APP);
69     auto result = EcologicalRuleInterceptor::GetAppTypeByBundleType(bundleType);
70     EXPECT_EQ(result, ErmsCallerInfo::TYPE_HARMONY_APP);
71 }
72 
73 /**
74  * @tc.name: EcologicalRuleInterceptorTest_GetAppTypeByBundleType_003
75  * @tc.desc: GetAppTypeByBundleType
76  * @tc.type: FUNC
77  * @tc.require: No
78  */
79 HWTEST_F(EcologicalRuleInterceptorTest, EcologicalRuleInterceptorTest_GetAppTypeByBundleType_003, TestSize.Level1)
80 {
81     int32_t bundleType = static_cast<int32_t>(AppExecFwk::BundleType::APP_SERVICE_FWK);
82     auto result = EcologicalRuleInterceptor::GetAppTypeByBundleType(bundleType);
83     EXPECT_EQ(result, ErmsCallerInfo::TYPE_APP_SERVICE);
84 }
85 
86 /**
87  * @tc.name: EcologicalRuleInterceptorTest_GetAppTypeByBundleType_004
88  * @tc.desc: GetAppTypeByBundleType
89  * @tc.type: FUNC
90  * @tc.require: No
91  */
92 HWTEST_F(EcologicalRuleInterceptorTest, EcologicalRuleInterceptorTest_GetAppTypeByBundleType_004, TestSize.Level1)
93 {
94     int32_t bundleType = static_cast<int32_t>(-1);
95     auto result = EcologicalRuleInterceptor::GetAppTypeByBundleType(bundleType);
96     EXPECT_EQ(result, ErmsCallerInfo::TYPE_INVALID);
97 }
98 
99 } // namespace AAFwk
100 } // namespace OHOS
101