• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "local_want_agent_info.h"
17 
18 #include <gtest/gtest.h>
19 #include "element_name.h"
20 
21 using namespace testing::ext;
22 namespace OHOS::AbilityRuntime::WantAgent {
23 /*
24  * @tc.number    : LocalWantAgentInfo_0100
25  * @tc.name      : LocalWantAgentInfo Constructor1
26  * @tc.desc      : LocalWantAgentInfo Constructor1
27  */
28 HWTEST(LocalWantAgentInfoTest, LocalWantAgentInfo_0100, Function | MediumTest | Level1)
29 {
30     std::vector<std::shared_ptr<AAFwk::Want>> wants;
31     LocalWantAgentInfo info = LocalWantAgentInfo(100, WantAgentConstant::OperationType::START_ABILITY, wants);
32     ASSERT_EQ(info.GetRequestCode(), 100);
33     ASSERT_TRUE(info.GetOperationType() == WantAgentConstant::OperationType::START_ABILITY);
34     ASSERT_TRUE(info.GetWants().empty());
35 }
36 
37 /*
38  * @tc.number    : LocalWantAgentInfo_0200
39  * @tc.name      : LocalWantAgentInfo Constructor2
40  * @tc.desc      : LocalWantAgentInfo Constructor2
41  */
42 HWTEST(LocalWantAgentInfoTest, LocalWantAgentInfo_0200, Function | MediumTest | Level1)
43 {
44     std::vector<std::shared_ptr<AAFwk::Want>> wants;
45     std::shared_ptr<AAFwk::Want> want1 = std::make_shared<AAFwk::Want>();
46     want1->SetElement(AppExecFwk::ElementName("deviceId1", "bundleName1", "abilityName1"));
47     wants.emplace_back(want1);
48     std::shared_ptr<AAFwk::Want> want2 = nullptr;
49     wants.emplace_back(want2);
50     std::shared_ptr<AAFwk::Want> want3 = std::make_shared<AAFwk::Want>();
51     want3->SetElement(AppExecFwk::ElementName("deviceId3", "bundleName3", "abilityName3"));
52     wants.emplace_back(want3);
53 
54     LocalWantAgentInfo info = LocalWantAgentInfo(200, WantAgentConstant::OperationType::START_ABILITY, wants);
55     ASSERT_EQ(info.GetWants().size(), 2);
56     const auto actualWants = info.GetWants();
57     ASSERT_EQ(actualWants[0]->GetElement().GetBundleName(), want1->GetElement().GetBundleName());
58     ASSERT_EQ(actualWants[1]->GetElement().GetBundleName(), want3->GetElement().GetBundleName());
59 }
60 }