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
18 #include "insight_intent/insight_intent_profile.cpp"
19 #include "insight_intent_profile.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace AbilityRuntime {
26 namespace {
27 const std::string profileJsonStr = "{"
28 "\"insightIntents\":["
29 "{"
30 "\"intentName\":\"test1\","
31 "\"domain\":\"domain1\","
32 "\"intentVersion\":\"1.0\","
33 "\"srcEntry\":\"entry1\","
34 "\"uiAbility\":{"
35 "\"ability\":\"ability1\","
36 "\"executeMode\":[\"foreground\"]"
37 "},"
38 "\"uiExtension\":{"
39 "\"ability\":\"ability1\""
40 "},"
41 "\"serviceExtension\":{"
42 "\"ability\":\"ability1\""
43 "},"
44 "\"form\":{"
45 "\"ability\":\"ability1\","
46 "\"formName\":\"form1\""
47 "}"
48 "},"
49 "{"
50 "\"intentName\":\"test2\","
51 "\"domain\":\"domain1\","
52 "\"intentVersion\":\"1.0\","
53 "\"srcEntry\":\"entry1\","
54 "\"uiAbility\":{"
55 "\"ability\":\"ability1\","
56 "\"executeMode\":[\"foreground\"]"
57 "},"
58 "\"uiExtension\":{"
59 "\"ability\":\"ability1\""
60 "},"
61 "\"serviceExtension\":{"
62 "\"ability\":\"ability1\""
63 "},"
64 "\"form\": {"
65 "\"ability\":\"ability1\","
66 "\"formName\":\"form1\""
67 "}"
68 "}"
69 "]"
70 "}";
71 }
72
73 class InsightIntentProfileTest : public testing::Test {
74 public:
75 static void SetUpTestCase();
76 static void TearDownTestCase();
77 void SetUp() override;
78 void TearDown() override;
79 };
80
SetUpTestCase()81 void InsightIntentProfileTest::SetUpTestCase()
82 {}
83
TearDownTestCase()84 void InsightIntentProfileTest::TearDownTestCase()
85 {}
86
SetUp()87 void InsightIntentProfileTest::SetUp()
88 {}
89
TearDown()90 void InsightIntentProfileTest::TearDown()
91 {}
92
93 /**
94 * @tc.number: TransformToInsightIntentInfo_0100
95 * @tc.name: TransformToInsightIntentInfo
96 * @tc.desc: Test whether TransformToInsightIntentInfo and are called normally.
97 */
98 HWTEST_F(InsightIntentProfileTest, TransformToInsightIntentInfo_0100, TestSize.Level2)
99 {
100 InsightIntentProfileInfo insightIntent;
101 InsightIntentInfo info;
102 insightIntent.intentName = "";
103 EXPECT_FALSE(TransformToInsightIntentInfo(insightIntent, info));
104
105 insightIntent.intentName = "testIntent";
106 insightIntent.intentDomain = "testDomain";
107 insightIntent.intentVersion = "1.0";
108 insightIntent.srcEntry = "testEntry";
109 EXPECT_TRUE(TransformToInsightIntentInfo(insightIntent, info));
110 EXPECT_EQ(info.intentName, "testIntent");
111 EXPECT_EQ(info.intentDomain, "testDomain");
112 EXPECT_EQ(info.intentVersion, "1.0");
113 EXPECT_EQ(info.srcEntry, "testEntry");
114 }
115
116 /**
117 * @tc.number: TransformToInsightIntentInfo_0200
118 * @tc.name: TransformToInsightIntentInfo
119 * @tc.desc: Test whether TransformToInsightIntentInfo and are called normally.
120 */
121 HWTEST_F(InsightIntentProfileTest, TransformToInsightIntentInfo_0200, TestSize.Level2)
122 {
123 InsightIntentProfileInfo insightIntent;
124 InsightIntentInfo info;
125
126 insightIntent.intentName = "testIntent";
127 insightIntent.uiAbilityProfileInfo.supportExecuteMode = {"invalidMode"};
128
129 TransformToInsightIntentInfo(insightIntent, info);
130
131 EXPECT_EQ(info.uiAbilityIntentInfo.supportExecuteMode.size(), 0);
132 }
133
134 /**
135 * @tc.number: TransformToInfos_0300
136 * @tc.name: TransformToInfos
137 * @tc.desc: Test whether TransformToInfos and are called normally.
138 */
139 HWTEST_F(InsightIntentProfileTest, TransformToInfos_0300, TestSize.Level2)
140 {
141 InsightIntentProfileInfoVec profileInfos;
142 InsightIntentProfileInfo insightIntent;
143 insightIntent.intentName = "testIntent";
144 insightIntent.intentDomain = "testDomain";
145 insightIntent.intentVersion = "1.0";
146 insightIntent.srcEntry = "testEntry";
147 profileInfos.insightIntents.push_back(insightIntent);
148 std::vector<InsightIntentInfo> intentInfos;
149 bool result = TransformToInfos(profileInfos, intentInfos);
150 EXPECT_TRUE(result);
151 EXPECT_EQ(intentInfos.size(), 1);
152 }
153
154 /**
155 * @tc.number: TransformToInfos_0400
156 * @tc.name: TransformToInfos
157 * @tc.desc: Test whether TransformToInfos and are called normally.
158 */
159 HWTEST_F(InsightIntentProfileTest, TransformToInfos_0400, TestSize.Level2)
160 {
161 InsightIntentProfileInfoVec profileInfos;
162 std::vector<InsightIntentInfo> intentInfos;
163 InsightIntentProfileInfo insightIntent;
164 insightIntent.intentName = "";
165 profileInfos.insightIntents.push_back(insightIntent);
166 bool result = TransformToInfos(profileInfos, intentInfos);
167 EXPECT_FALSE(result);
168 EXPECT_EQ(intentInfos.size(), 0);
169 }
170
171 /**
172 * @tc.number: TransformTo_0500
173 * @tc.name: TransformTo
174 * @tc.desc: Test whether TransformTo and are called normally.
175 */
176 HWTEST_F(InsightIntentProfileTest, TransformTo_0500, TestSize.Level2)
177 {
178 std::string profileStr = "not a valid json string";
179 std::vector<InsightIntentInfo> intentInfos;
180 bool result = InsightIntentProfile::TransformTo(profileStr, intentInfos);
181 EXPECT_FALSE(result);
182 EXPECT_EQ(intentInfos.size(), 0);
183 }
184
185 /**
186 * @tc.number: TransformTo_0600
187 * @tc.name: TransformTo
188 * @tc.desc: Test whether TransformTo and are called normally.
189 */
190 HWTEST_F(InsightIntentProfileTest, TransformTo_0600, TestSize.Level2)
191 {
192 std::vector<InsightIntentInfo> intentInfos;
193 bool result = InsightIntentProfile::TransformTo(profileJsonStr, intentInfos);
194 EXPECT_TRUE(result);
195 EXPECT_EQ(intentInfos.size(), 2);
196 }
197
198 /**
199 * @tc.number: TransformTo_0700
200 * @tc.name: TransformTo
201 * @tc.desc: Test whether TransformTo and are called normally.
202 */
203 HWTEST_F(InsightIntentProfileTest, TransformTo_0700, TestSize.Level2)
204 {
205 std::string profileStr = "{\"insightIntents\":\"test\"}";
206 std::vector<InsightIntentInfo> intentInfos;
207 bool result = InsightIntentProfile::TransformTo(profileStr, intentInfos);
208 EXPECT_EQ(intentInfos.size(), 0);
209 }
210 } // namespace AbilityRuntime
211 } // namespace OHOS
212