void Test_iniparser_getnsec(CuTest *tc) { int i; char sec_name[32]; dictionary *dic; /* NULL test */ CuAssertIntEquals(tc, -1, iniparser_getnsec(NULL)); /* Empty dictionary */ dic = dictionary_new(10); CuAssertIntEquals(tc, 0, iniparser_getnsec(dic)); dictionary_del(dic); /* Regular dictionary */ dic = generate_dictionary(512, 0); CuAssertIntEquals(tc, 512, iniparser_getnsec(dic)); /* Check after removing sections */ for (i = 1; i < 512; ++i) { sprintf(sec_name, "sec%d", i); dictionary_unset(dic, sec_name); CuAssertIntEquals(tc, 512 - i, iniparser_getnsec(dic)); } dictionary_del(dic); /* Mix sections and regular keys */ dic = generate_dictionary(10, 512); CuAssertIntEquals(tc, 10, iniparser_getnsec(dic)); dictionary_del(dic); }
void Test_iniparser_getsecname(CuTest *tc) { unsigned i; char sec_name[32]; dictionary *dic; /* NULL test */ CuAssertTrue(tc, iniparser_getsecname(NULL, 0) == NULL); /* Empty dictionary */ dic = dictionary_new(10); CuAssertPtrEquals(tc, NULL, iniparser_getsecname(dic, 0)); dictionary_del(dic); /* Sections without entries dictionary */ dic = generate_dictionary(100, 0); for (i = 0; i < 100; ++i) { sprintf(sec_name, "sec%d", i); CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i)); } dictionary_del(dic); /* Generic dictionary */ dic = generate_dictionary(10, 100); for (i = 0; i < 10; ++i) { sprintf(sec_name, "sec%d", i); CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i)); } dictionary_del(dic); }
void Test_iniparser_getseckeys(CuTest *tc) { unsigned i; char key_name[64]; dictionary *dic; int nkeys; const char * keys[10]; /* At most 10 elements per section */ /* NULL test */ CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, NULL, NULL)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", NULL)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", keys)); /* Empty dictionary */ dic = dictionary_new(10); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys)); dictionary_del(dic); /* Generic dictionary */ dic = generate_dictionary(100, 10); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec0", NULL)); nkeys = iniparser_getsecnkeys(dic, "sec42"); CuAssertIntEquals(tc, nkeys, 10); CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec42", keys)); for (i = 0; i < 10; ++i) { sprintf(key_name, "sec42:key%d", i); CuAssertStrEquals(tc, key_name, keys[i]); } /* Remove some keys to make the dictionary more real */ dictionary_unset(dic, "sec42"); dictionary_unset(dic, "sec99:key9"); dictionary_unset(dic, "sec0:key0"); dictionary_unset(dic, "sec0:key1"); dictionary_unset(dic, "sec0:key2"); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec42", keys)); nkeys = iniparser_getsecnkeys(dic, "sec99"); CuAssertIntEquals(tc, nkeys, 9); CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec99", keys)); for (i = 0; i < 9; ++i) { sprintf(key_name, "sec99:key%d", i); CuAssertStrEquals(tc, key_name, keys[i]); } nkeys = iniparser_getsecnkeys(dic, "sec0"); CuAssertIntEquals(tc, nkeys, 7); CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec0", keys)); for (i = 0; i < 7; ++i) { sprintf(key_name, "sec0:key%d", i + 3); CuAssertStrEquals(tc, key_name, keys[i]); } dictionary_del(dic); }
void Test_iniparser_getseckeys(CuTest *tc) { unsigned i; char key_name[64]; dictionary *dic; const char ** sections; /* NULL test */ CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, NULL)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy")); /* Empty dictionary */ dic = dictionary_new(10); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy")); dictionary_del(dic); /* Generic dictionary */ dic = generate_dictionary(100, 10); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL)); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy")); sections = iniparser_getseckeys(dic, "sec42"); CuAssertPtrNotNull(tc, sections); for (i = 0; i < 10; ++i) { sprintf(key_name, "sec42:key%d", i); CuAssertStrEquals(tc, key_name, sections[i]); } free(sections); /* Remove some keys to make the dictionary more real */ dictionary_unset(dic, "sec42"); dictionary_unset(dic, "sec99:key9"); dictionary_unset(dic, "sec0:key0"); dictionary_unset(dic, "sec0:key1"); dictionary_unset(dic, "sec0:key2"); CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec42")); sections = iniparser_getseckeys(dic, "sec99"); CuAssertPtrNotNull(tc, sections); for (i = 0; i < 9; ++i) { sprintf(key_name, "sec99:key%d", i); CuAssertStrEquals(tc, key_name, sections[i]); } free(sections); sections = iniparser_getseckeys(dic, "sec0"); CuAssertPtrNotNull(tc, sections); for (i = 0; i < 7; ++i) { sprintf(key_name, "sec0:key%d", i + 3); CuAssertStrEquals(tc, key_name, sections[i]); } free(sections); dictionary_del(dic); }
void Test_iniparser_getstring(CuTest *tc) { dictionary *dic; /* NULL test */ CuAssertPtrEquals(tc, NULL, iniparser_getstring(NULL, NULL, NULL)); CuAssertPtrEquals(tc, NULL, iniparser_getstring(NULL, "dummy", NULL)); /* Check the def return element */ dic = dictionary_new(10); CuAssertPtrEquals(tc, NULL, iniparser_getstring(dic, "dummy", NULL)); CuAssertStrEquals(tc, "def", iniparser_getstring(dic, NULL, "def")); CuAssertStrEquals(tc, "def", iniparser_getstring(dic, "dummy", "def")); dictionary_del(dic); /* Generic dictionary */ dic = generate_dictionary(100, 10); CuAssertStrEquals(tc, "value-0/0", iniparser_getstring(dic, "sec0:key0", NULL)); CuAssertStrEquals(tc, "value-42/5", iniparser_getstring(dic, "sec42:key5", NULL)); CuAssertStrEquals(tc, "value-99/9", iniparser_getstring(dic, "sec99:key9", NULL)); dictionary_del(dic); }