Skip to content

Commit

Permalink
Test UTF-8 and dots in keys
Browse files Browse the repository at this point in the history
refs #67
refs #103
refs #43
  • Loading branch information
lmoellendorf committed Mar 3, 2024
1 parent 644b925 commit 5a5ff19
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/ressources/gruezi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Das isch en Biispiel INI Datei
#

[Chuchichäschtli]

10.123=example
Gruss=Grüzi
10 changes: 10 additions & 0 deletions test/ressources/utf8.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# これはiniファイルの例です。
#

[拉麺]

叉焼 = no ;
味噌 = TRUE ;
海苔 = 0 ;
メンマ = そうだね ;
35 changes: 35 additions & 0 deletions test/test_iniparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#define NEW_INI_PATH "ressources/new.ini"
#define TEST_INI_PATH "ressources/test.ini"
#define TEST_TXT_PATH "ressources/test.txt"
#define GRUEZI_INI_PATH "ressources/gruezi.ini"
#define UTF8_INI_PATH "ressources/utf8.ini"

#define stringify_2(x) #x
#define stringify(x) stringify_2(x)
Expand Down Expand Up @@ -989,3 +991,36 @@ void Test_iniparser_find_entry(CuTest *tc)

iniparser_freedict(dic);
}

void Test_iniparser_utf8(CuTest *tc)
{
dictionary *dic;

dic = iniparser_load(GRUEZI_INI_PATH);

if (!dic) {
fprintf(stderr, "cannot parse file: %s\n", GRUEZI_INI_PATH);
return;
}

/* Generic dictionary */
CuAssertStrEquals(tc, "example",
iniparser_getstring(dic, "Chuchichäschtli:10.123", NULL));
CuAssertStrEquals(tc, "Grüzi",
iniparser_getstring(dic, "Chuchichäschtli:Gruss", NULL));
dictionary_del(dic);
dic = iniparser_load(UTF8_INI_PATH);

if (!dic) {
fprintf(stderr, "cannot parse file: %s\n", UTF8_INI_PATH);
return;
}

/* Generic dictionary */
CuAssertIntEquals(tc, 0, iniparser_getboolean(dic, "拉麺:叉焼", -1));
CuAssertIntEquals(tc, 1, iniparser_getboolean(dic, "拉麺:味噌", -1));
CuAssertIntEquals(tc, 0, iniparser_getboolean(dic, "拉麺:海苔", -1));
CuAssertStrEquals(tc, "そうだね",
iniparser_getstring(dic, "拉麺:メンマ", NULL));
dictionary_del(dic);
}

0 comments on commit 5a5ff19

Please sign in to comment.