summaryrefslogtreecommitdiffstats
path: root/ini/ini_valueobj_ut.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-07-28 16:37:14 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-09-22 14:57:53 -0400
commit85c26abd9dabc0f192fe9bb695c3aac1493a9e34 (patch)
tree65e23761b5b8036f54fc6b959d27d25614f2df05 /ini/ini_valueobj_ut.c
parentfed9fb7462a5ee8afcae8741cb66d8167f9372b1 (diff)
downloadding-libs-85c26abd9dabc0f192fe9bb695c3aac1493a9e34.tar.gz
ding-libs-85c26abd9dabc0f192fe9bb695c3aac1493a9e34.tar.xz
ding-libs-85c26abd9dabc0f192fe9bb695c3aac1493a9e34.zip
Fixes to the value object
* Removed the annoyong type casting in the serialization since there is a new function in the simplebuffer to addstring. * Changed the serialization code to not create simple buffer object but rather add to the passed in one. * Added serialization of the value that stores section * Started cleaning constants but then stopped since this effor should be done a bit later when the new high level ini config interface is better baked.
Diffstat (limited to 'ini/ini_valueobj_ut.c')
-rw-r--r--ini/ini_valueobj_ut.c64
1 files changed, 11 insertions, 53 deletions
diff --git a/ini/ini_valueobj_ut.c b/ini/ini_valueobj_ut.c
index 7736663..3def3f7 100644
--- a/ini/ini_valueobj_ut.c
+++ b/ini/ini_valueobj_ut.c
@@ -84,9 +84,14 @@ int save_value(FILE *ff, const char *key, struct value_obj *vo)
TRACE_FLOW_ENTRY();
+ error = simplebuffer_alloc(&sbobj);
+ if (error) {
+ TRACE_ERROR_NUMBER("Failed to allocate dynamic string.", error);
+ return error;
+ }
/* Serialize */
- error = value_serialize(vo, key, &sbobj);
+ error = value_serialize(vo, key, sbobj);
if (error) {
printf("Failed to serialize a value object %d.\n", error);
return error;
@@ -200,7 +205,7 @@ int other_create_test(FILE *ff, struct value_obj **vo)
}
/* Save value to the file */
- error = save_value(stdout, "bar", new_vo);
+ error = save_value(ff, "baz", new_vo);
if (error) {
printf("Failed to save value to file %d.\n", error);
value_destroy(new_vo);
@@ -342,6 +347,10 @@ int modify_test(FILE *ff, struct value_obj *vo)
strlen(strval),
INI_VALUE_CREATED,
10);
+ if (error) {
+ printf("Failed to update value %d.\n", error);
+ return error;
+ }
/* Save value to the file */
@@ -456,62 +465,11 @@ int vo_basic_test(void)
}
-int vo_file_test(void)
-{
- int error = EOK;
- FILE *ff = NULL;
- uint32_t line = 0;
- char *oneline = NULL;
- char buffer[BUFFER_SIZE + 1];
-
- TRACE_FLOW_ENTRY();
-
- errno = 0;
- ff = fopen("test.ini","r");
- if (ff == NULL) {
- error = errno;
- printf("Failed to open file. Error %d.\n", error);
- return error;
- }
-
- while (1) {
-
- oneline = NULL;
- errno = 0;
- line++;
-
- oneline = fgets(buffer, BUFFER_SIZE, ff);
- if (oneline == NULL) {
- error = errno;
- if (feof(ff)) break;
- printf("Failed to read file %d\n", error);
- fclose(ff);
- return error;
- }
-
- VOOUT(printf("Line %04d: %s", line, oneline));
-
- }
-
- fclose(ff);
-
- /* THIS TEST IS INCOMPLETE.
- * BUT I NEED TO ADD PARSING
- * TO COMPLETE IT.
- * Will be delivered later.
- */
-
- TRACE_FLOW_EXIT();
- return EOK;
-}
-
-
/* Main function of the unit test */
int main(int argc, char *argv[])
{
int error = 0;
test_fn tests[] = { vo_basic_test,
- vo_file_test,
NULL };
test_fn t;
int i = 0;