2013-07-22 19:25:22 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2016-02-04 05:42:13 -08:00
|
|
|
#include <stdlib.h>
|
2011-01-16 11:07:19 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-02-04 05:42:13 -08:00
|
|
|
|
|
|
|
#include <Efreet.h>
|
|
|
|
|
2013-01-09 05:39:36 -08:00
|
|
|
#include "ef_test.h"
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
int
|
|
|
|
ef_cb_ini_parse(void)
|
|
|
|
{
|
2013-01-14 13:04:30 -08:00
|
|
|
int ret = 1;
|
|
|
|
Efreet_Ini *ini;
|
2011-01-16 11:07:19 -08:00
|
|
|
|
2013-01-14 13:04:30 -08:00
|
|
|
putenv("LC_ALL=en_US");
|
2011-01-16 11:07:19 -08:00
|
|
|
|
2013-01-14 13:04:30 -08:00
|
|
|
ini = efreet_ini_new(ef_test_path_get("test.ini"));
|
|
|
|
if (!ini)
|
|
|
|
{
|
2011-01-16 11:07:19 -08:00
|
|
|
printf("efreet_ini_parse() Failed to initialize Efreet_Ini\n");
|
|
|
|
return 0;
|
2013-01-14 13:04:30 -08:00
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
2013-01-14 13:04:30 -08:00
|
|
|
if (efreet_ini_section_set(ini, "contact"))
|
|
|
|
{
|
2011-01-16 11:07:19 -08:00
|
|
|
const char *val;
|
|
|
|
int ival;
|
|
|
|
unsigned int bval;
|
|
|
|
|
|
|
|
val = efreet_ini_string_get(ini, "Name");
|
|
|
|
if (!val || strcmp(val, "Foo Bar"))
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_string_get() Name parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
val = efreet_ini_localestring_get(ini, "Name");
|
|
|
|
if (!val || strcmp(val, "English Foo Bar"))
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_localestring_get() Name parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
val = efreet_ini_string_get(ini, "Email");
|
|
|
|
if (!val || strcmp(val, "foo@bar.com"))
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_string_get() Email parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
val = efreet_ini_localestring_get(ini, "Email");
|
|
|
|
if (!val || strcmp(val, "foo@bar.com"))
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_localestring_get() Email parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
ival = efreet_ini_int_get(ini, "Age");
|
|
|
|
if (ival != 30)
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_int_get() Age parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
bval = efreet_ini_boolean_get(ini, "TrueBoolean");
|
|
|
|
if (!bval)
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_boolean_get() TrueBoolean parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
bval = efreet_ini_boolean_get(ini, "FalseBoolean");
|
|
|
|
if (bval)
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_boolean_get() FalseBoolean parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
bval = efreet_ini_boolean_get(ini, "InvalidBoolean");
|
|
|
|
if (bval)
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_boolean_get() InvalidBoolean parsed incorrectly\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
|
|
|
val = efreet_ini_string_get(ini, "Escaped");
|
|
|
|
if (!val || strcmp(val, "line1\nline2\r\nline3\ttabbed \\ with a backslash and spaces"))
|
2013-01-14 13:04:30 -08:00
|
|
|
{
|
|
|
|
printf("efreet_ini_unescape() improperly unescaped value\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-16 11:07:19 -08:00
|
|
|
printf("efreet_ini_section_set() Failed to set 'contact' section\n");
|
|
|
|
ret = 0;
|
2013-01-14 13:04:30 -08:00
|
|
|
}
|
2011-01-16 11:07:19 -08:00
|
|
|
|
2013-01-14 13:04:30 -08:00
|
|
|
efreet_ini_free(ini);
|
2011-01-16 11:07:19 -08:00
|
|
|
|
2013-01-14 13:04:30 -08:00
|
|
|
return ret;
|
2011-01-16 11:07:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ef_cb_ini_long_line(void)
|
|
|
|
{
|
2013-01-14 13:04:30 -08:00
|
|
|
Efreet_Ini *ini;
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
char *key;
|
|
|
|
int len;
|
|
|
|
} tests[] = {
|
|
|
|
{"key", 5099},
|
|
|
|
{"key2", 5099},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
ini = efreet_ini_new(ef_test_path_get("long.ini"));
|
|
|
|
if (!ini)
|
|
|
|
{
|
|
|
|
printf("Ini failed to parse.\n");
|
2011-01-16 11:07:19 -08:00
|
|
|
ret = 0;
|
2013-01-14 13:04:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) ret = efreet_ini_section_set(ini, "section");
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
const char *val;
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
for (i = 0; tests[i].key; i++)
|
|
|
|
{
|
|
|
|
val = efreet_ini_string_get(ini, tests[i].key);
|
|
|
|
if (val)
|
|
|
|
{
|
|
|
|
len = strlen(val);
|
|
|
|
if (len != tests[i].len)
|
|
|
|
{
|
|
|
|
printf("Invalid long line parsing. Value length: %d (expected %d)\n", len, tests[i].len);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Key missing: %s.", tests[i].key);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Section missing: 'section'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ini) efreet_ini_free(ini);
|
|
|
|
return ret;
|
2011-01-16 11:07:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ef_cb_ini_garbage(void)
|
|
|
|
{
|
2013-01-14 13:04:30 -08:00
|
|
|
Efreet_Ini *ini;
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
ini = efreet_ini_new(ef_test_path_get("test_garbage"));
|
|
|
|
if (!ini)
|
|
|
|
{
|
|
|
|
printf("Ini failed to parse.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ini->data) ret = 0;
|
|
|
|
efreet_ini_free(ini);
|
|
|
|
return ret;
|
2011-01-16 11:07:19 -08:00
|
|
|
}
|