summaryrefslogtreecommitdiffstats
path: root/ini/ini_config_ut.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-03-29 16:58:29 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-04-14 12:15:54 -0400
commit3c189c57a30eaba8a6af4bb35eed45535fc8d16f (patch)
treed11bb5d2c2cf6f2ec23e0e14eded12f5d5ef6a31 /ini/ini_config_ut.c
parent52fe67cfc9d427495e237acf9468f3cf94393007 (diff)
downloadding-libs-3c189c57a30eaba8a6af4bb35eed45535fc8d16f.tar.gz
ding-libs-3c189c57a30eaba8a6af4bb35eed45535fc8d16f.tar.xz
ding-libs-3c189c57a30eaba8a6af4bb35eed45535fc8d16f.zip
Adding metadata interface
This patch: 1) Adds the definition of the metadata interface to the header file. The functions that were exposed for no good reason are now hidden. 2) Previously exposed functions and their descriptions are removed from the public header and placed into the source code for now. 3) The function that reads the config file no longer tries to close file in case of error. 4) Lines collection is still passed in into the reading function but as a collection itself not as a pointer to it. 5) All the parts related to processing lines are currently ifdefed using HAVE_VALIDATION that is currently is not defined. This is done to disable creation of the lines collection utill it is actually needed. I did not want to blindly remove it though and loose already done work that will be useful in future. 6) Version of the library and interface is updated 7) New header and source modules are introduced to hold functions related to the meta data. They are mostly stubbed out. This is incomplete patch. It builds and make check runs. It is created just to simplify the review a bit.
Diffstat (limited to 'ini/ini_config_ut.c')
-rw-r--r--ini/ini_config_ut.c113
1 files changed, 97 insertions, 16 deletions
diff --git a/ini/ini_config_ut.c b/ini/ini_config_ut.c
index 1c82a05..dde1c52 100644
--- a/ini/ini_config_ut.c
+++ b/ini/ini_config_ut.c
@@ -87,7 +87,8 @@ int single_file(void)
int error;
struct collection_item *ini_config = NULL;
struct collection_item *error_set = NULL;
- struct collection_item *lines = NULL;
+ struct collection_item *metadata = NULL;
+ uint32_t flags;
error = config_from_file("test", "./not_exist_ini.conf",
&ini_config, INI_STOP_ON_NONE, &error_set);
@@ -123,18 +124,54 @@ int single_file(void)
ini_config = NULL;
error_set = NULL;
- COLOUT(printf("TEST WITH LINES\n"));
+ COLOUT(printf("TEST WITH METADATA NO PARSE\n"));
+ flags = INI_META_SEC_ACCESS_FLAG |
+ INI_META_SEC_ERROR_FLAG |
+ INI_META_ACTION_NOPARSE;
- error = config_from_file_with_lines("test", "./ini.conf",
- &ini_config, INI_STOP_ON_NONE,
- &error_set, &lines);
+ error = config_from_file_with_metadata("test", "./ini.conf",
+ &ini_config, INI_STOP_ON_NONE,
+ NULL,
+ flags,
+ &metadata);
if (error) {
printf("Attempt to read configuration returned error: %d\n",error);
+ printf("\n\nMetadata\n");
+ col_debug_collection(metadata, COL_TRAVERSE_DEFAULT);
+ free_ini_config_metadata(metadata);
return error;
}
+ if (ini_config) {
+ printf("Expected no config but got some.\n");
+ col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT);
+ free_ini_config(ini_config);
+ printf("\n\nMetadata\n");
+ col_debug_collection(metadata, COL_TRAVERSE_DEFAULT);
+ free_ini_config_metadata(metadata);
+ return EINVAL;
+ }
+
+ COLOUT(printf("\n\nMeta data\n"));
+ COLOUT(col_debug_collection(metadata, COL_TRAVERSE_DEFAULT));
+ free_ini_config_metadata(metadata);
+
+ COLOUT(printf("\n\n----------------------\n"));
+
+ error = config_from_file_with_metadata("test", "./ini.conf",
+ &ini_config, INI_STOP_ON_NONE,
+ &error_set,
+ 0,
+ NULL);
+ if (error) {
+ printf("Attempt to read configuration returned error: %d\n",error);
+ print_file_parsing_errors(stdout, error_set);
+ free_ini_config_errors(error_set);
+ return error;
+ }
+
+ COLOUT(printf("\n\n----------------------\n"));
COLOUT(col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT));
- COLOUT(col_debug_collection(lines, COL_TRAVERSE_DEFAULT));
COLOUT(printf("\n\n----------------------\n"));
/* Output parsing errors (if any) */
@@ -144,7 +181,6 @@ int single_file(void)
free_ini_config(ini_config);
free_ini_config_errors(error_set);
- free_ini_config_lines(lines);
return 0;
}
@@ -154,7 +190,8 @@ int single_fd(void)
int error;
struct collection_item *ini_config = NULL;
struct collection_item *error_set = NULL;
- struct collection_item *lines = NULL;
+ struct collection_item *metadata = NULL;
+ uint32_t flags;
int fd = open("./ini.conf", O_RDONLY);
if (fd < 0) {
@@ -187,7 +224,7 @@ int single_fd(void)
ini_config = NULL;
error_set = NULL;
- COLOUT(printf("TEST WITH LINES\n"));
+ COLOUT(printf("TEST WITH FILE FD & META DATA\n"));
fd = open("./ini.conf", O_RDONLY);
if (fd < 0) {
@@ -195,18 +232,63 @@ int single_fd(void)
printf("Attempt to read configuration returned error: %d\n", error);
return error;
}
- error = config_from_fd_with_lines("test", fd,
- "./ini.conf",
- &ini_config,
- INI_STOP_ON_NONE,
- &error_set, &lines);
+
+ flags = INI_META_SEC_ACCESS_FLAG |
+ INI_META_SEC_ERROR_FLAG |
+ INI_META_ACTION_NOPARSE;
+
+ error = config_from_fd_with_metadata("test", fd,
+ "./ini.conf",
+ &ini_config,
+ INI_STOP_ON_NONE,
+ &error_set,
+ flags,
+ &metadata);
+ if (error) {
+ printf("Attempt to read configuration returned error: %d\n",error);
+ printf("\n\nErrors\n");
+ print_file_parsing_errors(stdout, error_set);
+ free_ini_config_errors(error_set);
+ printf("\n\nMetadata\n");
+ col_debug_collection(metadata, COL_TRAVERSE_DEFAULT);
+ free_ini_config_metadata(metadata);
+ return error;
+ }
+
+ if (ini_config) {
+ printf("Expected no config but got some.\n");
+ col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT);
+ free_ini_config(ini_config);
+ return EINVAL;
+ }
+
+ /* FIXME get elements of the meta data and check them */
+
+
+ COLOUT(printf("\n\nMeta data\n"));
+ COLOUT(col_debug_collection(metadata, COL_TRAVERSE_DEFAULT));
+ free_ini_config_metadata(metadata);
+
+
+ error = config_from_fd_with_metadata("test", fd,
+ "./ini.conf",
+ &ini_config,
+ INI_STOP_ON_NONE,
+ &error_set,
+ 0,
+ NULL);
+
+ close(fd);
+
if (error) {
printf("Attempt to read configuration returned error: %d\n",error);
+ printf("\n\nErrors\n");
+ print_file_parsing_errors(stdout, error_set);
+ free_ini_config_errors(error_set);
return error;
}
COLOUT(col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT));
- COLOUT(col_debug_collection(lines, COL_TRAVERSE_DEFAULT));
COLOUT(printf("\n\n----------------------\n"));
/* Output parsing errors (if any) */
@@ -216,7 +298,6 @@ int single_fd(void)
free_ini_config(ini_config);
free_ini_config_errors(error_set);
- free_ini_config_lines(lines);
return 0;
}