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 "tool_system_test.h" 21 22 using namespace testing::ext; 23 using namespace OHOS; 24 using namespace OHOS::AAFwk; 25 using namespace OHOS::AppExecFwk; 26 27 namespace { 28 const std::string STRING_DEVICE_NAME = "device"; 29 30 const std::string STRING_SERVICE_ABILITY_BUNDLE_PATH = "/data/test/resource/aa/serviceAbilityBundleForStop.hap"; 31 const std::string STRING_SERVICE_ABILITY_BUNDLE_NAME = "com.ohos.tools.serviceAbilityBundleForStop"; 32 const std::string STRING_SERVICE_ABILITY_BUNDLE_NAME_INVALID = STRING_SERVICE_ABILITY_BUNDLE_NAME + ".invalid"; 33 const std::string STRING_SERVICE_ABILITY_NAME = "com.ohos.tools.serviceAbilityBundleForStop.ServiceAbility"; 34 const std::string STRING_SERVICE_ABILITY_NAME_INVALID = STRING_SERVICE_ABILITY_NAME + ".Invalid"; 35 } // namespace 36 37 class AaCommandStopServiceSystemTest : public ::testing::Test { 38 public: 39 static void SetUpTestCase(); 40 static void TearDownTestCase(); 41 void SetUp() override; 42 void TearDown() override; 43 }; 44 SetUpTestCase()45void AaCommandStopServiceSystemTest::SetUpTestCase() 46 {} 47 TearDownTestCase()48void AaCommandStopServiceSystemTest::TearDownTestCase() 49 {} 50 SetUp()51void AaCommandStopServiceSystemTest::SetUp() 52 { 53 // reset optind to 0 54 optind = 0; 55 } 56 TearDown()57void AaCommandStopServiceSystemTest::TearDown() 58 {} 59 60 /** 61 * @tc.number: Aa_Command_StopService_SystemTest_0200 62 * @tc.name: ExecCommand 63 * @tc.desc: Verify the "aa stop-service -d <device-id> -a <ability-name> -b <bundle-name>" command. 64 */ 65 HWTEST_F(AaCommandStopServiceSystemTest, Aa_Command_StopService_SystemTest_0200, Function | MediumTest | Level1) 66 { 67 // stop the invalid service ability 68 std::string command = "aa stop-service -d " + STRING_DEVICE_NAME + " -a " + STRING_SERVICE_ABILITY_NAME_INVALID + 69 " -b " + STRING_SERVICE_ABILITY_BUNDLE_NAME_INVALID; 70 std::string commandResult = ToolSystemTest::ExecuteCommand(command); 71 72 EXPECT_PRED2(ToolSystemTest::IsSubSequence, commandResult, STRING_STOP_SERVICE_ABILITY_NG + "\n"); 73 } 74