5 static const char TEST_INI_01[] =
"; This is a sample .ini config file\n"
13 "path = \"/usr/local/bin\"\n"
14 "URL = \"http://www.example.com/~username\"\n"
17 static const char TEST_INI_02[] =
"[FreeRDS]\n"
18 "prefix=\"/usr/local\"\n"
22 "datarootdir=\"share\"\n"
23 "localstatedir=\"var\"\n"
24 "sysconfdir=\"etc\"\n"
27 static const char TEST_INI_03[] =
"[FreeRDS]\n"
28 "prefix=\"/usr/local\"\n"
30 "# some illegal string\n"
33 "invalid key-value pair\n"
34 "datarootdir=\"share\"\n"
35 "localstatedir=\"var\"\n"
36 "sysconfdir=\"etc\"\n"
39 int TestIni(
int argc,
char* argv[])
46 const char* sValue = NULL;
47 char** keyNames = NULL;
48 char** sectionNames = NULL;
58 if (IniFile_ReadBuffer(ini, TEST_INI_01) < 0)
62 sectionNames = IniFile_GetSectionNames(ini, &nSections);
63 if (!sectionNames && (nSections > 0))
66 for (
size_t i = 0; i < nSections; i++)
69 keyNames = IniFile_GetSectionKeyNames(ini, sectionNames[i], &nKeys);
70 printf(
"[%s]\n", sectionNames[i]);
71 if (!keyNames && (nKeys > 0))
73 for (
size_t j = 0; j < nKeys; j++)
75 sValue = IniFile_GetKeyValueString(ini, sectionNames[i], keyNames[j]);
76 printf(
"%s = %s\n", keyNames[j], sValue);
80 iValue = IniFile_GetKeyValueInt(ini,
"first_section",
"one");
84 printf(
"IniFile_GetKeyValueInt failure\n");
88 iValue = IniFile_GetKeyValueInt(ini,
"first_section",
"five");
92 printf(
"IniFile_GetKeyValueInt failure\n");
96 sValue = IniFile_GetKeyValueString(ini,
"first_section",
"animal");
98 if (strcmp(sValue,
"BIRD") != 0)
100 printf(
"IniFile_GetKeyValueString failure\n");
104 sValue = IniFile_GetKeyValueString(ini,
"second_section",
"path");
106 if (strcmp(sValue,
"/usr/local/bin") != 0)
108 printf(
"IniFile_GetKeyValueString failure\n");
112 sValue = IniFile_GetKeyValueString(ini,
"second_section",
"URL");
114 if (strcmp(sValue,
"http://www.example.com/~username") != 0)
116 printf(
"IniFile_GetKeyValueString failure\n");
125 if (IniFile_ReadBuffer(ini, TEST_INI_02) < 0)
128 sectionNames = IniFile_GetSectionNames(ini, &nSections);
129 if (!sectionNames && (nSections > 0))
132 for (
size_t i = 0; i < nSections; i++)
135 keyNames = IniFile_GetSectionKeyNames(ini, sectionNames[i], &nKeys);
136 printf(
"[%s]\n", sectionNames[i]);
138 if (!keyNames && (nKeys > 0))
140 for (
size_t j = 0; j < nKeys; j++)
142 sValue = IniFile_GetKeyValueString(ini, sectionNames[i], keyNames[j]);
143 printf(
"%s = %s\n", keyNames[j], sValue);
151 if (IniFile_ReadBuffer(ini, TEST_INI_03) != -1)