summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2012-07-13 19:12:13 -0400
committerJakub Hrozek <jhrozek@redhat.com>2012-10-17 14:02:52 +0200
commitd6759220c7ce3b9e3e821256bd0be145520a747b (patch)
treea54657e8523a8e7f20a9cdfb6c26579f963ee4cb
parent537667f02826563e6f3199e283630b45c58aed31 (diff)
downloadding-libs-d6759220c7ce3b9e3e821256bd0be145520a747b.tar.gz
ding-libs-d6759220c7ce3b9e3e821256bd0be145520a747b.tar.xz
ding-libs-d6759220c7ce3b9e3e821256bd0be145520a747b.zip
Added new tests for the multi value keys
-rw-r--r--ini/ini.d/real.conf3
-rw-r--r--ini/ini_parse_ut.c1133
2 files changed, 1136 insertions, 0 deletions
diff --git a/ini/ini.d/real.conf b/ini/ini.d/real.conf
index 4d5a319..32bc9da 100644
--- a/ini/ini.d/real.conf
+++ b/ini/ini.d/real.conf
@@ -45,10 +45,13 @@ provider = ipa
server = ipaserver1.example.com
server = ipabackupserver.example.com
legacy = FALSE
+server = otheripabackupserver.example.com
enumerate = 0
binary_test = '010203'
+binary_test_two = '0A0b0C'
long_array = 1 2; 4' ;8p .16/ 32?
double_array = 1.1 2.222222; .4' . ;8p .16/ -32?
+server = yetanotheripabackupserver.example.com
empty_value =
space_value = " "
int32_t = -1000000000
diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c
index 73b618e..bd90613 100644
--- a/ini/ini_parse_ut.c
+++ b/ini/ini_parse_ut.c
@@ -973,6 +973,1138 @@ int reload_test(void)
return 0;
}
+int get_test(void)
+{
+
+ int error;
+ int number;
+ long number_long;
+ double number_double;
+ unsigned number_unsigned;
+ unsigned long number_ulong;
+ unsigned char logical;
+ char *str;
+ const char *cstr;
+ const char *cstrn;
+ void *binary;
+ int length;
+ int i = 0;
+ char **strarray;
+ char **strptr;
+ int size;
+ long *array;
+ double *darray;
+ char **prop_array;
+ int32_t val_int32;
+ uint32_t val_uint32;
+ int64_t val_int64;
+ uint64_t val_uint64;
+ struct ini_cfgfile *file_ctx = NULL;
+ struct ini_cfgobj *ini_config = NULL;
+ struct value_obj *vo = NULL;
+ char **error_list = NULL;
+ char infile[PATH_MAX];
+ char *srcdir = NULL;
+ int bad_val = 0;
+
+ INIOUT(printf("\n\n<==== GET TEST START =====>\n"));
+ INIOUT(printf("Creating configuration object\n"));
+
+ /* Create config collection */
+ error = ini_config_create(&ini_config);
+ if (error) {
+ printf("Failed to create collection. Error %d.\n", error);
+ return error;
+ }
+
+ srcdir = getenv("srcdir");
+ sprintf(infile, "%s/ini/ini.d/real.conf", (srcdir == NULL) ? "." : srcdir);
+
+ INIOUT(printf("Reading file %s\n", infile));
+
+ error = ini_config_file_open(infile,
+ INI_STOP_ON_NONE,
+ /* Merge section but allow duplicates */
+ INI_MS_MERGE |
+ INI_MV1S_ALLOW |
+ INI_MV2S_ALLOW,
+ 0,
+ &file_ctx);
+ if (error) {
+ printf("Failed to open file for reading. Error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ error = ini_config_parse(file_ctx,
+ ini_config);
+ if (error) {
+ INIOUT(printf("Failed to parse configuration. Error %d.\n", error));
+
+ if (ini_config_error_count(file_ctx)) {
+ INIOUT(printf("Errors detected while parsing: %s\n",
+ ini_config_get_filename(file_ctx)));
+ ini_config_get_errors(file_ctx, &error_list);
+ INIOUT(ini_config_print_errors(stdout, error_list));
+ ini_config_free_errors(error_list);
+ }
+ /* We do not return here intentionally */
+ }
+
+ ini_config_file_destroy(file_ctx);
+
+ INIOUT(printf("Negtive test - trying to get non"
+ " existing key-value pair.\n"));
+
+ /* Negative test */
+ vo = NULL;
+ error = ini_get_config_valueobj("monitor1",
+ "description1",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Values should not be found */
+ if (vo != NULL) {
+ printf("Expected NULL but got something else!\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ /* Another negative test but section exists this time */
+ vo = NULL;
+ error = ini_get_config_valueobj("monitor",
+ "description1",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Valueobj should not be found */
+ if(vo != NULL) {
+ printf("Expected NULL but got something else!\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Trying to get a value.\n"));
+
+ /* Positive test */
+ vo = NULL;
+ error = ini_get_config_valueobj("monitor",
+ "description",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected value but got NULL!\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("description", vo));
+
+ INIOUT(printf("Get values as string without duplication"
+ " from the NULL valueobj.\n"));
+
+ /* Get a string without duplicication */
+ /* Negative test */
+ cstrn = ini_get_const_string_config_value(NULL, NULL);
+ if (cstrn != NULL) {
+ printf("Expected error got success.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Get value as string without duplication"
+ "from the correct value object.\n"));
+
+ /* Now get string from the right value object */
+ error = 0;
+ cstr = ini_get_const_string_config_value(vo, &error);
+ if (error) {
+ printf("Expected success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Value: [%s]\n", cstr));
+
+ /* Same thing but create a dup */
+
+ INIOUT(printf("Get value as string with duplication"
+ " from correct value object.\n"));
+
+ error = 0;
+ str = ini_get_string_config_value(vo, &error);
+ if (error) {
+ printf("Expected success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Value: [%s]\n", str));
+ free(str);
+
+
+ /* Get a badly formated number */
+ INIOUT(printf("Convert value to number with strict conversion.\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("monitor",
+ "bad_number",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected value but got something NULL!\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("bad_number", vo));
+
+ /* Now try to get value in different ways */
+ error = 0;
+ number = ini_get_int_config_value(vo, 1, 10, &error);
+ if (error) {
+ /* We expected error in this case */
+ INIOUT(printf("Expected error.\n"));
+ if(number != 10) {
+ printf("It failed to set default value.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+ }
+ else {
+ printf("Expected error got success.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Convert value to number without strict conversion.\n"));
+
+ error = 0;
+ number = 1;
+ number = ini_get_int_config_value(vo, 0, 10, &error);
+ if (error) {
+ printf("Did not expect error.\n");
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ if (number != 5) {
+ printf("We expected that the conversion will return 5.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ /* Get real integer */
+
+ INIOUT(printf("Fetch another value from section \"domains/LOCAL\""
+ " named \"enumerate\".\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/LOCAL",
+ "enumerate",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Convert value to integer.\n"));
+
+ /* Take number out of it */
+ error = 0;
+ number = ini_get_int_config_value(vo, 1, 100, &error);
+ if (error) {
+ printf("Did not expect error. Got %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* It is 3 in the file */
+ if (number != 3) {
+ printf("We expected that the conversion will return 3.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Expected 3 got %d\n", number));
+
+ INIOUT(printf("Convert value to long.\n"));
+
+ /* Take number out of it */
+ error = 0;
+ number_long = ini_get_long_config_value(vo, 1, 100, &error);
+ if (error) {
+ printf("Did not expect error. Got %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* It is 3 in the file */
+ if (number_long != 3) {
+ printf("We expected that the conversion will return 3.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Expected 3 got %ld\n", number_long));
+
+ INIOUT(printf("Convert value to unsigned.\n"));
+
+ /* Take number out of it */
+ error = 0;
+ number_unsigned = ini_get_unsigned_config_value(vo, 1, 100, &error);
+ if (error) {
+ printf("Did not expect error. Got %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* It is 3 in the file */
+ if (number_unsigned != 3) {
+ printf("We expected that the conversion will return 3.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Expected 3 got %d\n", number_unsigned));
+
+ INIOUT(printf("Convert value to unsigned long.\n"));
+
+ /* Take number out of it */
+ error = 0;
+ number_ulong = ini_get_ulong_config_value(vo, 1, 100, &error);
+ if (error) {
+ printf("Did not expect error. Got %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* It is 3 in the file */
+ if (number_ulong != 3) {
+ printf("We expected that the conversion will return 3.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Expected 3 got %lu\n", number_ulong));
+
+ INIOUT(printf("Convert value to double.\n"));
+
+ /* Take number out of it */
+ error = 0;
+ number_double = ini_get_double_config_value(vo, 1, 100., &error);
+ if (error) {
+ printf("Did not expect error. Got %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* It is 3 in the file */
+ if (number_double != 3.) {
+ printf("We expected that the conversion will return 3.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Expected 3 got %e\n", number_double));
+
+ INIOUT(printf("Convert value to bool.\n"));
+
+ /* Take number out of it */
+ error = 0;
+ logical = ini_get_bool_config_value(vo, 1, &error);
+ if (!error) {
+ printf("Expect error. Got success.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ /* Get real bool values and convert it */
+ INIOUT(printf("Get real bool value \"legacy\" and convert it.\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/LOCAL",
+ "legacy",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n",error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Convert values to bool.\n"));
+
+ error = 0;
+ logical = ini_get_bool_config_value(vo, 1, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ if (logical) {
+ printf("Expected false but got true - bad.\n");
+ return -1;
+ }
+
+ INIOUT(printf("In the files it is FALSE so we got false.\n"));
+
+ INIOUT(printf("Get binary value\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "binary_test",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("binary_test", vo));
+
+ error = 0;
+ binary = ini_get_bin_config_value(vo, &length, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Binary value (expect 123) = "));
+ INIOUT(for (i = 0; i < length; i++) {
+ printf("%d",*((unsigned char*)(binary) + i));
+ if (*((unsigned char*)(binary) + i) != (i + 1)) bad_val = 1;
+ });
+ INIOUT(printf("\n"));
+
+ ini_free_bin_config_value(binary);
+
+ if (bad_val) {
+ printf("Unexpected binary value.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Get another binary value\n"));
+
+ bad_val = 0;
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "binary_test_two",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("binary_test_two", vo));
+
+ error = 0;
+ binary = ini_get_bin_config_value(vo, &length, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Binary value (expect abc) = "));
+ INIOUT(for (i = 0; i < length; i++) {
+ printf("%x",*((unsigned char*)(binary) + i));
+ if (*((unsigned char*)(binary) + i) - 10 != i) bad_val = 1;
+ });
+ INIOUT(printf("\n"));
+
+ ini_free_bin_config_value(binary);
+
+ if (bad_val) {
+ printf("Unexpected binary value.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(printf("Get string array value\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains",
+ "domainsorder",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n",error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("domainsorder", vo));
+
+ INIOUT(printf("Get str array without size.\n"));
+
+ error = 0;
+ strarray = ini_get_string_config_array(vo, ",", NULL, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Can be used with this cycle */
+ strptr = strarray;
+ while (*strptr != NULL) {
+ INIOUT(printf("[%s]\n",*strptr));
+ strptr++;
+ }
+
+ ini_free_string_config_array(strarray);
+
+ INIOUT(printf("Get raw str array without size.\n"));
+
+ error = 0;
+ strarray = ini_get_raw_string_config_array(vo, ",", NULL, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Can be used with this cycle */
+ strptr = strarray;
+ while (*strptr != NULL) {
+ INIOUT(printf("[%s]\n",*strptr));
+ strptr++;
+ }
+
+ ini_free_string_config_array(strarray);
+
+ INIOUT(printf("Get str array with size.\n"));
+
+ error = 0;
+ size = 0;
+ strarray = ini_get_string_config_array(vo, ",", &size, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Can be used with this cycle */
+ INIOUT(for (i=0;i<size;i++) printf("[%s]\n",*(strarray + i)));
+
+ ini_free_string_config_array(strarray);
+
+ INIOUT(printf("Get raw str array with size.\n"));
+
+ error = 0;
+ size = 0;
+ strarray = ini_get_raw_string_config_array(vo, ",", &size, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Can be used with this cycle */
+ INIOUT(for (i=0;i<size;i++) printf("[%s]\n",*(strarray + i)));
+
+ ini_free_string_config_array(strarray);
+
+ /**********************************************************/
+
+ INIOUT(printf("Get bad string array \n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains",
+ "badarray",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n",error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("badarray", vo));
+
+ INIOUT(printf("Get bad str array without size.\n"));
+
+ error = 0;
+ strarray = ini_get_string_config_array(vo, ",", NULL, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Can be used with this cycle */
+ strptr = strarray;
+ while (*strptr != NULL) {
+ INIOUT(printf("[%s]\n",*strptr));
+ strptr++;
+ }
+
+ ini_free_string_config_array(strarray);
+
+ /**********************************************************/
+
+ INIOUT(printf("Get long array value\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "long_array",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("long_array", vo));
+
+ error = 0;
+ size = 0; /* Here size is not optional!!! */
+ array = ini_get_long_config_array(vo, &size, &error);
+ if(error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Can be used with this cycle */
+ INIOUT(for (i=0;i<size;i++) printf("%ld\n", *(array + i)));
+
+ ini_free_long_config_array(array);
+
+ INIOUT(printf("Get double array value\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "double_array",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Values should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("double_array", vo));
+
+ error = 0;
+ size = 0; /* Here size is not optional!!! */
+ darray = ini_get_double_config_array(vo, &size, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Can be used with this cycle */
+ INIOUT(for (i=0;i<size;i++) printf("%.4f\n", darray[i]));
+
+ ini_free_double_config_array(darray);
+
+ INIOUT(printf("\n\nSection list - no size\n"));
+
+ /* Do not care about the error or size */
+ prop_array = ini_get_section_list(ini_config, NULL, NULL);
+ if (prop_array == NULL) {
+ printf("Expect success got error.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ i = 0;
+ INIOUT(while (prop_array[i]) {
+ printf("Section: [%s]\n", prop_array[i]);
+ i++;
+ });
+
+ ini_free_section_list(prop_array);
+
+ INIOUT(printf("\n\nSection list - with size\n"));
+
+ /* Do not care about the error or size */
+ prop_array = ini_get_section_list(ini_config, &size, NULL);
+ if (prop_array == NULL) {
+ printf("Expect success got error.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(for (i=0;i<size;i++) printf("Section: [%s]\n", prop_array[i]));
+ ini_free_section_list(prop_array);
+
+ INIOUT(printf("\n\nAttributes in the section - with size and error\n"));
+
+ /* Do not care about the error or size */
+ prop_array = ini_get_attribute_list(ini_config,
+ "domains/EXAMPLE.COM",
+ &size,
+ &error);
+ if (prop_array == NULL) {
+ printf("Expect success got error.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(for (i=0;i<size;i++) printf("Attribute: [%s]\n", prop_array[i]));
+ ini_free_attribute_list(prop_array);
+
+
+ /***************************************/
+ /* Test special types */
+ /***************************************/
+ INIOUT(printf("Test int32_t\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "int32_t",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("int32_t", vo));
+
+ error = 0;
+ val_int32 = ini_get_int32_config_value(vo, 1, 0, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Value: %d\n", val_int32));
+
+ /***************************************/
+
+ INIOUT(printf("Test uint32_t\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "uint32_t",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Valu should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("uint32_t", vo));
+
+ error = 0;
+ val_uint32 = ini_get_uint32_config_value(vo, 1, 0, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Value: %u\n", val_uint32));
+
+ /***************************************/
+
+ INIOUT(printf("Test int64_t\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "int64_t",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("int64_t", vo));
+
+ error = 0;
+ val_int64 = ini_get_int64_config_value(vo, 1, 0, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Value: %lld\n", (long long)val_int64));
+
+ /***************************************/
+
+ INIOUT(printf("Test uint32_t\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "uint64_t",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if (error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("uint64_t", vo));
+
+ error = 0;
+ val_uint64 = ini_get_uint64_config_value(vo, 1, 0, &error);
+ if (error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ INIOUT(printf("Value: %llu\n", (unsigned long long)val_uint64));
+
+ /***************************************/
+
+ INIOUT(printf("Get empty array value object\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "empty_value",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("empty_value", vo));
+
+ error = 0;
+ size = 0; /* Here size is not optional!!! */
+ strarray = ini_get_string_config_array(vo, ",", &size, &error);
+ if(error) {
+ printf("Expect success got error %d.\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ if (size != 0) {
+ for (i=0; i<size; i++) printf("%s\n", *(strarray + i));
+ printf("Expected size=0, got size=%d\n", size);
+ ini_free_string_config_array(strarray);
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ ini_free_string_config_array(strarray);
+
+ /***************************************/
+
+ INIOUT(printf("\nGet sequence of the multi-value keys\n"));
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "server",
+ ini_config,
+ INI_GET_FIRST_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ /* Value should be found */
+ if (vo == NULL) {
+ printf("Expected success but got NULL.\n");
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ INIOUT(value_print("server", vo));
+
+ do {
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "server",
+ ini_config,
+ INI_GET_NEXT_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ if (vo == NULL) break;
+
+ INIOUT(value_print("server", vo));
+ }
+ while(1);
+
+ /***************************************/
+
+ INIOUT(printf("\nGet multi-value keys without prefetching\n"));
+
+ do {
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "server",
+ ini_config,
+ INI_GET_NEXT_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ if (vo == NULL) break;
+
+ INIOUT(value_print("server", vo));
+ }
+ while(1);
+
+ /***************************************/
+
+ INIOUT(printf("\nGet multi-value keys with key interrupt\n"));
+
+ i = 0;
+
+ vo = NULL;
+ do {
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "server",
+ ini_config,
+ INI_GET_NEXT_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ if (vo == NULL) break;
+
+ INIOUT(value_print("server", vo));
+ i++;
+
+ if (i==2) {
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "empty_value",
+ ini_config,
+ INI_GET_NEXT_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+ }
+ }
+ while(1);
+
+ if (i != 6) {
+ printf("Expected 6 iterations got %d\n", i);
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ /***************************************/
+
+ INIOUT(printf("\nGet multi-value keys with key interrupt\n"));
+
+ i = 0;
+
+ vo = NULL;
+ do {
+
+ vo = NULL;
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
+ "server",
+ ini_config,
+ INI_GET_NEXT_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+
+ if (vo == NULL) break;
+
+ INIOUT(value_print("server", vo));
+ i++;
+
+ if (i==2) {
+ vo = NULL;
+ error = ini_get_config_valueobj("domains",
+ "badarray",
+ ini_config,
+ INI_GET_NEXT_VALUE,
+ &vo);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ ini_config_destroy(ini_config);
+ return error;
+ }
+ }
+ }
+ while(1);
+
+ if (i != 6) {
+ printf("Expected 6 iterations got %d\n", i);
+ ini_config_destroy(ini_config);
+ return -1;
+ }
+
+ ini_config_destroy(ini_config);
+
+ INIOUT(printf("\n<==== GET TEST END =====>\n\n"));
+ return EOK;
+}
/* Main function of the unit test */
@@ -985,6 +2117,7 @@ int main(int argc, char *argv[])
merge_section_test,
startup_test,
reload_test,
+ get_test,
NULL };
test_fn t;
int i = 0;