>From 095955d5a44d190f8562d801ce351b65b0f32ea7 Mon Sep 17 00:00:00 2001
From: Dmitri Pal <dpal@dpal.csb>
Date: Sun, 7 Sep 2014 22:53:19 +0200
Subject: [PATCH 05/10] [INI] Test file for unit test

Test file and unit test cleanup.
---
 ini/ini.d/merge.validator |   60 +++++++++++++++++++++++++++++++++++++++++++++
 ini/ini_augment_ut.c      |   53 +++++++++++++++++++++++++++++++++------
 2 files changed, 105 insertions(+), 8 deletions(-)
 create mode 100644 ini/ini.d/merge.validator

diff --git a/ini/ini.d/merge.validator b/ini/ini.d/merge.validator
new file mode 100644
index 0000000..dc6d6aa
--- /dev/null
+++ b/ini/ini.d/merge.validator
@@ -0,0 +1,60 @@
+File merge.validator did not match provided patterns. Skipping.
+File real8.conf did not match provided patterns. Skipping.
+File new_line.conf did not match provided patterns. Skipping.
+File real32be.conf did not match provided patterns. Skipping.
+File real32le.conf did not match provided patterns. Skipping.
+File real16be.conf did not match provided patterns. Skipping.
+File real16le.conf did not match provided patterns. Skipping.
+File foo.conf.in did not match provided patterns. Skipping.
+Errors detected while parsing: %s%s/comment.conf.
+Error (9) on line 22: Invalid space character at the beginning of the line.
+Error (9) on line 24: Invalid space character at the beginning of the line.
+Error (9) on line 26: Invalid space character at the beginning of the line.
+Error (15) on line 32: Incomplete comment at the end of the file.
+No sections found in file %s%s/comment.conf. Skipping.
+Section [section_a] found in file %s%s/first.conf is not allowed.
+Section [section_c] found in file %s%s/first.conf is not allowed.
+Section [section_b] found in file %s%s/first.conf is not allowed.
+File %s%s/first.conf contains sections that are not allowed. Skipping.
+Section [section_a] found in file %s%s/mergecheck.conf is not allowed.
+Section [section_c] found in file %s%s/mergecheck.conf is not allowed.
+Section [section_b] found in file %s%s/mergecheck.conf is not allowed.
+Section [section_d] found in file %s%s/mergecheck.conf is not allowed.
+File %s%s/mergecheck.conf contains sections that are not allowed. Skipping.
+Section [service] found in file %s%s/mysssd.conf is not allowed.
+Section [sssd] found in file %s%s/mysssd.conf is not allowed.
+Section [nss] found in file %s%s/mysssd.conf is not allowed.
+Section [pam] found in file %s%s/mysssd.conf is not allowed.
+Section [domain] found in file %s%s/mysssd.conf is not allowed.
+File %s%s/mysssd.conf contains sections that are not allowed. Skipping.
+Section [section_a] found in file %s%s/second.conf is not allowed.
+Section [section_b] found in file %s%s/second.conf is not allowed.
+Section [section_d] found in file %s%s/second.conf is not allowed.
+File %s%s/second.conf contains sections that are not allowed. Skipping.
+Section [section1] found in file %s%s/sexpect.conf is not allowed.
+Section [section2] found in file %s%s/sexpect.conf is not allowed.
+File %s%s/sexpect.conf contains sections that are not allowed. Skipping.
+Section [section1] found in file %s%s/smerge.conf is not allowed.
+Section [section2] found in file %s%s/smerge.conf is not allowed.
+File %s%s/smerge.conf contains sections that are not allowed. Skipping.
+Errors detected while parsing: %s%s/space.conf.
+Error (9) on line 1: Invalid space character at the beginning of the line.
+Error (9) on line 2: Invalid space character at the beginning of the line.
+Error (9) on line 3: Invalid space character at the beginning of the line.
+Error (9) on line 4: Invalid space character at the beginning of the line.
+No sections found in file %s%s/space.conf. Skipping.
+Section [info] found in file %s%s/symbols.conf is not allowed.
+Section [languages] found in file %s%s/symbols.conf is not allowed.
+Section [text] found in file %s%s/symbols.conf is not allowed.
+File %s%s/symbols.conf contains sections that are not allowed. Skipping.
+Errors detected while parsing: %s%s/test.conf.
+Error (9) on line 11: Invalid space character at the beginning of the line.
+Error (9) on line 12: Invalid space character at the beginning of the line.
+Error (9) on line 14: Invalid space character at the beginning of the line.
+Error (9) on line 15: Invalid space character at the beginning of the line.
+Error (9) on line 16: Invalid space character at the beginning of the line.
+Error (9) on line 26: Invalid space character at the beginning of the line.
+Error (9) on line 35: Invalid space character at the beginning of the line.
+No sections found in file %s%s/test.conf. Skipping.
+%s%s/ipa.conf
+%s%s/real.conf
diff --git a/ini/ini_augment_ut.c b/ini/ini_augment_ut.c
index 8e017e0..917773a 100644
--- a/ini/ini_augment_ut.c
+++ b/ini/ini_augment_ut.c
@@ -189,7 +189,6 @@ int print_list_to_file(struct ref_array *list,
 static int basic_test(void)
 {
     int error = EOK;
-    int error1 = EOK;
     char indir[PATH_MAX];
     char srcname[PATH_MAX];
     char filename[PATH_MAX];
@@ -238,8 +237,8 @@ static int basic_test(void)
 
     /* When run in dev environment there can be some temp files which
      * we need to clean. */
-    snprintf(command, PATH_MAX * 3, "rm %s/*~", indir);
-    system(command);
+    snprintf(command, PATH_MAX * 3, "rm %s/*~ > /dev/null 2>&1", indir);
+    (void)system(command);
 
     /* Make the file path independent */
     snprintf(srcname, PATH_MAX, "%s/ini/ini.d/merge.validator",
@@ -291,12 +290,50 @@ static int basic_test(void)
     }
     else INIOUT(col_debug_collection(result_cfg->cfg, COL_TRAVERSE_DEFAULT));
 
-    error = print_list_to_file(error_list, "merge.validator.out", "w");
-    error1 = print_list_to_file(success_list, "merge.validator.out", "a");
-    /* Save error */
-    if ((error1 !=0) && (error == 0)) error = error1;
+    /* Print results to file */
+    if ((print_list_to_file(error_list, resname, "w")) ||
+        (print_list_to_file(success_list, resname, "a"))) {
+        printf("Failed to save results in %s.\n",  resname);
+        ref_array_destroy(error_list);
+        ref_array_destroy(success_list);
+        ini_config_destroy(in_cfg);
+        ini_config_destroy(result_cfg);
+        return -1;
+    }
+
+    /* NOTE: The order of the scanning of the files in the ini.d directory
+     * is not predicatble so before comparing the results we have to sort
+     * them since otherwise the projected output and real output might
+     * not match.
+     */
+
+    snprintf(command, PATH_MAX * 3, "sort %s > %s2", filename, filename);
+    error = system(command);
+    if ((error) || (WEXITSTATUS(error))) {
+        printf("Failed to run first sort command %d %d.\n",  error,
+               WEXITSTATUS(error));
+        ref_array_destroy(error_list);
+        ref_array_destroy(success_list);
+        ini_config_destroy(in_cfg);
+        ini_config_destroy(result_cfg);
+        return -1;
+    }
+
+    snprintf(command, PATH_MAX * 3, "sort %s > %s2", resname, resname);
+    error = system(command);
+    error = system(command);
+    if ((error) || (WEXITSTATUS(error))) {
+        printf("Failed to run second sort command %d %d.\n",  error,
+               WEXITSTATUS(error));
+        ref_array_destroy(error_list);
+        ref_array_destroy(success_list);
+        ini_config_destroy(in_cfg);
+        ini_config_destroy(result_cfg);
+        return -1;
+    }
+
 
-    snprintf(command, PATH_MAX * 3, "diff -q %s %s", filename, resname);
+    snprintf(command, PATH_MAX * 3, "diff -q %s2 %s2", filename, resname);
     error = system(command);
     INIOUT(printf("Comparison of %s %s returned: %d\n",
                   filename, resname, error));
-- 
1.7.1

