From 61fb6e33b3e3835ad334c24465d09253e64b982e Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Sat, 19 Jan 2013 18:56:40 +0300 Subject: [PATCH] Code refactoring in tests. Signed-off-by: Slava Zanko --- tests/lib/{name_quote.c => mc_build_filename.c} | 124 ++--- tests/lib/name_quote.c | 2 +- tests/lib/serialize.c | 684 ++++++++++++++---------- tests/lib/vfs/tempdir.c | 37 +- tests/lib/vfs/vfs_parse_ls_lga.c | 334 ++++++------ tests/lib/vfs/vfs_path_string_convert.c | 377 +++++++------ tests/lib/vfs/vfs_prefix_to_class.c | 95 ++-- tests/lib/vfs/vfs_s_get_path.c | 28 +- tests/lib/vfs/vfs_split.c | 566 ++++++++------------ 9 files changed, 1151 insertions(+), 1096 deletions(-) copy tests/lib/{name_quote.c => mc_build_filename.c} (51%) rewrite tests/lib/serialize.c (63%) rewrite tests/lib/vfs/vfs_split.c (74%) diff --git a/tests/lib/name_quote.c b/tests/lib/mc_build_filename.c similarity index 51% copy from tests/lib/name_quote.c copy to tests/lib/mc_build_filename.c index 8fde62985..c701634c8 100644 --- a/tests/lib/name_quote.c +++ b/tests/lib/mc_build_filename.c @@ -1,5 +1,5 @@ /* - lib/vfs - Quote file names + lib/vfs - mc_build_filename() function testing Copyright (C) 2011, 2013 The Free Software Foundation, Inc. @@ -23,10 +23,13 @@ along with this program. If not, see . */ -#define TEST_SUITE_NAME "/lib/util" +#define TEST_SUITE_NAME "/lib" #include "tests/mctest.h" +#include + +#include "lib/strutil.h" #include "lib/util.h" /* --------------------------------------------------------------------------------------------- */ @@ -37,6 +40,8 @@ setup (void) { } +/* --------------------------------------------------------------------------------------------- */ + /* @After */ static void teardown (void) @@ -45,79 +50,79 @@ teardown (void) /* --------------------------------------------------------------------------------------------- */ -/* @DataSource("data_source1") */ -/* *INDENT-OFF* */ -static const struct data_source1 -{ - gboolean input_quote_percent; - const char *input_string; - - const char *expected_string; -} data_source1[] = -{ - { TRUE, "%%", "%%%%"}, - { FALSE, "%%", "%%"}, -}; -/* *INDENT-ON* */ - -/* @Test(dataSource = "data_source1") */ -/* *INDENT-OFF* */ -START_PARAMETRIZED_TEST (quote_percent_test, data_source1) -/* *INDENT-ON* */ +static char * +run_mc_build_filename (int iteration) { - /* given */ - char *actual_string; - - /* when */ - actual_string = name_quote (data->input_string, data->input_quote_percent); - - /* then */ - mctest_assert_str_eq (actual_string, data->expected_string); - - g_free (actual_string); + switch (iteration) + { + case 0: + return mc_build_filename ("test", "path", NULL); + case 1: + return mc_build_filename ("/test", "path/", NULL); + case 2: + return mc_build_filename ("/test", "pa/th", NULL); + case 3: + return mc_build_filename ("/test", "#vfsprefix:", "path ", NULL); + case 4: + return mc_build_filename ("/test", "vfsprefix://", "path ", NULL); + case 5: + return mc_build_filename ("/test", "vfs/../prefix:///", "p\\///ath", NULL); + case 6: + return mc_build_filename ("/test", "path", "..", "/test", "path/", NULL); + case 7: + return mc_build_filename ("", "path", NULL); + case 8: + return mc_build_filename ("", "/path", NULL); + case 9: + return mc_build_filename ("path", "", NULL); + case 10: + return mc_build_filename ("/path", "", NULL); + case 11: + return mc_build_filename ("pa", "", "th", NULL); + case 12: + return mc_build_filename ("/pa", "", "/th", NULL); + } + return NULL; } -/* *INDENT-OFF* */ -END_PARAMETRIZED_TEST -/* *INDENT-ON* */ -/* --------------------------------------------------------------------------------------------- */ - -/* @DataSource("data_source2") */ +/* @DataSource("test_mc_build_filename_ds") */ /* *INDENT-OFF* */ -static const struct data_source2 +static const struct test_mc_build_filename_ds { - const char *input_string; - - const char *expected_string; -} data_source2[] = + const char *expected_result; +} test_mc_build_filename_ds[] = { - {"-", "./-"}, - {"blabla-", "blabla-"}, - {"\r\n\t", "\\\r\\\n\\\t"}, - {"'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)"}, - {"a b c ", "a\\ b\\ c\\ "}, - {"#", "\\#"}, - {"blabla#", "blabla#"}, - {"~", "\\~"}, - {"blabla~", "blabla~"}, + {"test/path"}, + {"/test/path"}, + {"/test/pa/th"}, + {"/test/#vfsprefix:/path "}, + {"/test/vfsprefix://path "}, + {"/test/prefix://p\\/ath"}, + {"/test/test/path"}, + {"path"}, + {"path"}, + {"path"}, + {"/path"}, + {"pa/th"}, + {"/pa/th"}, }; /* *INDENT-ON* */ -/* @Test(dataSource = "data_source2") */ +/* @Test(dataSource = "test_mc_build_filename_ds") */ /* *INDENT-OFF* */ -START_PARAMETRIZED_TEST (name_quote_test, data_source2) +START_PARAMETRIZED_TEST (test_mc_build_filename, test_mc_build_filename_ds) /* *INDENT-ON* */ { /* given */ - char *actual_string; + char *actual_result; /* when */ - actual_string = name_quote (data->input_string, FALSE); + actual_result = run_mc_build_filename (_i); /* then */ - mctest_assert_str_eq (actual_string, data->expected_string); + mctest_assert_str_eq (actual_result, data->expected_result); - g_free (actual_string); + g_free (actual_result); } /* *INDENT-OFF* */ END_PARAMETRIZED_TEST @@ -137,13 +142,12 @@ main (void) tcase_add_checked_fixture (tc_core, setup, teardown); /* Add new tests here: *************** */ - mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1); - mctest_add_parameterized_test (tc_core, name_quote_test, data_source2); + mctest_add_parameterized_test (tc_core, test_mc_build_filename, test_mc_build_filename_ds); /* *********************************** */ suite_add_tcase (s, tc_core); sr = srunner_create (s); - srunner_set_log (sr, "serialize.log"); + srunner_set_log (sr, "mc_build_filename.log"); srunner_run_all (sr, CK_NORMAL); number_failed = srunner_ntests_failed (sr); srunner_free (sr); diff --git a/tests/lib/name_quote.c b/tests/lib/name_quote.c index 8fde62985..421cc3c69 100644 --- a/tests/lib/name_quote.c +++ b/tests/lib/name_quote.c @@ -143,7 +143,7 @@ main (void) suite_add_tcase (s, tc_core); sr = srunner_create (s); - srunner_set_log (sr, "serialize.log"); + srunner_set_log (sr, "name_quote.log"); srunner_run_all (sr, CK_NORMAL); number_failed = srunner_ntests_failed (sr); srunner_free (sr); diff --git a/tests/lib/serialize.c b/tests/lib/serialize.c dissimilarity index 63% index fc30366aa..9dc35c80f 100644 --- a/tests/lib/serialize.c +++ b/tests/lib/serialize.c @@ -1,291 +1,393 @@ -/* - lib/vfs - common serialize/deserialize functions - - Copyright (C) 2011, 2013 - The Free Software Foundation, Inc. - - Written by: - Slava Zanko , 2011, 2013 - - This file is part of the Midnight Commander. - - The Midnight Commander 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 3 of the License, - or (at your option) any later version. - - The Midnight Commander 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, see . - */ - -#define TEST_SUITE_NAME "/lib" - -#include "tests/mctest.h" - -#include "lib/strutil.h" -#include "lib/serialize.h" - - -static void -setup (void) -{ - str_init_strings (NULL); -} - -static void -teardown (void) -{ - str_uninit_strings (); -} - -/* --------------------------------------------------------------------------------------------- */ -#define deserialize_check_incorrect( etalon_code, etalon_str ) { \ - if (actual != NULL) \ - { \ - fail("actual value is '%s', but should be NULL", actual); \ - g_free(actual); \ - } \ - else \ - { \ - fail_unless (error->code == etalon_code && strcmp(error->message, etalon_str) == 0, \ - "\nerror code is %d (should be %d);\nerror message is '%s' (should be '%s')", \ - error->code, etalon_code, error->message, etalon_str); \ - g_clear_error(&error); \ - } \ -} - -/* *INDENT-OFF* */ -START_TEST (test_serialize_deserialize_str) -/* *INDENT-ON* */ -{ - GError *error = NULL; - char *actual; - - - actual = mc_serialize_str ('s', "some test string", &error); - - if (actual == NULL) - { - fail ("actual value is NULL!\nError code is '%d'; error message is '%s'", error->code, - error->message); - g_clear_error (&error); - return; - } - fail_unless (strcmp (actual, "s16:some test string") == 0, - "Actual value(%s) doesn't equal to etalon(s16:some test string)", actual); - g_free (actual); - - actual = mc_deserialize_str ('s', NULL, &error); - deserialize_check_incorrect (-1, "mc_serialize_str(): Input data is NULL or empty."); - - actual = mc_deserialize_str ('s', "incorrect string", &error); - deserialize_check_incorrect (-2, "mc_serialize_str(): String prefix doesn't equal to 's'"); - - actual = mc_deserialize_str ('s', "s12345string without delimiter", &error); - deserialize_check_incorrect (-3, "mc_serialize_str(): Length delimiter ':' doesn't exists"); - - actual = - mc_deserialize_str ('s', - "s1234567890123456789012345678901234567890123456789012345678901234567890:too big number", - &error); - deserialize_check_incorrect (-3, "mc_serialize_str(): Too big string length"); - - actual = - mc_deserialize_str ('s', "s500:actual string length less that specified length", &error); - deserialize_check_incorrect (-3, - "mc_serialize_str(): Specified data length (500) is greater than actual data length (47)"); - - actual = - mc_deserialize_str ('s', "s10:actual string length great that specified length", &error); - fail_unless (actual != NULL - && strcmp (actual, "actual str") == 0, - "actual (%s) doesn't equal to etalon(actual str)", actual); - g_free (actual); - - actual = mc_deserialize_str ('s', "s21:The right test string", &error); - fail_unless (actual != NULL - && strcmp (actual, "The right test string") == 0, - "actual (%s) doesn't equal to etalon(The right test string)", actual); - g_free (actual); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -#define etalon_str "g6:group1p6:param1v10:some valuep6:param2v11:some value " \ - "g6:group2p6:param1v4:truep6:param2v6:123456" \ - "g6:group3p6:param1v11:::bla-bla::p6:param2v31:bla-:p1:w:v2:12:g3:123:bla-bla\n" \ - "g6:group4p6:param1v5:falsep6:param2v6:654321" - -/* *INDENT-OFF* */ -START_TEST (test_serialize_config) -/* *INDENT-ON* */ -{ - mc_config_t *test_data; - GError *error = NULL; - char *actual; - - test_data = mc_config_init (NULL, FALSE); - - mc_config_set_string_raw (test_data, "group1", "param1", "some value"); - mc_config_set_string (test_data, "group1", "param2", "some value "); - - mc_config_set_bool (test_data, "group2", "param1", TRUE); - mc_config_set_int (test_data, "group2", "param2", 123456); - - mc_config_set_string_raw (test_data, "group3", "param1", "::bla-bla::"); - mc_config_set_string (test_data, "group3", "param2", "bla-:p1:w:v2:12:g3:123:bla-bla\n"); - - mc_config_set_bool (test_data, "group4", "param1", FALSE); - mc_config_set_int (test_data, "group4", "param2", 654321); - - actual = mc_serialize_config (test_data, &error); - mc_config_deinit (test_data); - - if (actual == NULL) - { - fail ("actual value is NULL!\nError code is '%d'; error message is '%s'", error->code, - error->message); - g_clear_error (&error); - return; - } - - fail_unless (strcmp (actual, etalon_str) == 0, "Not equal:\nactual (%s)\netalon (%s)", actual, - etalon_str); - g_free (actual); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -#undef deserialize_check_incorrect -#define deserialize_check_incorrect( etalon_code, etalon_str ) { \ - if (actual != NULL) \ - { \ - fail("actual value but should be NULL", actual); \ - mc_config_deinit(actual); \ - } \ - else \ - { \ - fail_unless (error->code == etalon_code && strcmp(error->message, etalon_str) == 0, \ - "\nerror code is %d (should be %d);\nerror message is '%s' (should be '%s')", \ - error->code, etalon_code, error->message, etalon_str); \ - g_clear_error(&error); \ - } \ -} - -/* *INDENT-OFF* */ -START_TEST (test_deserialize_config) -/* *INDENT-ON* */ -{ - mc_config_t *actual; - GError *error = NULL; - char *actual_value; - - actual = mc_deserialize_config ("g123error in group name", &error); - deserialize_check_incorrect (-3, - "mc_deserialize_config() at 1: mc_serialize_str(): Length delimiter ':' doesn't exists"); - - actual = mc_deserialize_config ("p6:param1v10:some valuep6:param2v11:some value ", &error); - deserialize_check_incorrect (-2, - "mc_deserialize_config() at 1: mc_serialize_str(): String prefix doesn't equal to 'g'"); - - actual = mc_deserialize_config ("g6:group1v10:some valuep6:param2v11:some value ", &error); - deserialize_check_incorrect (-2, - "mc_deserialize_config() at 10: mc_serialize_str(): String prefix doesn't equal to 'p'"); - - actual = mc_deserialize_config ("g6:group1p6000:param2v11:some value ", &error); - deserialize_check_incorrect (-3, - "mc_deserialize_config() at 10: mc_serialize_str(): Specified data length (6000) is greater than actual data length (21)"); - - actual = mc_deserialize_config (etalon_str, &error); - - if (actual == NULL) - { - fail ("actual value is NULL!\nError code is '%d'; error message is '%s'", error->code, - error->message); - g_clear_error (&error); - return; - } - - actual_value = mc_config_get_string_raw (actual, "group1", "param1", ""); - fail_unless (strcmp (actual_value, "some value") == 0, - "group1->param1(%s) should be equal to 'some value'", actual_value); - g_free (actual_value); - - actual_value = mc_config_get_string (actual, "group1", "param2", ""); - fail_unless (strcmp (actual_value, "some value ") == 0, - "group1->param2(%s) should be equal to 'some value '", actual_value); - g_free (actual_value); - - fail_unless (mc_config_get_bool (actual, "group2", "param1", FALSE) == TRUE, - "group2->param1(FALSE) should be equal to TRUE"); - - fail_unless (mc_config_get_int (actual, "group2", "param2", 0) == 123456, - "group2->param2(%d) should be equal to 123456", mc_config_get_int (actual, - "group2", - "param2", 0)); - - actual_value = mc_config_get_string_raw (actual, "group3", "param1", ""); - fail_unless (strcmp (actual_value, "::bla-bla::") == 0, - "group3->param1(%s) should be equal to '::bla-bla::'", actual_value); - g_free (actual_value); - - actual_value = mc_config_get_string (actual, "group3", "param2", ""); - fail_unless (strcmp (actual_value, "bla-:p1:w:v2:12:g3:123:bla-bla\n") == 0, - "group3->param2(%s) should be equal to 'bla-:p1:w:v2:12:g3:123:bla-bla\n'", - actual_value); - g_free (actual_value); - - fail_unless (mc_config_get_bool (actual, "group4", "param1", TRUE) == FALSE, - "group4->param1(TRUE) should be equal to FALSE"); - - fail_unless (mc_config_get_int (actual, "group4", "param2", 0) == 654321, - "group4->param2(%d) should be equal to 654321", mc_config_get_int (actual, - "group4", - "param2", 0)); - - mc_config_deinit (actual); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -int -main (void) -{ - int number_failed; - - Suite *s = suite_create (TEST_SUITE_NAME); - TCase *tc_core = tcase_create ("Core"); - SRunner *sr; - - tcase_add_checked_fixture (tc_core, setup, teardown); - - /* Add new tests here: *************** */ - tcase_add_test (tc_core, test_serialize_deserialize_str); - tcase_add_test (tc_core, test_serialize_config); - tcase_add_test (tc_core, test_deserialize_config); - /* *********************************** */ - - suite_add_tcase (s, tc_core); - sr = srunner_create (s); - srunner_set_log (sr, "serialize.log"); - srunner_run_all (sr, CK_NORMAL); - number_failed = srunner_ntests_failed (sr); - srunner_free (sr); - return (number_failed == 0) ? 0 : 1; -} - -/* --------------------------------------------------------------------------------------------- */ +/* + lib/vfs - common serialize/deserialize functions + + Copyright (C) 2011, 2013 + The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011, 2013 + + This file is part of the Midnight Commander. + + The Midnight Commander 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 3 of the License, + or (at your option) any later version. + + The Midnight Commander 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, see . + */ + +#define TEST_SUITE_NAME "/lib" + +#include "tests/mctest.h" + +#include "lib/strutil.h" +#include "lib/serialize.h" + +static GError *error = NULL; + +static const char *deserialize_input_value1 = + "g6:group1p6:param1v10:some valuep6:param2v11:some value " + "g6:group2p6:param1v4:truep6:param2v6:123456" + "g6:group3p6:param1v11:::bla-bla::p6:param2v31:bla-:p1:w:v2:12:g3:123:bla-bla\n" + "g6:group4p6:param1v5:falsep6:param2v6:654321"; + +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ +static void +setup (void) +{ + str_init_strings (NULL); + error = NULL; +} + +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ +static void +teardown (void) +{ + g_clear_error (&error); + str_uninit_strings (); +} + +/* --------------------------------------------------------------------------------------------- */ + +/* @DataSource("test_serialize_ds") */ +/* *INDENT-OFF* */ +static const struct test_serialize_ds +{ + const char input_char_prefix; + const char *input_string; + const char *expected_result; +} test_serialize_ds[] = +{ + { + 's', + "some test string", + "s16:some test string" + }, + { + 'a', + "some test test test string", + "a26:some test test test string" + }, +}; +/* *INDENT-ON* */ +/* @Test(dataSource = "test_serialize_ds") */ +/* *INDENT-OFF* */ +START_PARAMETRIZED_TEST (test_serialize, test_serialize_ds) +/* *INDENT-ON* */ +{ + /* given */ + char *actual_result; + + /* when */ + actual_result = mc_serialize_str (data->input_char_prefix, data->input_string, &error); + + /* then */ + mctest_assert_str_eq (actual_result, data->expected_result); + + g_free (actual_result); + +} +/* *INDENT-OFF* */ +END_PARAMETRIZED_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ + +/* @DataSource("test_deserialize_incorrect_ds") */ +/* *INDENT-OFF* */ +static const struct test_deserialize_incorrect_ds +{ + const char input_char_prefix; + const char *input_string; + const int expected_error_code; + const char *expected_error_string; +} test_deserialize_incorrect_ds[] = +{ + { + 's', + NULL, + -1, + "mc_serialize_str(): Input data is NULL or empty." + }, + { + 's', + "incorrect string", + -2, + "mc_serialize_str(): String prefix doesn't equal to 's'" + }, + { + 's', + "s12345string without delimiter", + -3, + "mc_serialize_str(): Length delimiter ':' doesn't exists" + }, + { + 's', + "s1234567890123456789012345678901234567890123456789012345678901234567890:too big number", + -3, + "mc_serialize_str(): Too big string length" + }, + { + 's', + "s500:actual string length less that specified length", + -3, + "mc_serialize_str(): Specified data length (500) is greater than actual data length (47)" + }, +}; +/* *INDENT-ON* */ +/* @Test(dataSource = "test_deserialize_incorrect_ds") */ +/* *INDENT-OFF* */ +START_PARAMETRIZED_TEST (test_deserialize_incorrect, test_deserialize_incorrect_ds) +/* *INDENT-ON* */ +{ + /* given */ + char *actual_result; + + /* when */ + actual_result = mc_deserialize_str (data->input_char_prefix, data->input_string, &error); + + /* then */ + mctest_assert_null (actual_result); + + mctest_assert_int_eq (error->code, data->expected_error_code); + mctest_assert_str_eq (error->message, data->expected_error_string); +} +/* *INDENT-OFF* */ +END_PARAMETRIZED_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ + +/* @DataSource("test_deserialize_ds") */ +/* *INDENT-OFF* */ +static const struct test_deserialize_ds +{ + const char input_char_prefix; + const char *input_string; + const char *expected_result; +} test_deserialize_ds[] = +{ + { + 's', + "s10:actual string length great that specified length", + "actual str" + }, + { + 'r', + "r21:The right test string", + "The right test string" + }, +}; +/* *INDENT-ON* */ +/* @Test(dataSource = "test_deserialize_ds") */ +/* *INDENT-OFF* */ +START_PARAMETRIZED_TEST (test_deserialize, test_deserialize_ds) +/* *INDENT-ON* */ +{ + /* given */ + char *actual_result; + + /* when */ + actual_result = mc_deserialize_str (data->input_char_prefix, data->input_string, &error); + + /* then */ + mctest_assert_str_eq (actual_result, data->expected_result); + + g_free (actual_result); +} +/* *INDENT-OFF* */ +END_PARAMETRIZED_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ + +/* *INDENT-OFF* */ +START_TEST (test_serialize_config) +/* *INDENT-ON* */ +{ + /* given */ + mc_config_t *test_data; + char *actual; + const char *expected_result = "g6:group1p6:param1v10:some valuep6:param2v11:some value " + "g6:group2p6:param1v4:truep6:param2v6:123456" + "g6:group3p6:param1v11:::bla-bla::p6:param2v31:bla-:p1:w:v2:12:g3:123:bla-bla\n" + "g6:group4p6:param1v5:falsep6:param2v6:654321"; + + test_data = mc_config_init (NULL, FALSE); + + mc_config_set_string_raw (test_data, "group1", "param1", "some value"); + mc_config_set_string (test_data, "group1", "param2", "some value "); + + mc_config_set_bool (test_data, "group2", "param1", TRUE); + mc_config_set_int (test_data, "group2", "param2", 123456); + + mc_config_set_string_raw (test_data, "group3", "param1", "::bla-bla::"); + mc_config_set_string (test_data, "group3", "param2", "bla-:p1:w:v2:12:g3:123:bla-bla\n"); + + mc_config_set_bool (test_data, "group4", "param1", FALSE); + mc_config_set_int (test_data, "group4", "param2", 654321); + + /* when */ + actual = mc_serialize_config (test_data, &error); + mc_config_deinit (test_data); + + /* then */ + mctest_assert_not_null (actual); + mctest_assert_str_eq (actual, expected_result); + + g_free (actual); +} +/* *INDENT-OFF* */ +END_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ +/* @DataSource("test_deserialize_config_incorrect_ds") */ +/* *INDENT-OFF* */ +static const struct test_deserialize_config_incorrect_ds +{ + const char *input_string; + const int expected_error_code; + const char *expected_error_string; +} test_deserialize_config_incorrect_ds[] = +{ + { + "g123error in group name", + -3, + "mc_deserialize_config() at 1: mc_serialize_str(): Length delimiter ':' doesn't exists" + }, + { + "p6:param1v10:some valuep6:param2v11:some value ", + -2, + "mc_deserialize_config() at 1: mc_serialize_str(): String prefix doesn't equal to 'g'" + }, + { + "g6:group1v10:some valuep6:param2v11:some value ", + -2, + "mc_deserialize_config() at 10: mc_serialize_str(): String prefix doesn't equal to 'p'" + }, + { + "g6:group1p6000:param2v11:some value ", + -3, + "mc_deserialize_config() at 10: mc_serialize_str(): Specified data length (6000) is greater than actual data length (21)" + }, +}; +/* *INDENT-ON* */ +/* @Test(dataSource = "test_deserialize_config_incorrect_ds") */ +/* *INDENT-OFF* */ +START_PARAMETRIZED_TEST (test_deserialize_config_incorrect, test_deserialize_config_incorrect_ds) +/* *INDENT-ON* */ +{ + /* given */ + mc_config_t *actual_result; + + /* when */ + actual_result = mc_deserialize_config (data->input_string, &error); + + /* then */ + mctest_assert_null (actual_result); + + mctest_assert_int_eq (error->code, data->expected_error_code); + mctest_assert_str_eq (error->message, data->expected_error_string); +} +/* *INDENT-OFF* */ +END_PARAMETRIZED_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ + +/* *INDENT-OFF* */ +START_TEST (test_deserialize_config) +/* *INDENT-ON* */ +{ + /* given */ + mc_config_t *actual; + char *actual_value; + + /* when */ + actual = mc_deserialize_config (deserialize_input_value1, &error); + + /* then */ + mctest_assert_not_null (actual); + + actual_value = mc_config_get_string_raw (actual, "group1", "param1", ""); + mctest_assert_str_eq (actual_value, "some value"); + g_free (actual_value); + + actual_value = mc_config_get_string (actual, "group1", "param2", ""); + mctest_assert_str_eq (actual_value, "some value "); + g_free (actual_value); + + mctest_assert_int_eq (mc_config_get_bool (actual, "group2", "param1", FALSE), TRUE); + + mctest_assert_int_eq (mc_config_get_int (actual, "group2", "param2", 0), 123456); + + actual_value = mc_config_get_string_raw (actual, "group3", "param1", ""); + mctest_assert_str_eq (actual_value, "::bla-bla::"); + g_free (actual_value); + + actual_value = mc_config_get_string (actual, "group3", "param2", ""); + mctest_assert_str_eq (actual_value, "bla-:p1:w:v2:12:g3:123:bla-bla\n"); + g_free (actual_value); + + mctest_assert_int_eq (mc_config_get_bool (actual, "group4", "param1", TRUE), FALSE); + + mctest_assert_int_eq (mc_config_get_int (actual, "group4", "param2", 0), 654321); + + mc_config_deinit (actual); +} +/* *INDENT-OFF* */ +END_TEST +/* *INDENT-ON* */ + +#undef input_value +/* --------------------------------------------------------------------------------------------- */ + +int +main (void) +{ + int number_failed; + + Suite *s = suite_create (TEST_SUITE_NAME); + TCase *tc_core = tcase_create ("Core"); + SRunner *sr; + + tcase_add_checked_fixture (tc_core, setup, teardown); + + /* Add new tests here: *************** */ + mctest_add_parameterized_test (tc_core, test_serialize, test_serialize_ds); + + mctest_add_parameterized_test (tc_core, test_deserialize_incorrect, + test_deserialize_incorrect_ds); + + mctest_add_parameterized_test (tc_core, test_deserialize, test_deserialize_ds); + + tcase_add_test (tc_core, test_serialize_config); + + mctest_add_parameterized_test (tc_core, test_deserialize_config_incorrect, + test_deserialize_config_incorrect_ds); + + tcase_add_test (tc_core, test_deserialize_config); + /* *********************************** */ + + suite_add_tcase (s, tc_core); + sr = srunner_create (s); + srunner_set_log (sr, "serialize.log"); + srunner_run_all (sr, CK_NORMAL); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + return (number_failed == 0) ? 0 : 1; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/tempdir.c b/tests/lib/vfs/tempdir.c index abf37c613..77f17689b 100644 --- a/tests/lib/vfs/tempdir.c +++ b/tests/lib/vfs/tempdir.c @@ -43,6 +43,9 @@ struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3; struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3; +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ static void setup (void) { @@ -53,6 +56,9 @@ setup (void) vfs_setup_work_dir (); } +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ static void teardown (void) { @@ -61,20 +67,24 @@ teardown (void) } /* --------------------------------------------------------------------------------------------- */ + +/* @Test */ /* *INDENT-OFF* */ START_TEST (test_mc_tmpdir) /* *INDENT-ON* */ { + /* given */ const char *tmpdir; const char *env_tmpdir; + /* when */ tmpdir = mc_tmpdir (); + env_tmpdir = g_getenv ("MC_TMPDIR"); + + /* then */ fail_unless (g_file_test (tmpdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR), "\nNo such directory: %s\n", tmpdir); - - env_tmpdir = g_getenv ("MC_TMPDIR"); - fail_unless (strcmp (env_tmpdir, tmpdir) == 0, - "\nenv_tmpdir=%s\n tmpdir=%s\n", env_tmpdir, tmpdir); + mctest_assert_str_eq (env_tmpdir, tmpdir); } /* *INDENT-OFF* */ END_TEST @@ -82,29 +92,30 @@ END_TEST /* --------------------------------------------------------------------------------------------- */ +/* @Test */ /* *INDENT-OFF* */ START_TEST (test_mc_mkstemps) /* *INDENT-ON* */ { + /* given */ vfs_path_t *pname_vpath = NULL; - char *pname; + char *pname = NULL; char *begin_pname; int fd; + /* when */ fd = mc_mkstemps (&pname_vpath, "mctest-", NULL); - if (fd == -1) - { - fail ("\nerror creating temp file!\n"); - } - pname = vfs_path_to_str (pname_vpath); + if (fd != -1) + pname = vfs_path_to_str (pname_vpath); + begin_pname = g_build_filename (mc_tmpdir (), "mctest-", NULL); + + /* then */ vfs_path_free (pname_vpath); close (fd); - + mctest_assert_int_ne (fd, -1); fail_unless (g_file_test (pname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR), "\nNo such file: %s\n", pname); unlink (pname); - - begin_pname = g_build_filename (mc_tmpdir (), "mctest-", NULL); fail_unless (strncmp (pname, begin_pname, strlen (begin_pname)) == 0, "\nstart of %s should be equal to %s\n", pname, begin_pname); g_free (pname); diff --git a/tests/lib/vfs/vfs_parse_ls_lga.c b/tests/lib/vfs/vfs_parse_ls_lga.c index c33549327..6501e8a2f 100644 --- a/tests/lib/vfs/vfs_parse_ls_lga.c +++ b/tests/lib/vfs/vfs_parse_ls_lga.c @@ -45,7 +45,9 @@ static struct vfs_s_super *vfs_test_super; void message (int flags, const char *title, const char *text, ...); +/* --------------------------------------------------------------------------------------------- */ +/* @Before */ static void setup (void) { @@ -71,6 +73,9 @@ setup (void) vfs_root_entry = vfs_s_new_entry (&vfs_test_ops1, "/", vfs_root_inode); } +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ static void teardown (void) { @@ -79,7 +84,9 @@ teardown (void) str_uninit_strings (); } +/* --------------------------------------------------------------------------------------------- */ +/* @Mock */ void message (int flags, const char *title, const char *text, ...) { @@ -98,198 +105,211 @@ message (int flags, const char *title, const char *text, ...) /* --------------------------------------------------------------------------------------------- */ -#define check_one_stat_field(etalon_stat, test_stat, field, format, input_str)\ -{\ - fail_unless(etalon_stat.field == test_stat.field,\ - "\ninput string: %s\netalon."#field" = " format "\nactual."#field" = " format "\n",\ - input_str, etalon_stat.field, test_stat.field);\ -} - -#define check_stat_struct(etalon_stat, test_stat, input_str)\ -{\ - check_one_stat_field(etalon_stat, test_stat, st_dev, "%zu", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_ino, "%zu", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_ino, "%zu", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_mode, "%04x", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_uid, "%u", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_gid, "%u", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_rdev, "%zu", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_size, "%zd", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_blksize, "%zu", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_blocks, "%zd", input_str);\ -\ -/* FIXME: these commented checks are related to time zone! \ - check_one_stat_field(etalon_stat, test_stat, st_atime, "%zd", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_mtime, "%zd", input_str);\ - check_one_stat_field(etalon_stat, test_stat, st_ctime, "%zd", input_str);\ -*/\ -} - static void -check_vfs_parse_ls_lga_call (const char *input_data, int etalon_result, - const char *etalon_filename, const char *etalon_linkname, - struct stat etalon_stat, size_t * filepos) +fill_stat_struct (struct stat *etalon_stat, int iterator) { - static struct stat test_stat; - char *filename = NULL; - char *linkname = NULL; - gboolean result; - - result = vfs_parse_ls_lga (input_data, &test_stat, &filename, &linkname, filepos); - - fail_if (result != etalon_result, - "\nactual result: %d\netalon result: %d\n", result, etalon_result); - - fail_unless ((filename != NULL && etalon_filename != NULL - && strcmp (filename, etalon_filename) == 0) || (filename == NULL - && etalon_filename == filename), - "\nactual filename '%s'\netalon filename '%s'", filename, etalon_filename); + switch (iterator) + { + case 0: + etalon_stat->st_dev = 0; + etalon_stat->st_ino = 0; + etalon_stat->st_mode = 0x41fd; + etalon_stat->st_nlink = 10; + etalon_stat->st_uid = 500; + etalon_stat->st_gid = 500; + etalon_stat->st_rdev = 0; + etalon_stat->st_size = 4096; + etalon_stat->st_blksize = 512; + etalon_stat->st_blocks = 8; + etalon_stat->st_atime = 1308838140; + etalon_stat->st_mtime = 1308838140; + etalon_stat->st_ctime = 1308838140; + break; + case 1: + etalon_stat->st_dev = 0; + etalon_stat->st_ino = 0; + etalon_stat->st_mode = 0xa1ff; + etalon_stat->st_nlink = 10; + etalon_stat->st_uid = 500; + etalon_stat->st_gid = 500; + etalon_stat->st_rdev = 0; + etalon_stat->st_size = 11; + etalon_stat->st_blksize = 512; + etalon_stat->st_blocks = 1; + etalon_stat->st_atime = 1268431200; + etalon_stat->st_mtime = 1268431200; + etalon_stat->st_ctime = 1268431200; + break; + case 2: + etalon_stat->st_dev = 0; + etalon_stat->st_ino = 0; + etalon_stat->st_mode = 0x41fd; + etalon_stat->st_nlink = 10; + etalon_stat->st_uid = 500; + etalon_stat->st_gid = 500; + etalon_stat->st_rdev = 0; + etalon_stat->st_size = 4096; + etalon_stat->st_blksize = 512; + etalon_stat->st_blocks = 8; + etalon_stat->st_atime = 1308838140; + etalon_stat->st_mtime = 1308838140; + etalon_stat->st_ctime = 1308838140; + break; + case 3: + etalon_stat->st_dev = 0; + etalon_stat->st_ino = 0; + etalon_stat->st_mode = 0x41fd; + etalon_stat->st_nlink = 10; + etalon_stat->st_uid = 500; + etalon_stat->st_gid = 500; + etalon_stat->st_rdev = 0; + etalon_stat->st_size = 4096; + etalon_stat->st_blksize = 512; + etalon_stat->st_blocks = 8; + etalon_stat->st_atime = 1308838140; + etalon_stat->st_mtime = 1308838140; + etalon_stat->st_ctime = 1308838140; + break; + } +} - fail_unless ((linkname != NULL && etalon_linkname != NULL - && strcmp (linkname, etalon_linkname) == 0) || (linkname == NULL - && etalon_linkname == linkname), - "\nactual linkname '%s'\netalon linkname '%s'", linkname, etalon_linkname); +/* --------------------------------------------------------------------------------------------- */ - check_stat_struct (etalon_stat, test_stat, input_data); -} +/* @DataSource("test_vfs_parse_ls_lga_ds") */ +/* *INDENT-OFF* */ +static const struct test_vfs_parse_ls_lga_ds +{ + const char *input_string; + int expected_result; + const char *expected_filename; + const char *expected_linkname; + const size_t expected_filepos; +} test_vfs_parse_ls_lga_ds[] = +{ + { /* 0. */ + "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root", + 1, + "build_root", + NULL, + 0 + }, + { /* 1. */ + "lrwxrwxrwx 1 500 500 11 Mar 13 2010 COPYING -> doc/COPYING", + 1, + "COPYING", + "doc/COPYING", + 0 + }, + { /* 2. */ + "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..", + 1, + "..", + NULL, + 0 + }, + { /* 3. */ + "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root", + 1, + "build_root", + NULL, + 0 + }, +}; +/* *INDENT-ON* */ +/* @Test(dataSource = "test_vfs_parse_ls_lga_ds") */ /* *INDENT-OFF* */ -START_TEST (test_vfs_parse_ls_lga) +START_PARAMETRIZED_TEST (test_vfs_parse_ls_lga, test_vfs_parse_ls_lga_ds) /* *INDENT-ON* */ { + /* given */ size_t filepos = 0; - struct stat etalon_stat; - - etalon_stat.st_dev = 0; - etalon_stat.st_ino = 0; - etalon_stat.st_mode = 0x41fd; - etalon_stat.st_nlink = 10; - etalon_stat.st_uid = 500; - etalon_stat.st_gid = 500; - etalon_stat.st_rdev = 0; - etalon_stat.st_size = 4096; - etalon_stat.st_blksize = 512; - etalon_stat.st_blocks = 8; - etalon_stat.st_atime = 1308838140; - etalon_stat.st_mtime = 1308838140; - etalon_stat.st_ctime = 1308838140; + static struct stat test_stat; + char *filename = NULL; + char *linkname = NULL; + gboolean actual_result; vfs_parse_ls_lga_init (); - check_vfs_parse_ls_lga_call - ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root", 1, "build_root", - NULL, etalon_stat, NULL); - - etalon_stat.st_dev = 0; - etalon_stat.st_ino = 0; - etalon_stat.st_mode = 0xa1ff; - etalon_stat.st_nlink = 10; - etalon_stat.st_uid = 500; - etalon_stat.st_gid = 500; - etalon_stat.st_rdev = 0; - etalon_stat.st_size = 11; - etalon_stat.st_blksize = 512; - etalon_stat.st_blocks = 1; - etalon_stat.st_atime = 1268431200; - etalon_stat.st_mtime = 1268431200; - etalon_stat.st_ctime = 1268431200; - - check_vfs_parse_ls_lga_call - ("lrwxrwxrwx 1 500 500 11 Mar 13 2010 COPYING -> doc/COPYING", 1, - "COPYING", "doc/COPYING", etalon_stat, NULL); - - etalon_stat.st_dev = 0; - etalon_stat.st_ino = 0; - etalon_stat.st_mode = 0x41fd; - etalon_stat.st_nlink = 10; - etalon_stat.st_uid = 500; - etalon_stat.st_gid = 500; - etalon_stat.st_rdev = 0; - etalon_stat.st_size = 4096; - etalon_stat.st_blksize = 512; - etalon_stat.st_blocks = 8; - etalon_stat.st_atime = 1308838140; - etalon_stat.st_mtime = 1308838140; - etalon_stat.st_ctime = 1308838140; - - check_vfs_parse_ls_lga_call ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..", - 1, "..", NULL, etalon_stat, &filepos); - - - etalon_stat.st_dev = 0; - etalon_stat.st_ino = 0; - etalon_stat.st_mode = 0x41fd; - etalon_stat.st_nlink = 10; - etalon_stat.st_uid = 500; - etalon_stat.st_gid = 500; - etalon_stat.st_rdev = 0; - etalon_stat.st_size = 4096; - etalon_stat.st_blksize = 512; - etalon_stat.st_blocks = 8; - etalon_stat.st_atime = 1308838140; - etalon_stat.st_mtime = 1308838140; - etalon_stat.st_ctime = 1308838140; - - check_vfs_parse_ls_lga_call - ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root", 1, "build_root", - NULL, etalon_stat, &filepos); - + etalon_stat.st_blocks = 0; + etalon_stat.st_size = 0; + etalon_stat.st_mode = 0; + fill_stat_struct (&etalon_stat, _i); + + /* when */ + actual_result = + vfs_parse_ls_lga (data->input_string, &test_stat, &filename, &linkname, &filepos); + + /* then */ + mctest_assert_int_eq (actual_result, data->expected_result); + + mctest_assert_str_eq (filename, data->expected_filename); + mctest_assert_str_eq (linkname, data->expected_linkname); + + mctest_assert_int_eq (etalon_stat.st_dev, test_stat.st_dev); + mctest_assert_int_eq (etalon_stat.st_ino, test_stat.st_ino); + mctest_assert_int_eq (etalon_stat.st_mode, test_stat.st_mode); + mctest_assert_int_eq (etalon_stat.st_uid, test_stat.st_uid); + mctest_assert_int_eq (etalon_stat.st_gid, test_stat.st_gid); + mctest_assert_int_eq (etalon_stat.st_rdev, test_stat.st_rdev); + mctest_assert_int_eq (etalon_stat.st_size, test_stat.st_size); + mctest_assert_int_eq (etalon_stat.st_blksize, test_stat.st_blksize); + mctest_assert_int_eq (etalon_stat.st_blocks, test_stat.st_blocks); + + /* FIXME: these commented checks are related to time zone! + mctest_assert_int_eq (etalon_stat.st_atime, test_stat.st_atime); + mctest_assert_int_eq (etalon_stat.st_mtime, test_stat.st_mtime); + mctest_assert_int_eq (etalon_stat.st_ctime, test_stat.st_ctime); + */ } /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ +/* @Test */ /* *INDENT-OFF* */ START_TEST (test_vfs_parse_ls_lga_reorder) /* *INDENT-ON* */ { + /* given */ size_t filepos = 0; struct vfs_s_entry *ent1, *ent2, *ent3; vfs_parse_ls_lga_init (); + /* init ent1 */ ent1 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); - if (!vfs_parse_ls_lga + vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root1", &ent1->ino->st, - &ent1->name, &ent1->ino->linkname, &filepos)) - { - fail ("An error occured while parse ls output"); - return; - } + &ent1->name, &ent1->ino->linkname, &filepos); vfs_s_store_filename_leading_spaces (ent1, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent1); + /* init ent2 */ ent2 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); - if (!vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2", - &ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos)) - { - fail ("An error occured while parse ls output"); - return; - } + vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2", + &ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos); vfs_s_store_filename_leading_spaces (ent2, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent2); + /* init ent3 */ ent3 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0); - if (!vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..", - &ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos)) - { - fail ("An error occured while parse ls output"); - return; - } + vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..", + &ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos); vfs_s_store_filename_leading_spaces (ent3, filepos); vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent3); + /* when */ vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ()); - fail_unless (strcmp (ent1->name, " build_root1") == 0, "\nactual '%s'\nnot equal to '%s'\n", - ent1->name, " build_root1"); - fail_unless (strcmp (ent2->name, " build_root2") == 0, "\nactual '%s'\nnot equal to '%s'\n", - ent2->name, " build_root2"); + /* then */ + mctest_assert_str_eq (ent1->name, " build_root1"); + mctest_assert_str_eq (ent2->name, " build_root2"); } /* *INDENT-OFF* */ END_TEST @@ -308,17 +328,13 @@ END_TEST vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent[ent_index]);\ \ } -#define fail_unless_ent(ent_index, etalon_str){\ - fail_unless(\ - strcmp(ent[ent_index]->name, etalon_str) == 0,\ - "\nactual '%s'\nnot equal to '%s'\n", ent[ent_index]->name, etalon_str\ - );\ -} +/* @Test */ /* *INDENT-OFF* */ START_TEST (test_vfs_parse_ls_lga_unaligned) /* *INDENT-ON* */ { + /* given */ size_t filepos = 0; struct vfs_s_entry *ent[4]; @@ -330,12 +346,14 @@ START_TEST (test_vfs_parse_ls_lga_unaligned) parce_one_line (3, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root 0"); + /* when */ vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ()); - fail_unless_ent (0, "build_root1"); - fail_unless_ent (1, " build_root2"); - fail_unless_ent (3, " build_root 0"); - + /* then */ + mctest_assert_str_eq (ent[0]->name, "build_root1"); + mctest_assert_str_eq (ent[0]->name, "build_root1"); + mctest_assert_str_eq (ent[1]->name, " build_root2"); + mctest_assert_str_eq (ent[3]->name, " build_root 0"); } /* *INDENT-OFF* */ END_TEST @@ -355,7 +373,7 @@ main (void) tcase_add_checked_fixture (tc_core, setup, teardown); /* Add new tests here: *************** */ - tcase_add_test (tc_core, test_vfs_parse_ls_lga); + mctest_add_parameterized_test (tc_core, test_vfs_parse_ls_lga, test_vfs_parse_ls_lga_ds); tcase_add_test (tc_core, test_vfs_parse_ls_lga_reorder); tcase_add_test (tc_core, test_vfs_parse_ls_lga_unaligned); /* *********************************** */ diff --git a/tests/lib/vfs/vfs_path_string_convert.c b/tests/lib/vfs/vfs_path_string_convert.c index 4f4c672a4..a27e11f49 100644 --- a/tests/lib/vfs/vfs_path_string_convert.c +++ b/tests/lib/vfs/vfs_path_string_convert.c @@ -40,17 +40,21 @@ struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3; struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3; +#define ETALON_PATH_STR "/#test1/bla-bla/some/path/#test2/bla-bla/some/path#test3/111/22/33" +#define ETALON_PATH_URL_STR "/test1://bla-bla/some/path/test2://bla-bla/some/path/test3://111/22/33" + +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ static void setup (void) { - str_init_strings (NULL); vfs_init (); init_localfs (); vfs_setup_work_dir (); - vfs_s_init_class (&vfs_test_ops1, &test_subclass1); vfs_test_ops1.name = "testfs1"; @@ -69,226 +73,248 @@ setup (void) vfs_test_ops3.prefix = "test3"; vfs_register_class (&vfs_test_ops3); +#ifdef HAVE_CHARSET + mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; + load_codepages_list (); +#endif /* HAVE_CHARSET */ } +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ static void teardown (void) { +#ifdef HAVE_CHARSET + free_codepages_list (); +#endif /* HAVE_CHARSET */ + vfs_shut (); str_uninit_strings (); } /* --------------------------------------------------------------------------------------------- */ -#define ETALON_PATH_STR "/#test1/bla-bla/some/path/#test2/bla-bla/some/path#test3/111/22/33" -#define ETALON_PATH_URL_STR "/test1://bla-bla/some/path/test2://bla-bla/some/path/test3://111/22/33" +/* @DataSource("test_from_to_string_ds") */ /* *INDENT-OFF* */ -START_TEST (test_vfs_path_from_to_string) -/* *INDENT-ON* */ +static const struct test_from_to_string_ds { - vfs_path_t *vpath; - size_t vpath_len; - char *result; - vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER); - - - vpath_len = vfs_path_elements_count (vpath); - fail_unless (vpath_len == 4, "vpath length should be 4 (actial: %d)", vpath_len); - - result = vfs_path_to_str (vpath); - fail_unless (strcmp (ETALON_PATH_URL_STR, result) == 0, - "expected(%s) doesn't equal to actual(%s)", ETALON_PATH_URL_STR, result); - g_free (result); - - vfs_path_free (vpath); -} -/* *INDENT-OFF* */ -END_TEST + const char *input_string; + const char *expected_result; + const char *expected_element_path; + const size_t expected_elements_count; + struct vfs_class *expected_vfs_class; +} test_from_to_string_ds[] = +{ + { /* 0. */ + ETALON_PATH_STR, + ETALON_PATH_URL_STR, + "111/22/33", + 4, + &vfs_test_ops3 + }, + { /* 1. */ + "/", + "/", + "/", + 1, + &vfs_local_ops + }, + { /* 2. */ + "/test1://bla-bla/some/path/test2://user:passwd@some.host:1234/bla-bla/some/path/test3://111/22/33", + "/test1://bla-bla/some/path/test2://user:passwd@some.host:1234/bla-bla/some/path/test3://111/22/33", + "111/22/33", + 4, + &vfs_test_ops3 + }, +#ifdef HAVE_CHARSET + { /* 3. */ + "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", + "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33", + "111/22/33", + 4, + &vfs_test_ops3 + }, + { /* 4. */ + "/#test1/bla-bla1/#enc:IBM866/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", + "/test1://#enc:IBM866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33", + "111/22/33", + 4, + &vfs_test_ops3 + }, + { /* 5. */ + "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:IBM866/#enc:KOI8-R/some/path#test3/111/22/33", + "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33", + "111/22/33", + 4, + &vfs_test_ops3 + }, + { /* 6. */ + "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:IBM866/some/#enc:KOI8-R/path#test3/111/22/33", + "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33", + "111/22/33", + 4, + &vfs_test_ops3 + }, + { /* 7. */ + "/#test1/bla-bla1/some/path/#test2/#enc:IBM866/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", + "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33", + "111/22/33", + 4, + &vfs_test_ops3 + }, + { /* 8. */ + "/#test1/bla-bla1/some/path/#enc:IBM866/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", + "/test1://#enc:IBM866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33", + "111/22/33", + 4, + &vfs_test_ops3 + }, +#endif /* HAVE_CHARSET */ +}; /* *INDENT-ON* */ -/* --------------------------------------------------------------------------------------------- */ - +/* @Test */ /* *INDENT-OFF* */ -START_TEST (test_vfs_path_from_to_string2) +START_PARAMETRIZED_TEST (test_from_to_string, test_from_to_string_ds) /* *INDENT-ON* */ { + /* given */ vfs_path_t *vpath; size_t vpath_len; - char *result; const vfs_path_element_t *path_element; + char *actual_result; - vpath = vfs_path_from_str ("/"); + vpath = vfs_path_from_str_flags (data->input_string, VPF_USE_DEPRECATED_PARSER); + /* when */ vpath_len = vfs_path_elements_count (vpath); - fail_unless (vpath_len == 1, "vpath length should be 1 (actial: %d)", vpath_len); - - result = vfs_path_to_str (vpath); - fail_unless (strcmp ("/", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/", - result); - g_free (result); + actual_result = vfs_path_to_str (vpath); path_element = vfs_path_get_by_index (vpath, -1); - fail_unless (strcmp ("/", path_element->path) == 0, "expected(%s) doesn't equal to actual(%s)", - "/", path_element->path); - fail_unless (path_element->class == &vfs_local_ops, - "actual vfs-class doesn't equal to localfs"); + /* then */ + mctest_assert_int_eq (vpath_len, data->expected_elements_count); + mctest_assert_str_eq (actual_result, data->expected_result); + mctest_assert_ptr_eq (path_element->class, data->expected_vfs_class); + mctest_assert_str_eq (path_element->path, data->expected_element_path); + g_free (actual_result); vfs_path_free (vpath); } /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ -/* *INDENT-OFF* */ -START_TEST (test_vfs_path_from_to_partial_string_by_class) -/* *INDENT-ON* */ -{ - vfs_path_t *vpath; - char *result; - vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER); - - result = vfs_path_to_str_elements_count (vpath, -1); - fail_unless (strcmp ("/test1://bla-bla/some/path/test2://bla-bla/some/path", result) == 0, - "expected(%s) doesn't equal to actual(%s)", - "/test1://bla-bla/some/path/test2://bla-bla/some/path", result); - g_free (result); - - result = vfs_path_to_str_elements_count (vpath, -2); - fail_unless (strcmp ("/test1://bla-bla/some/path/", result) == 0, - "expected(%s) doesn't equal to actual(%s)", "/test1://bla-bla/some/path/", result); - g_free (result); - - result = vfs_path_to_str_elements_count (vpath, -3); - fail_unless (strcmp ("/", result) == 0, - "expected(%s) doesn't equal to actual(%s)", "/", result); - g_free (result); - - /* index out of bound */ - result = vfs_path_to_str_elements_count (vpath, -4); - fail_unless (strcmp ("", result) == 0, "expected(%s) doesn't equal to actual(%s)", "", result); - g_free (result); - - - result = vfs_path_to_str_elements_count (vpath, 1); - fail_unless (strcmp ("/", result) == 0, - "expected(%s) doesn't equal to actual(%s)", "/", result); - g_free (result); - - result = vfs_path_to_str_elements_count (vpath, 2); - fail_unless (strcmp ("/test1://bla-bla/some/path/", result) == 0, - "expected(%s) doesn't equal to actual(%s)", "/test1://bla-bla/some/path/", result); - g_free (result); - - result = vfs_path_to_str_elements_count (vpath, 3); - fail_unless (strcmp ("/test1://bla-bla/some/path/test2://bla-bla/some/path", result) == 0, - "expected(%s) doesn't equal to actual(%s)", - "/test1://bla-bla/some/path/test2://bla-bla/some/path", result); - g_free (result); - - result = vfs_path_to_str_elements_count (vpath, 4); - fail_unless (strcmp (ETALON_PATH_URL_STR, result) == 0, - "expected(%s) doesn't equal to actual(%s)", ETALON_PATH_URL_STR, result); - g_free (result); - - /* index out of bound */ - result = vfs_path_to_str_elements_count (vpath, 5); - fail_unless (strcmp (ETALON_PATH_URL_STR, result) == 0, - "expected(%s) doesn't equal to actual(%s)", ETALON_PATH_URL_STR, result); - g_free (result); - - vfs_path_free (vpath); -} +/* @DataSource("test_partial_string_by_index_ds") */ /* *INDENT-OFF* */ -END_TEST +static const struct test_partial_string_by_index_ds +{ + const char *input_string; + const off_t element_index; + const char *expected_result; +} test_partial_string_by_index_ds[] = +{ + { /* 0. */ + ETALON_PATH_STR, + -1, + "/test1://bla-bla/some/path/test2://bla-bla/some/path" + }, + { /* 1. */ + ETALON_PATH_STR, + -2, + "/test1://bla-bla/some/path/" + }, + { /* 2. */ + ETALON_PATH_STR, + -3, + "/" + }, + { /* 3. Index out of bound */ + ETALON_PATH_STR, + -4, + "" + }, + { /* 4. */ + ETALON_PATH_STR, + 1, + "/" + }, + { /* 5. */ + ETALON_PATH_STR, + 2, + "/test1://bla-bla/some/path/" + }, + { /* 6. */ + ETALON_PATH_STR, + 3, + "/test1://bla-bla/some/path/test2://bla-bla/some/path" + }, + { /* 6. */ + ETALON_PATH_STR, + 4, + ETALON_PATH_URL_STR + }, + { /* 7. Index out of bound */ + ETALON_PATH_STR, + 5, + ETALON_PATH_URL_STR + }, +}; /* *INDENT-ON* */ -/* --------------------------------------------------------------------------------------------- */ -#ifdef HAVE_CHARSET -#define encoding_check( input , etalon ) \ -{ \ - vfs_path_t *vpath; \ - char *result; \ -\ - vpath = vfs_path_from_str_flags (input, VPF_USE_DEPRECATED_PARSER); \ - result = vfs_path_to_str(vpath); \ - fail_unless( result != NULL && strcmp(result, etalon) ==0, \ - "\ninput : %s\nactual: %s\netalon: %s", input, result , etalon ); \ -\ - g_free(result); \ - vfs_path_free(vpath); \ -} - +/* @Test(dataSource = "test_partial_string_by_index_ds") */ /* *INDENT-OFF* */ -START_TEST (test_vfs_path_from_to_string_encoding) +START_PARAMETRIZED_TEST (test_partial_string_by_index, test_partial_string_by_index_ds) /* *INDENT-ON* */ { - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - load_codepages_list (); - - encoding_check - ("/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", - "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33"); - - encoding_check - ("/#test1/bla-bla1/#enc:IBM866/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", - "/test1://#enc:IBM866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33"); - - encoding_check - ("/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:IBM866/#enc:KOI8-R/some/path#test3/111/22/33", - "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33"); - - encoding_check - ("/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:IBM866/some/#enc:KOI8-R/path#test3/111/22/33", - "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33"); + /* given */ + vfs_path_t *vpath; + char *actual_result; + vpath = vfs_path_from_str_flags (data->input_string, VPF_USE_DEPRECATED_PARSER); - encoding_check - ("/#test1/bla-bla1/some/path/#test2/#enc:IBM866/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", - "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33"); + /* when */ + actual_result = vfs_path_to_str_elements_count (vpath, data->element_index); - encoding_check - ("/#test1/bla-bla1/some/path/#enc:IBM866/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33", - "/test1://#enc:IBM866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33"); + /* then */ + mctest_assert_str_eq (actual_result, data->expected_result); + g_free (actual_result); - free_codepages_list (); + vfs_path_free (vpath); } - /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ +#ifdef HAVE_CHARSET +/* --------------------------------------------------------------------------------------------- */ + #define ETALON_STR "/path/to/file.ext/test1://#enc:KOI8-R" +/* @Test */ /* *INDENT-OFF* */ START_TEST (test_vfs_path_encoding_at_end) /* *INDENT-ON* */ { + /* given */ vfs_path_t *vpath; char *result; const vfs_path_element_t *element; - mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR; - load_codepages_list (); - vpath = vfs_path_from_str_flags ("/path/to/file.ext#test1:/#enc:KOI8-R", VPF_USE_DEPRECATED_PARSER); - result = vfs_path_to_str (vpath); + /* when */ + result = vfs_path_to_str (vpath); element = vfs_path_get_by_index (vpath, -1); - fail_unless (*element->path == '\0', "element->path should be empty, but actual value is '%s'", - element->path); - fail_unless (element->encoding != NULL - && strcmp (element->encoding, "KOI8-R") == 0, - "element->encoding should be 'KOI8-R', but actual value is '%s'", - element->encoding); - fail_unless (result != NULL && strcmp (result, ETALON_STR) == 0, - "\nactual: %s\netalon: %s", result, ETALON_STR); + /* then */ + mctest_assert_str_eq (element->path, ""); + mctest_assert_not_null (element->encoding); + mctest_assert_str_eq (result, ETALON_STR); g_free (result); vfs_path_free (vpath); - - free_codepages_list (); } /* *INDENT-OFF* */ @@ -297,33 +323,6 @@ END_TEST #endif /* HAVE_CHARSET */ /* --------------------------------------------------------------------------------------------- */ -#undef ETALON_PATH_STR -#define ETALON_PATH_STR "/test1://bla-bla/some/path/test2://user:passwd@some.host:1234/bla-bla/some/path/test3://111/22/33" -/* *INDENT-OFF* */ -START_TEST (test_vfs_path_from_to_string_uri) -/* *INDENT-ON* */ -{ - vfs_path_t *vpath; - size_t vpath_len; - char *result; - vpath = vfs_path_from_str (ETALON_PATH_STR); - - vpath_len = vfs_path_elements_count (vpath); - fail_unless (vpath_len == 4, "vpath length should be 4 (actial: %d)", vpath_len); - - result = vfs_path_to_str (vpath); - fail_unless (strcmp (ETALON_PATH_STR, result) == 0, - "\nexpected(%s)\ndoesn't equal to actual(%s)", ETALON_PATH_STR, result); - g_free (result); - - vfs_path_free (vpath); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - int main (void) { @@ -336,14 +335,12 @@ main (void) tcase_add_checked_fixture (tc_core, setup, teardown); /* Add new tests here: *************** */ - tcase_add_test (tc_core, test_vfs_path_from_to_string); - tcase_add_test (tc_core, test_vfs_path_from_to_string2); - tcase_add_test (tc_core, test_vfs_path_from_to_partial_string_by_class); + mctest_add_parameterized_test (tc_core, test_from_to_string, test_from_to_string_ds); + mctest_add_parameterized_test (tc_core, test_partial_string_by_index, + test_partial_string_by_index_ds); #ifdef HAVE_CHARSET - tcase_add_test (tc_core, test_vfs_path_from_to_string_encoding); tcase_add_test (tc_core, test_vfs_path_encoding_at_end); #endif - tcase_add_test (tc_core, test_vfs_path_from_to_string_uri); /* *********************************** */ suite_add_tcase (s, tc_core); diff --git a/tests/lib/vfs/vfs_prefix_to_class.c b/tests/lib/vfs/vfs_prefix_to_class.c index c6520b757..29f0fbb7f 100644 --- a/tests/lib/vfs/vfs_prefix_to_class.c +++ b/tests/lib/vfs/vfs_prefix_to_class.c @@ -36,6 +36,7 @@ struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3; struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3; +/* --------------------------------------------------------------------------------------------- */ static int test_which (struct vfs_class *me, const char *path) @@ -49,17 +50,18 @@ test_which (struct vfs_class *me, const char *path) return -1; } +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ static void setup (void) { - str_init_strings (NULL); vfs_init (); init_localfs (); vfs_setup_work_dir (); - test_subclass1.flags = VFS_S_REMOTE; vfs_s_init_class (&vfs_test_ops1, &test_subclass1); vfs_test_ops1.name = "testfs1"; @@ -80,6 +82,9 @@ setup (void) } +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ static void teardown (void) { @@ -89,44 +94,69 @@ teardown (void) /* --------------------------------------------------------------------------------------------- */ +/* @DataSource("test_vfs_prefix_to_class_ds") */ /* *INDENT-OFF* */ -START_TEST (test_vfs_prefix_to_class_valid) -/* *INDENT-ON* */ +static const struct test_vfs_prefix_to_class_ds { - fail_unless (vfs_prefix_to_class ((char *) "test_1:") == &vfs_test_ops1, - "'test_1:' doesn't transform to vfs_test_ops1"); - fail_unless (vfs_prefix_to_class ((char *) "test_2:") == &vfs_test_ops1, - "'test_2:' doesn't transform to vfs_test_ops1"); - fail_unless (vfs_prefix_to_class ((char *) "test_3:") == &vfs_test_ops1, - "'test_3:' doesn't transform to vfs_test_ops1"); - fail_unless (vfs_prefix_to_class ((char *) "test_4:") == &vfs_test_ops1, - "'test_4:' doesn't transform to vfs_test_ops1"); - - fail_unless (vfs_prefix_to_class ((char *) "test2:") == &vfs_test_ops2, - "'test2:' doesn't transform to vfs_test_ops2"); - - fail_unless (vfs_prefix_to_class ((char *) "test3:") == &vfs_test_ops3, - "'test3:' doesn't transform to vfs_test_ops3"); -} -/* *INDENT-OFF* */ -END_TEST + const char *input_string; + const struct vfs_class *expected_result; +} test_vfs_prefix_to_class_ds[] = +{ + { /* 0 */ + "test_1:", + &vfs_test_ops1 + }, + { /* 1 */ + "test_2:", + &vfs_test_ops1 + }, + { /* 2 */ + "test_3:", + &vfs_test_ops1 + }, + { /* 3 */ + "test_4:", + &vfs_test_ops1 + }, + { /* 4 */ + "test2:", + &vfs_test_ops2 + }, + { /* 5 */ + "test3:", + &vfs_test_ops3 + }, + { + "test1:", + NULL + }, + { /* 6 */ + "test_5:", + NULL + }, + { /* 7 */ + "test4:", + NULL + }, +}; /* *INDENT-ON* */ -/* --------------------------------------------------------------------------------------------- */ - +/* @Test(dataSource = "test_vfs_prefix_to_class_ds") */ /* *INDENT-OFF* */ -START_TEST (test_vfs_prefix_to_class_invalid) +START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds) /* *INDENT-ON* */ { - fail_unless (vfs_prefix_to_class ((char *) "test1:") == NULL, - "'test1:' doesn't transform to NULL"); - fail_unless (vfs_prefix_to_class ((char *) "test_5:") == NULL, - "'test_5:' doesn't transform to NULL"); - fail_unless (vfs_prefix_to_class ((char *) "test4:") == NULL, - "'test4:' doesn't transform to NULL"); + /* given */ + struct vfs_class *actual_result; + + /* when */ + actual_result = vfs_prefix_to_class ((char *) data->input_string); + + /* then */ + mctest_assert_ptr_eq (actual_result, data->expected_result); } /* *INDENT-OFF* */ -END_TEST +END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ @@ -143,8 +173,7 @@ main (void) tcase_add_checked_fixture (tc_core, setup, teardown); /* Add new tests here: *************** */ - tcase_add_test (tc_core, test_vfs_prefix_to_class_valid); - tcase_add_test (tc_core, test_vfs_prefix_to_class_invalid); + mctest_add_parameterized_test (tc_core, test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds); /* *********************************** */ suite_add_tcase (s, tc_core); diff --git a/tests/lib/vfs/vfs_s_get_path.c b/tests/lib/vfs/vfs_s_get_path.c index 6a2071d5c..a907b7c12 100644 --- a/tests/lib/vfs/vfs_s_get_path.c +++ b/tests/lib/vfs/vfs_s_get_path.c @@ -40,6 +40,8 @@ struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3; struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3; +/* --------------------------------------------------------------------------------------------- */ + static int test1_mock_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath, const vfs_path_element_t * vpath_element) @@ -47,9 +49,7 @@ test1_mock_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath, struct vfs_s_inode *root; char *spath = vfs_path_to_str (vpath); - fail_unless (strcmp ("/" ETALON_VFS_URL_NAME ARCH_NAME, spath) == 0, - "etalon(%s) doesn't equal to actual(%s)", "/" ETALON_VFS_URL_NAME ARCH_NAME, - spath); + mctest_assert_str_eq (spath, "/" ETALON_VFS_URL_NAME ARCH_NAME); super->name = g_strdup (spath); super->data = g_new (char *, 1); @@ -59,6 +59,8 @@ test1_mock_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath, return 0; } +/* --------------------------------------------------------------------------------------------- */ + static int test1_mock_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *super, const vfs_path_t * vpath, void *cookie) @@ -75,6 +77,9 @@ test1_mock_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_ return 1; } +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ static void setup (void) { @@ -108,6 +113,9 @@ setup (void) vfs_register_class (&vfs_test_ops3); } +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ static void teardown (void) { @@ -124,25 +132,25 @@ vfs_die (const char *m) /* --------------------------------------------------------------------------------------------- */ +/* @Test */ /* *INDENT-OFF* */ START_TEST (test_vfs_s_get_path) /* *INDENT-ON* */ { + /* given */ struct vfs_s_super *archive; - const char *result; + + /* when */ vfs_path_t *vpath = vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME "#test1:/" ETALON_PATH, VPF_USE_DEPRECATED_PARSER); result = vfs_s_get_path (vpath, &archive, 0); - fail_unless (strcmp (ETALON_PATH, result) == 0, - "expected(%s) doesn't equal to actual(%s)", ETALON_PATH, result); - - fail_unless (strcmp ("/" ETALON_VFS_URL_NAME ARCH_NAME, archive->name) == 0, - "expected(%s) doesn't equal to actual(%s)", "/" ETALON_VFS_URL_NAME ARCH_NAME, - archive->name); + /* then */ + mctest_assert_str_eq (result, ETALON_PATH); + mctest_assert_str_eq (archive->name, "/" ETALON_VFS_URL_NAME ARCH_NAME); g_free (vpath); diff --git a/tests/lib/vfs/vfs_split.c b/tests/lib/vfs/vfs_split.c dissimilarity index 74% index db17eff80..549d6dbb7 100644 --- a/tests/lib/vfs/vfs_split.c +++ b/tests/lib/vfs/vfs_split.c @@ -1,340 +1,226 @@ -/* - lib/vfs - test vfs_split() functionality - - Copyright (C) 2011, 2013 - The Free Software Foundation, Inc. - - Written by: - Slava Zanko , 2011, 2013 - - This file is part of the Midnight Commander. - - The Midnight Commander 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 3 of the License, - or (at your option) any later version. - - The Midnight Commander 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, see . - */ - -#define TEST_SUITE_NAME "/lib/vfs" - -#include "tests/mctest.h" - -#include "lib/strutil.h" -#include "lib/vfs/xdirentry.h" -#include "lib/vfs/path.c" /* for testing static methods */ - -#include "src/vfs/local/local.c" - -struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3; -struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3; - -static void -setup (void) -{ - - str_init_strings (NULL); - - vfs_init (); - init_localfs (); - vfs_setup_work_dir (); - - - test_subclass1.flags = VFS_S_REMOTE; - vfs_s_init_class (&vfs_test_ops1, &test_subclass1); - - vfs_test_ops1.name = "testfs1"; - vfs_test_ops1.flags = VFSF_NOLINKS; - vfs_test_ops1.prefix = "test1:"; - vfs_register_class (&vfs_test_ops1); - - vfs_s_init_class (&vfs_test_ops2, &test_subclass2); - vfs_test_ops2.name = "testfs2"; - vfs_test_ops2.prefix = "test2:"; - vfs_register_class (&vfs_test_ops2); - - vfs_s_init_class (&vfs_test_ops3, &test_subclass3); - vfs_test_ops3.name = "testfs3"; - vfs_test_ops3.prefix = "test3:"; - vfs_register_class (&vfs_test_ops3); - -} - -static void -teardown (void) -{ - vfs_shut (); - str_uninit_strings (); -} - -/* --------------------------------------------------------------------------------------------- */ - -/* *INDENT-OFF* */ -START_TEST (test_vfs_split) -/* *INDENT-ON* */ -{ - char *path; - const char *local, *op, *etalon_path, *etalon_local, *etalon_op; - struct vfs_class *result; - - path = g_strdup ("#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/#test3:/qqq/www/eee.rr"); - - etalon_path = "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/"; - etalon_local = "qqq/www/eee.rr"; - etalon_op = "test3:"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops3, "Result(%p) doesn't match to vfs_test_ops3(%p)", result, - &vfs_test_ops3); - fail_unless (strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (strcmp (local, etalon_local) == 0, "parsed local path('%s') doesn't match to '%s'", - local, etalon_local); - fail_unless (strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - etalon_path = "#test1:/bla-bla/some/path/"; - etalon_local = "bla-bla/some/path2/"; - etalon_op = "test2:"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops2, "Result(%p) doesn't match to vfs_test_ops2(%p)", result, - &vfs_test_ops2); - fail_unless (strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (strcmp (local, etalon_local) == 0, "parsed local path('%s') doesn't match to '%s'", - local, etalon_local); - fail_unless (strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - etalon_path = ""; - etalon_local = "bla-bla/some/path/"; - etalon_op = "test1:"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops1, "Result(%p) doesn't match to vfs_test_ops1(%p)", result, - &vfs_test_ops2); - fail_unless (strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (strcmp (local, etalon_local) == 0, "parsed local path('%s') doesn't match to '%s'", - local, etalon_local); - fail_unless (strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == NULL, "Result(%p) doesn't match to vfs_test_ops1(NULL)", result); - fail_unless (strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (strcmp (local, etalon_local) == 0, "parsed local path('%s') doesn't match to '%s'", - local, etalon_local); - fail_unless (strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - g_free (path); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -/* *INDENT-OFF* */ -START_TEST (test_vfs_split_with_local) -/* *INDENT-ON* */ -{ - char *path; - const char *local, *op, *etalon_path, *etalon_local, *etalon_op; - struct vfs_class *result; - - path = - g_strdup - ("/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2#test3:/qqq/www/eee.rr"); - - etalon_path = "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2"; - etalon_local = "qqq/www/eee.rr"; - etalon_op = "test3:"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops3, "Result(%p) doesn't match to vfs_test_ops3(%p)", result, - &vfs_test_ops3); - fail_unless (strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (strcmp (local, etalon_local) == 0, "parsed local path('%s') doesn't match to '%s'", - local, etalon_local); - fail_unless (strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - etalon_path = "/local/path/#test1:/bla-bla/some/path/"; - etalon_local = "bla-bla/some/path2"; - etalon_op = "test2:"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops2, "Result(%p) doesn't match to vfs_test_ops2(%p)", result, - &vfs_test_ops2); - fail_unless (strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (strcmp (local, etalon_local) == 0, "parsed local path('%s') doesn't match to '%s'", - local, etalon_local); - fail_unless (strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - etalon_path = "/local/path/"; - etalon_local = "bla-bla/some/path/"; - etalon_op = "test1:"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops1, "Result(%p) doesn't match to vfs_test_ops1(%p)", result, - &vfs_test_ops2); - fail_unless (strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (strcmp (local, etalon_local) == 0, "parsed local path('%s') doesn't match to '%s'", - local, etalon_local); - fail_unless (strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == NULL, "Result(%p) doesn't match to vfs_test_ops1(NULL)", result); - - g_free (path); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ -/* *INDENT-OFF* */ -START_TEST (test_vfs_split_url) -/* *INDENT-ON* */ -{ - char *path; - const char *local, *op, *etalon_path, *etalon_local, *etalon_op; - struct vfs_class *result; - - path = g_strdup ("#test2:username:passwd@somehost.net/bla-bla/some/path2"); - - etalon_path = ""; - etalon_local = "bla-bla/some/path2"; - etalon_op = "test2:username:passwd@somehost.net"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops2, "Result(%p) doesn't match to vfs_test_ops2(%p)", result, - &vfs_test_ops2); - fail_unless (path != NULL - && strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (local != NULL - && strcmp (local, etalon_local) == 0, - "parsed local path('%s') doesn't match to '%s'", local, etalon_local); - fail_unless (op != NULL - && strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - g_free (path); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -/* *INDENT-OFF* */ -START_TEST (test_vfs_split_url_with_semi) -/* *INDENT-ON* */ -{ - char *path; - const char *local, *op, *etalon_path, *etalon_local, *etalon_op; - struct vfs_class *result; - - - path = - g_strdup - ("/local/path/#test1:/bla-bla/some/path/#test2:username:p!a@s#s$w%d@somehost.net/bla-bla/some/path2"); - - etalon_path = "/local/path/#test1:/bla-bla/some/path/"; - etalon_local = "bla-bla/some/path2"; - etalon_op = "test2:username:p!a@s#s$w%d@somehost.net"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops2, "Result(%p) doesn't match to vfs_test_ops2(%p)", result, - &vfs_test_ops2); - fail_unless (path != NULL - && strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (local != NULL - && strcmp (local, etalon_local) == 0, - "parsed local path('%s') doesn't match to '%s'", local, etalon_local); - fail_unless (op != NULL - && strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - g_free (path); - -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -/* *INDENT-OFF* */ -START_TEST (test_vfs_split_with_semi_in_path) -/* *INDENT-ON* */ -{ - char *path; - const char *local, *op, *etalon_path, *etalon_local, *etalon_op; - struct vfs_class *result; - - path = g_strdup ("#test2:/bl#a-bl#a/so#me/pa#th2"); - - etalon_path = ""; - etalon_local = "bl#a-bl#a/so#me/pa#th2"; - etalon_op = "test2:"; - result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); - fail_unless (result == &vfs_test_ops2, "Result(%p) doesn't match to vfs_test_ops2(%p)", result, - &vfs_test_ops2); - fail_unless (path != NULL - && strcmp (path, etalon_path) == 0, "path('%s') doesn't match to '%s'", path, - etalon_path); - fail_unless (local != NULL - && strcmp (local, etalon_local) == 0, - "parsed local path('%s') doesn't match to '%s'", local, etalon_local); - fail_unless (op != NULL - && strcmp (op, etalon_op) == 0, "parsed VFS name ('%s') doesn't match to '%s'", op, - etalon_op); - - g_free (path); -} -/* *INDENT-OFF* */ -END_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -int -main (void) -{ - int number_failed; - - Suite *s = suite_create (TEST_SUITE_NAME); - TCase *tc_core = tcase_create ("Core"); - SRunner *sr; - - tcase_add_checked_fixture (tc_core, setup, teardown); - - /* Add new tests here: *************** */ - tcase_add_test (tc_core, test_vfs_split); - tcase_add_test (tc_core, test_vfs_split_with_local); - tcase_add_test (tc_core, test_vfs_split_url); - tcase_add_test (tc_core, test_vfs_split_url_with_semi); - tcase_add_test (tc_core, test_vfs_split_with_semi_in_path); - /* *********************************** */ - - suite_add_tcase (s, tc_core); - sr = srunner_create (s); - srunner_set_log (sr, "vfs_split.log"); - srunner_run_all (sr, CK_NORMAL); - number_failed = srunner_ntests_failed (sr); - srunner_free (sr); - return (number_failed == 0) ? 0 : 1; -} - -/* --------------------------------------------------------------------------------------------- */ +/* + lib/vfs - test vfs_split() functionality + + Copyright (C) 2011, 2013 + The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011, 2013 + + This file is part of the Midnight Commander. + + The Midnight Commander 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 3 of the License, + or (at your option) any later version. + + The Midnight Commander 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, see . + */ + +#define TEST_SUITE_NAME "/lib/vfs" + +#include "tests/mctest.h" + +#include "lib/strutil.h" +#include "lib/vfs/xdirentry.h" +#include "lib/vfs/path.c" /* for testing static methods */ + +#include "src/vfs/local/local.c" + +struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3; +struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3; + +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ +static void +setup (void) +{ + str_init_strings (NULL); + + vfs_init (); + init_localfs (); + vfs_setup_work_dir (); + + + test_subclass1.flags = VFS_S_REMOTE; + vfs_s_init_class (&vfs_test_ops1, &test_subclass1); + + vfs_test_ops1.name = "testfs1"; + vfs_test_ops1.flags = VFSF_NOLINKS; + vfs_test_ops1.prefix = "test1:"; + vfs_register_class (&vfs_test_ops1); + + vfs_s_init_class (&vfs_test_ops2, &test_subclass2); + vfs_test_ops2.name = "testfs2"; + vfs_test_ops2.prefix = "test2:"; + vfs_register_class (&vfs_test_ops2); + + vfs_s_init_class (&vfs_test_ops3, &test_subclass3); + vfs_test_ops3.name = "testfs3"; + vfs_test_ops3.prefix = "test3:"; + vfs_register_class (&vfs_test_ops3); +} + +/* --------------------------------------------------------------------------------------------- */ + +/* @After */ +static void +teardown (void) +{ + vfs_shut (); + str_uninit_strings (); +} + +/* --------------------------------------------------------------------------------------------- */ + +/* @DataSource("test_vfs_split_ds") */ +/* *INDENT-OFF* */ +static const struct test_vfs_split_ds +{ + const char *input_string; + const char *expected_path; + const char *expected_local; + const char *expected_op; + const struct vfs_class *expected_result; +} test_vfs_split_ds[] = +{ + { /* 0. */ + "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/#test3:/qqq/www/eee.rr", + "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/", + "qqq/www/eee.rr", + "test3:", + &vfs_test_ops3 + }, + { /* 1. */ + "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/", + "#test1:/bla-bla/some/path/", + "bla-bla/some/path2/", + "test2:", + &vfs_test_ops2 + }, + { /* 2. */ + "#test1:/bla-bla/some/path/", + "", + "bla-bla/some/path/", + "test1:", + &vfs_test_ops1 + }, + { /* 3. */ + "", + "", + NULL, + NULL, + NULL + }, + { /* 4. split with local */ + "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2#test3:/qqq/www/eee.rr", + "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2", + "qqq/www/eee.rr", + "test3:", + &vfs_test_ops3 + }, + { /* 5. split with local */ + "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2", + "/local/path/#test1:/bla-bla/some/path/", + "bla-bla/some/path2", + "test2:", + &vfs_test_ops2, + }, + { /* 6. split with local */ + "/local/path/#test1:/bla-bla/some/path/", + "/local/path/", + "bla-bla/some/path/", + "test1:", + &vfs_test_ops1 + }, + { /* 7. split with local */ + "/local/path/", + "/local/path/", + NULL, + NULL, + NULL + }, + { /* 8. split with URL */ + "#test2:username:passwd@somehost.net/bla-bla/some/path2", + "", + "bla-bla/some/path2", + "test2:username:passwd@somehost.net", + &vfs_test_ops2 + }, + { /* 9. split URL with semi */ + "/local/path/#test1:/bla-bla/some/path/#test2:username:p!a@s#s$w%d@somehost.net/bla-bla/some/path2", + "/local/path/#test1:/bla-bla/some/path/", + "bla-bla/some/path2", + "test2:username:p!a@s#s$w%d@somehost.net", + &vfs_test_ops2 + }, + { /* 10. split with semi in path */ + "#test2:/bl#a-bl#a/so#me/pa#th2", + "", + "bl#a-bl#a/so#me/pa#th2", + "test2:", + &vfs_test_ops2 + }, +}; +/* *INDENT-ON* */ + +/* @Test(dataSource = "test_vfs_split_ds") */ +/* *INDENT-OFF* */ +START_PARAMETRIZED_TEST (test_vfs_split, test_vfs_split_ds) +/* *INDENT-ON* */ +{ + /* given */ + const char *local = NULL, *op = NULL; + struct vfs_class *actual_result; + char *path; + + path = g_strdup (data->input_string); + + /* when */ + actual_result = _vfs_split_with_semi_skip_count (path, &local, &op, 0); + + /* then */ + mctest_assert_ptr_eq (actual_result, data->expected_result); + mctest_assert_str_eq (path, data->expected_path); + mctest_assert_str_eq (local, data->expected_local); + mctest_assert_str_eq (op, data->expected_op); + g_free (path); +} +/* *INDENT-OFF* */ +END_PARAMETRIZED_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ + +int +main (void) +{ + int number_failed; + + Suite *s = suite_create (TEST_SUITE_NAME); + TCase *tc_core = tcase_create ("Core"); + SRunner *sr; + + tcase_add_checked_fixture (tc_core, setup, teardown); + + /* Add new tests here: *************** */ + mctest_add_parameterized_test (tc_core, test_vfs_split, test_vfs_split_ds); + /* *********************************** */ + + suite_add_tcase (s, tc_core); + sr = srunner_create (s); + srunner_set_log (sr, "vfs_split.log"); + srunner_run_all (sr, CK_NOFORK); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + return (number_failed == 0) ? 0 : 1; +} + +/* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT