1 /*
2  * Copyright (c) 2021 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 #define private public
18 #include "pending_want_key.h"
19 #undef private
20 #include "want.h"
21 #include "wants_info.h"
22 
23 constexpr int PENDING_WANT_TYPE = 1;
24 const std::string PENDING_WANT_BUNDLENAME = "bundleName";
25 const std::string PENDING_WANT_WHO = "who";
26 constexpr int PENDING_WANT_REQUESTCODE = 2;
27 const std::string PENDING_WANT_REQUESTRESLOVEDTYPE = "requestResolvedType";
28 constexpr int PENDING_WANT_FLAGS = 10;
29 constexpr int PENDING_WANT_CODE = 20;
30 constexpr int PENDING_WANT_USERID = 123456;
31 
32 using namespace testing::ext;
33 using namespace OHOS::AppExecFwk;
34 namespace OHOS {
35 namespace AAFwk {
36 class PendingWantKeyTest : public testing::Test {
37 public:
38     static void SetUpTestCase(void);
39     static void TearDownTestCase(void);
40     void SetUp();
41     void TearDown();
42 };
43 
SetUpTestCase(void)44 void PendingWantKeyTest::SetUpTestCase(void)
45 {}
TearDownTestCase(void)46 void PendingWantKeyTest::TearDownTestCase(void)
47 {}
SetUp(void)48 void PendingWantKeyTest::SetUp(void)
49 {}
TearDown(void)50 void PendingWantKeyTest::TearDown(void)
51 {}
52 
53 /*
54  * @tc.number    : SetType_0100
55  * @tc.name      : set type
56  * @tc.desc      : Set type, use GetType to verify whether the type value is set successfully
57  */
58 HWTEST_F(PendingWantKeyTest, SetType_0100, TestSize.Level1)
59 {
60     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
61 
62     amsPendingWantKey->SetType(PENDING_WANT_TYPE);
63     EXPECT_EQ(PENDING_WANT_TYPE, amsPendingWantKey->GetType());
64 }
65 
66 /*
67  * @tc.number    : SetBundleName_0100
68  * @tc.name      : set BundleName
69  * @tc.desc      : Set BundleName, use GetBundleName to verify whether the BundleName  is set successfully
70  */
71 HWTEST_F(PendingWantKeyTest, SetBundleName_0100, TestSize.Level1)
72 {
73     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
74 
75     amsPendingWantKey->SetBundleName(PENDING_WANT_BUNDLENAME);
76     EXPECT_EQ(PENDING_WANT_BUNDLENAME, amsPendingWantKey->GetBundleName());
77 }
78 
79 /*
80  * @tc.number    : SetRequestWho_0100
81  * @tc.name      : set RequestWho
82  * @tc.desc      : Set RequestWho, use GetWho to verify whether the RequestWho is set successfully
83  */
84 HWTEST_F(PendingWantKeyTest, SetRequestWho_0100, TestSize.Level1)
85 {
86     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
87 
88     amsPendingWantKey->SetRequestWho(PENDING_WANT_WHO);
89     EXPECT_EQ(PENDING_WANT_WHO, amsPendingWantKey->GetRequestWho());
90 }
91 
92 /*
93  * @tc.number    : SetRequestCode_0100
94  * @tc.name      : set RequestCode
95  * @tc.desc      : Set RequestCode, use GetRequestCode to verify whether the RequestCode  is set successfully
96  */
97 HWTEST_F(PendingWantKeyTest, SetRequestCode_0100, TestSize.Level1)
98 {
99     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
100 
101     amsPendingWantKey->SetRequestCode(PENDING_WANT_REQUESTCODE);
102     EXPECT_EQ(PENDING_WANT_REQUESTCODE, amsPendingWantKey->GetRequestCode());
103 }
104 
105 /*
106  * @tc.number    : SetRequestWant_0100
107  * @tc.name      : set RequestWant
108  * @tc.desc      : Set RequestWant, use GetRequestWant to verify whether the RequestWant  is set successfully
109  */
110 HWTEST_F(PendingWantKeyTest, SetRequestWant_0100, TestSize.Level1)
111 {
112     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
113 
114     Want requestWant;
115     OHOS::AAFwk::Operation operation;
116     std::string bundleName = "ohos.pending.want.key.test";
117     operation.SetBundleName(bundleName);
118     requestWant.SetOperation(operation);
119     amsPendingWantKey->SetRequestWant(requestWant);
120     Want requestWant_ = amsPendingWantKey->GetRequestWant();
121     EXPECT_EQ(bundleName, requestWant_.GetOperation().GetBundleName());
122 }
123 
124 /*
125  * @tc.number    : SetRequestResolvedType_0100
126  * @tc.name      : set request resolved Type
127  * @tc.desc      : Set RequestResolvedType, use GetRequestResolvedType to verify whether the RequestResolvedType  is
128  * set successfully
129  */
130 HWTEST_F(PendingWantKeyTest, SetRequestResolvedType_0100, TestSize.Level1)
131 {
132     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
133 
134     amsPendingWantKey->SetRequestResolvedType(PENDING_WANT_REQUESTRESLOVEDTYPE);
135     EXPECT_EQ(PENDING_WANT_REQUESTRESLOVEDTYPE, amsPendingWantKey->GetRequestResolvedType());
136 }
137 
138 /*
139  * @tc.number    : SetAllWantsInfos_0100
140  * @tc.name      : set All WantsInfos
141  * @tc.desc      : Set AllWantsInfos, use GetAllWantsInfos to verify whether the AllWantsInfos  is set successfully
142  */
143 HWTEST_F(PendingWantKeyTest, SetAllWantsInfos_0100, TestSize.Level1)
144 {
145     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
146 
147     amsPendingWantKey->allWantsInfos_.clear();
148     std::vector<WantsInfo> allWantsInfos;
149     WantsInfo wantsInfo;
150 
151     wantsInfo.resolvedTypes = "resolvedTypes";
152     allWantsInfos.push_back(wantsInfo);
153     amsPendingWantKey->SetAllWantsInfos(allWantsInfos);
154     std::vector<WantsInfo> wantsInfo_ = amsPendingWantKey->GetAllWantsInfos();
155     EXPECT_EQ(wantsInfo.resolvedTypes, wantsInfo_.front().resolvedTypes);
156 }
157 
158 /*
159  * @tc.number    : SetFlags_0100
160  * @tc.name      : set Flags
161  * @tc.desc      : Set Flags, use GetFlags to verify whether the Flags  is set successfully
162  */
163 HWTEST_F(PendingWantKeyTest, SetFlags_0100, TestSize.Level1)
164 {
165     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
166 
167     amsPendingWantKey->SetFlags(PENDING_WANT_FLAGS);
168     EXPECT_EQ(PENDING_WANT_FLAGS, amsPendingWantKey->GetFlags());
169 }
170 
171 /*
172  * @tc.number    : SetCode_0100
173  * @tc.name      : set Code
174  * @tc.desc      : Set Code, use GetCode to verify whether the Code  is set successfully
175  */
176 HWTEST_F(PendingWantKeyTest, SetCode_0100, TestSize.Level1)
177 {
178     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
179 
180     amsPendingWantKey->SetCode(PENDING_WANT_CODE);
181     EXPECT_EQ(PENDING_WANT_CODE, amsPendingWantKey->GetCode());
182 }
183 
184 /*
185  * @tc.number    : SetUserId_0100
186  * @tc.name      : set UserId
187  * @tc.desc      : Set UserId, use GetUserId to verify whether the UserId  is set successfully
188  */
189 HWTEST_F(PendingWantKeyTest, SetUserId_0100, TestSize.Level1)
190 {
191     std::unique_ptr<PendingWantKey> amsPendingWantKey = std::make_unique<PendingWantKey>();
192 
193     amsPendingWantKey->SetUserId(PENDING_WANT_USERID);
194     EXPECT_EQ(PENDING_WANT_USERID, amsPendingWantKey->GetUserId());
195 }
196 }  // namespace AAFwk
197 }  // namespace OHOS
198