• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (C) 2025 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15import pytest
16from utils import GP, check_app_install, check_app_install_multi, check_app_uninstall, \
17    check_app_uninstall_multi, check_hdc_cmd, get_local_path, load_gp, check_app_not_exist, \
18    check_app_dir_not_exist
19
20
21class TestInstallBase:
22    hap_tables = {
23        "AACommand07.hap" : "com.example.aacommand07",
24        "AACommand08.hap" : "com.example.aacommand08"
25    }
26    hsp_tables = {
27        "libA_v10001.hsp" : "com.example.liba",
28        "libB_v10001.hsp" : "com.example.libb",
29    }
30    hsp_hap_tables = {
31        "AACommandpackage.hap" : "com.example.actsaacommandtestatest",
32        "libB_v10001.hsp" : "com.example.libb",
33    }
34
35    # 来自原hdc_normal_test.py的基础install 用例
36    @pytest.mark.L0
37    @pytest.mark.repeat(2)
38    @pytest.mark.parametrize("package_hap, hap_name_default", hap_tables.items())
39    def test_hap_install(self, package_hap, hap_name_default):
40        assert check_hdc_cmd(f"install -r {get_local_path(f'{package_hap}')}",
41                                bundle=f"{hap_name_default}")
42        assert check_app_uninstall(f"{hap_name_default}")
43
44    @pytest.mark.L1
45    @pytest.mark.repeat(2)
46    @pytest.mark.parametrize("package_hap, hap_name_default", hap_tables.items())
47    def test_install_hap(self, package_hap, hap_name_default):
48
49        # default
50        assert check_app_install(package_hap, hap_name_default)
51        assert check_app_uninstall(hap_name_default)
52
53        # -r
54        assert check_app_install(package_hap, hap_name_default, "-r")
55        assert check_app_uninstall(hap_name_default)
56
57        # -k
58        assert check_app_install(package_hap, hap_name_default, "-r")
59        assert check_app_uninstall(hap_name_default, "-k")
60
61        # -s
62        assert check_app_install(package_hap, hap_name_default, "-s")
63
64    @pytest.mark.L0
65    @pytest.mark.repeat(2)
66    @pytest.mark.parametrize("package_hsp, hsp_name_default", hsp_tables.items())
67    def test_install_hsp(self, package_hsp, hsp_name_default):
68        assert check_app_install(package_hsp, hsp_name_default, "-s")
69        assert check_app_uninstall(hsp_name_default, "-s")
70        assert check_app_install(package_hsp, hsp_name_default)
71
72    @pytest.mark.L0
73    @pytest.mark.repeat(2)
74    def test_install_multi_hap(self):
75        # default multi hap
76        assert check_app_install_multi(self.hap_tables)
77        assert check_app_uninstall_multi(self.hap_tables)
78        assert check_app_install_multi(self.hap_tables, "-s")
79        assert check_app_install_multi(self.hap_tables, "-r")
80        assert check_app_uninstall_multi(self.hap_tables, "-k")
81
82
83    @pytest.mark.L0
84    @pytest.mark.repeat(2)
85    def test_install_multi_hsp(self):
86        # default multi hsp -s
87        assert check_app_install_multi(self.hsp_tables, "-s")
88        assert check_app_uninstall_multi(self.hsp_tables, "-s")
89        assert check_app_install_multi(self.hsp_tables)
90
91    @pytest.mark.L0
92    @pytest.mark.repeat(2)
93    def test_install_hsp_and_hap(self):
94        #default multi hsp and hsp
95        assert check_app_install_multi(self.hsp_hap_tables)
96        assert check_app_install_multi(self.hsp_hap_tables, "-s")
97
98    @pytest.mark.L0
99    @pytest.mark.repeat(2)
100    def test_install_dir(self):
101        package_haps_dir = "app_dir"
102        hap_name_default_default = "com.example.aacommand07"
103        assert check_app_install(package_haps_dir, hap_name_default_default)
104        assert check_app_uninstall(hap_name_default_default)
105
106    @pytest.mark.L0
107    @pytest.mark.repeat(2)
108    def test_install_hsp_not_exist(self):
109        package_haps_dir = "not_exist.hsp"
110        hap_name_default_default = "com.not.exist.hsp"
111        assert check_app_not_exist(package_haps_dir, hap_name_default_default)
112
113    @pytest.mark.L0
114    @pytest.mark.repeat(2)
115    def test_install_hap_not_exist(self):
116        package_haps_dir = "not_exist.hap"
117        hap_name_default_default = "com.not.exist.hap"
118        assert check_app_not_exist(package_haps_dir, hap_name_default_default, "-s")
119
120    @pytest.mark.L0
121    @pytest.mark.repeat(2)
122    def test_install_dir_not_exist(self):
123        package_haps_dir = "abcdef_dir_not_exist"
124        hap_name_default_default = "com.abcedf.dir.not.exist"
125        assert check_app_dir_not_exist(package_haps_dir, hap_name_default_default)
126