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 class WantUtilsTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp();
31 void TearDown();
32 };
33
SetUpTestCase()34 void WantUtilsTest::SetUpTestCase() {}
35
TearDownTestCase()36 void WantUtilsTest::TearDownTestCase() {}
37
SetUp()38 void WantUtilsTest::SetUp() {}
39
TearDown()40 void WantUtilsTest::TearDown() {}
41
42 /*
43 * Feature: WantUtilsTest
44 * Function: ConvertToExplicitWant
45 * SubFunction: NA
46 * FunctionPoints: AbilityManagerService ConvertToExplicitWant
47 */
HWTEST_F(WantUtilsTest, ConvertToExplicitWant_001, TestSize.Level1)48 HWTEST_F(WantUtilsTest, ConvertToExplicitWant_001, TestSize.Level1)
49 {
50 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_001 start");
51 Want want;
52 want.SetUri("a_short_atomic_service_uri");
53 auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
54 EXPECT_NE(client, nullptr);
55 AppDomainVerify::AppDomainVerifyMgrClient::convertResultCode_ = 0;
56 AppDomainVerify::AppDomainVerifyMgrClient::explicitWant_.SetElementName("short_bundle", "short_ability");
57 auto errCode = WantUtils::ConvertToExplicitWant(want);
58 auto bundle = want.GetElement().GetBundleName();
59 auto ability = want.GetElement().GetAbilityName();
60 EXPECT_EQ(errCode, 0);
61 EXPECT_EQ(bundle, "short_bundle");
62 EXPECT_EQ(ability, "short_ability");
63 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_001 end");
64 }
65
66 /*
67 * Feature: WantUtilsTest
68 * Function: ConvertToExplicitWant
69 * SubFunction: NA
70 * FunctionPoints: AbilityManagerService ConvertToExplicitWant
71 */
HWTEST_F(WantUtilsTest, ConvertToExplicitWant_002, TestSize.Level1)72 HWTEST_F(WantUtilsTest, ConvertToExplicitWant_002, TestSize.Level1)
73 {
74 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_002 start");
75 Want want;
76 want.SetUri("a_short_atomic_service_uri");
77 auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
78 EXPECT_NE(client, nullptr);
79 AppDomainVerify::AppDomainVerifyMgrClient::convertResultCode_ = -1;
80 auto errCode = WantUtils::ConvertToExplicitWant(want);
81 EXPECT_EQ(errCode, -1);
82 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_002 end");
83 }
84
85 /*
86 * Feature: WantUtilsTest
87 * Function: ConvertToExplicitWant
88 * SubFunction: NA
89 * FunctionPoints: AbilityManagerService ConvertToExplicitWant
90 */
HWTEST_F(WantUtilsTest, ConvertToExplicitWant_003, TestSize.Level1)91 HWTEST_F(WantUtilsTest, ConvertToExplicitWant_003, TestSize.Level1)
92 {
93 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_003 start");
94 Want want;
95 want.SetUri("a_short_atomic_service_uri");
96 auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
97 EXPECT_NE(client, nullptr);
98 AppDomainVerify::AppDomainVerifyMgrClient::convertResultCode_ = ERR_TIMED_OUT;
99 auto errCode = WantUtils::ConvertToExplicitWant(want);
100 EXPECT_EQ(errCode, ERR_TIMED_OUT);
101 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest ConvertToExplicitWant_003 end");
102 }
103
104 /*
105 * Feature: WantUtilsTest
106 * Function: IsAtomicServiceUrl
107 * SubFunction: NA
108 * FunctionPoints: AbilityManagerService IsAtomicServiceUrl
109 */
HWTEST_F(WantUtilsTest, IsAtomicServiceUrl_001, TestSize.Level1)110 HWTEST_F(WantUtilsTest, IsAtomicServiceUrl_001, TestSize.Level1)
111 {
112 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicServiceUrl_001 start");
113 Want want;
114 want.SetUri("not_a_short_atomic_service_uri");
115 auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
116 EXPECT_NE(client, nullptr);
117 AppDomainVerify::AppDomainVerifyMgrClient::isAtomicServiceUrlFlag_ = false;
118 auto result = WantUtils::IsAtomicServiceUrl(want);
119 EXPECT_EQ(result, false);
120 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicServiceUrl_001 end");
121 }
122
123 /*
124 * Feature: WantUtilsTest
125 * Function: IsAtomicServiceUrl
126 * SubFunction: NA
127 * FunctionPoints: AbilityManagerService IsAtomicServiceUrl
128 */
HWTEST_F(WantUtilsTest, IsAtomicServiceUrl_002, TestSize.Level1)129 HWTEST_F(WantUtilsTest, IsAtomicServiceUrl_002, TestSize.Level1)
130 {
131 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicServiceUrl_002 start");
132 Want want;
133 want.SetUri("a_short_atomic_service_uri");
134 auto client = AppDomainVerify::AppDomainVerifyMgrClient::GetInstance();
135 EXPECT_NE(client, nullptr);
136 AppDomainVerify::AppDomainVerifyMgrClient::isAtomicServiceUrlFlag_ = true;
137 auto result = WantUtils::IsAtomicServiceUrl(want);
138 EXPECT_EQ(result, true);
139 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest IsAtomicServiceUrl_002 end");
140 }
141
142 /*
143 * Feature: WantUtilsTest
144 * Function: GetCallerBundleName
145 * SubFunction: NA
146 * FunctionPoints: AbilityManagerService GetCallerBundleName
147 */
HWTEST_F(WantUtilsTest, GetCallerBundleName_001, TestSize.Level1)148 HWTEST_F(WantUtilsTest, GetCallerBundleName_001, TestSize.Level1)
149 {
150 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest GetCallerBundleName_001 start");
151 std::string callerBundleName;
152 auto errCode = WantUtils::GetCallerBundleName(callerBundleName);
153 EXPECT_NE(errCode, 0);
154 TAG_LOGI(AAFwkTag::TEST, "WantUtilsTest GetCallerBundleName_001 end");
155 }
156 } // namespace AAFwk
157 } // namespace OHOS
158