diff --git a/tests/Makefile.am b/tests/Makefile.am index 45996340f..fc1637130 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1 +1,3 @@ SUBDIRS = lib src + +EXTRA_DIST = mctest.h diff --git a/tests/lib/library_independ.c b/tests/lib/library_independ.c index 1d4d0cd3a..7a491ec4e 100644 --- a/tests/lib/library_independ.c +++ b/tests/lib/library_independ.c @@ -1,11 +1,11 @@ /* libmc - check if library is independ to $(topsrc)/src directory - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,7 @@ #define TEST_SUITE_NAME "lib/library_independ" -#include - -#include - -#include "lib/global.h" +#include "tests/mctest.h" /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/mc_build_filename.c b/tests/lib/mc_build_filename.c index 43b8d5a2e..1df0162fc 100644 --- a/tests/lib/mc_build_filename.c +++ b/tests/lib/mc_build_filename.c @@ -1,11 +1,11 @@ /* lib/vfs - mc_build_filename() function testing - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,13 +25,10 @@ #define TEST_SUITE_NAME "/lib" -#include - -#include +#include "tests/mctest.h" #include -#include "lib/global.h" #include "lib/strutil.h" #include "lib/util.h" diff --git a/tests/lib/mcconfig/config_string.c b/tests/lib/mcconfig/config_string.c index 4e4617f24..6c9fd2c2f 100644 --- a/tests/lib/mcconfig/config_string.c +++ b/tests/lib/mcconfig/config_string.c @@ -1,11 +1,11 @@ /* libmc - check mcconfig submodule. read and write config files - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "lib/mcconfig" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "lib/mcconfig.h" #include "lib/strutil.h" #include "lib/strescape.h" diff --git a/tests/lib/mcconfig/user_configs_path.c b/tests/lib/mcconfig/user_configs_path.c index f25b510c7..b06b2488e 100644 --- a/tests/lib/mcconfig/user_configs_path.c +++ b/tests/lib/mcconfig/user_configs_path.c @@ -1,11 +1,11 @@ /* libmc - check mcconfig submodule. Get full paths to user's config files. - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -24,10 +24,8 @@ */ #define TEST_SUITE_NAME "lib/mcconfig" -#include -#include -#include "lib/global.h" +#include "tests/mctest.h" #include "lib/strutil.h" #include "lib/strescape.h" diff --git a/tests/lib/name_quote.c b/tests/lib/name_quote.c index 091d4a203..8fde62985 100644 --- a/tests/lib/name_quote.c +++ b/tests/lib/name_quote.c @@ -1,11 +1,11 @@ /* lib/vfs - Quote file names - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,20 +25,19 @@ #define TEST_SUITE_NAME "/lib/util" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "lib/util.h" /* --------------------------------------------------------------------------------------------- */ +/* @Before */ static void setup (void) { } +/* @After */ static void teardown (void) { @@ -46,8 +45,9 @@ teardown (void) /* --------------------------------------------------------------------------------------------- */ +/* @DataSource("data_source1") */ /* *INDENT-OFF* */ -static const struct data_source1_struct +static const struct data_source1 { gboolean input_quote_percent; const char *input_string; @@ -60,30 +60,31 @@ static const struct data_source1_struct }; /* *INDENT-ON* */ +/* @Test(dataSource = "data_source1") */ /* *INDENT-OFF* */ -START_TEST (quote_percent_test) +START_PARAMETRIZED_TEST (quote_percent_test, data_source1) /* *INDENT-ON* */ { /* given */ char *actual_string; - const struct data_source1_struct test_data = data_source1[_i]; /* when */ - actual_string = name_quote (test_data.input_string, test_data.input_quote_percent); + actual_string = name_quote (data->input_string, data->input_quote_percent); /* then */ - g_assert_cmpstr (actual_string, ==, test_data.expected_string); + mctest_assert_str_eq (actual_string, data->expected_string); g_free (actual_string); } /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ +/* @DataSource("data_source2") */ /* *INDENT-OFF* */ -static const struct data_source2_struct +static const struct data_source2 { const char *input_string; @@ -102,24 +103,24 @@ static const struct data_source2_struct }; /* *INDENT-ON* */ +/* @Test(dataSource = "data_source2") */ /* *INDENT-OFF* */ -START_TEST (name_quote_test) +START_PARAMETRIZED_TEST (name_quote_test, data_source2) /* *INDENT-ON* */ { /* given */ char *actual_string; - const struct data_source2_struct test_data = data_source2[_i]; /* when */ - actual_string = name_quote (test_data.input_string, FALSE); + actual_string = name_quote (data->input_string, FALSE); /* then */ - g_assert_cmpstr (actual_string, ==, test_data.expected_string); + mctest_assert_str_eq (actual_string, data->expected_string); g_free (actual_string); } /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ @@ -136,11 +137,8 @@ main (void) tcase_add_checked_fixture (tc_core, setup, teardown); /* Add new tests here: *************** */ - tcase_add_loop_test (tc_core, quote_percent_test, 0, - sizeof (data_source1) / sizeof (data_source1[0])); - - tcase_add_loop_test (tc_core, name_quote_test, 0, - sizeof (data_source2) / sizeof (data_source2[0])); + mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1); + mctest_add_parameterized_test (tc_core, name_quote_test, data_source2); /* *********************************** */ suite_add_tcase (s, tc_core); diff --git a/tests/lib/search/regex_process_escape_sequence.c b/tests/lib/search/regex_process_escape_sequence.c index 7bb478eea..2b5a0a2ac 100644 --- a/tests/lib/search/regex_process_escape_sequence.c +++ b/tests/lib/search/regex_process_escape_sequence.c @@ -1,11 +1,11 @@ /* libmc - checks for processing esc sequences in replace string - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,9 +25,7 @@ #define TEST_SUITE_NAME "lib/search/regex" -#include - -#include +#include "tests/mctest.h" #include "regex.c" /* for testing static functions */ diff --git a/tests/lib/search/regex_replace_esc_seq.c b/tests/lib/search/regex_replace_esc_seq.c index 05790cf4f..b8c17db06 100644 --- a/tests/lib/search/regex_replace_esc_seq.c +++ b/tests/lib/search/regex_replace_esc_seq.c @@ -1,11 +1,11 @@ /* libmc - checks for processing esc sequences in replace string - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,9 +25,7 @@ #define TEST_SUITE_NAME "lib/search/regex" -#include - -#include +#include "tests/mctest.h" #include "regex.c" /* for testing static functions */ diff --git a/tests/lib/serialize.c b/tests/lib/serialize.c index bdaca2e30..fc30366aa 100644 --- a/tests/lib/serialize.c +++ b/tests/lib/serialize.c @@ -1,11 +1,11 @@ /* lib/vfs - common serialize/deserialize functions - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "/lib" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "lib/strutil.h" #include "lib/serialize.h" diff --git a/tests/lib/vfs/canonicalize_pathname.c b/tests/lib/vfs/canonicalize_pathname.c index fc2e83686..434b491a9 100644 --- a/tests/lib/vfs/canonicalize_pathname.c +++ b/tests/lib/vfs/canonicalize_pathname.c @@ -1,11 +1,11 @@ /* lib - canonicalize path - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "lib/strutil.h" #include "lib/util.h" #include "lib/vfs/xdirentry.h" diff --git a/tests/lib/vfs/current_dir.c b/tests/lib/vfs/current_dir.c index 7dec19fb4..fe35203d0 100644 --- a/tests/lib/vfs/current_dir.c +++ b/tests/lib/vfs/current_dir.c @@ -1,11 +1,11 @@ /* lib/vfs - manipulate with current directory - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,9 +25,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include +#include "tests/mctest.h" #include "lib/global.h" #include "lib/strutil.h" diff --git a/tests/lib/vfs/path_cmp.c b/tests/lib/vfs/path_cmp.c index a4136ae89..1cd1540da 100644 --- a/tests/lib/vfs/path_cmp.c +++ b/tests/lib/vfs/path_cmp.c @@ -1,9 +1,10 @@ /* lib/vfs - vfs_path_t compare functions - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011, 2013 + The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License @@ -22,9 +23,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include "lib/global.c" +#include "tests/mctest.h" #ifdef HAVE_CHARSET #include "lib/charsets.h" diff --git a/tests/lib/vfs/path_len.c b/tests/lib/vfs/path_len.c index 2e53486dd..db47808fc 100644 --- a/tests/lib/vfs/path_len.c +++ b/tests/lib/vfs/path_len.c @@ -1,9 +1,10 @@ /* lib/vfs - vfs_path_t compare functions - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011, 2013 + The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License @@ -22,9 +23,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include "lib/global.c" +#include "tests/mctest.h" #ifdef HAVE_CHARSET #include "lib/charsets.h" diff --git a/tests/lib/vfs/path_manipulations.c b/tests/lib/vfs/path_manipulations.c index ad014a9f4..cb5e31446 100644 --- a/tests/lib/vfs/path_manipulations.c +++ b/tests/lib/vfs/path_manipulations.c @@ -1,9 +1,10 @@ /* lib/vfs - test vfs_path_t manipulation functions - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011, 2013 + The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License @@ -22,9 +23,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include "lib/global.c" +#include "tests/mctest.h" #ifdef HAVE_CHARSET #include "lib/charsets.h" diff --git a/tests/lib/vfs/path_recode.c b/tests/lib/vfs/path_recode.c index b39dfa1a0..6d4a31548 100644 --- a/tests/lib/vfs/path_recode.c +++ b/tests/lib/vfs/path_recode.c @@ -1,11 +1,11 @@ /* lib/vfs - vfs_path_t charset recode functions - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include - -#include "lib/global.c" +#include "tests/mctest.h" #include "lib/charsets.h" diff --git a/tests/lib/vfs/path_serialize.c b/tests/lib/vfs/path_serialize.c index 0c992b8ba..02c5adde6 100644 --- a/tests/lib/vfs/path_serialize.c +++ b/tests/lib/vfs/path_serialize.c @@ -1,11 +1,11 @@ /* lib/vfs - vfs_path_t serialize/deserialize functions - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include - -#include "lib/global.c" +#include "tests/mctest.h" #ifdef HAVE_CHARSET #include "lib/charsets.h" diff --git a/tests/lib/vfs/relative_cd.c b/tests/lib/vfs/relative_cd.c index a391a00c6..7728d14ba 100644 --- a/tests/lib/vfs/relative_cd.c +++ b/tests/lib/vfs/relative_cd.c @@ -1,9 +1,10 @@ /* lib/vfs - test vfs_path_t manipulation functions - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011, 2013 + The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License @@ -22,9 +23,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include "lib/global.c" +#include "tests/mctest.h" #include "lib/strutil.h" #include "lib/vfs/xdirentry.h" diff --git a/tests/lib/vfs/tempdir.c b/tests/lib/vfs/tempdir.c index 7bd025863..abf37c613 100644 --- a/tests/lib/vfs/tempdir.c +++ b/tests/lib/vfs/tempdir.c @@ -1,11 +1,11 @@ /* lib/vfs - manipulations with temp files and dirs - Copyright (C) 2012 + Copyright (C) 2012, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2012 + Slava Zanko , 2012, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include - -#include "lib/global.c" +#include "tests/mctest.h" #ifndef HAVE_CHARSET #define HAVE_CHARSET 1 diff --git a/tests/lib/vfs/vfs_parse_ls_lga.c b/tests/lib/vfs/vfs_parse_ls_lga.c index 9998c948c..c33549327 100644 --- a/tests/lib/vfs/vfs_parse_ls_lga.c +++ b/tests/lib/vfs/vfs_parse_ls_lga.c @@ -1,11 +1,11 @@ /* lib/vfs - test vfs_parse_ls_lga() functionality - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,12 +25,10 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include +#include "tests/mctest.h" -#include #include -#include "lib/global.h" #include "lib/vfs/utilvfs.h" #include "lib/vfs/xdirentry.h" #include "lib/strutil.h" diff --git a/tests/lib/vfs/vfs_path_string_convert.c b/tests/lib/vfs/vfs_path_string_convert.c index d86a8a08b..4f4c672a4 100644 --- a/tests/lib/vfs/vfs_path_string_convert.c +++ b/tests/lib/vfs/vfs_path_string_convert.c @@ -1,11 +1,11 @@ /* lib/vfs - get vfs_path_t from string - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,7 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include - -#include - -#include "lib/global.c" +#include "tests/mctest.h" #ifdef HAVE_CHARSET #include "lib/charsets.h" diff --git a/tests/lib/vfs/vfs_prefix_to_class.c b/tests/lib/vfs/vfs_prefix_to_class.c index 59dedb066..c6520b757 100644 --- a/tests/lib/vfs/vfs_prefix_to_class.c +++ b/tests/lib/vfs/vfs_prefix_to_class.c @@ -1,11 +1,11 @@ /* lib/vfs - test vfs_prefix_to_class() functionality - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "lib/strutil.h" #include "lib/vfs/xdirentry.h" #include "lib/vfs/vfs.c" /* for testing static methods */ diff --git a/tests/lib/vfs/vfs_s_get_path.c b/tests/lib/vfs/vfs_s_get_path.c index e3f270daf..6a2071d5c 100644 --- a/tests/lib/vfs/vfs_s_get_path.c +++ b/tests/lib/vfs/vfs_s_get_path.c @@ -1,11 +1,11 @@ /* lib/vfs - test vfs_s_get_path() function - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "lib/strutil.h" #include "lib/vfs/direntry.c" /* for testing static methods */ diff --git a/tests/lib/vfs/vfs_split.c b/tests/lib/vfs/vfs_split.c index ab6d9f30b..db17eff80 100644 --- a/tests/lib/vfs/vfs_split.c +++ b/tests/lib/vfs/vfs_split.c @@ -1,11 +1,11 @@ /* lib/vfs - test vfs_split() functionality - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "/lib/vfs" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "lib/strutil.h" #include "lib/vfs/xdirentry.h" #include "lib/vfs/path.c" /* for testing static methods */ diff --git a/tests/lib/x_basename.c b/tests/lib/x_basename.c index 1435bfc97..867b94c88 100644 --- a/tests/lib/x_basename.c +++ b/tests/lib/x_basename.c @@ -1,11 +1,11 @@ /* lib/vfs - x_basename() function testing - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,57 +25,86 @@ #define TEST_SUITE_NAME "/lib" -#include - -#include +#include "tests/mctest.h" #include -#include "lib/global.h" #include "lib/strutil.h" #include "lib/util.h" +/* --------------------------------------------------------------------------------------------- */ +/* @Before */ static void setup (void) { } +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ static void teardown (void) { } /* --------------------------------------------------------------------------------------------- */ -#define check_x_basename( input, etalon ) \ -{ \ - result = x_basename ( input ); \ - fail_unless(strcmp(result, etalon) == 0, \ - "\ninput (%s)\nactial (%s) not equal to\netalon (%s)", input, result, etalon); \ -} +/* @DataSource("test_x_basename_ds") */ /* *INDENT-OFF* */ -START_TEST (test_x_basename) +static const struct test_x_basename_ds +{ + const char *input_value; + const char *expected_result; +} test_x_basename_ds[] = +{ + { + "/test/path/test2/path2", + "path2" + }, + { + "/test/path/test2/path2#vfsprefix", + "path2#vfsprefix" + }, + { + "/test/path/test2/path2/vfsprefix://", + "path2/vfsprefix://" + }, + { + "/test/path/test2/path2/vfsprefix://subdir", + "subdir" + }, + { + "/test/path/test2/path2/vfsprefix://subdir/", + "subdir/" + }, + { + "/test/path/test2/path2/vfsprefix://subdir/subdir2", + "subdir2" + }, + { + "/test/path/test2/path2/vfsprefix:///", + "/" + }, +}; +/* *INDENT-ON* */ + +/* @Test(dataSource = "test_x_basename_ds") */ +/* *INDENT-OFF* */ +START_PARAMETRIZED_TEST (test_x_basename, test_x_basename_ds) /* *INDENT-ON* */ { - const char *result; - check_x_basename ("/test/path/test2/path2", "path2"); + /* given */ + const char *actual_result; - check_x_basename ("/test/path/test2/path2#vfsprefix", "path2#vfsprefix"); + /* when */ + actual_result = x_basename (data->input_value); - check_x_basename ("/test/path/test2/path2/vfsprefix://", "path2/vfsprefix://"); - - - check_x_basename ("/test/path/test2/path2/vfsprefix://subdir", "subdir"); - - check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/", "subdir/"); - - check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/subdir2", "subdir2"); - - check_x_basename ("/test/path/test2/path2/vfsprefix:///", "/"); + /* then */ + mctest_assert_str_eq (actual_result, data->expected_result); } /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ @@ -92,7 +121,7 @@ main (void) tcase_add_checked_fixture (tc_core, setup, teardown); /* Add new tests here: *************** */ - tcase_add_test (tc_core, test_x_basename); + mctest_add_parameterized_test (tc_core, test_x_basename, test_x_basename_ds); /* *********************************** */ suite_add_tcase (s, tc_core); diff --git a/tests/mctest.h b/tests/mctest.h new file mode 100644 index 000000000..4699acfe8 --- /dev/null +++ b/tests/mctest.h @@ -0,0 +1,77 @@ +#ifndef MC__TEST +#define MC__TEST + +#include +#include + +#include "lib/global.h" + +/*** typedefs(not structures) and defined constants **********************************************/ + +#define mctest_add_parameterized_test(tc_core, test_func, test_data_source) {\ + tcase_add_loop_test (tc_core, test_func, 0, \ + sizeof (test_data_source) / sizeof (test_data_source[0])); \ +} + +#define mctest_assert_str_eq(actual_result, etalon_result) { \ + g_assert_cmpstr (actual_result, ==, etalon_result); \ +} + +#define mctest_assert_int_eq(actual_result, etalon_result) { \ + ck_assert_int_eq (actual_result, etalon_result); \ +} + +#define mctest_assert_int_ne(actual_result, etalon_result) { \ + ck_assert_int_ne (actual_result, etalon_result); \ +} + +#define mctest_assert_ptr_eq(actual_pointer, etalon_pointer) { \ + fail_unless ( actual_pointer == etalon_pointer, \ + "%s(%p) pointer should be equal to %s(%p)\n", \ + #actual_pointer, actual_pointer, #etalon_pointer , etalon_pointer \ + );\ +} + +#define mctest_assert_ptr_ne(actual_pointer, etalon_pointer) { \ + fail_unless ( actual_pointer != etalon_pointer, \ + "%s(%p) pointer should not be equal to %s(%p)\n", \ + #actual_pointer, actual_pointer, #etalon_pointer , etalon_pointer \ + );\ +} + +#define mctest_assert_null(actual_pointer) { \ + fail_unless( \ + (void *) actual_pointer == NULL, \ + "%s(%p) variable should be NULL", #actual_pointer, actual_pointer \ + ); \ +} + +#define mctest_assert_not_null(actual_pointer) { \ + fail_if( \ + (void *) actual_pointer == NULL, \ + "%s(nil) variable should not be NULL", #actual_pointer \ + ); \ +} + +/** + * Define header for a parameterized test. + * Declare 'data' variable for access to the parameters in current iteration + */ +#define START_PARAMETRIZED_TEST(name_test, struct_name) START_TEST (name_test) { const struct struct_name *data = &struct_name[_i]; + +/** + * Define footer for a parameterized test. + */ +#define END_PARAMETRIZED_TEST } END_TEST + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/*** inline functions ****************************************************************************/ + +#endif /* MC__TEST */ diff --git a/tests/src/filemanager/do_cd_command.c b/tests/src/filemanager/do_cd_command.c index defbc92c4..433fe3865 100644 --- a/tests/src/filemanager/do_cd_command.c +++ b/tests/src/filemanager/do_cd_command.c @@ -1,11 +1,11 @@ /* src/filemanager - tests for do_cd_command() function - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2011 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "/src/filemanager" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "src/vfs/local/local.c" #include "src/filemanager/command.c" @@ -128,11 +125,10 @@ static const struct test_empty_mean_home_ds /* @Test(dataSource = "test_empty_mean_home_ds") */ /* *INDENT-OFF* */ -START_TEST (test_empty_mean_home) +START_PARAMETRIZED_TEST (test_empty_mean_home, test_empty_mean_home_ds) /* *INDENT-ON* */ { /* given */ - get_current_type__return_value = view_listing; do_cd__return_value = TRUE; mc_config_get_home_dir__return_value = "/home/test"; @@ -141,7 +137,7 @@ START_TEST (test_empty_mean_home) { char *input_command; - input_command = g_strdup (test_empty_mean_home_ds[_i].command); + input_command = g_strdup (data->command); do_cd_command (input_command); g_free (input_command); } @@ -150,13 +146,13 @@ START_TEST (test_empty_mean_home) char *actual_path; actual_path = vfs_path_to_str (do_cd__new_dir_vpath__captured); - g_assert_cmpstr (mc_config_get_home_dir__return_value, ==, actual_path); + mctest_assert_str_eq (mc_config_get_home_dir__return_value, actual_path); g_free (actual_path); } - ck_assert_int_eq (do_cd__cd_type__captured, cd_parse_command); + mctest_assert_int_eq (do_cd__cd_type__captured, cd_parse_command); } /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ @@ -173,8 +169,7 @@ main (void) tcase_add_checked_fixture (tc_core, setup, teardown); /* Add new tests here: *************** */ - tcase_add_loop_test (tc_core, test_empty_mean_home, 0, - sizeof (test_empty_mean_home_ds) / sizeof (test_empty_mean_home_ds[0])); + mctest_add_parameterized_test (tc_core, test_empty_mean_home, test_empty_mean_home_ds); /* *********************************** */ suite_add_tcase (s, tc_core); diff --git a/tests/src/filemanager/examine_cd.c b/tests/src/filemanager/examine_cd.c index 7da927f7b..ee769b9a6 100644 --- a/tests/src/filemanager/examine_cd.c +++ b/tests/src/filemanager/examine_cd.c @@ -1,11 +1,12 @@ /* src/filemanager - examine_cd() function testing - Copyright (C) 2012 + Copyright (C) 2012, 2013 The Free Software Foundation, Inc. Written by: Andrew Borodin , 2012 + Slava Zanko , 2013 This file is part of the Midnight Commander. @@ -25,13 +26,10 @@ #define TEST_SUITE_NAME "/src/filemanager" -#include - -#include +#include "tests/mctest.h" #include -#include "lib/global.h" #include "lib/vfs/path.h" #include "src/filemanager/layout.h" #include "src/filemanager/midnight.h" diff --git a/tests/src/filemanager/exec_get_export_variables_ext.c b/tests/src/filemanager/exec_get_export_variables_ext.c index c95e70b73..086c7fa3b 100644 --- a/tests/src/filemanager/exec_get_export_variables_ext.c +++ b/tests/src/filemanager/exec_get_export_variables_ext.c @@ -1,11 +1,11 @@ /* src/filemanager - filemanager functions - Copyright (C) 2011 + Copyright (C) 2011, 2013 The Free Software Foundation, Inc. Written by: - Slava Zanko , 2012 + Slava Zanko , 2011, 2013 This file is part of the Midnight Commander. @@ -25,11 +25,8 @@ #define TEST_SUITE_NAME "/src/filemanager" -#include +#include "tests/mctest.h" -#include - -#include "lib/global.h" #include "src/vfs/local/local.c" #include "src/filemanager/midnight.c" @@ -102,7 +99,7 @@ export MC_EXT_SELECTED\n\ MC_EXT_ONLYTAGGED=\"tagged\\ file1.txt tagged\\ file2.txt \"\n\ export MC_EXT_ONLYTAGGED\n"; - g_assert_cmpstr (actual_string, ==, expected_string); + mctest_assert_str_eq (actual_string, expected_string); g_free (actual_string); }