1 /*
2  * Copyright (c) 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 <gtest/gtest.h>
17 #include "system_ability_definition.h"
18 #include "ecological_rule_mgr_service_client.h"
19 #include "ecological_rule_mgr_service.h"
20 
21 namespace OHOS {
22 namespace EcologicalRuleMgrService {
23 using namespace testing::ext;
24 
25 class EcologicalRuleMgrServiceClientTest : public testing::Test {
26 public:
EcologicalRuleMgrServiceClientTest()27     EcologicalRuleMgrServiceClientTest() {}
~EcologicalRuleMgrServiceClientTest()28     ~EcologicalRuleMgrServiceClientTest() {}
29 
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 
35 protected:
36     sptr<EcologicalRuleMgrServiceClient> ecologicalRuleMgrServiceClient;
37 };
38 
SetUpTestCase(void)39 void EcologicalRuleMgrServiceClientTest::SetUpTestCase(void) {}
40 
TearDownTestCase(void)41 void EcologicalRuleMgrServiceClientTest::TearDownTestCase(void) {}
42 
SetUp()43 void EcologicalRuleMgrServiceClientTest::SetUp()
44 {
45     ecologicalRuleMgrServiceClient = OHOS::EcologicalRuleMgrService::EcologicalRuleMgrServiceClient::GetInstance();
46 }
47 
TearDown()48 void EcologicalRuleMgrServiceClientTest::TearDown()
49 {
50     ecologicalRuleMgrServiceClient = nullptr;
51 }
52 
53 HWTEST_F(EcologicalRuleMgrServiceClientTest, QueryFreeInstallExperience_Test, TestSize.Level1)
54 {
55     GTEST_LOG_(INFO) << "QueryFreeInstallExperience_Test1 start";
56     Want want;
57     want.SetBundle("com.myapplication.demo");
58     CallerInfo callerInfo;
59     callerInfo.packageName = "com.myapplication.test";
60     callerInfo.callerAppType = CallerInfo::TYPE_HARMONY_APP;
61     callerInfo.targetAppType = CallerInfo::TYPE_ATOM_SERVICE;
62     ExperienceRule rule;
63 
64     int32_t res = ecologicalRuleMgrServiceClient->QueryFreeInstallExperience(want, callerInfo, rule);
65     ASSERT_EQ(OHOS::EcologicalRuleMgrService::ReturnCode::SUCCESS, res);
66     GTEST_LOG_(INFO) << "QueryFreeInstallExperience_Test1 end";
67 }
68 
69 HWTEST_F(EcologicalRuleMgrServiceClientTest, QueryStartExperience_Test, TestSize.Level1)
70 {
71     GTEST_LOG_(INFO) << "QueryStartExperience_Test1 start";
72     Want want;
73     want.SetBundle("com.myapplication.demo");
74     CallerInfo callerInfo;
75     callerInfo.packageName = "com.myapplication.test";
76     callerInfo.callerAppType = CallerInfo::TYPE_HARMONY_APP;
77     callerInfo.targetAppType = CallerInfo::TYPE_ATOM_SERVICE;
78     ExperienceRule rule;
79 
80     int32_t res = ecologicalRuleMgrServiceClient->QueryStartExperience(want, callerInfo, rule);
81     ASSERT_EQ(OHOS::EcologicalRuleMgrService::ReturnCode::SUCCESS, res);
82     GTEST_LOG_(INFO) << "QueryStartExperience_Test1 end";
83 }
84 
85 HWTEST_F(EcologicalRuleMgrServiceClientTest, IsSupportPublishForm_Test, TestSize.Level1)
86 {
87     GTEST_LOG_(INFO) << "IsSupportPublishForm_Test start";
88     Want want;
89     want.SetBundle("com.myapplication.demo");
90     std::vector<Want> wants;
91     wants.push_back(want);
92     CallerInfo callerInfo;
93     callerInfo.packageName = "com.myapplication.test";
94     bool bSupport;
95 
96     int32_t res = ecologicalRuleMgrServiceClient->IsSupportPublishForm(wants, callerInfo, bSupport);
97     ASSERT_EQ(OHOS::EcologicalRuleMgrService::ReturnCode::SUCCESS, res);
98     GTEST_LOG_(INFO) << "IsSupportPublishForm_Test end";
99 }
100 
101 HWTEST_F(EcologicalRuleMgrServiceClientTest, EvaluateResolveInfos_Test, TestSize.Level1)
102 {
103     GTEST_LOG_(INFO) << "EvaluateResolveInfos_Test start";
104     Want want;
105     want.SetBundle("com.myapplication.demo");
106 
107     CallerInfo callerInfo;
108     int32_t type = 1;
109 
110     vector<AbilityInfo> abilityInfos;
111     AbilityInfo abilityInfo;
112     abilityInfos.push_back(abilityInfo);
113 
114     vector<ExtensionAbilityInfo> extInfos;
115     ExtensionAbilityInfo extInfo;
116     extInfos.push_back(extInfo);
117 
118     int32_t res = ecologicalRuleMgrServiceClient->EvaluateResolveInfos(want, callerInfo, type, abilityInfos, extInfos);
119     ASSERT_EQ(OHOS::EcologicalRuleMgrService::ReturnCode::SUCCESS, res);
120     GTEST_LOG_(INFO) << "EvaluateResolveInfos_Test end";
121 }
122 }
123 }