|
| 1 | +/* |
| 2 | + SPDX-FileCopyrightText: © 2025 Siemens Healthineers AG |
| 3 | + SPDX-FileContributor: Sushant Kumar <sushant.kumar@siemens-healthineers.com> |
| 4 | +
|
| 5 | + SPDX-License-Identifier: GPL-2.0-only |
| 6 | +*/ |
| 7 | + |
| 8 | +#include "run_tests.h" |
| 9 | + |
| 10 | +/** |
| 11 | + * \file |
| 12 | + * \brief Unit test cases for ExtractLzip() |
| 13 | + */ |
| 14 | + |
| 15 | +/* locals */ |
| 16 | +static int Result = 0; |
| 17 | + |
| 18 | +/** |
| 19 | + * @brief unpack lzip file |
| 20 | + * \test |
| 21 | + * -# Try to extract `.lz` file using ExtractLzip() |
| 22 | + * -# Check if the files are unpacked |
| 23 | + */ |
| 24 | +void testExtractLzipFile() |
| 25 | +{ |
| 26 | + deleteTmpFiles("./test-result/"); |
| 27 | + exists = file_dir_exists("./test-result/"); |
| 28 | + FO_ASSERT_EQUAL(exists, 0); // not existing |
| 29 | + |
| 30 | + MkDirs("./test-result/test.lz.dir/"); |
| 31 | + Filename = "../testdata/test.lz"; |
| 32 | + /* Ensure test.lz contains a file named 'data.tar' for this assertion */ |
| 33 | + Result = ExtractLzip(Filename, "test.lz", "./test-result/test.lz.dir"); |
| 34 | + |
| 35 | + exists = file_dir_exists("./test-result/test.lz.dir/test"); |
| 36 | + FO_ASSERT_EQUAL(exists, 1); // existing |
| 37 | + FO_ASSERT_EQUAL(Result, 0); // Extract lzip successfully |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * @brief unpack tlz (tar.lz) file |
| 42 | + * \test |
| 43 | + * -# Try to extract `.tlz` archives using ExtractLzip() |
| 44 | + * -# Check if the files are unpacked |
| 45 | + */ |
| 46 | +void testExtractTlzFile() |
| 47 | +{ |
| 48 | + deleteTmpFiles("./test-result/"); |
| 49 | + exists = file_dir_exists("./test-result/"); |
| 50 | + FO_ASSERT_EQUAL(exists, 0); |
| 51 | + |
| 52 | + MkDirs("./test-result/test.tlz.dir/"); |
| 53 | + Filename = "../testdata/test.tlz"; |
| 54 | + Result = ExtractLzip(Filename, "test.tlz", "./test-result/test.tlz.dir"); |
| 55 | + |
| 56 | + exists = file_dir_exists("./test-result/test.tlz.dir/test.tar"); |
| 57 | + FO_ASSERT_EQUAL(exists, 1); |
| 58 | + FO_ASSERT_EQUAL(Result, 0); |
| 59 | +} |
| 60 | + |
| 61 | +/** |
| 62 | + * @brief unpack tar.lz file |
| 63 | + * \test |
| 64 | + * -# Try to extract `.tar.lz` archives using ExtractLzip() |
| 65 | + * -# Check if the files are unpacked |
| 66 | + */ |
| 67 | +void testExtractTarLzFile() |
| 68 | +{ |
| 69 | + deleteTmpFiles("./test-result/"); |
| 70 | + exists = file_dir_exists("./test-result/"); |
| 71 | + FO_ASSERT_EQUAL(exists, 0); |
| 72 | + |
| 73 | + MkDirs("./test-result/test.tar.lz.dir/"); |
| 74 | + Filename = "../testdata/test.tar.lz"; |
| 75 | + Result = ExtractLzip(Filename, "test.tar.lz", "./test-result/test.tar.lz.dir"); |
| 76 | + |
| 77 | + exists = file_dir_exists("./test-result/test.tar.lz.dir/test.tar"); |
| 78 | + FO_ASSERT_EQUAL(exists, 1); |
| 79 | + FO_ASSERT_EQUAL(Result, 0); |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * @brief abnormal parameters |
| 84 | + * \test |
| 85 | + * -# Call ExtractLzip() with empty parameters |
| 86 | + * -# Check if the function return NOT OK |
| 87 | + */ |
| 88 | +void testExtractLzipEmptyParameters() |
| 89 | +{ |
| 90 | + deleteTmpFiles("./test-result/"); |
| 91 | + exists = file_dir_exists("./test-result/"); |
| 92 | + FO_ASSERT_EQUAL(exists, 0); |
| 93 | + |
| 94 | + Result = ExtractLzip("", "", ""); |
| 95 | + FO_ASSERT_EQUAL(Result, 1); |
| 96 | +} |
| 97 | + |
| 98 | +/** |
| 99 | + * @brief abnormal parameters |
| 100 | + * \test |
| 101 | + * -# Try to extract non-existent archives using ExtractLzip() |
| 102 | + * -# Check if the function return NOT OK |
| 103 | + */ |
| 104 | +void testExtractLzipErrorParameters() |
| 105 | +{ |
| 106 | + deleteTmpFiles("./test-result/"); |
| 107 | + exists = file_dir_exists("./test-result/"); |
| 108 | + FO_ASSERT_EQUAL(exists, 0); |
| 109 | + |
| 110 | + MkDirs("./test-result/no_file.dir/"); |
| 111 | + Filename = "../testdata/non_existent_file.lz"; |
| 112 | + Result = ExtractLzip(Filename, "non_existent_file.lz", "./test-result/no_file.dir"); |
| 113 | + FO_ASSERT_EQUAL(Result, 1); |
| 114 | +} |
| 115 | + |
| 116 | +/* ************************************************************************** */ |
| 117 | +/* **** cunit test cases **************************************************** */ |
| 118 | +/* ************************************************************************** */ |
| 119 | + |
| 120 | +CU_TestInfo ExtractLzip_testcases[] = |
| 121 | +{ |
| 122 | + {"Testing function ExtractLzip for .lz file:", testExtractLzipFile}, |
| 123 | + {"Testing function ExtractLzip for .tlz file:", testExtractTlzFile}, |
| 124 | + {"Testing function ExtractLzip for .tar.lz file:", testExtractTarLzFile}, |
| 125 | + {"Testing function ExtractLzip for empty parameters:", testExtractLzipEmptyParameters}, |
| 126 | + {"Testing function ExtractLzip for error parameters:", testExtractLzipErrorParameters}, |
| 127 | + CU_TEST_INFO_NULL |
| 128 | +}; |
0 commit comments