1
1
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
Slava Zanko 2013-01-28 15:18:15 +00:00 коммит произвёл Andrew Borodin
родитель c984447f8e
Коммит 063d5a134f
12 изменённых файлов: 1513 добавлений и 704 удалений

Просмотреть файл

@ -33,145 +33,201 @@
#include "lib/vfs/vfs.h"
#include "src/vfs/local/local.c"
static mc_config_t *mc_config;
static char *ini_filename;
/* --------------------------------------------------------------------------------------------- */
static void
config_object__init (void)
{
ini_filename = g_build_filename (WORKDIR, "config_string.ini", NULL);
unlink (ini_filename);
mc_config = mc_config_init (ini_filename, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
static void
config_object__reopen (void)
{
GError *error = NULL;
if (!mc_config_save_file (mc_config, &error))
{
fail ("Unable to save config file: %s", error->message);
g_error_free (error);
}
mc_config_deinit (mc_config);
mc_config = mc_config_init (ini_filename, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
static void
config_object__deinit (void)
{
mc_config_deinit (mc_config);
g_free (ini_filename);
}
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
str_init_strings ("KOI8-R");
vfs_init ();
init_localfs ();
config_object__init ();
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
config_object__deinit ();
vfs_shut ();
str_uninit_strings ();
}
/* --------------------------------------------------------------------------------------------- */
#define fail_unless_strcmp( etalon ) \
fail_unless( \
strcmp(actual_value, etalon) == 0, \
"Actial value '%s' doesn't equal to etalon '%s'", actual_value, etalon \
)
/* @DataSource("test_create_ini_file_ds") */
/* *INDENT-OFF* */
START_TEST (create_ini_file)
static const struct test_create_ini_file_ds
{
const char *input_group;
const char *input_param;
const char *input_default_value;
const char *expected_value;
const char *expected_raw_value;
} test_create_ini_file_ds[] =
{
{ /* 0. */
"group-not-exists",
"param-not_exists",
NULL,
NULL,
"" /* it's a bug: should be NULL. Will be fixed in another branch */
},
{ /* 1. */
"test-group1",
"test-param1",
"not-exists",
" some value ",
" some value "
},
{ /* 2. */
"test-group1",
"test-param2",
"not-exists",
" \tkoi8-r: Ї┼╙╘╧╫╧┼ ┌╬┴▐┼╬╔┼ ",
" \tkoi8-r: \320\242\320\265\321\201\321\202\320\276\320\262\320\276\320\265 \320\267\320\275\320\260\321\207\320\265\320\275\320\270\320\265 "
},
{ /* 3. */
"test-group1",
"test-param3",
"not-exists",
" \tsome value2\n\nf\b\005fff ",
" \tsome value2\n\nf\b\005fff "
},
{ /* 4. */
"test-group2",
"test-param1",
"not-exists",
" some value ",
" some value "
},
{ /* 5. */
"test-group2",
"test-param2",
"not-exists",
"not-exists",
"not-exists"
},
{ /* 6. */
"test-group2",
"test-param3",
"not-exists",
" \tsome value2\n\nf\b\005fff ",
" \tsome value2\n\nf\b\005fff "
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_create_ini_file_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_create_ini_file_paths, test_create_ini_file_ds)
/* *INDENT-ON* */
{
mc_config_t *mc_config;
GError *error = NULL;
char *actual_value;
char *ini_filename = NULL;
ini_filename = g_build_filename (WORKDIR, "test-create_ini_file.ini", NULL);
unlink (ini_filename);
mc_config = mc_config_init (ini_filename, FALSE);
if (mc_config == NULL)
{
fail ("unable to create mc_congif_t object!");
return;
}
/* given */
char *actual_value, *actual_raw_value;
mc_config_set_string (mc_config, "test-group1", "test-param1", " some value ");
mc_config_set_string (mc_config, "test-group1", "test-param2", " \tkoi8-r: Ї┼╙╘╧╫╧┼ ┌╬┴▐┼╬╔┼ ");
mc_config_set_string (mc_config, "test-group1", "test-param3", " \tsome value2\n\nf\b\005fff ");
mc_config_set_string_raw (mc_config, "test-group2", "test-param1", " some value ");
mc_config_set_string_raw (mc_config, "test-group2", "test-param2",
" koi8-r: Ї┼╙╘╧╫╧┼ ┌╬┴▐┼╬╔┼");
mc_config_set_string_raw (mc_config, "test-group2", "test-param3",
" \tsome value2\n\nf\b\005fff ");
if (!mc_config_save_file (mc_config, &error))
{
fail ("Unable to save config file: %s", error->message);
g_error_free (error);
}
config_object__reopen ();
mc_config_deinit (mc_config);
mc_config = mc_config_init (ini_filename, FALSE);
/* when */
actual_value =
mc_config_get_string (mc_config, data->input_group, data->input_param,
data->input_default_value);
actual_raw_value =
mc_config_get_string_raw (mc_config, data->input_group, data->input_param,
data->input_default_value);
actual_value = mc_config_get_string (mc_config, "group-not-exists", "param-not_exists", NULL);
fail_unless (actual_value == NULL,
"return value for nonexistent ini-parameters isn't NULL (default value)!");
/* then */
mctest_assert_str_eq (actual_value, data->expected_value);
mctest_assert_str_eq (actual_raw_value, data->expected_raw_value);
actual_value = mc_config_get_string (mc_config, "test-group1", "test-param1", "not-exists");
fail_unless_strcmp (" some value ");
g_free (actual_value);
actual_value = mc_config_get_string (mc_config, "test-group1", "test-param2", "not-exists");
fail_unless_strcmp (" \tkoi8-r: Ї┼╙╘╧╫╧┼ ┌╬┴▐┼╬╔┼ ");
g_free (actual_value);
actual_value = mc_config_get_string (mc_config, "test-group1", "test-param3", "not-exists");
fail_unless_strcmp (" \tsome value2\n\nf\b\005fff ");
g_free (actual_value);
actual_value = mc_config_get_string_raw (mc_config, "test-group2", "test-param1", "not-exists");
fail_unless_strcmp (" some value ");
g_free (actual_value);
actual_value = mc_config_get_string_raw (mc_config, "test-group2", "test-param2", "not-exists");
fail_unless_strcmp ("not-exists");
g_free (actual_value);
actual_value = mc_config_get_string_raw (mc_config, "test-group2", "test-param3", "not-exists");
fail_unless_strcmp (" \tsome value2\n\nf\b\005fff ");
g_free (actual_value);
mc_config_deinit (mc_config);
g_free (ini_filename);
g_free (actual_raw_value);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/* @Test(group='Integration') */
/* *INDENT-OFF* */
START_TEST (emulate__learn_save)
/* *INDENT-ON* */
{
mc_config_t *mc_config;
char *actual_value, *esc_str;
char *ini_filename = NULL;
GError *error = NULL;
/* given */
char *actual_value;
ini_filename = g_build_filename (WORKDIR, "test-emulate__learn_save.ini", NULL);
unlink (ini_filename);
mc_config = mc_config_init (ini_filename, FALSE);
if (mc_config == NULL)
{
fail ("unable to create mc_congif_t object!");
return;
char *esc_str;
esc_str = strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE);
mc_config_set_string_raw (mc_config, "test-group1", "test-param1", esc_str);
g_free (esc_str);
}
esc_str = strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE);
mc_config_set_string_raw (mc_config, "test-group1", "test-param1", esc_str);
g_free (esc_str);
if (!mc_config_save_file (mc_config, &error))
{
fail ("Unable to save config file: %s", error->message);
g_error_free (error);
}
mc_config_deinit (mc_config);
mc_config = mc_config_init (ini_filename, FALSE);
config_object__reopen ();
/* when */
actual_value = mc_config_get_string_raw (mc_config, "test-group1", "test-param1", "not-exists");
fail_unless_strcmp ("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
g_free (actual_value);
mc_config_deinit (mc_config);
g_free (ini_filename);
/* then */
mctest_assert_str_eq (actual_value, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
g_free (actual_value);
}
/* *INDENT-OFF* */
END_TEST
@ -191,7 +247,7 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, create_ini_file);
mctest_add_parameterized_test (tc_core, test_create_ini_file_paths, test_create_ini_file_ds);
tcase_add_test (tc_core, emulate__learn_save);
/* *********************************** */

Просмотреть файл

@ -47,7 +47,9 @@
#define CONF_CACHE CONF_MAIN
#endif
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
@ -62,6 +64,9 @@ setup (void)
init_localfs ();
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -69,49 +74,139 @@ teardown (void)
str_uninit_strings ();
}
#define path_fail_unless(conf_dir, conf_name) {\
result = mc_config_get_full_path (conf_name); \
fail_unless (strcmp( conf_dir PATH_SEP_STR MC_USERCONF_DIR PATH_SEP_STR conf_name, result) == 0); \
g_free (result); \
}
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("test_user_config_paths_ds") */
/* *INDENT-OFF* */
START_TEST (user_configs_path_test)
static const struct test_user_config_paths_ds
{
const char *input_base_dir;
const char *input_file_name;
} test_user_config_paths_ds[] =
{
{ /* 0. */
CONF_MAIN,
MC_CONFIG_FILE
},
{ /* 0. */
CONF_MAIN,
MC_FHL_INI_FILE
},
{ /* 0. */
CONF_MAIN,
MC_HOTLIST_FILE
},
{ /* 0. */
CONF_MAIN,
GLOBAL_KEYMAP_FILE
},
{ /* 0. */
CONF_MAIN,
MC_USERMENU_FILE
},
{ /* 0. */
CONF_MAIN,
EDIT_SYNTAX_FILE
},
{ /* 0. */
CONF_MAIN,
EDIT_HOME_MENU
},
{ /* 0. */
CONF_MAIN,
EDIT_DIR PATH_SEP_STR "edit.indent.rc"
},
{ /* 0. */
CONF_MAIN,
EDIT_DIR PATH_SEP_STR "edit.spell.rc"
},
{ /* 0. */
CONF_MAIN,
MC_PANELS_FILE
},
{ /* 0. */
CONF_MAIN,
MC_FILEBIND_FILE
},
{ /* 0. */
CONF_DATA,
MC_SKINS_SUBDIR
},
{ /* 0. */
CONF_DATA,
FISH_PREFIX
},
{ /* 0. */
CONF_DATA,
"bashrc"
},
{ /* 0. */
CONF_DATA,
"inputrc"
},
{ /* 0. */
CONF_DATA,
MC_EXTFS_DIR
},
{ /* 0. */
CONF_DATA,
MC_HISTORY_FILE
},
{ /* 0. */
CONF_DATA,
MC_FILEPOS_FILE
},
{ /* 0. */
CONF_DATA,
EDIT_CLIP_FILE
},
{ /* 0. */
CONF_DATA,
MC_MACRO_FILE
},
{ /* 0. */
CONF_CACHE,
"mc.log"
},
{ /* 0. */
CONF_CACHE,
MC_TREESTORE_FILE
},
{ /* 0. */
CONF_CACHE,
EDIT_TEMP_FILE
},
{ /* 0. */
CONF_CACHE,
EDIT_BLOCK_FILE
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_user_config_paths_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
/* *INDENT-ON* */
{
char *result;
/* given */
char *actual_result;
path_fail_unless (CONF_MAIN, MC_CONFIG_FILE);
/* when */
actual_result = mc_config_get_full_path (data->input_file_name);
path_fail_unless (CONF_MAIN, MC_FHL_INI_FILE);
path_fail_unless (CONF_MAIN, MC_HOTLIST_FILE);
path_fail_unless (CONF_MAIN, GLOBAL_KEYMAP_FILE);
path_fail_unless (CONF_MAIN, MC_USERMENU_FILE);
path_fail_unless (CONF_MAIN, EDIT_SYNTAX_FILE);
path_fail_unless (CONF_MAIN, EDIT_HOME_MENU);
path_fail_unless (CONF_MAIN, EDIT_DIR PATH_SEP_STR "edit.indent.rc");
path_fail_unless (CONF_MAIN, EDIT_DIR PATH_SEP_STR "edit.spell.rc");
path_fail_unless (CONF_MAIN, MC_PANELS_FILE);
path_fail_unless (CONF_MAIN, MC_FILEBIND_FILE);
path_fail_unless (CONF_DATA, MC_SKINS_SUBDIR);
path_fail_unless (CONF_DATA, FISH_PREFIX);
path_fail_unless (CONF_DATA, "bashrc");
path_fail_unless (CONF_DATA, "inputrc");
path_fail_unless (CONF_DATA, MC_EXTFS_DIR);
path_fail_unless (CONF_DATA, MC_HISTORY_FILE);
path_fail_unless (CONF_DATA, MC_FILEPOS_FILE);
path_fail_unless (CONF_DATA, EDIT_CLIP_FILE);
path_fail_unless (CONF_DATA, MC_MACRO_FILE);
path_fail_unless (CONF_CACHE, "mc.log");
path_fail_unless (CONF_CACHE, MC_TREESTORE_FILE);
path_fail_unless (CONF_CACHE, EDIT_TEMP_FILE);
path_fail_unless (CONF_CACHE, EDIT_BLOCK_FILE);
/* then */
{
char *expected_file_path;
expected_file_path =
g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name, NULL);
mctest_assert_str_eq (actual_result, expected_file_path);
g_free (expected_file_path);
}
g_free (actual_result);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -128,7 +223,7 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, user_configs_path_test);
mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -29,38 +29,110 @@
#include "regex.c" /* for testing static functions */
/* --------------------------------------------------------------------------------------------- */
#define test_helper_valid_data(from, etalon, dest_str, replace_flags, utf) { \
dest_str = g_string_new(""); \
mc_search_regex__process_escape_sequence (dest_str, from, -1, &replace_flags, utf); \
fail_if (strcmp(dest_str->str, etalon), "dest_str(%s) != %s", dest_str->str, etalon); \
g_string_free(dest_str, TRUE); \
}
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("test_regex_process_escape_sequence_ds") */
/* *INDENT-OFF* */
START_TEST (test_regex_process_escape_sequence_valid)
static const struct test_regex_process_escape_sequence_ds
{
const char *input_from;
const replace_transform_type_t input_initial_flags;
const gboolean input_use_utf;
const char *expected_string;
} test_regex_process_escape_sequence_ds[] =
{
{ /* 0. */
"{101}",
REPLACE_T_NO_TRANSFORM,
FALSE,
"A"
},
{ /* 1. */
"x42",
REPLACE_T_NO_TRANSFORM,
FALSE,
"B"
},
{ /* 2. */
"x{444}",
REPLACE_T_NO_TRANSFORM,
FALSE,
"D"
},
{ /* 3. */
"x{444}",
REPLACE_T_NO_TRANSFORM,
TRUE,
"ф"
},
{ /* 4. */
"n",
REPLACE_T_NO_TRANSFORM,
FALSE,
"\n"
},
{ /* 5. */
"t",
REPLACE_T_NO_TRANSFORM,
FALSE,
"\t"
},
{ /* 6. */
"v",
REPLACE_T_NO_TRANSFORM,
FALSE,
"\v"
},
{ /* 7. */
"b",
REPLACE_T_NO_TRANSFORM,
FALSE,
"\b"
},
{ /* 8. */
"r",
REPLACE_T_NO_TRANSFORM,
FALSE,
"\r"
},
{ /* 9. */
"f",
REPLACE_T_NO_TRANSFORM,
FALSE,
"\f"
},
{ /* 10. */
"a",
REPLACE_T_NO_TRANSFORM,
FALSE,
"\a"
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_regex_process_escape_sequence_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_regex_process_escape_sequence, test_regex_process_escape_sequence_ds)
/* *INDENT-ON* */
{
GString *dest_str;
/* given */
GString *actual_string;
replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
test_helper_valid_data ("{101}", "A", dest_str, replace_flags, FALSE);
test_helper_valid_data ("x42", "B", dest_str, replace_flags, FALSE);
test_helper_valid_data ("x{444}", "D", dest_str, replace_flags, FALSE);
test_helper_valid_data ("x{444}", "ф", dest_str, replace_flags, TRUE);
replace_flags = data->input_initial_flags;
actual_string = g_string_new ("");
test_helper_valid_data ("n", "\n", dest_str, replace_flags, FALSE);
test_helper_valid_data ("t", "\t", dest_str, replace_flags, FALSE);
test_helper_valid_data ("v", "\v", dest_str, replace_flags, FALSE);
test_helper_valid_data ("b", "\b", dest_str, replace_flags, FALSE);
test_helper_valid_data ("r", "\r", dest_str, replace_flags, FALSE);
test_helper_valid_data ("f", "\f", dest_str, replace_flags, FALSE);
test_helper_valid_data ("a", "\a", dest_str, replace_flags, FALSE);
/* when */
mc_search_regex__process_escape_sequence (actual_string, data->input_from, -1, &replace_flags,
data->input_use_utf);
/* then */
mctest_assert_str_eq (actual_string->str, data->expected_string);
g_string_free (actual_string, TRUE);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -75,7 +147,8 @@ main (void)
SRunner *sr;
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_regex_process_escape_sequence_valid);
mctest_add_parameterized_test (tc_core, test_regex_process_escape_sequence,
test_regex_process_escape_sequence_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -49,59 +49,160 @@
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("test_regex_replace_esc_seq_prepare_ds") */
/* *INDENT-OFF* */
START_TEST (test_regex_replace_esc_seq_prepare_valid)
static const struct test_regex_replace_esc_seq_prepare_ds
{
const char *input_string;
const size_t input_pos;
const gboolean expected_result;
const gsize expected_skipped_len;
const int expected_flags;
} test_regex_replace_esc_seq_prepare_ds[] =
{
{ /* 0. \\{123} */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
7,
FALSE,
6,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 1. \\xab */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
20,
FALSE,
4,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 2. \\x{456abcd} */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
36,
FALSE,
11,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 3. \\xtre */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
54,
FALSE,
2,
REPLACE_PREPARE_T_NOTHING_SPECIAL
},
{ /* 4. \\n */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
59,
FALSE,
2,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 5. \\t */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
61,
FALSE,
2,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 6. \\v */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
63,
FALSE,
2,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 7. \\b */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
65,
FALSE,
2,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 8. \\r */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
67,
FALSE,
2,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 9. \\f */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
69,
FALSE,
2,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 10. \\a */
"bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
71,
FALSE,
2,
REPLACE_PREPARE_T_ESCAPE_SEQ
},
{ /* 11. \\{123 */
"\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
0,
TRUE,
5,
REPLACE_PREPARE_T_NOTHING_SPECIAL
},
{ /* 12. \\x{qwerty} */
"\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
6,
TRUE,
3,
REPLACE_PREPARE_T_NOTHING_SPECIAL
},
{ /* 13. \\12} */
"\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
17,
TRUE,
0,
0
},
{ /* 14. \\x{456a-bcd} */
"\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
22,
TRUE,
7,
REPLACE_PREPARE_T_NOTHING_SPECIAL
},
{ /* 15. \\satre */
"\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
41,
TRUE,
0,
0
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_regex_replace_esc_seq_prepare_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_regex_replace_esc_seq_prepare, test_regex_replace_esc_seq_prepare_ds)
/* *INDENT-ON* */
{
/* given */
GString *replace_str;
gsize skip_len;
int ret;
gsize actual_skipped_len = 0;
int actual_flags = 0;
gboolean actual_result;
replace_str =
g_string_new
("bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a");
replace_str = g_string_new (data->input_string);
test_helper_handle_esc_seq (7, FALSE, 6, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\{123} */
test_helper_handle_esc_seq (20, FALSE, 4, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\xab */
test_helper_handle_esc_seq (36, FALSE, 11, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\x{456abcd} */
test_helper_handle_esc_seq (54, FALSE, 2, REPLACE_PREPARE_T_NOTHING_SPECIAL); /* \\xtre */
test_helper_handle_esc_seq (59, FALSE, 2, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\n */
test_helper_handle_esc_seq (61, FALSE, 2, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\t */
test_helper_handle_esc_seq (63, FALSE, 2, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\v */
test_helper_handle_esc_seq (65, FALSE, 2, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\b */
test_helper_handle_esc_seq (67, FALSE, 2, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\r */
test_helper_handle_esc_seq (69, FALSE, 2, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\f */
test_helper_handle_esc_seq (71, FALSE, 2, REPLACE_PREPARE_T_ESCAPE_SEQ); /* \\a */
/* when */
actual_result =
mc_search_regex__replace_handle_esc_seq (replace_str, data->input_pos, &actual_skipped_len,
&actual_flags);
/* then */
mctest_assert_int_eq (actual_result, data->expected_result);
mctest_assert_int_eq (actual_skipped_len, data->expected_skipped_len);
mctest_assert_int_eq (actual_flags, data->expected_flags);
g_string_free (replace_str, TRUE);
}
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/* *INDENT-OFF* */
START_TEST (test_regex_replace_esc_seq_prepare_invalid)
/* *INDENT-ON* */
{
GString *replace_str;
gsize skip_len;
int ret;
replace_str = g_string_new ("\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre");
test_helper_handle_esc_seq (0, TRUE, 5, REPLACE_PREPARE_T_NOTHING_SPECIAL); /* \\{123 */
test_helper_handle_esc_seq (6, TRUE, 3, REPLACE_PREPARE_T_NOTHING_SPECIAL); /* \\x{qwerty} */
test_helper_handle_esc_seq (17, TRUE, 0, REPLACE_PREPARE_T_NOTHING_SPECIAL); /* \\12} */
test_helper_handle_esc_seq (22, TRUE, 7, REPLACE_PREPARE_T_NOTHING_SPECIAL); /* \\x{456a-bcd} */
test_helper_handle_esc_seq (41, TRUE, 0, REPLACE_PREPARE_T_NOTHING_SPECIAL); /* \\satre */
g_string_free (replace_str, TRUE);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -116,8 +217,8 @@ main (void)
SRunner *sr;
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_regex_replace_esc_seq_prepare_valid);
tcase_add_test (tc_core, test_regex_replace_esc_seq_prepare_invalid);
mctest_add_parameterized_test (tc_core, test_regex_replace_esc_seq_prepare,
test_regex_replace_esc_seq_prepare_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -33,6 +33,12 @@
#include "src/vfs/local/local.c"
static struct vfs_s_subclass test_subclass;
static struct vfs_class vfs_test_ops;
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
@ -41,8 +47,19 @@ setup (void)
vfs_init ();
init_localfs ();
vfs_setup_work_dir ();
vfs_s_init_class (&vfs_test_ops, &test_subclass);
vfs_test_ops.name = "testfs";
vfs_test_ops.flags = VFSF_NOLINKS;
vfs_test_ops.prefix = "ftp";
test_subclass.flags = VFS_S_REMOTE;
vfs_register_class (&vfs_test_ops);
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -52,63 +69,75 @@ teardown (void)
/* --------------------------------------------------------------------------------------------- */
#define check_canonicalize( input, etalon ) { \
path = g_strdup(input); \
canonicalize_pathname (path); \
fail_unless ( \
strcmp(path, etalon) == 0, \
"\nactual value (%s)\nnot equal to etalon (%s)", path, etalon \
); \
g_free(path); \
}
/* @DataSource("test_canonicalize_path_ds") */
/* *INDENT-OFF* */
START_TEST (test_canonicalize_path)
static const struct test_canonicalize_path_ds
{
const char *input_path;
const char *expected_path;
} test_canonicalize_path_ds[] =
{
{ /* 0. UNC path */
"//some_server/ww",
"//some_server/ww"
},
{ /* 1. join slashes */
"///some_server/////////ww",
"/some_server/ww"
},
{ /* 2. Collapse "/./" -> "/" */
"//some_server//.///////ww/./././.",
"//some_server/ww"
},
{/* 3. Remove leading "./" */
"./some_server/ww",
"some_server/ww"
},
{ /* 4. some/.. -> . */
"some_server/..",
"."
},
{ /* 5. Collapse "/.." with the previous part of path */
"/some_server/ww/some_server/../ww/../some_server/..//ww/some_server/ww",
"/some_server/ww/ww/some_server/ww"
},
{ /* 6. URI style */
"/some_server/ww/ftp://user:pass@host.net/path/",
"/some_server/ww/ftp://user:pass@host.net/path"
},
{ /* 7. */
"/some_server/ww/ftp://user:pass@host.net/path/../../",
"/some_server/ww"
},
{ /* 8. */
"ftp://user:pass@host.net/path/../../",
"."
},
{ /* 9. */
"ftp://user/../../",
".."
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_canonicalize_path_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_canonicalize_path, test_canonicalize_path_ds)
/* *INDENT-ON* */
{
char *path;
static struct vfs_s_subclass test_subclass;
static struct vfs_class vfs_test_ops;
/* given */
char *actual_path;
vfs_s_init_class (&vfs_test_ops, &test_subclass);
actual_path = g_strdup (data->input_path);
vfs_test_ops.name = "testfs";
vfs_test_ops.flags = VFSF_NOLINKS;
vfs_test_ops.prefix = "ftp";
test_subclass.flags = VFS_S_REMOTE;
vfs_register_class (&vfs_test_ops);
/* when */
canonicalize_pathname (actual_path);
/* UNC path */
check_canonicalize ("//some_server/ww", "//some_server/ww");
/* join slashes */
check_canonicalize ("///some_server/////////ww", "/some_server/ww");
/* Collapse "/./" -> "/" */
check_canonicalize ("//some_server//.///////ww/./././.", "//some_server/ww");
/* Remove leading "./" */
check_canonicalize ("./some_server/ww", "some_server/ww");
/* some/.. -> . */
check_canonicalize ("some_server/..", ".");
/* Collapse "/.." with the previous part of path */
check_canonicalize ("/some_server/ww/some_server/../ww/../some_server/..//ww/some_server/ww",
"/some_server/ww/ww/some_server/ww");
/* URI style */
check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/",
"/some_server/ww/ftp://user:pass@host.net/path");
check_canonicalize ("/some_server/ww/ftp://user:pass@host.net/path/../../", "/some_server/ww");
check_canonicalize ("ftp://user:pass@host.net/path/../../", ".");
check_canonicalize ("ftp://user/../../", "..");
/* then */
mctest_assert_str_eq (actual_path, data->expected_path) g_free (actual_path);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -125,7 +154,7 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_canonicalize_path);
mctest_add_parameterized_test (tc_core, test_canonicalize_path, test_canonicalize_path_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -33,6 +33,23 @@
#include "src/vfs/local/local.c"
static struct vfs_s_subclass test_subclass;
static struct vfs_class vfs_test_ops;
/* --------------------------------------------------------------------------------------------- */
/* @Mock */
static int
test_chdir (const vfs_path_t * vpath)
{
(void) vpath;
return 0;
}
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
@ -41,8 +58,18 @@ setup (void)
vfs_init ();
init_localfs ();
vfs_setup_work_dir ();
vfs_s_init_class (&vfs_test_ops, &test_subclass);
vfs_test_ops.name = "testfs";
vfs_test_ops.prefix = "test";
vfs_test_ops.chdir = test_chdir;
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -50,71 +77,117 @@ teardown (void)
str_uninit_strings ();
}
static int
test_chdir (const vfs_path_t * vpath)
{
#if 0
char *path = vfs_path_to_str (vpath);
printf ("test_chdir: %s\n", path);
g_free (path);
#else
(void) vpath;
#endif
return 0;
}
/* --------------------------------------------------------------------------------------------- */
#define cd_and_check( cd_dir, etalon ) \
vpath = vfs_path_from_str (cd_dir); \
mc_chdir(vpath); \
vfs_path_free (vpath); \
buffer = _vfs_get_cwd (); \
fail_unless( \
strcmp(etalon, buffer) == 0, \
"\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer); \
g_free (buffer);
/* @DataSource("test_cd_ds") */
/* *INDENT-OFF* */
START_TEST (set_up_current_dir_url)
static const struct test_cd_ds
{
const char *input_initial_path;
const char *input_cd_path;
const vfs_class_flags_t input_class_flags;
const vfs_subclass_flags_t input_subclass_flags;
const char *expected_cd_path;
} test_cd_ds[] =
{
{ /* 0. */
"/",
"/dev/some.file/test://",
VFSF_NOLINKS,
0,
"/dev/some.file/test://"
},
{ /* 1. */
"/",
"/dev/some.file/test://bla-bla",
VFSF_NOLINKS,
0,
"/dev/some.file/test://bla-bla"
},
{ /* 2. */
"/dev/some.file/test://bla-bla",
"..",
VFSF_NOLINKS,
0,
"/dev/some.file/test://"
},
{ /* 3. */
"/dev/some.file/test://",
"..",
VFSF_NOLINKS,
0,
"/dev"
},
{ /* 4. */
"/dev",
"..",
VFSF_NOLINKS,
0,
"/"
},
{ /* 5. */
"/",
"..",
VFSF_NOLINKS,
0,
"/"
},
{ /* 6. */
"/",
"/test://user:pass@host.net/path",
VFSF_NOLINKS,
VFS_S_REMOTE,
"/test://user:pass@host.net/path"
},
{ /* 7. */
"/test://user:pass@host.net/path",
"..",
VFSF_NOLINKS,
VFS_S_REMOTE,
"/test://user:pass@host.net/"
},
{ /* 8. */
"/test://user:pass@host.net/",
"..",
VFSF_NOLINKS,
VFS_S_REMOTE,
"/"
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_cd_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_cd, test_cd_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
static struct vfs_s_subclass test_subclass;
static struct vfs_class vfs_test_ops;
char *buffer;
vfs_s_init_class (&vfs_test_ops, &test_subclass);
vfs_test_ops.name = "testfs";
vfs_test_ops.flags = VFSF_NOLINKS;
vfs_test_ops.prefix = "test";
vfs_test_ops.chdir = test_chdir;
vfs_test_ops.flags = data->input_class_flags;
test_subclass.flags = data->input_subclass_flags;
vfs_register_class (&vfs_test_ops);
vfs_set_raw_current_dir (vfs_path_from_str (data->input_initial_path));
cd_and_check ("/dev/some.file/test://", "/dev/some.file/test://");
vpath = vfs_path_from_str (data->input_cd_path);
cd_and_check ("/dev/some.file/test://bla-bla", "/dev/some.file/test://bla-bla");
/* when */
mc_chdir (vpath);
cd_and_check ("..", "/dev/some.file/test://");
cd_and_check ("..", "/dev");
cd_and_check ("..", "/");
cd_and_check ("..", "/");
test_subclass.flags = VFS_S_REMOTE;
cd_and_check ("/test://user:pass@host.net/path", "/test://user:pass@host.net/path");
cd_and_check ("..", "/test://user:pass@host.net/");
cd_and_check ("..", "/");
/* then */
{
char *actual_cd_path;
actual_cd_path = _vfs_get_cwd ();
mctest_assert_str_eq (actual_cd_path, data->expected_cd_path);
g_free (actual_cd_path);
}
vfs_path_free (vpath);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -131,7 +204,7 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, set_up_current_dir_url);
mctest_add_parameterized_test (tc_core, test_cd, test_cd_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -35,7 +35,9 @@
#include "src/vfs/local/local.c"
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
@ -51,6 +53,9 @@ setup (void)
#endif
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -63,74 +68,167 @@ teardown (void)
}
/* --------------------------------------------------------------------------------------------- */
#define path_cmp_one_check(input1, input2, etalon_condition) {\
vpath1 = vfs_path_from_str (input1);\
vpath2 = vfs_path_from_str (input2);\
result = vfs_path_equal (vpath1, vpath2);\
vfs_path_free (vpath1); \
vfs_path_free (vpath2); \
fail_unless ( result == etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\
input1, input2, #etalon_condition, result); \
}
/* @DataSource("test_path_equal_ds") */
/* *INDENT-OFF* */
START_TEST (test_path_compare)
static const struct test_path_equal_ds
{
const char *input_path1;
const char *input_path2;
const gboolean expected_result;
} test_path_equal_ds[] =
{
{ /* 0. */
NULL,
NULL,
FALSE
},
{ /* 1. */
NULL,
"/test/path",
FALSE
},
{ /* 2. */
"/test/path",
NULL,
FALSE
},
{ /* 3. */
"/test/path",
"/test/path",
TRUE
},
#ifdef HAVE_CHARSET
{ /* 4. */
"/#enc:KOI8-R/тестовый/путь",
"/тестовый/путь",
FALSE
},
{ /* 5. */
"/тестовый/путь",
"/#enc:KOI8-R/тестовый/путь",
FALSE
},
{ /* 6. */
"/#enc:KOI8-R/тестовый/путь",
"/#enc:KOI8-R/тестовый/путь",
TRUE
},
#endif
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_path_equal_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_equal, test_path_equal_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath1, *vpath2;
int result;
gboolean actual_result;
path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", TRUE);
vpath1 = vfs_path_from_str (data->input_path1);
vpath2 = vfs_path_from_str (data->input_path2);
#ifdef HAVE_CHARSET
path_cmp_one_check ("/#enc:KOI8-R/тестовый/путь", "/тестовый/путь",
FALSE);
path_cmp_one_check ("/тестовый/путь", "/#enc:KOI8-R/тестовый/путь",
FALSE);
#endif
/* when */
actual_result = vfs_path_equal (vpath1, vpath2);
path_cmp_one_check (NULL, "/тестовый/путь", FALSE);
path_cmp_one_check ("/тестовый/путь", NULL, FALSE);
path_cmp_one_check (NULL, NULL, FALSE);
/* then */
mctest_assert_int_eq (actual_result, data->expected_result);
vfs_path_free (vpath1);
vfs_path_free (vpath2);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
#undef path_cmp_one_check
#define path_cmp_one_check(input1, input2, len, etalon_condition) {\
vpath1 = vfs_path_from_str (input1);\
vpath2 = vfs_path_from_str (input2);\
result = vfs_path_equal_len (vpath1, vpath2, len);\
vfs_path_free (vpath1); \
vfs_path_free (vpath2); \
fail_unless ( result == etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\
input1, input2, #etalon_condition, result); \
}
/* @DataSource("test_path_equal_len_ds") */
/* *INDENT-OFF* */
START_TEST (test_path_compare_len)
static const struct test_path_equal_len_ds
{
const char *input_path1;
const char *input_path2;
const size_t input_length;
const gboolean expected_result;
} test_path_equal_len_ds[] =
{
{ /* 0. */
NULL,
NULL,
0,
FALSE
},
{ /* 1. */
NULL,
NULL,
100,
FALSE
},
{ /* 2. */
NULL,
"/тестовый/путь",
10,
FALSE
},
{ /* 3. */
"/тестовый/путь",
NULL,
10,
FALSE
},
{ /* 4. */
"/тестовый/путь",
"/тестовый/путь",
10,
TRUE
},
{ /* 5. */
"/тест/овый/путь",
"/тестовый/путь",
8,
TRUE
},
{ /* 6. */
"/тест/овый/путь",
"/тестовый/путь",
10,
FALSE
},
{ /* 7. */
"/тестовый/путь",
"/тест/овый/путь",
10,
FALSE
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_path_equal_len_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_equal_len, test_path_equal_len_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath1, *vpath2;
int result;
gboolean actual_result;
path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", 10, TRUE);
vpath1 = vfs_path_from_str (data->input_path1);
vpath2 = vfs_path_from_str (data->input_path2);
path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 10, FALSE);
/* when */
actual_result = vfs_path_equal_len (vpath1, vpath2, data->input_length);
path_cmp_one_check ("/тестовый/путь", "/тест/овый/путь", 10, FALSE);
/* then */
mctest_assert_int_eq (actual_result, data->expected_result);
path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 9, TRUE);
path_cmp_one_check (NULL, "/тестовый/путь", 0, FALSE);
path_cmp_one_check ("/тестовый/путь", NULL, 0, FALSE);
path_cmp_one_check (NULL, NULL, 0, FALSE);
vfs_path_free (vpath1);
vfs_path_free (vpath2);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -147,8 +245,8 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_path_compare);
tcase_add_test (tc_core, test_path_compare_len);
mctest_add_parameterized_test (tc_core, test_path_equal, test_path_equal_ds);
mctest_add_parameterized_test (tc_core, test_path_equal_len, test_path_equal_len_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -1,4 +1,4 @@
/* lib/vfs - vfs_path_t compare functions
/* lib/vfs - tests for vfspath_len() function.
Copyright (C) 2011, 2013
The Free Software Foundation, Inc.
@ -35,7 +35,9 @@
#include "src/vfs/local/local.c"
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
@ -51,6 +53,9 @@ setup (void)
#endif
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -63,29 +68,56 @@ teardown (void)
}
/* --------------------------------------------------------------------------------------------- */
#define path_len_one_check(input,etalon) {\
vpath = vfs_path_from_str (input);\
result = vfs_path_len (vpath);\
vfs_path_free (vpath); \
fail_unless ( result == etalon, "\ninput: %s\nexpected: %d\nactual: %d\n",\
input, etalon, result); \
}
/* @DataSource("test_path_length_ds") */
/* *INDENT-OFF* */
START_TEST (test_path_length)
static const struct test_path_length_ds
{
const char *input_path;
const size_t expected_length;
} test_path_length_ds[] =
{
{ /* 0. */
NULL,
0
},
{ /* 1. */
"/",
1
},
{ /* 2. */
"/тестовый/путь",
26
},
#ifdef HAVE_CHARSET
{ /* 3. */
"/#enc:KOI8-R/тестовый/путь",
38
},
#endif /* HAVE_CHARSET */
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_path_length_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
size_t result;
size_t actual_length;
path_len_one_check ("/тестовый/путь", 26);
#ifdef HAVE_CHARSET
path_len_one_check ("/#enc:KOI8-R/тестовый/путь", 38);
#endif
path_len_one_check (NULL, 0);
vpath = vfs_path_from_str (data->input_path);
/* when */
actual_length = vfs_path_len (vpath);
/* then */
mctest_assert_int_eq (actual_length, data->expected_length);
vfs_path_free (vpath);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -102,7 +134,7 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_path_length);
mctest_add_parameterized_test (tc_core, test_path_length, test_path_length_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -39,17 +39,11 @@
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)
init_test_classes (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);
@ -68,6 +62,22 @@ setup (void)
vfs_test_ops3.prefix = "test3";
vfs_test_ops3.flags = VFSF_LOCAL;
vfs_register_class (&vfs_test_ops3);
}
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
str_init_strings (NULL);
vfs_init ();
init_localfs ();
vfs_setup_work_dir ();
init_test_classes ();
mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
#ifdef HAVE_CHARSET
@ -75,6 +85,9 @@ setup (void)
#endif
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -88,217 +101,361 @@ teardown (void)
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("test_vfs_path_tokens_count_ds") */
/* *INDENT-OFF* */
START_TEST (test_vfs_path_tokens_count)
static const struct test_vfs_path_tokens_count_ds
{
const char *input_path;
const vfs_path_flag_t input_flags;
const size_t expected_token_count;
} test_vfs_path_tokens_count_ds[] =
{
{ /* 0. */
"/",
VPF_NONE,
0
},
{ /* 1. */
"/path",
VPF_NONE,
1
},
{ /* 2. */
"/path1/path2/path3",
VPF_NONE,
3
},
{ /* 3. */
"test3://path1/path2/path3/path4",
VPF_NO_CANON,
4
},
{ /* 4. */
"path1/path2/path3",
VPF_NO_CANON,
3
},
{ /* 5. */
"/path1/path2/path3/",
VPF_NONE,
3
},
{ /* 6. */
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/",
VPF_NONE,
5
},
#ifdef HAVE_CHARSET
{ /* 7. */
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/"
"test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33",
VPF_NONE,
11
},
#endif
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_vfs_path_tokens_count_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_tokens_count, test_vfs_path_tokens_count_ds)
/* *INDENT-ON* */
{
/* given */
size_t tokens_count;
vfs_path_t *vpath;
vpath = vfs_path_from_str ("/");
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 0, "actual: %zu; expected: 0\n", tokens_count);
vfs_path_free (vpath);
vpath = vfs_path_from_str_flags (data->input_path, data->input_flags);
vpath = vfs_path_from_str ("/path");
/* when */
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 1, "actual: %zu; expected: 1\n", tokens_count);
vfs_path_free (vpath);
vpath = vfs_path_from_str ("/path1/path2/path3");
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 3, "actual: %zu; expected: 3\n", tokens_count);
vfs_path_free (vpath);
/* then */
mctest_assert_int_eq (tokens_count, data->expected_token_count);
vpath = vfs_path_from_str_flags ("test3://path1/path2/path3/path4", VPF_NO_CANON);
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 4, "actual: %zu; expected: 4\n", tokens_count);
vfs_path_free (vpath);
vpath = vfs_path_from_str_flags ("path1/path2/path3", VPF_NO_CANON);
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 3, "actual: %zu; expected: 3\n", tokens_count);
vfs_path_free (vpath);
vpath = vfs_path_from_str ("/path1/path2/path3/");
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 3, "actual: %zu; expected: 3\n", tokens_count);
vfs_path_free (vpath);
vpath = vfs_path_from_str ("/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/");
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 5, "actual: %zu; expected: 5\n", tokens_count);
vfs_path_free (vpath);
#ifdef HAVE_CHARSET
vpath =
vfs_path_from_str
("/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33");
tokens_count = vfs_path_tokens_count (vpath);
fail_unless (tokens_count == 11, "actual: %zu; expected: 11\n", tokens_count);
vfs_path_free (vpath);
#endif
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
#define check_invalid_token_str(input, start, length) { \
vpath = vfs_path_from_str (input); \
path_tokens = vfs_path_tokens_get(vpath, start, length); \
fail_unless (path_tokens == NULL, "path_tokens should be NULL!\n"); \
g_free (path_tokens); \
vfs_path_free (vpath); \
}
#define check_token_str(input, start, length, etalon) { \
vpath = vfs_path_from_str_flags (input, VPF_NO_CANON); \
path_tokens = vfs_path_tokens_get(vpath, start, length); \
fail_unless (path_tokens != NULL, "path_tokens shouldn't equal to NULL!\n"); \
if (path_tokens != NULL) \
fail_unless (strcmp(path_tokens, etalon) == 0, "\nactual: '%s'\netalon: '%s'", path_tokens, etalon); \
g_free (path_tokens); \
vfs_path_free (vpath); \
}
/* @DataSource("test_vfs_path_tokens_get_ds") */
/* *INDENT-OFF* */
START_TEST (test_vfs_path_tokens_get)
static const struct test_vfs_path_tokens_get_ds
{
const char *input_path;
const ssize_t input_start_position;
const ssize_t input_length;
const char *expected_path;
} test_vfs_path_tokens_get_ds[] =
{
{ /* 0. Invalid start position */
"/",
2,
1,
NULL
},
{ /* 1. Invalid negative position */
"/path",
-3,
1,
NULL
},
{ /* 2. Count of tokens is zero. Count should be autocorrected */
"/path",
0,
0,
"path"
},
{ /* 3. get 'path2/path3' by 1,2 */
"/path1/path2/path3/path4",
1,
2,
"path2/path3"
},
{ /* 4. get 'path2/path3' by 1,2 from LOCAL VFS */
"test3://path1/path2/path3/path4",
1,
2,
"path2/path3"
},
{ /* 5. get 'path2/path3' by 1,2 from non-LOCAL VFS */
"test2://path1/path2/path3/path4",
1,
2,
"test2://path2/path3"
},
{ /* 6. get 'path2/path3' by 1,2 throught non-LOCAL VFS */
"/path1/path2/test1://user:pass@some.host:12345/path3/path4",
1,
2,
"path2/test1://user:pass@some.host:12345/path3"
},
{ /* 7. get 'path2/path3' by 1,2 where path2 it's LOCAL VFS */
"test3://path1/path2/test2://path3/path4",
1,
2,
"path2/test2://path3"
},
{ /* 8. get 'path2/path3' by 1,2 where path3 it's LOCAL VFS */
"test2://path1/path2/test3://path3/path4",
1,
2,
"test2://path2/test3://path3"
},
{ /* 9. get 'path4' by -1,1 */
"/path1/path2/path3/path4",
-1,
1,
"path4"
},
{ /* 10. get 'path2/path3/path4' by -3,0 */
"/path1/path2/path3/path4",
-3,
0,
"path2/path3/path4"
},
#ifdef HAVE_CHARSET
{ /* 11. get 'path2/path3' by 1,2 from LOCAL VFS with encoding */
"test3://path1/path2/test3://#enc:KOI8-R/path3/path4",
1,
2,
"path2/test3://#enc:KOI8-R/path3"
},
{ /* 12. get 'path2/path3' by 1,2 with encoding */
"#enc:KOI8-R/path1/path2/path3/path4",
1,
2,
"#enc:KOI8-R/path2/path3"
},
#endif
/* TODO: currently this test don't passed. Probably broken string URI parser
{ *//* 13. get 'path2/path3' by 1,2 from LOCAL VFS *//*
"test3://path1/path2/test2://test3://path3/path4",
1,
2,
"path2/path3"
},
*/
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_vfs_path_tokens_get_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_tokens_get, test_vfs_path_tokens_get_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
char *path_tokens;
char *actual_path;
/* Invalid start position */
check_invalid_token_str ("/", 2, 1);
vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);
/* Invalid negative position */
check_invalid_token_str ("/path", -3, 1);
/* when */
actual_path = vfs_path_tokens_get (vpath, data->input_start_position, data->input_length);
/* Count of tokens is zero. Count should be autocorrected */
check_token_str ("/path", 0, 0, "path");
/* get 'path2/path3' by 1,2 */
check_token_str ("/path1/path2/path3/path4", 1, 2, "path2/path3");
/* get 'path2/path3' by 1,2 from LOCAL VFS */
check_token_str ("test3://path1/path2/path3/path4", 1, 2, "path2/path3");
#ifdef HAVE_CHARSET
/* get 'path2/path3' by 1,2 from LOCAL VFS with encoding */
check_token_str ("test3://path1/path2/test3://#enc:KOI8-R/path3/path4", 1, 2,
"path2/test3://#enc:KOI8-R/path3");
/* get 'path2/path3' by 1,2 with encoding */
check_token_str ("#enc:KOI8-R/path1/path2/path3/path4", 1, 2, "#enc:KOI8-R/path2/path3");
#endif
/* get 'path2/path3' by 1,2 from non-LOCAL VFS */
check_token_str ("test2://path1/path2/path3/path4", 1, 2, "test2://path2/path3");
/* get 'path2/path3' by 1,2 throught non-LOCAL VFS */
check_token_str ("/path1/path2/test1://user:pass@some.host:12345/path3/path4", 1, 2,
"path2/test1://user:pass@some.host:12345/path3");
/* get 'path2/path3' by 1,2 from LOCAL VFS */
/* TODO: currently this test don't passed. Probably broken string URI parser */
/* check_token_str ("test3://path1/path2/test2://test3://path3/path4", 1, 2, "path2/path3"); */
/* get 'path2/path3' by 1,2 where path2 it's LOCAL VFS */
check_token_str ("test3://path1/path2/test2://path3/path4", 1, 2, "path2/test2://path3");
/* get 'path2/path3' by 1,2 where path3 it's LOCAL VFS */
check_token_str ("test2://path1/path2/test3://path3/path4", 1, 2,
"test2://path2/test3://path3");
/* get 'path4' by -1,1 */
check_token_str ("/path1/path2/path3/path4", -1, 1, "path4");
/* get 'path2/path3/path4' by -3,0 */
check_token_str ("/path1/path2/path3/path4", -3, 0, "path2/path3/path4");
/* then */
mctest_assert_str_eq (actual_path, data->expected_path);
g_free (actual_path);
vfs_path_free (vpath);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("test_vfs_path_append_vpath_ds") */
/* *INDENT-OFF* */
START_TEST (test_vfs_path_append_vpath)
static const struct test_vfs_path_append_vpath_ds
{
const char *input_path1;
const char *input_path2;
const size_t expected_element_count;
const char *expected_path;
} test_vfs_path_append_vpath_ds[] =
{
{ /* 0. */
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://bla-bla/some/path/test3://111/22/33",
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/",
6,
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://bla-bla/some/path/test3://111/22/33"
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path",
},
#ifdef HAVE_CHARSET
{ /* 1. */
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33",
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/",
6,
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33"
"/local/path/test1://user:pass@some.host:12345/bla-bla/some/path",
},
#endif /* HAVE_CHARSET */
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_vfs_path_append_vpath_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_append_vpath, test_vfs_path_append_vpath_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath1, *vpath2, *vpath3;
#ifdef HAVE_CHARSET
vpath1 =
vfs_path_from_str
("/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33");
#else
vpath1 =
vfs_path_from_str
("/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://bla-bla/some/path/test3://111/22/33");
#endif
vpath2 = vfs_path_from_str ("/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/");
vpath1 = vfs_path_from_str (data->input_path1);
vpath2 = vfs_path_from_str (data->input_path2);
/* when */
vpath3 = vfs_path_append_vpath_new (vpath1, vpath2, NULL);
fail_unless (vfs_path_elements_count (vpath3) == 6,
"\nvpath elements count should be %d, actial is %d\n",
6, vfs_path_elements_count (vpath3));
/* then */
{
char *path;
mctest_assert_int_eq (vfs_path_elements_count (vpath3), data->expected_element_count);
path = vfs_path_to_str (vpath3);
mctest_assert_str_eq (path, data->expected_path);
g_free (path);
}
vfs_path_free (vpath1);
vfs_path_free (vpath2);
vfs_path_free (vpath3);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("test_vfs_path_relative_ds") */
/* *INDENT-OFF* */
START_TEST (test_vfs_path_relative)
static const struct test_vfs_path_relative_ds
{
const char *input_path;
const char *expected_path;
const char *expected_last_path_in_element;
} test_vfs_path_relative_ds[] =
{
{ /* 0. */
"../bla-bla",
"../bla-bla",
"../bla-bla"
},
{ /* 1. */
"../path/test1://user:pass@some.host:12345/bla-bla/some/path/",
"../path/test1://user:pass@some.host:12345/bla-bla/some/path/",
"bla-bla/some/path/"
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_vfs_path_relative_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_relative, test_vfs_path_relative_ds)
/* *INDENT-ON* */
{
vfs_path_t *vpath, *copy_vpath;
char *path_str;
/* given */
vfs_path_t *vpath;
vpath = vfs_path_from_str_flags ("../bla-bla", VPF_NO_CANON);
fail_unless (vpath->relative, "relative flag fail!\n");
/* when */
path_str = vfs_path_to_str (vpath);
vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);
fail_unless (strcmp (path_str, "../bla-bla") == 0, "relative fail!\nactual: [%s]\n", path_str);
g_free (path_str);
/* then */
mctest_assert_int_eq (vpath->relative, TRUE);
mctest_assert_str_eq (vfs_path_get_last_path_str (vpath), data->expected_last_path_in_element);
path_str = (char *) vfs_path_get_last_path_str (vpath);
fail_unless (strcmp (path_str, "../bla-bla") == 0,
"relative fail!\nactual: element->path=[%s]\n", path_str);
{
char *path_str;
copy_vpath = vfs_path_clone (vpath);
path_str = vfs_path_to_str (copy_vpath);
fail_unless (strcmp (path_str, "../bla-bla") == 0, "relative fail!\nactual: [%s]\n", path_str);
g_free (path_str);
vfs_path_free (copy_vpath);
path_str = vfs_path_to_str (vpath);
mctest_assert_str_eq (path_str, data->expected_path);
g_free (path_str);
}
vfs_path_free (vpath);
vpath =
vfs_path_from_str_flags ("../path/test1://user:pass@some.host:12345/bla-bla/some/path/",
VPF_NO_CANON);
path_str = vfs_path_to_str (vpath);
fail_unless (strcmp (path_str, "../path/test1://user:pass@some.host:12345/bla-bla/some/path/")
== 0, "relative fail!\nactual: [%s]\n", path_str);
g_free (path_str);
vfs_path_free (vpath);
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/* @Test(dataSource = "test_vfs_path_relative_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_relative_clone, test_vfs_path_relative_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath, *cloned_vpath;
vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);
/* when */
cloned_vpath = vfs_path_clone (vpath);
/* then */
mctest_assert_int_eq (cloned_vpath->relative, TRUE);
mctest_assert_str_eq (vfs_path_get_last_path_str (cloned_vpath),
data->expected_last_path_in_element);
{
char *path_str;
path_str = vfs_path_to_str (cloned_vpath);
mctest_assert_str_eq (path_str, data->expected_path);
g_free (path_str);
}
vfs_path_free (vpath);
vfs_path_free (cloned_vpath);
}
/* *INDENT-OFF* */
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
@ -315,10 +472,14 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_vfs_path_tokens_count);
tcase_add_test (tc_core, test_vfs_path_tokens_get);
tcase_add_test (tc_core, test_vfs_path_append_vpath);
tcase_add_test (tc_core, test_vfs_path_relative);
mctest_add_parameterized_test (tc_core, test_vfs_path_tokens_count,
test_vfs_path_tokens_count_ds);
mctest_add_parameterized_test (tc_core, test_vfs_path_tokens_get, test_vfs_path_tokens_get_ds);
mctest_add_parameterized_test (tc_core, test_vfs_path_append_vpath,
test_vfs_path_append_vpath_ds);
mctest_add_parameterized_test (tc_core, test_vfs_path_relative, test_vfs_path_relative_ds);
mctest_add_parameterized_test (tc_core, test_vfs_path_relative_clone,
test_vfs_path_relative_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -37,18 +37,26 @@
const char *mc_config_get_home_dir (void);
/* --------------------------------------------------------------------------------------------- */
/* @Mock */
const char *
mc_config_get_home_dir (void)
{
return "/mock/home";
}
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -83,70 +91,158 @@ test_deinit_vfs ()
/* --------------------------------------------------------------------------------------------- */
#define path_recode_one_check(input, etalon1, etalon2) {\
vpath = vfs_path_from_str (input);\
element = vfs_path_get_by_index(vpath, -1);\
fail_unless ( strcmp (element->path, etalon1) == 0, "expected: %s\nactual: %s\n", etalon1, element->path);\
result = vfs_path_to_str(vpath);\
fail_unless ( strcmp (result, etalon2) == 0, "\nexpected: %s\nactual: %s\n", etalon2, result);\
g_free(result);\
vfs_path_free (vpath);\
}
/* @DataSource("test_path_recode_ds") */
/* *INDENT-OFF* */
START_TEST (test_path_recode_base_utf8)
static const struct test_path_recode_ds
{
const char *input_codepage;
const char *input_path;
const char *expected_element_path;
const char *expected_recoded_path;
} test_path_recode_ds[] =
{
{ /* 0. */
"UTF-8",
"/╘┼╙╘╧╫┘╩/╨╒╘╪",
"/╘┼╙╘╧╫┘╩/╨╒╘╪",
"/╘┼╙╘╧╫┘╩/╨╒╘╪"
},
{ /* 1. */
"UTF-8",
"/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
"/╘┼╙╘╧╫┘╩/╨╒╘╪",
"/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М"
},
{ /* 2. */
"KOI8-R",
"/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
"/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
"/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М"
},
{ /* 3. */
"KOI8-R",
"/#enc:UTF-8/╘┼╙╘╧╫┘╩/╨╒╘╪",
"/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
"/#enc:UTF-8/╘┼╙╘╧╫┘╩/╨╒╘╪"
},
{ /* 4. Test encode info at start */
"UTF-8",
"#enc:KOI8-R/bla-bla/some/path",
"/bla-bla/some/path",
"/#enc:KOI8-R/bla-bla/some/path"
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_path_recode_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_recode, test_path_recode_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
char *result;
const vfs_path_element_t *element;
test_init_vfs ("UTF-8");
test_init_vfs (data->input_codepage);
path_recode_one_check ("/╘┼╙╘╧╫┘╩/╨╒╘╪", "/╘┼╙╘╧╫┘╩/╨╒╘╪", "/╘┼╙╘╧╫┘╩/╨╒╘╪");
/* when */
vpath = vfs_path_from_str (data->input_path);
element = vfs_path_get_by_index (vpath, -1);
result = vfs_path_to_str (vpath);
path_recode_one_check ("/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М", "/╘┼╙╘╧╫┘╩/╨╒╘╪",
"/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М");
/* then */
mctest_assert_str_eq (element->path, data->expected_element_path);
mctest_assert_str_eq (result, data->expected_recoded_path);
g_free (result);
vfs_path_free (vpath);
test_deinit_vfs ();
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
static struct vfs_s_subclass test_subclass1;
static struct vfs_class vfs_test_ops1;
/* @DataSource("test_path_to_str_flags_ds") */
/* *INDENT-OFF* */
START_TEST (test_path_recode_base_koi8r)
static const struct test_path_to_str_flags_ds
{
const char *input_path;
const vfs_path_flag_t input_from_str_flags;
const vfs_path_flag_t input_to_str_flags;
const char *expected_path;
} test_path_to_str_flags_ds[] =
{
{ /* 0. */
"test1://user:passwd@127.0.0.1",
VPF_NO_CANON,
VPF_STRIP_PASSWORD,
"test1://user@127.0.0.1/"
},
{ /* 1. */
"/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
VPF_NONE,
VPF_STRIP_PASSWORD,
"/test1://user@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М"
},
{ /* 2. */
"/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
VPF_NONE,
VPF_RECODE,
"/test1://user:passwd@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪"
},
{ /* 3. */
"/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
VPF_NONE,
VPF_RECODE | VPF_STRIP_PASSWORD,
"/test1://user@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪"
},
{ /* 4. */
"/mock/home/test/dir",
VPF_NONE,
VPF_STRIP_HOME,
"~/test/dir"
},
{ /* 5. */
"/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
VPF_NONE,
VPF_STRIP_HOME | VPF_STRIP_PASSWORD,
"~/test1://user@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М"
},
{ /* 6. */
"/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
VPF_NONE,
VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET,
"~/test1://user@host.name/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М"
},
{ /* 7. */
"/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
VPF_NONE,
VPF_STRIP_HOME | VPF_RECODE,
"~/test1://user:passwd@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪"
},
{ /* 8. */
"/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
VPF_NONE,
VPF_STRIP_HOME | VPF_RECODE | VPF_STRIP_PASSWORD,
"~/test1://user@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪"
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_path_to_str_flags_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_to_str_flags, test_path_to_str_flags_ds)
/* *INDENT-ON* */
{
vfs_path_t *vpath;
char *result;
const vfs_path_element_t *element;
test_init_vfs ("KOI8-R");
path_recode_one_check ("/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М", "/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
"/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М");
path_recode_one_check ("/#enc:UTF-8/╘┼╙╘╧╫┘╩/╨╒╘╪", "/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
"/#enc:UTF-8/╘┼╙╘╧╫┘╩/╨╒╘╪");
test_deinit_vfs ();
}
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
struct vfs_s_subclass test_subclass1;
struct vfs_class vfs_test_ops1;
/* *INDENT-OFF* */
START_TEST(test_path_to_str_flags)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
char *str_path;
@ -159,100 +255,24 @@ START_TEST(test_path_to_str_flags)
vfs_test_ops1.prefix = "test1";
vfs_register_class (&vfs_test_ops1);
vpath = vfs_path_from_str_flags ("test1://user:passwd@127.0.0.1", VPF_NO_CANON);
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
fail_unless (strcmp ("test1://user@127.0.0.1/", str_path) == 0, "\nstr=%s\n", str_path);
/* when */
vpath = vfs_path_from_str_flags (data->input_path, data->input_from_str_flags);
str_path = vfs_path_to_str_flags (vpath, 0, data->input_to_str_flags);
/* then */
mctest_assert_str_eq (str_path, data->expected_path);
g_free (str_path);
vfs_path_free (vpath);
vpath =
vfs_path_from_str ("/test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М");
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
fail_unless (strcmp ("/test1://user@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М", str_path)
== 0, "\nstr=%s\n", str_path);
g_free (str_path);
str_path = vfs_path_to_str_flags (vpath, 0, VPF_RECODE);
fail_unless (strcmp ("/test1://user:passwd@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪", str_path) == 0,
"\nstr=%s\n", str_path);
g_free (str_path);
str_path = vfs_path_to_str_flags (vpath, 0, VPF_RECODE | VPF_STRIP_PASSWORD);
fail_unless (strcmp ("/test1://user@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪", str_path) == 0, "\nstr=%s\n",
str_path);
g_free (str_path);
vfs_path_free (vpath);
vpath = vfs_path_build_filename (mc_config_get_home_dir (), "test", "dir", NULL);
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME);
fail_unless (strcmp ("~/test/dir", str_path) == 0, "\nstr=%s\n", str_path);
g_free (str_path);
vfs_path_free (vpath);
vpath =
vfs_path_build_filename (mc_config_get_home_dir (),
"test1://user:passwd@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М",
NULL);
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
fail_unless (strcmp ("~/test1://user@host.name/#enc:KOI8-R/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М", str_path)
== 0, "\nstr=%s\n", str_path);
g_free (str_path);
str_path =
vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
fail_unless (strcmp ("~/test1://user@host.name/╤В╨╡╤Б╤В╨╛╨▓╤Л╨╣/╨┐╤Г╤В╤М", str_path) == 0,
"\nstr=%s\n", str_path);
g_free (str_path);
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_RECODE);
fail_unless (strcmp ("~/test1://user:passwd@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪", str_path) == 0,
"\nstr=%s\n", str_path);
g_free (str_path);
str_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_HOME | VPF_RECODE | VPF_STRIP_PASSWORD);
fail_unless (strcmp ("~/test1://user@host.name/╘┼╙╘╧╫┘╩/╨╒╘╪", str_path) == 0, "\nstr=%s\n",
str_path);
g_free (str_path);
vfs_path_free (vpath);
test_deinit_vfs ();
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/* *INDENT-OFF* */
START_TEST(test_encode_info_at_start)
/* *INDENT-ON* */
{
vfs_path_t *vpath;
char *actual;
const vfs_path_element_t *vpath_element;
test_init_vfs ("UTF-8");
vpath = vfs_path_from_str ("#enc:KOI8-R/bla-bla/some/path");
actual = vfs_path_to_str (vpath);
fail_unless (strcmp ("/#enc:KOI8-R/bla-bla/some/path", actual) == 0, "\nactual=%s\n", actual);
vpath_element = vfs_path_get_by_index (vpath, -1);
fail_unless (strcmp ("/bla-bla/some/path", vpath_element->path) == 0,
"\nvpath_element->path=%s\n", vpath_element->path);
g_free (actual);
vfs_path_free (vpath);
test_deinit_vfs ();
}
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
int
main (void)
{
@ -265,10 +285,8 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_path_recode_base_utf8);
tcase_add_test (tc_core, test_path_recode_base_koi8r);
tcase_add_test (tc_core, test_path_to_str_flags);
tcase_add_test (tc_core, test_encode_info_at_start);
mctest_add_parameterized_test (tc_core, test_path_recode, test_path_recode_ds);
mctest_add_parameterized_test (tc_core, test_path_to_str_flags, test_path_to_str_flags_ds);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -37,10 +37,12 @@
#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)
{
@ -76,6 +78,9 @@ setup (void)
#endif
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
@ -88,6 +93,7 @@ teardown (void)
}
/* --------------------------------------------------------------------------------------------- */
#ifdef HAVE_CHARSET
#define ETALON_PATH_STR "/local/path/#test1:user:pass@some.host:12345/bla-bla/some/path/#test2/#enc:KOI8-R/bla-bla/some/path#test3/111/22/33"
#define ETALON_PATH_URL_STR "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33"
@ -138,46 +144,48 @@ teardown (void)
#endif
/* *INDENT-OFF* */
START_TEST (test_path_serialize_deserialize)
START_TEST (test_path_serialize)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
char *serialized_vpath;
GError *error = NULL;
/* when */
vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER);
serialized_vpath = vfs_path_serialize (vpath, &error);
vfs_path_free (vpath);
if (serialized_vpath == NULL)
{
fail ("serialized_vpath is NULL!\nError code is '%d'; error message is '%s'", error->code,
error->message);
g_clear_error (&error);
return;
}
/* then */
mctest_assert_ptr_ne (serialized_vpath, NULL);
mctest_assert_str_eq (serialized_vpath, ETALON_SERIALIZED_PATH);
}
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */
fail_unless (strcmp (serialized_vpath, ETALON_SERIALIZED_PATH) == 0,
"\nserialized_vpath (%s)\nnot equal to etalon (%s)", serialized_vpath,
ETALON_SERIALIZED_PATH);
/* --------------------------------------------------------------------------------------------- */
vpath = vfs_path_deserialize (serialized_vpath, &error);
g_free (serialized_vpath);
/* *INDENT-OFF* */
START_TEST (test_path_deserialize)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
char *path;
GError *error = NULL;
if (vpath == NULL)
{
fail ("vpath is NULL!\nError code is '%d'; error message is '%s'", error->code,
error->message);
g_clear_error (&error);
return;
}
/* when */
vpath = vfs_path_deserialize (ETALON_SERIALIZED_PATH, &error);
path = vfs_path_to_str (vpath);
/* then */
mctest_assert_ptr_ne (vpath, NULL);
mctest_assert_str_eq (path, ETALON_PATH_URL_STR);
serialized_vpath = vfs_path_to_str (vpath);
fail_unless (strcmp (serialized_vpath, ETALON_PATH_URL_STR) == 0,
"\ndeserialized path (%s)\nnot equal to etalon (%s)", serialized_vpath,
ETALON_PATH_URL_STR);
vfs_path_free (vpath);
g_free (serialized_vpath);
g_free (path);
}
/* *INDENT-OFF* */
@ -198,7 +206,8 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_path_serialize_deserialize);
tcase_add_test (tc_core, test_path_serialize);
tcase_add_test (tc_core, test_path_deserialize);
/* *********************************** */
suite_add_tcase (s, tc_core);

Просмотреть файл

@ -37,7 +37,36 @@ struct vfs_class vfs_test_ops1;
static int test_chdir (const vfs_path_t * vpath);
/* --------------------------------------------------------------------------------------------- */
/* @CapturedValue */
static vfs_path_t *test_chdir__vpath__captured;
/* @ThenReturnValue */
static int test_chdir__return_value;
/* @Mock */
static int
test_chdir (const vfs_path_t * vpath)
{
test_chdir__vpath__captured = vfs_path_clone (vpath);
return test_chdir__return_value;
}
static void
test_chdir__init (void)
{
test_chdir__vpath__captured = NULL;
}
static void
test_chdir__deinit (void)
{
vfs_path_free (test_chdir__vpath__captured);
}
/* --------------------------------------------------------------------------------------------- */
/* @Before */
static void
setup (void)
{
@ -58,58 +87,92 @@ setup (void)
vfs_register_class (&vfs_test_ops1);
mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
vfs_local_ops.chdir = test_chdir;
test_chdir__init ();
}
/* --------------------------------------------------------------------------------------------- */
/* @After */
static void
teardown (void)
{
test_chdir__deinit ();
vfs_shut ();
str_uninit_strings ();
}
/* --------------------------------------------------------------------------------------------- */
static int
test_chdir (const vfs_path_t * vpath)
{
char *path = vfs_path_to_str (vpath);
printf ("test_chdir: %s\n", path);
g_free (path);
return 0;
}
/* --------------------------------------------------------------------------------------------- */
/* @DataSource("test_relative_cd_ds") */
/* *INDENT-OFF* */
START_TEST (test_relative_cd)
static const struct test_relative_cd_ds
{
const char *input_string;
const vfs_path_flag_t input_flags;
const char *expected_element_path;
} test_relative_cd_ds[] =
{
{ /* 0. */
"/test1://user:pass@some.host:12345/path/to/dir",
VPF_NONE,
"path/to/dir"
},
{ /* 1. */
"some-non-exists-dir",
VPF_NO_CANON,
"some-non-exists-dir"
},
};
/* *INDENT-ON* */
/* @Test(dataSource = "test_relative_cd_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_relative_cd, test_relative_cd_ds)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath;
int actual_result;
vpath = vfs_path_from_str ("/test1://user:pass@some.host:12345/path/to/dir");
fail_if (mc_chdir (vpath) == -1);
vfs_path_free (vpath);
test_chdir__return_value = 0;
vpath = vfs_path_from_str_flags ("some-non-exists-dir", VPF_NO_CANON);
fail_if (mc_chdir (vpath) == -1);
vfs_path_free (vpath);
vpath = vfs_path_from_str_flags (data->input_string, data->input_flags);
/* when */
actual_result = mc_chdir (vpath);
/* then */
{
const vfs_path_element_t *element;
mctest_assert_int_eq (actual_result, 0);
element = vfs_path_get_by_index (vpath, -1);
mctest_assert_str_eq (element->path, data->expected_element_path);
vfs_path_free (vpath);
}
}
/* *INDENT-OFF* */
END_TEST
END_PARAMETRIZED_TEST
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/* Relative to panel_correct_path_to_show() */
/* @Test */
/* *INDENT-OFF* */
START_TEST (test_vpath_to_str_filter)
/* *INDENT-ON* */
{
/* given */
vfs_path_t *vpath, *last_vpath;
char *filtered_path;
const vfs_path_element_t *path_element;
/* when */
vpath = vfs_path_from_str ("/test1://some.host/dir");
path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, -1));
vfs_path_free (vpath);
@ -121,11 +184,12 @@ START_TEST (test_vpath_to_str_filter)
filtered_path = vfs_path_to_str_flags (last_vpath, 0,
VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
/* then */
mctest_assert_str_eq (filtered_path, "test1://some.host/dir");
vfs_path_free (last_vpath);
fail_unless (strcmp ("test1://some.host/dir", filtered_path) == 0, "actual: %s", filtered_path);
g_free (filtered_path);
}
/* *INDENT-OFF* */
END_TEST
@ -145,7 +209,7 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, test_relative_cd);
mctest_add_parameterized_test (tc_core, test_relative_cd, test_relative_cd_ds);
tcase_add_test (tc_core, test_vpath_to_str_filter);
/* *********************************** */