Ejemplo n.º 1
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_create_ini_file_paths, test_create_ini_file_ds)
/* *INDENT-ON* */
{
    /* 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 ");

    config_object__reopen ();

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

    /* then */
    mctest_assert_str_eq (actual_value, data->expected_value);
    mctest_assert_str_eq (actual_raw_value, data->expected_raw_value);

    g_free (actual_value);
    g_free (actual_raw_value);
}
Ejemplo n.º 2
0
Archivo: history.c Proyecto: BrEacK/mc
/**
  * Save history to the mc_config, but don't save config to file
  */
void
history_save (struct mc_config_t *cfg, const char *name, GList * h)
{
    GIConv conv = INVALID_CONV;
    GString *buffer;
    int i;

    if (name == NULL || *name == '\0' || h == NULL)
        return;

    /* go to end of list */
    h = g_list_last (h);

    /* go back 60 places */
    for (i = 0; (i < num_history_items_recorded - 1) && (h->prev != NULL); i++)
        h = g_list_previous (h);

    if (name != NULL)
        mc_config_del_group (cfg, name);

    /* create charset conversion handler to convert strings
       from system codepage to UTF-8 */
    if (!mc_global.utf8_display)
        conv = str_crt_conv_to ("UTF-8");

    buffer = g_string_sized_new (64);
    /* dump history into profile */
    for (i = 0; h != NULL; h = g_list_next (h))
    {
        char key[BUF_TINY];
        char *text = (char *) h->data;

        /* We shouldn't have null entries, but let's be sure */
        if (text == NULL)
            continue;

        g_snprintf (key, sizeof (key), "%d", i++);

        if (conv == INVALID_CONV)
            mc_config_set_string_raw (cfg, name, key, text);
        else
        {
            g_string_set_size (buffer, 0);
            if (str_convert (conv, text, buffer) == ESTR_FAILURE)
                mc_config_set_string_raw (cfg, name, key, text);
            else
                mc_config_set_string_raw (cfg, name, key, buffer->str);
        }
    }

    g_string_free (buffer, TRUE);
    if (conv != INVALID_CONV)
        str_close_conv (conv);
}
Ejemplo n.º 3
0
/* *INDENT-OFF* */
END_PARAMETRIZED_TEST
/* *INDENT-ON* */

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

/* @Test(group='Integration') */
/* *INDENT-OFF* */
START_TEST (emulate__learn_save)
/* *INDENT-ON* */
{
    /* given */
    char *actual_value;

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

    config_object__reopen ();

    /* when */
    actual_value = mc_config_get_string_raw (mc_config, "test-group1", "test-param1", "not-exists");

    /* then */
    mctest_assert_str_eq (actual_value, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
    g_free (actual_value);
}
Ejemplo n.º 4
0
static void
create_default_keymap_section (mc_config_t * keymap, const char *section,
                               const global_keymap_ini_t * k)
{
    size_t i;

    for (i = 0; k[i].key != NULL; i++)
        mc_config_set_string_raw (keymap, section, k[i].key, k[i].value);
}
Ejemplo n.º 5
0
END_TEST

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

#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"

START_TEST (test_serialize_config)
{
    mc_config_t *test_data;
    GError *error = NULL;
    char *actual;

    test_data = mc_config_init (NULL);

    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);
}
Ejemplo n.º 6
0
/* *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);
}
Ejemplo n.º 7
0
END_TEST

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

START_TEST (emulate__learn_save)
{
    mc_config_t *mc_config;
    char *actual_value, *esc_str;
    char *ini_filename = NULL;
    GError *error = NULL;

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

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

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