/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (the_file_is_local, the_file_is_local_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *filename_vpath;
    filename_vpath = vfs_path_from_str (data->input_path);

    vfs_file_is_local__return_value = TRUE;

    /* when */
    execute_with_vfs_arg ("cmd_for_local_file", filename_vpath);

    /* then */
    mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_local_file");
    mctest_assert_str_eq (do_execute__command__captured, data->input_path);

    mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
    {
        const vfs_path_t *tmp_vpath;

        tmp_vpath = (data->input_path == NULL) ? vfs_get_raw_current_dir () : filename_vpath;
        mctest_assert_int_eq (vfs_path_equal
                              (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
                               tmp_vpath), TRUE);
    }
    mctest_assert_int_eq (do_execute__flags__captured, EXECUTE_INTERNAL);
    fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL,
                 "\nFunction mc_getlocalcopy() shouldn't be called!");

    vfs_path_free (filename_vpath);
}
/* *INDENT-OFF* */
END_PARAMETRIZED_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */

/* @Test */
/* *INDENT-OFF* */
START_TEST (the_file_is_remote_but_empty)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *filename_vpath;
    filename_vpath = NULL;

    vfs_file_is_local__return_value = FALSE;

    /* when */
    execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);

    /* then */
    mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
    mctest_assert_str_eq (do_execute__command__captured, NULL);

    mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 2);

    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
                           vfs_get_raw_current_dir ()), TRUE);
    fail_unless (g_ptr_array_index (vfs_file_is_local__vpath__captured, 1) == NULL,
                 "\nParameter for second call to vfs_file_is_local() should be NULL!");
    fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL,
                 "\nFunction mc_getlocalcopy() shouldn't be called!");

    vfs_path_free (filename_vpath);
}
Exemple #3
0
/* *INDENT-OFF* */
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);
    mctest_assert_str_eq (vfs_path_as_str (cloned_vpath), data->expected_path);

    vfs_path_free (vpath);
    vfs_path_free (cloned_vpath);
}
Exemple #4
0
/* *INDENT-OFF* */
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;
    static struct stat test_stat;
    char *filename = NULL;
    char *linkname = NULL;
    gboolean actual_result;

    vfs_parse_ls_lga_init ();

    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);
     */
}
Exemple #5
0
/* *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* */

/* --------------------------------------------------------------------------------------------- */

/* @Test */
/* *INDENT-OFF* */
START_TEST (the_file_is_remote)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *filename_vpath, *local_vpath, *local_vpath_should_be_freeing;

    filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
    local_vpath = vfs_path_from_str ("/tmp/blabla-editme.txt");
    local_vpath_should_be_freeing = vfs_path_clone (local_vpath);

    vfs_file_is_local__return_value = FALSE;
    mc_getlocalcopy__return_value = local_vpath_should_be_freeing;

    /* when */
    execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);

    /* then */
    mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_remote_file");
    mctest_assert_str_eq (do_execute__command__captured, "/tmp/blabla-editme.txt");

    mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);

    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
                           filename_vpath), TRUE);

    mctest_assert_int_eq (vfs_path_equal
                          (mc_getlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);

    mctest_assert_int_eq (mc_stat__vpath__captured->len, 2);

    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (mc_stat__vpath__captured, 0), local_vpath), TRUE);
    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (mc_stat__vpath__captured, 0),
                           g_ptr_array_index (mc_stat__vpath__captured, 1)), TRUE);

    mctest_assert_int_eq (vfs_path_equal
                          (mc_ungetlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);

    mctest_assert_int_eq (vfs_path_equal (mc_ungetlocalcopy__local_vpath__captured, local_vpath),
                          TRUE);

    vfs_path_free (filename_vpath);
    vfs_path_free (local_vpath);
}
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */

/* @Test */
/* *INDENT-OFF* */
START_TEST (the_file_is_remote_fail_to_create_local_copy)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *filename_vpath;

    filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");

    vfs_file_is_local__return_value = FALSE;
    mc_getlocalcopy__return_value = NULL;

    /* when */
    execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);

    /* then */
    mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
    mctest_assert_str_eq (do_execute__command__captured, NULL);

    mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);

    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
                           filename_vpath), TRUE);

    mctest_assert_int_eq (vfs_path_equal
                          (mc_getlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);

    mctest_assert_str_eq (message_title__captured, _("Error"));
    mctest_assert_str_eq (message_text__captured,
                          _("Cannot fetch a local copy of /ftp://some.host/editme.txt"));


    vfs_path_free (filename_vpath);
}
Exemple #8
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_complete_engine_fill_completions,
                         test_complete_engine_fill_completions_ds)
/* *INDENT-ON* */
{
    /* given */
    WInput *w_input;

    w_input = g_new (WInput, 1);
    w_input->buffer = g_strdup (data->input_buffer);
    w_input->point = data->input_point;
    w_input->completion_flags = data->input_completion_flags;

    /* when */
    complete_engine_fill_completions (w_input);

    /* then */
    mctest_assert_str_eq (try_complete__text__captured, data->input_buffer);
    mctest_assert_int_eq (try_complete__lc_start__captured, data->expected_start);
    mctest_assert_int_eq (try_complete__lc_end__captured, data->expected_end);
    mctest_assert_int_eq (try_complete__flags__captured, data->input_completion_flags);
}
Exemple #9
0
/* *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 actual_skipped_len = 0;
    int actual_flags = 0;
    gboolean actual_result;

    replace_str = g_string_new (data->input_string);

    /* 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);
}
Exemple #10
0
/* *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);
}
Exemple #11
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath;
    size_t actual_length;

    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);
}
Exemple #12
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_relative, test_vfs_path_relative_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath;

    /* when */

    vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);

    /* 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);
    mctest_assert_str_eq (vfs_path_as_str (vpath), data->expected_path);

    vfs_path_free (vpath);
}
Exemple #13
0
/* *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_flags (data->input_path, data->input_flags);

    /* when */
    tokens_count = vfs_path_tokens_count (vpath);

    /* then */
    mctest_assert_int_eq (tokens_count, data->expected_token_count);

    vfs_path_free (vpath);
}
Exemple #14
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_equal_len, test_path_equal_len_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath1, *vpath2;
    gboolean actual_result;

    vpath1 = vfs_path_from_str (data->input_path1);
    vpath2 = vfs_path_from_str (data->input_path2);

    /* when */
    actual_result = vfs_path_equal_len (vpath1, vpath2, data->input_length);

    /* then */
    mctest_assert_int_eq (actual_result, data->expected_result);

    vfs_path_free (vpath1);
    vfs_path_free (vpath2);
}
Exemple #15
0
/* *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;

    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);

    /* then */
    mctest_assert_int_eq (vfs_path_elements_count (vpath3), data->expected_element_count);
    mctest_assert_str_eq (vfs_path_as_str (vpath3), data->expected_path);

    vfs_path_free (vpath1);
    vfs_path_free (vpath2);
    vfs_path_free (vpath3);
}
Exemple #16
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_empty_mean_home, test_empty_mean_home_ds)
/* *INDENT-ON* */
{
    /* given */
    get_current_type__return_value = view_listing;
    do_cd__return_value = TRUE;
    mc_config_get_home_dir__return_value = "/home/test";

    /* when */
    {
        char *input_command;

        input_command = g_strdup (data->command);
        do_cd_command (input_command);
        g_free (input_command);
    }
    /* then */
    mctest_assert_str_eq (mc_config_get_home_dir__return_value,
                          vfs_path_as_str (do_cd__new_dir_vpath__captured));
    mctest_assert_int_eq (do_cd__cd_type__captured, cd_parse_command);
}
Exemple #17
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_relative_cd, test_relative_cd_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath;
    int actual_result;

    test_chdir__return_value = 0;

    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);
    }
}