• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include <thread>
19 #include "ability_command.h"
20 #include "ability_manager_client.h"
21 #include "ability_manager_interface.h"
22 #include "bundle_command.h"
23 #include "tool_system_test.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::AAFwk;
28 using namespace OHOS::AppExecFwk;
29 
30 namespace {
31 const std::string STRING_DEVICE_NAME = "device";
32 
33 const std::string STRING_PAGE_ABILITY_BUNDLE_PATH = "/data/test/resource/aa/pageAbilityBundleForStart.hap";
34 const std::string STRING_PAGE_ABILITY_BUNDLE_NAME = "com.ohos.tools.pageAbilityBundleForStart";
35 const std::string STRING_PAGE_ABILITY_BUNDLE_NAME_INVALID = STRING_PAGE_ABILITY_BUNDLE_NAME + ".invalid";
36 const std::string STRING_PAGE_ABILITY_NAME = "com.ohos.tools.pageAbilityForStart.MainAbility";
37 const std::string STRING_PAGE_ABILITY_NAME_INVALID = STRING_PAGE_ABILITY_NAME + ".Invalid";
38 
39 const std::string STRING_SERVICE_ABILITY_BUNDLE_PATH = "/data/test/resource/aa/serviceAbilityBundleForStart.hap";
40 const std::string STRING_SERVICE_ABILITY_BUNDLE_NAME = "com.ohos.tools.serviceAbilityBundleForStart";
41 const std::string STRING_SERVICE_ABILITY_BUNDLE_NAME_INVALID = STRING_SERVICE_ABILITY_BUNDLE_NAME + ".invalid";
42 const std::string STRING_SERVICE_ABILITY_NAME = "MainAbility";
43 const std::string STRING_SERVICE_ABILITY_NAME_INVALID = STRING_SERVICE_ABILITY_NAME + ".Invalid";
44 }  // namespace
45 
46 class AaCommandStartSystemTest : public ::testing::Test {
47 public:
48     static void SetUpTestCase();
49     static void TearDownTestCase();
50     void SetUp() override;
51     void TearDown() override;
52 };
53 
SetUpTestCase()54 void AaCommandStartSystemTest::SetUpTestCase()
55 {}
56 
TearDownTestCase()57 void AaCommandStartSystemTest::TearDownTestCase()
58 {}
59 
SetUp()60 void AaCommandStartSystemTest::SetUp()
61 {
62     // reset optind to 0
63     optind = 0;
64 }
65 
TearDown()66 void AaCommandStartSystemTest::TearDown()
67 {}
68 
69 /**
70  * @tc.number: Aa_Command_Start_SystemTest_0100
71  * @tc.name: ExecCommand
72  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
73  */
74 HWTEST_F(AaCommandStartSystemTest, Aa_Command_Start_SystemTest_0100, Function | MediumTest | Level1)
75 {
76     // uninstall the bundle
77     ToolSystemTest::UninstallBundle(STRING_PAGE_ABILITY_BUNDLE_NAME);
78 
79     // install the bundle
80     ToolSystemTest::InstallBundle(STRING_PAGE_ABILITY_BUNDLE_PATH, true);
81 
82     // start the page ability
83     std::string command = "aa start -d " + STRING_DEVICE_NAME + " -a " + STRING_PAGE_ABILITY_NAME + " -b " +
84                           STRING_PAGE_ABILITY_BUNDLE_NAME;
85     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
86 
87     EXPECT_EQ(commandResult, STRING_START_ABILITY_OK + "\n");
88 
89     // uninstall the bundle
90     ToolSystemTest::UninstallBundle(STRING_PAGE_ABILITY_BUNDLE_NAME);
91 }
92 
93 /**
94  * @tc.number: Aa_Command_Start_SystemTest_0200
95  * @tc.name: ExecCommand
96  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
97  */
98 HWTEST_F(AaCommandStartSystemTest, Aa_Command_Start_SystemTest_0200, Function | MediumTest | Level1)
99 {
100     // uninstall the bundle
101     ToolSystemTest::UninstallBundle(STRING_SERVICE_ABILITY_BUNDLE_NAME);
102 
103     // install the bundle
104     ToolSystemTest::InstallBundle(STRING_SERVICE_ABILITY_BUNDLE_PATH, true);
105 
106     // start the service ability
107     std::string command = "aa start -d " + STRING_DEVICE_NAME + " -a " + STRING_SERVICE_ABILITY_NAME + " -b " +
108                           STRING_SERVICE_ABILITY_BUNDLE_NAME;
109     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
110 
111     EXPECT_EQ(commandResult, STRING_START_ABILITY_OK + "\n");
112 
113     // uninstall the bundle
114     ToolSystemTest::UninstallBundle(STRING_SERVICE_ABILITY_BUNDLE_NAME);
115 }
116 
117 /**
118  * @tc.number: Aa_Command_Start_SystemTest_0300
119  * @tc.name: ExecCommand
120  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
121  */
122 HWTEST_F(AaCommandStartSystemTest, Aa_Command_Start_SystemTest_0300, Function | MediumTest | Level1)
123 {
124     // start the invalid page ability
125     std::string command = "aa start -d " + STRING_DEVICE_NAME + " -a " + STRING_PAGE_ABILITY_NAME_INVALID + " -b " +
126                           STRING_PAGE_ABILITY_BUNDLE_NAME_INVALID;
127     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
128 
129     EXPECT_EQ(commandResult, STRING_START_ABILITY_NG + "\n");
130 }
131 
132 /**
133  * @tc.number: Aa_Command_Start_SystemTest_0400
134  * @tc.name: ExecCommand
135  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
136  */
137 HWTEST_F(AaCommandStartSystemTest, Aa_Command_Start_SystemTest_0400, Function | MediumTest | Level1)
138 {
139     // start the invalid service ability
140     std::string command = "aa start -d " + STRING_DEVICE_NAME + " -a " + STRING_SERVICE_ABILITY_NAME_INVALID + " -b " +
141                           STRING_SERVICE_ABILITY_BUNDLE_NAME_INVALID;
142     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
143 
144     EXPECT_EQ(commandResult, STRING_START_ABILITY_NG + "\n");
145 }
146