From 5bd67adea1b979fcf51686eed32fd6ed6a7825b1 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Jun 2025 17:52:39 +0800 Subject: [PATCH] add a libhangul test case --- .../tc_libhangul_functional_fun001.yaml | 35 ++++++ .../tc_libhangul_functional_fun001.py | 114 ++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 docs/system_base/libhangul/tc_libhangul_functional_fun001.yaml create mode 100644 tests/system_base/libhangul/tc_libhangul_functional_fun001.py diff --git a/docs/system_base/libhangul/tc_libhangul_functional_fun001.yaml b/docs/system_base/libhangul/tc_libhangul_functional_fun001.yaml new file mode 100644 index 00000000..d05ed0f7 --- /dev/null +++ b/docs/system_base/libhangul/tc_libhangul_functional_fun001.yaml @@ -0,0 +1,35 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, libhangul +用例描述: 测试libhangul库的基本功能,包括键盘布局转换、输入输出处理等 + +前置条件: + - 系统需支持dnf包管理器 + - 能够访问软件仓库安装libhangul包 + +测试步骤: + - 安装libhangul软件包 + - 创建临时测试目录/tmp/hangul_test + - 生成测试输入文件test-1.in和test-2.in + - 测试hangul命令各参数功能: + - 测试--help选项 + - 测试--version选项 + - 测试-l/--list选项 + - 测试标准输入处理 + - 测试文件输入处理 + - 测试-i/--input选项 + - 测试-o/--output选项 + - 测试键盘布局选项(-k/--keyboard) + - 测试严格顺序选项(-s/--strict-order) + +期望结果: + - hangul命令所有选项功能正常 + - 标准输入和文件输入都能正确转换为韩文字符 + - 输出文件能正确保存转换结果 + - 键盘布局选项能正确应用指定布局 + - 严格顺序选项能正确处理输入顺序 + - 所有测试步骤返回码为0 + - 错误情况下能输出详细的调试信息 diff --git a/tests/system_base/libhangul/tc_libhangul_functional_fun001.py b/tests/system_base/libhangul/tc_libhangul_functional_fun001.py new file mode 100644 index 00000000..ddbf5e4f --- /dev/null +++ b/tests/system_base/libhangul/tc_libhangul_functional_fun001.py @@ -0,0 +1,114 @@ +""" +@File: tc_libhangul_functional_fun001.py +@Time: 2025/06/30 10:00:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +import os +import shutil +from avocado import Test +from avocado.utils import process + + +class LibhangulTest(Test): + """ + Test libhangul functionality + + :avocado: tags=P1,noarch,local,libhangul + """ + PARAM_DIC = {"pkg_name": "libhangul"} + TMP_DIR = "/tmp/hangul_test" + + def setUp(self): + """Prepare test environment""" + self.log.info("Start environment preparation") + + # Install dependencies + if not process.system("rpm -q expect", shell=True, ignore_status=True): + process.run("dnf install -y expect", shell=True) + + # Create test directory + os.makedirs(self.TMP_DIR, exist_ok=True) + + # Prepare test files + with open(f"{self.TMP_DIR}/test-1.in", "w") as f: + f.write("gksrmfdlqfur") + with open(f"{self.TMP_DIR}/test-2.in", "w") as f: + f.write("kljingj") + + # Install libhangul + result = process.run(f"dnf install -y {self.PARAM_DIC['pkg_name']}", + shell=True, ignore_status=True) + if result.exit_status != 0: + self.fail(f"Package installation failed: {result.stderr_text}") + + self.log.info("Environment preparation completed") + + def test(self): + """Test all hangul command functionality""" + test_cases = [ + # (command, pattern, error_msg) + ("hangul --help", "Usage: hangul", "--help option failed"), + ("hangul --version", "hangul (libhangul)", "--version option failed"), + ("hangul -l", "Sebeolsik", "-l option failed"), + ("hangul --list", "Sebeolsik", "--list option failed"), + (f"hangul < {self.TMP_DIR}/test-1.in", "한글입력", "STDIN processing failed"), + (f"hangul {self.TMP_DIR}/test-1.in", "한글입력", "FILEIN processing failed"), + ('hangul -i "gksrmfdlqfur"', "한글입력", "-i option failed"), + ('hangul --input="gksrmfdlqfur"', "한글입력", "--input option failed"), + (f"hangul -o {self.TMP_DIR}/test-1_1.out < {self.TMP_DIR}/test-1.in", + "한글입력", "-o option failed", f"{self.TMP_DIR}/test-1_1.out"), + (f"hangul --output={self.TMP_DIR}/test-1_2.out < {self.TMP_DIR}/test-1.in", + "한글입력", "--output option failed", f"{self.TMP_DIR}/test-1_2.out"), + # 修改键盘布局测试部分 + ("hangul -k 2 < {self.TMP_DIR}/test-1.in", "한글입력", "-k option failed"), + ("hangul --keyboard=2 < {self.TMP_DIR}/test-1.in", "한글입력", "--keyboard option failed"), + (f"hangul -s < {self.TMP_DIR}/test-2.in", "ㅏㅣㅓㅑㅜ허", "-s option failed"), + (f"hangul --strict-order < {self.TMP_DIR}/test-2.in", "ㅏㅣㅓㅑㅜ허", "--strict-order option failed") + ] + + for case in test_cases: + cmd = case[0].format(self=self) # 格式化字符串替换self.TMP_DIR + pattern = case[1] + error_msg = case[2] + output_file = case[3] if len(case) > 3 else None + + if output_file: + # For commands with output files + process.run(cmd, shell=True) + result = process.run(f"grep -q '{pattern}' {output_file}", shell=True, ignore_status=True) + else: + # For commands with direct output + result = process.run(f"{cmd} | grep -q '{pattern}'", shell=True, ignore_status=True) + + if result.exit_status != 0: + # 获取实际输出以便调试 + actual_output = process.run(cmd, shell=True, ignore_status=True) + self.log.debug(f"Command failed: {cmd}") + self.log.debug(f"Expected pattern: {pattern}") + self.log.debug(f"Actual output: {actual_output.stdout_text}") + self.fail(f"{error_msg}. Command: {cmd}") + + def tearDown(self): + """Clean up test environment""" + self.log.info("Start environment cleanup") + + # Remove test files + if os.path.exists(self.TMP_DIR): + shutil.rmtree(self.TMP_DIR) + + # Remove installed packages + remove_result = process.run( + f"dnf remove -y {self.PARAM_DIC['pkg_name']}", + shell=True, + ignore_status=True + ) + if remove_result.exit_status != 0: + self.log.warning("Package removal completed with warnings: %s", + remove_result.stderr_text.strip()) + + self.log.info("Cleanup completed") \ No newline at end of file -- Gitee