Пример #1
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);
}
Пример #2
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);
}
Пример #3
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);
}
Пример #4
0
/**
 * Load history form the mc_config
 */
GList *
history_load (struct mc_config_t * cfg, const char *name)
{
    size_t i;
    GList *hist = NULL;
    char **keys;
    size_t keys_num = 0;
    GIConv conv = INVALID_CONV;
    GString *buffer;

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

    /* get number of keys */
    keys = mc_config_get_keys (cfg, name, &keys_num);
    g_strfreev (keys);

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

    buffer = g_string_sized_new (64);

    for (i = 0; i < keys_num; i++)
    {
        char key[BUF_TINY];
        char *this_entry;

        g_snprintf (key, sizeof (key), "%lu", (unsigned long) i);
        this_entry = mc_config_get_string_raw (cfg, name, key, "");

        if (this_entry == NULL)
            continue;

        if (conv == INVALID_CONV)
            hist = list_append_unique (hist, this_entry);
        else
        {
            g_string_set_size (buffer, 0);
            if (str_convert (conv, this_entry, buffer) == ESTR_FAILURE)
                hist = list_append_unique (hist, this_entry);
            else
            {
                hist = list_append_unique (hist, g_strdup (buffer->str));
                g_free (this_entry);
            }
        }
    }

    g_string_free (buffer, TRUE);
    if (conv != INVALID_CONV)
        str_close_conv (conv);

    /* return pointer to the last entry in the list */
    return g_list_last (hist);
}
Пример #5
0
static char *
execute_get_opts_from_cfg (const char *command, const char *default_str)
{
    char *str_from_config;

    str_from_config =
        mc_config_get_string_raw (mc_main_config, CONFIG_EXT_EDITOR_VIEWER_SECTION, command, NULL);

    if (str_from_config == NULL)
    {
        mc_config_t *cfg;

        cfg = mc_config_init (global_profile_name, TRUE);
        if (cfg == NULL)
            return g_strdup (default_str);

        str_from_config =
            mc_config_get_string_raw (cfg, CONFIG_EXT_EDITOR_VIEWER_SECTION, command, default_str);

        mc_config_deinit (cfg);
    }

    return str_from_config;
}
Пример #6
0
Файл: lines.c Проект: LubkaB/mc
static int
mc_skin_lines_load_frm (mc_skin_t * mc_skin, const char *name)
{
    int ret;
    char *frm_val = NULL;
    frm_val = mc_config_get_string_raw (mc_skin->config, "Lines", name, " ");
    ret = mc_tty_normalize_lines_char (frm_val);

    g_free (frm_val);

#if 0
    switch (ret)
    {
    case 0x80:
        ret = ACS_HLINE;
        break;
    case 0x81:
        ret = ACS_VLINE;
        break;
    case 0x82:
        ret = ACS_ULCORNER;
        break;
    case 0x83:
        ret = ACS_URCORNER;
        break;
    case 0x84:
        ret = ACS_LLCORNER;
        break;
    case 0x85:
        ret = ACS_LRCORNER;
        break;
    case 0x86:
        ret = ACS_LTEE;
        break;
    case 0x87:
        ret = ACS_RTEE;
        break;
    case 0x8a:
        ret = ACS_PLUS;
        break;
    default:
        break;
    }
#endif

    return ret;
}
Пример #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);
}
Пример #8
0
END_TEST

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

#undef deserialize_check_incorrect
#define deserialize_check_incorrect( etalon_code, etalon_str ) { \
    if (actual != NULL) \
    { \
        fail("actual value but should be NULL", actual); \
        mc_config_deinit(actual); \
    } \
    else \
    { \
        fail_unless (error->code == etalon_code && strcmp(error->message, etalon_str) == 0, \
            "\nerror code is %d (should be %d);\nerror message is '%s' (should be '%s')", \
            error->code, etalon_code, error->message, etalon_str); \
        g_clear_error(&error); \
    } \
}

START_TEST (test_deserialize_config)
{
    mc_config_t *actual;
    GError *error = NULL;
    char *actual_value;

    actual = mc_deserialize_config ("g123error in group name", &error);
    deserialize_check_incorrect( -3,
        "mc_deserialize_config() at 1: mc_serialize_str(): Length delimiter ':' doesn't exists");

    actual = mc_deserialize_config ("p6:param1v10:some valuep6:param2v11:some value ", &error);
    deserialize_check_incorrect( -2,
        "mc_deserialize_config() at 1: mc_serialize_str(): String prefix doesn't equal to 'g'");

    actual = mc_deserialize_config ("g6:group1v10:some valuep6:param2v11:some value ", &error);
    deserialize_check_incorrect( -2,
        "mc_deserialize_config() at 10: mc_serialize_str(): String prefix doesn't equal to 'p'");

    actual = mc_deserialize_config ("g6:group1p6000:param2v11:some value ", &error);
    deserialize_check_incorrect( -3,
        "mc_deserialize_config() at 10: mc_serialize_str(): Specified data length (6000) is greater than actual data length (21)");

    actual = mc_deserialize_config (etalon_str, &error);

    if (actual == NULL)
    {
        fail("actual value is NULL!\nError code is '%d'; error message is '%s'", error->code, error->message);
        g_clear_error(&error);
        return;
    }

    actual_value = mc_config_get_string_raw(actual, "group1", "param1", "");
    fail_unless( strcmp(actual_value, "some value") == 0,
        "group1->param1(%s) should be equal to 'some value'", actual_value);
    g_free(actual_value);

    actual_value = mc_config_get_string(actual, "group1", "param2", "");
    fail_unless( strcmp(actual_value, "some value ") == 0,
        "group1->param2(%s) should be equal to 'some value '", actual_value);
    g_free(actual_value);

    fail_unless( mc_config_get_bool(actual, "group2", "param1", FALSE) == TRUE,
        "group2->param1(FALSE) should be equal to TRUE");

    fail_unless( mc_config_get_int(actual, "group2", "param2", 0) == 123456,
        "group2->param2(%d) should be equal to 123456", mc_config_get_int(actual, "group2", "param2", 0));

    actual_value = mc_config_get_string_raw(actual, "group3", "param1", "");
    fail_unless( strcmp(actual_value, "::bla-bla::") == 0,
        "group3->param1(%s) should be equal to '::bla-bla::'", actual_value);
    g_free(actual_value);

    actual_value = mc_config_get_string(actual, "group3", "param2", "");
    fail_unless( strcmp(actual_value, "bla-:p1:w:v2:12:g3:123:bla-bla\n") == 0,
        "group3->param2(%s) should be equal to 'bla-:p1:w:v2:12:g3:123:bla-bla\n'", actual_value);
    g_free(actual_value);

    fail_unless( mc_config_get_bool(actual, "group4", "param1", TRUE) == FALSE,
        "group4->param1(TRUE) should be equal to FALSE");

    fail_unless( mc_config_get_int(actual, "group4", "param2", 0) == 654321,
        "group4->param2(%d) should be equal to 654321", mc_config_get_int(actual, "group4", "param2", 0));

    mc_config_deinit (actual);
}
Пример #9
0
char *
mc_serialize_config (const mc_config_t * data, GError ** error)
{
    gchar **groups, **group_iterator;
    size_t group_count;
    GString *buffer;

    buffer = g_string_new ("");
    group_iterator = groups = mc_config_get_groups (data, &group_count);

    while (group_count-- != 0)
    {
        char *serialized_str;
        gchar **params, **param_iterator;
        size_t param_count;

        serialized_str = mc_serialize_str ('g', *group_iterator, error);
        if (serialized_str == NULL)
        {
            g_string_free (buffer, TRUE);
            g_strfreev (groups);
            return NULL;
        }
        g_string_append (buffer, serialized_str);
        g_free (serialized_str);

        param_iterator = params = mc_config_get_keys (data, *group_iterator, &param_count);

        while (param_count-- != 0)
        {
            char *value;
            serialized_str = mc_serialize_str ('p', *param_iterator, error);
            if (serialized_str == NULL)
            {
                g_string_free (buffer, TRUE);
                g_strfreev (params);
                g_strfreev (groups);
                return NULL;
            }
            g_string_append (buffer, serialized_str);
            g_free (serialized_str);

            value = mc_config_get_string_raw (data, *group_iterator, *param_iterator, "");
            serialized_str = mc_serialize_str ('v', value, error);
            g_free (value);

            if (serialized_str == NULL)
            {
                g_string_free (buffer, TRUE);
                g_strfreev (params);
                g_strfreev (groups);
                return NULL;
            }

            g_string_append (buffer, serialized_str);
            g_free (serialized_str);

            param_iterator++;
        }

        g_strfreev (params);

        group_iterator++;
    }
    return g_string_free (buffer, FALSE);
}