From cda4e079b12d5e2021ff1814e82dd750b99a7f8a Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Mon, 13 May 2013 12:57:03 +0200 Subject: [PATCH] tests: Add fixtures.h with common constants and other global stuff. --- tests/fixtures.h | 32 +++++++++++++++ tests/testcompression_wrapper.c | 64 ++++++++++++++++++------------ tests/testload_metadata.c | 24 ++++++------ tests/testmisc.c | 87 +++++++++++++++++++++++++++-------------- tests/testsqlite.c | 5 ++- 5 files changed, 141 insertions(+), 71 deletions(-) create mode 100644 tests/fixtures.h diff --git a/tests/fixtures.h b/tests/fixtures.h new file mode 100644 index 0000000..250a547 --- /dev/null +++ b/tests/fixtures.h @@ -0,0 +1,32 @@ +/* createrepo_c - Library of routines for manipulation with repodata + * Copyright (C) 2013 Tomas Mlcoch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ + +#ifndef __C_CREATEREPOLIB_TEST_FIXTURES_H__ +#define __C_CREATEREPOLIB_TEST_FIXTURES_H__ + +#define TEST_DATA_PATH "test_data/" + +#define TEST_FILES_PATH TEST_DATA_PATH"test_files/" +#define TEST_REPO_00 TEST_DATA_PATH"repo_00/" +#define TEST_REPO_01 TEST_DATA_PATH"repo_01/" +#define TEST_REPO_02 TEST_DATA_PATH"repo_02/" +#define TEST_PACKAGES_PATH TEST_DATA_PATH"packages/" +#define TEST_COMPRESSED_FILES_PATH TEST_DATA_PATH"compressed_files/" + +#endif diff --git a/tests/testcompression_wrapper.c b/tests/testcompression_wrapper.c index f9df6ca..88b8e30 100644 --- a/tests/testcompression_wrapper.c +++ b/tests/testcompression_wrapper.c @@ -22,6 +22,7 @@ #include #include #include +#include "fixtures.h" #include "createrepo/misc.h" #include "createrepo/compression_wrapper.h" @@ -31,29 +32,30 @@ #define FILE_COMPRESSED_0_CONTENT "" #define FILE_COMPRESSED_0_CONTENT_LEN 0 -#define FILE_COMPRESSED_0_PLAIN "test_data/compressed_files/00_plain.txt" -#define FILE_COMPRESSED_0_GZ "test_data/compressed_files/00_plain.txt.gz" -#define FILE_COMPRESSED_0_BZ2 "test_data/compressed_files/00_plain.txt.bz2" -#define FILE_COMPRESSED_0_XZ "test_data/compressed_files/00_plain.txt.xz" -#define FILE_COMPRESSED_0_PLAIN_BAD_SUFFIX "test_data/compressed_files/00_plain.foo0" -#define FILE_COMPRESSED_0_GZ_BAD_SUFFIX "test_data/compressed_files/00_plain.foo1" -#define FILE_COMPRESSED_0_BZ2_BAD_SUFFIX "test_data/compressed_files/00_plain.foo2" -#define FILE_COMPRESSED_0_XZ_BAD_SUFFIX "test_data/compressed_files/00_plain.foo3" +#define FILE_COMPRESSED_0_PLAIN TEST_COMPRESSED_FILES_PATH"/00_plain.txt" +#define FILE_COMPRESSED_0_GZ TEST_COMPRESSED_FILES_PATH"/00_plain.txt.gz" +#define FILE_COMPRESSED_0_BZ2 TEST_COMPRESSED_FILES_PATH"/00_plain.txt.bz2" +#define FILE_COMPRESSED_0_XZ TEST_COMPRESSED_FILES_PATH"/00_plain.txt.xz" +#define FILE_COMPRESSED_0_PLAIN_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/00_plain.foo0" +#define FILE_COMPRESSED_0_GZ_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/00_plain.foo1" +#define FILE_COMPRESSED_0_BZ2_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/00_plain.foo2" +#define FILE_COMPRESSED_0_XZ_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/00_plain.foo3" #define FILE_COMPRESSED_1_CONTENT "foobar foobar foobar foobar test test\nfolkjsaflkjsadokf\n" #define FILE_COMPRESSED_1_CONTENT_LEN 56 -#define FILE_COMPRESSED_1_PLAIN "test_data/compressed_files/01_plain.txt" -#define FILE_COMPRESSED_1_GZ "test_data/compressed_files/01_plain.txt.gz" -#define FILE_COMPRESSED_1_BZ2 "test_data/compressed_files/01_plain.txt.bz2" -#define FILE_COMPRESSED_1_XZ "test_data/compressed_files/01_plain.txt.xz" -#define FILE_COMPRESSED_1_PLAIN_BAD_SUFFIX "test_data/compressed_files/01_plain.foo0" -#define FILE_COMPRESSED_1_GZ_BAD_SUFFIX "test_data/compressed_files/01_plain.foo1" -#define FILE_COMPRESSED_1_BZ2_BAD_SUFFIX "test_data/compressed_files/01_plain.foo2" -#define FILE_COMPRESSED_1_XZ_BAD_SUFFIX "test_data/compressed_files/01_plain.foo3" +#define FILE_COMPRESSED_1_PLAIN TEST_COMPRESSED_FILES_PATH"/01_plain.txt" +#define FILE_COMPRESSED_1_GZ TEST_COMPRESSED_FILES_PATH"/01_plain.txt.gz" +#define FILE_COMPRESSED_1_BZ2 TEST_COMPRESSED_FILES_PATH"/01_plain.txt.bz2" +#define FILE_COMPRESSED_1_XZ TEST_COMPRESSED_FILES_PATH"/01_plain.txt.xz" +#define FILE_COMPRESSED_1_PLAIN_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/01_plain.foo0" +#define FILE_COMPRESSED_1_GZ_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/01_plain.foo1" +#define FILE_COMPRESSED_1_BZ2_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/01_plain.foo2" +#define FILE_COMPRESSED_1_XZ_BAD_SUFFIX TEST_COMPRESSED_FILES_PATH"/01_plain.foo3" -static void test_cr_compression_suffix(void) +static void +test_cr_compression_suffix(void) { const char *suffix; @@ -77,7 +79,8 @@ static void test_cr_compression_suffix(void) } -static void test_cr_detect_compression(void) +static void +test_cr_detect_compression(void) { cr_CompressionType ret; @@ -111,7 +114,8 @@ static void test_cr_detect_compression(void) } -static void test_cr_detect_compression_bad_suffix(void) +static void +test_cr_detect_compression_bad_suffix(void) { cr_CompressionType ret; @@ -145,7 +149,8 @@ static void test_cr_detect_compression_bad_suffix(void) } -void test_helper_cw_input(const char *filename, cr_CompressionType ctype, const char *content, int len) +void +test_helper_cw_input(const char *filename, cr_CompressionType ctype, const char *content, int len) { int ret; CR_FILE *file; @@ -162,7 +167,8 @@ void test_helper_cw_input(const char *filename, cr_CompressionType ctype, const } -static void test_cr_read_with_autodetection(void) +static void +test_cr_read_with_autodetection(void) { // Plain @@ -191,7 +197,8 @@ typedef struct { } Outputtest; -static void outputtest_setup(Outputtest *outputtest, gconstpointer test_data) +static void +outputtest_setup(Outputtest *outputtest, gconstpointer test_data) { CR_UNUSED(test_data); int fd; @@ -201,7 +208,8 @@ static void outputtest_setup(Outputtest *outputtest, gconstpointer test_data) } -static void outputtest_teardown(Outputtest *outputtest, gconstpointer test_data) +static void +outputtest_teardown(Outputtest *outputtest, gconstpointer test_data) { CR_UNUSED(test_data); @@ -216,7 +224,9 @@ static void outputtest_teardown(Outputtest *outputtest, gconstpointer test_data) #define OUTPUT_TYPE_PUTS 1 #define OUTPUT_TYPE_PRINTF 2 -void test_helper_cw_output(int type, const char *filename, cr_CompressionType ctype, const char *content, int len) { +void +test_helper_cw_output(int type, const char *filename, cr_CompressionType ctype, const char *content, int len) +{ int ret; CR_FILE *file; @@ -252,7 +262,8 @@ void test_helper_cw_output(int type, const char *filename, cr_CompressionType ct } -static void outputtest_cw_output(Outputtest *outputtest, gconstpointer test_data) +static void +outputtest_cw_output(Outputtest *outputtest, gconstpointer test_data) { CR_UNUSED(test_data); @@ -315,7 +326,8 @@ static void outputtest_cw_output(Outputtest *outputtest, gconstpointer test_data -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); diff --git a/tests/testload_metadata.c b/tests/testload_metadata.c index f4c5176..36b6fbe 100644 --- a/tests/testload_metadata.c +++ b/tests/testload_metadata.c @@ -20,24 +20,22 @@ #include #include #include +#include "fixtures.h" #include "createrepo/error.h" #include "createrepo/package.h" #include "createrepo/misc.h" #include "createrepo/load_metadata.h" -#define REPO_PATH_00 "test_data/repo_00/" #define REPO_SIZE_00 0 static const char *REPO_HASH_KEYS_00[] = {}; static const char *REPO_NAME_KEYS_00[] = {}; static const char *REPO_FILENAME_KEYS_00[] = {}; -#define REPO_PATH_01 "test_data/repo_01/" #define REPO_SIZE_01 1 static const char *REPO_HASH_KEYS_01[] = {"152824bff2aa6d54f429d43e87a3ff3a0286505c6d93ec87692b5e3a9e3b97bf"}; static const char *REPO_NAME_KEYS_01[] = {"super_kernel"}; static const char *REPO_FILENAME_KEYS_01[] = {"super_kernel-6.0.1-2.x86_64.rpm"}; -#define REPO_PATH_02 "test_data/repo_02/" #define REPO_SIZE_02 2 static const char *REPO_HASH_KEYS_02[] = {"6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3", "90f61e546938a11449b710160ad294618a5bd3062e46f8cf851fd0088af184b7"}; @@ -91,17 +89,17 @@ void test_helper_check_keys(const char *repopath, cr_HashTableKey key, guint rep static void test_cr_metadata_locate_and_load_xml(void) { - test_helper_check_keys(REPO_PATH_00, CR_HT_KEY_HASH, REPO_SIZE_00, REPO_HASH_KEYS_00); - test_helper_check_keys(REPO_PATH_00, CR_HT_KEY_NAME, REPO_SIZE_00, REPO_NAME_KEYS_00); - test_helper_check_keys(REPO_PATH_00, CR_HT_KEY_FILENAME, REPO_SIZE_00, REPO_FILENAME_KEYS_00); + test_helper_check_keys(TEST_REPO_00, CR_HT_KEY_HASH, REPO_SIZE_00, REPO_HASH_KEYS_00); + test_helper_check_keys(TEST_REPO_00, CR_HT_KEY_NAME, REPO_SIZE_00, REPO_NAME_KEYS_00); + test_helper_check_keys(TEST_REPO_00, CR_HT_KEY_FILENAME, REPO_SIZE_00, REPO_FILENAME_KEYS_00); - test_helper_check_keys(REPO_PATH_01, CR_HT_KEY_HASH, REPO_SIZE_01, REPO_HASH_KEYS_01); - test_helper_check_keys(REPO_PATH_01, CR_HT_KEY_NAME, REPO_SIZE_01, REPO_NAME_KEYS_01); - test_helper_check_keys(REPO_PATH_01, CR_HT_KEY_FILENAME, REPO_SIZE_01, REPO_FILENAME_KEYS_01); + test_helper_check_keys(TEST_REPO_01, CR_HT_KEY_HASH, REPO_SIZE_01, REPO_HASH_KEYS_01); + test_helper_check_keys(TEST_REPO_01, CR_HT_KEY_NAME, REPO_SIZE_01, REPO_NAME_KEYS_01); + test_helper_check_keys(TEST_REPO_01, CR_HT_KEY_FILENAME, REPO_SIZE_01, REPO_FILENAME_KEYS_01); - test_helper_check_keys(REPO_PATH_02, CR_HT_KEY_HASH, REPO_SIZE_02, REPO_HASH_KEYS_02); - test_helper_check_keys(REPO_PATH_02, CR_HT_KEY_NAME, REPO_SIZE_02, REPO_NAME_KEYS_02); - test_helper_check_keys(REPO_PATH_02, CR_HT_KEY_FILENAME, REPO_SIZE_02, REPO_FILENAME_KEYS_02); + test_helper_check_keys(TEST_REPO_02, CR_HT_KEY_HASH, REPO_SIZE_02, REPO_HASH_KEYS_02); + test_helper_check_keys(TEST_REPO_02, CR_HT_KEY_NAME, REPO_SIZE_02, REPO_NAME_KEYS_02); + test_helper_check_keys(TEST_REPO_02, CR_HT_KEY_FILENAME, REPO_SIZE_02, REPO_FILENAME_KEYS_02); } @@ -114,7 +112,7 @@ static void test_cr_metadata_locate_and_load_xml_detailed(void) metadata = cr_metadata_new(CR_HT_KEY_NAME, 0, NULL); g_assert(metadata); - ret = cr_metadata_locate_and_load_xml(metadata, REPO_PATH_01, NULL); + ret = cr_metadata_locate_and_load_xml(metadata, TEST_REPO_01, NULL); g_assert_cmpint(ret, ==, CRE_OK); size = g_hash_table_size(metadata->ht); g_assert_cmpuint(size, ==, REPO_SIZE_01); diff --git a/tests/testmisc.c b/tests/testmisc.c index cd7414b..c8a2340 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -22,19 +22,19 @@ #include #include #include +#include "fixtures.h" #include "createrepo/misc.h" -#define TEST_FILES_PATH "test_data/test_files/" #define EMPTY_FILE TEST_FILES_PATH"empty_file" #define TEXT_FILE TEST_FILES_PATH"text_file" #define BINARY_FILE TEST_FILES_PATH"binary_file" -#define PACKAGE_01 "test_data/packages/super_kernel-6.0.1-2.x86_64.rpm" +#define PACKAGE_01 TEST_PACKAGES_PATH"super_kernel-6.0.1-2.x86_64.rpm" #define PACKAGE_01_HEADER_START 280 #define PACKAGE_01_HEADER_END 2637 -#define PACKAGE_02 "test_data/packages/fake_bash-1.1.1-1.x86_64.rpm" +#define PACKAGE_02 TEST_PACKAGES_PATH"fake_bash-1.1.1-1.x86_64.rpm" #define PACKAGE_02_HEADER_START 280 #define PACKAGE_02_HEADER_END 2057 @@ -46,7 +46,8 @@ #define INVALID_URL "htp://foo.bar" -static void test_cr_str_to_evr(void) +static void +test_cr_str_to_evr(void) { struct cr_EVR evr; @@ -216,7 +217,8 @@ static void test_cr_str_to_evr(void) } -static void test_cr_str_to_evr_with_chunk(void) +static void +test_cr_str_to_evr_with_chunk(void) { struct cr_EVR evr; GStringChunk *chunk; @@ -333,7 +335,8 @@ static void test_cr_str_to_evr_with_chunk(void) } -static void test_cr_is_primary(void) +static void +test_cr_is_primary(void) { g_assert(cr_is_primary("/etc/foobar")); g_assert(cr_is_primary("/etc/")); @@ -356,7 +359,8 @@ static void test_cr_is_primary(void) } -static void test_cr_compute_file_checksum(void) +static void +test_cr_compute_file_checksum(void) { char *checksum; @@ -400,7 +404,8 @@ static void test_cr_compute_file_checksum(void) } -static void test_cr_get_header_byte_range(void) +static void +test_cr_get_header_byte_range(void) { struct cr_HeaderRangeStruct hdr_range; @@ -418,7 +423,8 @@ static void test_cr_get_header_byte_range(void) } -static void test_cr_checksum_name_str(void) +static void +test_cr_checksum_name_str(void) { const char *checksum_name; @@ -436,7 +442,8 @@ static void test_cr_checksum_name_str(void) } -static void test_cr_get_filename(void) +static void +test_cr_get_filename(void) { char *filename; @@ -474,7 +481,8 @@ typedef struct { } Copyfiletest; -static void copyfiletest_setup(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +copyfiletest_setup(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); copyfiletest->tmp_dir = g_strdup(TMP_DIR_PATTERN); @@ -483,7 +491,8 @@ static void copyfiletest_setup(Copyfiletest *copyfiletest, gconstpointer test_da } -static void copyfiletest_teardown(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +copyfiletest_teardown(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); remove(copyfiletest->dst_file); @@ -493,7 +502,8 @@ static void copyfiletest_teardown(Copyfiletest *copyfiletest, gconstpointer test } -static void copyfiletest_test_empty_file(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +copyfiletest_test_empty_file(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -509,7 +519,8 @@ static void copyfiletest_test_empty_file(Copyfiletest *copyfiletest, gconstpoint } -static void copyfiletest_test_text_file(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +copyfiletest_test_text_file(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -525,7 +536,8 @@ static void copyfiletest_test_text_file(Copyfiletest *copyfiletest, gconstpointe } -static void copyfiletest_test_binary_file(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +copyfiletest_test_binary_file(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -541,7 +553,8 @@ static void copyfiletest_test_binary_file(Copyfiletest *copyfiletest, gconstpoin } -static void copyfiletest_test_rewrite(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +copyfiletest_test_rewrite(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -564,7 +577,8 @@ static void copyfiletest_test_rewrite(Copyfiletest *copyfiletest, gconstpointer } -static void copyfiletest_test_corner_cases(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +copyfiletest_test_corner_cases(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -576,7 +590,8 @@ static void copyfiletest_test_corner_cases(Copyfiletest *copyfiletest, gconstpoi } -static void compressfile_test_text_file(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +compressfile_test_text_file(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -592,7 +607,8 @@ static void compressfile_test_text_file(Copyfiletest *copyfiletest, gconstpointe } -static void test_cr_download_valid_url_1(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +test_cr_download_valid_url_1(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); @@ -608,7 +624,8 @@ static void test_cr_download_valid_url_1(Copyfiletest *copyfiletest, gconstpoint -static void test_cr_download_valid_url_2(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +test_cr_download_valid_url_2(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); @@ -625,7 +642,8 @@ static void test_cr_download_valid_url_2(Copyfiletest *copyfiletest, gconstpoint } -static void test_cr_download_invalid_url(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +test_cr_download_invalid_url(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); @@ -642,7 +660,8 @@ static void test_cr_download_invalid_url(Copyfiletest *copyfiletest, gconstpoint -static void test_cr_better_copy_file_local(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +test_cr_better_copy_file_local(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -659,7 +678,8 @@ static void test_cr_better_copy_file_local(Copyfiletest *copyfiletest, gconstpoi -static void test_cr_better_copy_file_url(Copyfiletest *copyfiletest, gconstpointer test_data) +static void +test_cr_better_copy_file_url(Copyfiletest *copyfiletest, gconstpointer test_data) { CR_UNUSED(test_data); int ret; @@ -672,7 +692,8 @@ static void test_cr_better_copy_file_url(Copyfiletest *copyfiletest, gconstpoint -static void test_cr_remove_dir(void) +static void +test_cr_remove_dir(void) { char *tmp_dir; char *subdir01, *subdir02, *subsubdir011, *subsubsubdir0111; @@ -735,7 +756,8 @@ static void test_cr_remove_dir(void) } -static void test_cr_normalize_dir_path(void) +static void +test_cr_normalize_dir_path(void) { char *normalized; @@ -773,7 +795,8 @@ static void test_cr_normalize_dir_path(void) } -static void test_cr_str_to_version(void) +static void +test_cr_str_to_version(void) { struct cr_Version ver; @@ -884,7 +907,8 @@ static void test_cr_str_to_version(void) } -static void test_cr_cmp_version_str(void) +static void +test_cr_cmp_version_str(void) { int ret; @@ -940,7 +964,8 @@ static void test_cr_cmp_version_str(void) g_assert_cmpint(ret, ==, 2); } -static void test_cr_split_rpm_filename(void) +static void +test_cr_split_rpm_filename(void) { struct cr_NVREA *res; @@ -985,7 +1010,8 @@ static void test_cr_split_rpm_filename(void) } -static void test_cr_cmp_evr(void) +static void +test_cr_cmp_evr(void) { int res; @@ -1023,7 +1049,8 @@ static void test_cr_cmp_evr(void) } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); diff --git a/tests/testsqlite.c b/tests/testsqlite.c index 49b5d9d..bfef7f9 100644 --- a/tests/testsqlite.c +++ b/tests/testsqlite.c @@ -23,6 +23,7 @@ #include #include #include +#include "fixtures.h" #include "createrepo/misc.h" #include "createrepo/package.h" #include "createrepo/sqlite.h" @@ -34,8 +35,8 @@ #define TMP_FILELISTS_NAME "filelists.sqlite" #define TMP_OTHER_NAME "other.sqlite" -#define EMPTY_PKG "test_data/packages/empty-0-0.x86_64.rpm" -#define EMPTY_PKG_SRC "test_data/packages/empty-0-0.src.rpm" +#define EMPTY_PKG TEST_PACKAGES_PATH"empty-0-0.x86_64.rpm" +#define EMPTY_PKG_SRC TEST_PACKAGES_PATH"empty-0-0.src.rpm" typedef struct { -- 2.7.4