• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "app_mgr_util.h"
18 #include "want_utils.h"
19 #include "hilog_tag_wrapper.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace AAFwk {
26 constexpr uint32_t InitTargetType = 100;
27 class WantUtilsTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void WantUtilsTest::SetUpTestCase() {}
36 
TearDownTestCase()37 void WantUtilsTest::TearDownTestCase() {}
38 
SetUp()39 void WantUtilsTest::SetUp() {}
40 
TearDown()41 void WantUtilsTest::TearDown() {}
42 
43 /*
44  * Feature: WantUtilsTest
45  * Function: ConvertToExplicitWant
46  * SubFunction: NA
47  * FunctionPoints: AbilityManagerService ConvertToExplicitWant
48  */
49 HWTEST_F(WantUtilsTest, ConvertToExplicitWant_001, TestSize.Level1)
50 {
51     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_001 start");
52     Want want;
53     want.SetUri("a_short_atomic_service_uri");
54     auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
55     EXPECT_NE(client, nullptr);
56     AppDomainVerify::AppDomainVerifyMgrClient::convertResultCode_ = 0;
57     AppDomainVerify::AppDomainVerifyMgrClient::
58         convertTargetInfo_.targetWant.SetElementName("short_bundle", "short_ability");
59     AppDomainVerify::AppDomainVerifyMgrClient::convertTargetInfo_.targetType = AppDomainVerify::TargetType::APP;
60     uint32_t targetType = InitTargetType;
61     auto errCode = WantUtils::ConvertToExplicitWant(want, targetType);
62     auto bundle = want.GetElement().GetBundleName();
63     auto ability = want.GetElement().GetAbilityName();
64     EXPECT_EQ(errCode, 0);
65     EXPECT_EQ(bundle, "short_bundle");
66     EXPECT_EQ(ability, "short_ability");
67     EXPECT_EQ(targetType, AppDomainVerify::TargetType::APP);
68     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_001 end");
69 }
70 
71 /*
72  * Feature: WantUtilsTest
73  * Function: ConvertToExplicitWant
74  * SubFunction: NA
75  * FunctionPoints: AbilityManagerService ConvertToExplicitWant
76  */
77 HWTEST_F(WantUtilsTest, ConvertToExplicitWant_002, TestSize.Level1)
78 {
79     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_002 start");
80     Want want;
81     want.SetUri("a_short_atomic_service_uri");
82     auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
83     EXPECT_NE(client, nullptr);
84     uint32_t targetType = InitTargetType;
85     AppDomainVerify::AppDomainVerifyMgrClient::convertResultCode_ = -1;
86     auto errCode = WantUtils::ConvertToExplicitWant(want, targetType);
87     EXPECT_EQ(errCode, -1);
88     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_002 end");
89 }
90 
91 /*
92  * Feature: WantUtilsTest
93  * Function: ConvertToExplicitWant
94  * SubFunction: NA
95  * FunctionPoints: AbilityManagerService ConvertToExplicitWant
96  */
97 HWTEST_F(WantUtilsTest, ConvertToExplicitWant_003, TestSize.Level1)
98 {
99     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_003 start");
100     Want want;
101     want.SetUri("a_short_atomic_service_uri");
102     auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
103     EXPECT_NE(client, nullptr);
104     uint32_t targetType = InitTargetType;
105     AppDomainVerify::AppDomainVerifyMgrClient::convertResultCode_ = ERR_TIMED_OUT;
106     auto errCode = WantUtils::ConvertToExplicitWant(want, targetType);
107     EXPECT_EQ(errCode, ERR_TIMED_OUT);
108     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_003 end");
109 }
110 
111 /*
112  * Feature: WantUtilsTest
113  * Function: IsShortUrl
114  * SubFunction: NA
115  * FunctionPoints: AbilityManagerService IsShortUrl
116  */
117 HWTEST_F(WantUtilsTest, IsShortUrl_001, TestSize.Level1)
118 {
119     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsShortUrl_001 start");
120     Want want;
121     want.SetUri("not_a_short_atomic_service_uri");
122     auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
123     EXPECT_NE(client, nullptr);
124     AppDomainVerify::AppDomainVerifyMgrClient::isShortUrlFlag_ = false;
125     auto result = WantUtils::IsShortUrl(want);
126     EXPECT_EQ(result, false);
127     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsShortUrl_001 end");
128 }
129 
130 /*
131  * Feature: WantUtilsTest
132  * Function: IsShortUrl
133  * SubFunction: NA
134  * FunctionPoints: AbilityManagerService IsShortUrl
135  */
136 HWTEST_F(WantUtilsTest, IsShortUrl_002, TestSize.Level1)
137 {
138     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsShortUrl_002 start");
139     Want want;
140     want.SetUri("a_short_atomic_service_uri");
141     auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
142     EXPECT_NE(client, nullptr);
143     AppDomainVerify::AppDomainVerifyMgrClient::isShortUrlFlag_ = true;
144     auto result = WantUtils::IsShortUrl(want);
145     EXPECT_EQ(result, true);
146     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsShortUrl_002 end");
147 }
148 
149 /*
150  * Feature: WantUtilsTest
151  * Function: GetCallerBundleName
152  * SubFunction: NA
153  * FunctionPoints: AbilityManagerService GetCallerBundleName
154  */
155 HWTEST_F(WantUtilsTest, GetCallerBundleName_001, TestSize.Level1)
156 {
157     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest GetCallerBundleName_001 start");
158     std::string callerBundleName;
159     auto errCode = WantUtils::GetCallerBundleName(callerBundleName);
160     EXPECT_NE(errCode, 0);
161     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest GetCallerBundleName_001 end");
162 }
163 
164 /*
165  * Feature: WantUtilsTest
166  * Function: IsAtomicService
167  * SubFunction: NA
168  * FunctionPoints: AbilityManagerService IsAtomicService true
169  */
170 HWTEST_F(WantUtilsTest, IsAtomicService_001, TestSize.Level1)
171 {
172     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicService_001 start");
173     std::string callerBundleName;
174     uint32_t targetType = 0;
175     auto result = WantUtils::IsAtomicService(targetType);
176     EXPECT_EQ(result, true);
177     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicService_001 end");
178 }
179 
180 /*
181  * Feature: WantUtilsTest
182  * Function: IsAtomicService
183  * SubFunction: NA
184  * FunctionPoints: AbilityManagerService IsAtomicService false
185  */
186 HWTEST_F(WantUtilsTest, IsAtomicService_002, TestSize.Level1)
187 {
188     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicService_002 start");
189     std::string callerBundleName;
190     uint32_t targetType = 1;
191     auto result = WantUtils::IsAtomicService(targetType);
192     EXPECT_EQ(result, false);
193     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicService_002 end");
194 }
195 
196 /*
197  * Feature: WantUtilsTest
198  * Function: IsNormalApp
199  * SubFunction: NA
200  * FunctionPoints: AbilityManagerService IsNormalApp true
201  */
202 HWTEST_F(WantUtilsTest, IsNormalApp_001, TestSize.Level1)
203 {
204     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsNormalApp_001 start");
205     std::string callerBundleName;
206     uint32_t targetType = 1;
207     auto result = WantUtils::IsNormalApp(targetType);
208     EXPECT_EQ(result, true);
209     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsNormalApp_001 end");
210 }
211 
212 /*
213  * Feature: WantUtilsTest
214  * Function: IsNormalApp
215  * SubFunction: NA
216  * FunctionPoints: AbilityManagerService IsNormalApp false
217  */
218 HWTEST_F(WantUtilsTest, IsNormalApp_002, TestSize.Level1)
219 {
220     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsNormalApp_002 start");
221     std::string callerBundleName;
222     uint32_t targetType = 0;
223     auto result = WantUtils::IsNormalApp(targetType);
224     EXPECT_EQ(result, false);
225     TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsNormalApp_002 end");
226 }
227 } // namespace AAFwk
228 } // namespace OHOS
229