30 #include <libfocunit.h> 54 #define CONF_FILE "confdata/conftest.conf" 57 #define GROUP(g) GROUP_##g 58 #define KEY(g, k) GROUP_##g##_KEY_##k 59 #define VAL(g, v) GROUP_##g##_VALUE_##v 60 #define VAL_IDX(g, v, i) GROUP_##g##_VALUE_##v##_##i 63 #define GROUP_0_KEY_0 "key_a" 64 #define GROUP_0_VALUE_0 "hello" 65 #define GROUP_0_KEY_1 "key_b" 66 #define GROUP_0_VALUE_1 "goodbye" 69 #define GROUP_1_KEY_0 "another" 70 #define GROUP_1_VALUE_0 "value" 71 #define GROUP_1_KEY_1 "names" 72 #define GROUP_1_VALUE_1 "Bob, Marry, Mark, Larry, Vincent, Alex" 74 #define GROUP_2 "three" 75 #define GROUP_2_KEY_0 "this" 76 #define GROUP_2_VALUE_0 "group" 77 #define GROUP_2_KEY_1 "has" 78 #define GROUP_2_VALUE_1 "3" 79 #define GROUP_2_KEY_2 "key" 80 #define GROUP_2_VALUE_2 "literals" 82 #define GROUP_3 "four" 83 #define GROUP_3_KEY_0 "is" 84 #define GROUP_3_VALUE_0_0 "is" 85 #define GROUP_3_VALUE_0_1 "a" 86 #define GROUP_3_VALUE_0_2 "list" 87 #define GROUP_3_VALUE_0_3 "group" 88 #define GROUP_3_KEY_1 "there" 89 #define GROUP_3_VALUE_1_0 "there" 90 #define GROUP_3_VALUE_1_1 "are" 91 #define GROUP_3_VALUE_1_2 "two" 92 #define GROUP_3_VALUE_1_3 "lists" 93 #define GROUP_3_VALUE_1_4 "in" 94 #define GROUP_3_VALUE_1_5 "this" 95 #define GROUP_3_VALUE_1_6 "group" 96 #define GROUP_3_KEY_2 "not" 97 #define GROUP_3_VALUE_2 "list" 118 GError* error = NULL;
121 FO_ASSERT_PTR_NULL(test_data);
122 FO_ASSERT_PTR_NOT_NULL(error);
125 g_clear_error(&error);
127 test_data =
fo_config_load(
"confdata/invalid_group.conf", &error);
128 FO_ASSERT_PTR_NULL(test_data);
129 FO_ASSERT_PTR_NOT_NULL_FATAL(error);
132 g_clear_error(&error);
135 FO_ASSERT_PTR_NULL(test_data);
136 FO_ASSERT_PTR_NOT_NULL_FATAL(error);
139 g_clear_error(&error);
142 FO_ASSERT_PTR_NULL(test_data);
143 FO_ASSERT_PTR_NOT_NULL_FATAL(error);
146 g_clear_error(&error);
149 FO_ASSERT_PTR_NULL(test_data);
150 FO_ASSERT_PTR_NOT_NULL_FATAL(error);
153 g_clear_error(&error);
156 FO_ASSERT_PTR_NULL(test_data);
157 FO_ASSERT_PTR_NOT_NULL_FATAL(error);
160 g_clear_error(&error);
165 FO_FAIL_FATAL(
"can't load test configuration, aborting");
188 FO_ASSERT_EQUAL_FATAL(length, 4);
189 FO_ASSERT_STRING_EQUAL(names[0],
GROUP(3));
190 FO_ASSERT_STRING_EQUAL(names[1],
GROUP(0));
191 FO_ASSERT_STRING_EQUAL(names[2],
GROUP(2));
192 FO_ASSERT_STRING_EQUAL(names[3],
GROUP(1));
211 FO_ASSERT_EQUAL_FATAL(length, 2);
212 FO_ASSERT_STRING_EQUAL(names[0], KEY(0, 0));
213 FO_ASSERT_STRING_EQUAL(names[1], KEY(0, 1));
216 FO_ASSERT_EQUAL_FATAL(length, 2);
217 FO_ASSERT_STRING_EQUAL(names[0], KEY(1, 0));
218 FO_ASSERT_STRING_EQUAL(names[1], KEY(1, 1));
221 FO_ASSERT_EQUAL_FATAL(length, 3);
222 FO_ASSERT_STRING_EQUAL(names[0], KEY(2, 1));
223 FO_ASSERT_STRING_EQUAL(names[1], KEY(2, 2));
224 FO_ASSERT_STRING_EQUAL(names[2], KEY(2, 0));
227 FO_ASSERT_EQUAL_FATAL(length, 3);
228 FO_ASSERT_STRING_EQUAL(names[0], KEY(3, 0));
229 FO_ASSERT_STRING_EQUAL(names[1], KEY(3, 2));
230 FO_ASSERT_STRING_EQUAL(names[2], KEY(3, 1));
275 GError* error = NULL;
277 FO_ASSERT_STRING_EQUAL(
280 FO_ASSERT_STRING_EQUAL(
283 FO_ASSERT_STRING_EQUAL(
286 FO_ASSERT_STRING_EQUAL(
289 FO_ASSERT_STRING_EQUAL(
292 FO_ASSERT_STRING_EQUAL(
295 FO_ASSERT_STRING_EQUAL(
298 FO_ASSERT_STRING_EQUAL(
303 FO_ASSERT_EQUAL(error->domain, RETRIEVE_ERROR);
305 FO_ASSERT_STRING_EQUAL(error->message,
306 "ERROR: unknown key=\"none\" for group=\"one\"");
307 g_clear_error(&error);
309 FO_ASSERT_PTR_NULL(
fo_config_get(test_data, NONE, KEY(0, 0), &error));
310 FO_ASSERT_EQUAL(error->domain, RETRIEVE_ERROR);
312 FO_ASSERT_STRING_EQUAL(error->message,
313 "ERROR: unknown group \"none\"");
314 g_clear_error(&error);
328 GError* error = NULL;
346 GError* error = NULL;
350 FO_ASSERT_EQUAL(len, 4);
351 FO_ASSERT_PTR_NULL(error);
352 if (error) g_clear_error(&error);
355 FO_ASSERT_EQUAL(len, 7);
356 FO_ASSERT_PTR_NULL(error);
357 if (error) g_clear_error(&error);
360 FO_ASSERT_EQUAL(len, 0);
362 FO_ASSERT_PTR_NOT_NULL_FATAL(error);
363 FO_ASSERT_EQUAL(error->domain, RETRIEVE_ERROR);
365 FO_ASSERT_STRING_EQUAL(error->message,
366 "ERROR: four[not] must be of type list to get length");
367 g_clear_error(&error);
380 GError* error = NULL;
383 #define CONFIG_GET_LIST_ASSERT(g, k, i) \ 384 tmp = fo_config_get_list(test_data, GROUP(g), KEY(g, k), i, &error); \ 385 FO_ASSERT_STRING_EQUAL(tmp, VAL_IDX(g, k, i)); \ 386 FO_ASSERT_PTR_NULL(error); \ 387 if(error) g_clear_error(&error) 389 CONFIG_GET_LIST_ASSERT(3, 0, 0);
390 CONFIG_GET_LIST_ASSERT(3, 0, 1);
391 CONFIG_GET_LIST_ASSERT(3, 0, 2);
392 CONFIG_GET_LIST_ASSERT(3, 0, 3);
394 CONFIG_GET_LIST_ASSERT(3, 1, 0);
395 CONFIG_GET_LIST_ASSERT(3, 1, 1);
396 CONFIG_GET_LIST_ASSERT(3, 1, 2);
397 CONFIG_GET_LIST_ASSERT(3, 1, 3);
398 CONFIG_GET_LIST_ASSERT(3, 1, 4);
399 CONFIG_GET_LIST_ASSERT(3, 1, 5);
400 CONFIG_GET_LIST_ASSERT(3, 1, 6);
402 #undef CONFIG_GET_LIST_ASSERT 406 FO_ASSERT_EQUAL(error->domain, RETRIEVE_ERROR);
408 FO_ASSERT_STRING_EQUAL(error->message,
409 "ERROR: four[not] must be of type list to get list element")
410 g_clear_error(&error);
414 FO_ASSERT_EQUAL(error->domain, RETRIEVE_ERROR);
416 FO_ASSERT_STRING_EQUAL(error->message,
417 "ERROR: four[is] 4 is out of range");
418 g_clear_error(&error);
422 FO_ASSERT_EQUAL(error->domain, RETRIEVE_ERROR);
424 FO_ASSERT_STRING_EQUAL(error->message,
425 "ERROR: four[is] -1 is out of range");
426 g_clear_error(&error);
446 CU_TestInfo fossconfig_testcases[] =
int fo_config_has_group(fo_conf *conf, char *group)
Checks if the currently parsed configuration file has a specific group.
int fo_config_is_list(fo_conf *conf, char *group, char *key, GError **error)
Checks if a particular value is a list or just a normal value.
FOSSology library to read config file.
#define GROUP
Default group ID.
void test_fo_config_is_list()
Tests the is list function.
void test_fo_config_get_list()
Tests the get list function.
void test_fo_config_list_length()
Tests the list length function.
char * fo_config_get(fo_conf *conf, const char *group, const char *key, GError **error)
Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned.
char ** fo_config_group_set(fo_conf *conf, int *length)
Gets the set of group names.
void test_fo_config_load()
test the fo_config_load function.
void test_fo_config_key_set()
Test the key set function. Again, keys are stored in alphabetical order, so the comparison order may ...
int fo_config_has_key(fo_conf *conf, char *group, char *key)
Checks if the a specific group in the currently parsed configuration file has a specific key...
void test_fo_config_free()
Tests the config free function. This makes sure that everything is correctly set to NULL after a free...
Required group is missing.
Requested group is invalid.
void test_fo_config_has_group()
Tests the has group function.
char * fo_config_get_list(fo_conf *conf, char *group, char *key, int idx, GError **error)
int fo_config_list_length(fo_conf *conf, char *group, char *key, GError **error)
Gets the length of the list associated with a particular list key.
Requested key is invalid.
void test_fo_config_has_key()
Test the has key function.
void fo_config_free(fo_conf *conf)
Frees the memory associated with the internal configuration data structures.
char ** fo_config_key_set(fo_conf *conf, char *group, int *length)
Gets the set of key names for a particular group.
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
void test_fo_config_get()
Test the get function. This will also test the error cases of invalid key and invalid group names...
void test_fo_config_group_set()
Test the group set function.