From 1cae87d846fd80ce5d2ad8d90dd9928e718fa0f4 Mon Sep 17 00:00:00 2001
From: Dmitri Pal <dpal@redhat.com>
Date: Sat, 19 Oct 2013 15:49:11 -0400
Subject: [PATCH 13/13] [INI] Adding more unit tests

This patch introduces more unit test that hammer both
the unicode convertion and folding.
The new file symbols.conf contains characters in multiple
different languages. It actually comes from a Windows system.
The test adds this new file to the list of files that are read
and then saved. The saved files are read again and saved again.
Two saved files are compared to make sure they were processed
correctly.
The additional code change forces the creation of such files with
different folding boundary.
---
 Makefile.am            |    3 +-
 ini/ini.d/symbols.conf |  Bin 0 -> 1516666 bytes
 ini/ini_parse_ut.c     |   56 ++++++++++++++++++++++++++++-------------------
 3 files changed, 35 insertions(+), 24 deletions(-)
 create mode 100644 ini/ini.d/symbols.conf

diff --git a/Makefile.am b/Makefile.am
index 803db29..e931e2a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -265,7 +265,8 @@ dist_noinst_DATA += \
     ini/ini.d/real16be.conf \
     ini/ini.d/real16le.conf \
     ini/ini.d/real32be.conf \
-    ini/ini.d/real32le.conf
+    ini/ini.d/real32le.conf \
+    ini/ini.d/symbols.conf
 
 check_PROGRAMS += \
     ini_config_ut \
diff --git a/ini/ini.d/symbols.conf b/ini/ini.d/symbols.conf
new file mode 100644
index 0000000000000000000000000000000000000000..f15a9710dbaba33856cc5430ef43761bcc157ef7
GIT binary patch
diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c
index d53a171..33019b2 100644
--- a/ini/ini_parse_ut.c
+++ b/ini/ini_parse_ut.c
@@ -49,7 +49,8 @@ char *confdir = NULL;
 typedef int (*test_fn)(void);
 
 int test_one_file(const char *in_filename,
-                  const char *out_filename)
+                  const char *out_filename,
+                  int edge)
 {
     int error = EOK;
     struct ini_cfgfile *file_ctx = NULL;
@@ -114,7 +115,7 @@ int test_one_file(const char *in_filename,
 
     INIOUT(col_debug_collection(ini_config->cfg, COL_TRAVERSE_DEFAULT));
 
-    error = ini_config_set_wrap(ini_config, 5);
+    error = ini_config_set_wrap(ini_config, edge);
     if (error) {
         printf("Failed to set custom wrapper. Error %d.\n", error);
         ini_config_destroy(ini_config);
@@ -173,6 +174,7 @@ int read_save_test(void)
 {
     int error = EOK;
     int i = 0;
+    int edge = 5;
     char infile[PATH_MAX];
     char outfile[PATH_MAX];
     char *srcdir = NULL;
@@ -186,6 +188,7 @@ int read_save_test(void)
                             "real16le",
                             "real32be",
                             "real32le",
+                            "symbols",
                             NULL };
 
     INIOUT(printf("<==== Read save test ====>\n"));
@@ -193,12 +196,13 @@ int read_save_test(void)
     srcdir = getenv("srcdir");
 
     while(files[i]) {
-
-        snprintf(infile, PATH_MAX, "%s/ini/ini.d/%s.conf",
-                (srcdir == NULL) ? "." : srcdir, files[i]);
-        snprintf(outfile, PATH_MAX, "./%s.conf.out", files[i]);
-        error = test_one_file(infile, outfile);
-        INIOUT(printf("Test for file: %s returned %d\n", files[i], error));
+        for ( edge = 10; edge < 100; edge +=19) {
+            snprintf(infile, PATH_MAX, "%s/ini/ini.d/%s.conf",
+                    (srcdir == NULL) ? "." : srcdir, files[i]);
+            snprintf(outfile, PATH_MAX, "./%s_%d.conf.out", files[i], edge);
+            error = test_one_file(infile, outfile, edge);
+            INIOUT(printf("Test for file: %s returned %d\n", files[i], error));
+        }
         i++;
     }
 
@@ -212,6 +216,7 @@ int read_again_test(void)
 {
     int error = EOK;
     int i = 0;
+    int edge = 5;
     char infile[PATH_MAX];
     char outfile[PATH_MAX];
     char command[PATH_MAX * 3];
@@ -225,27 +230,32 @@ int read_again_test(void)
                             "real16le",
                             "real32be",
                             "real32le",
+                            "symbols",
                             NULL };
 
     INIOUT(printf("<==== Read again test ====>\n"));
 
     while(files[i]) {
-
-        snprintf(infile, PATH_MAX, "./%s.conf.out", files[i]);
-        snprintf(outfile, PATH_MAX, "./%s.conf.2.out", files[i]);
-        error = test_one_file(infile, outfile);
-        INIOUT(printf("Test for file: %s returned %d\n", files[i], error));
-        if (error) break;
-        snprintf(command, PATH_MAX * 3, "diff -q %s %s", infile, outfile);
-        error = system(command);
-        INIOUT(printf("Comparison of %s %s returned: %d\n",
-                      infile, outfile, error));
-        if ((error) || (WEXITSTATUS(error))) {
-            printf("Failed to run copy command %d %d.\n",  error,
-                   WEXITSTATUS(error));
-            error = -1;
-            break;
+        for ( edge = 10; edge < 100; edge +=19) {
+
+            snprintf(infile, PATH_MAX, "./%s_%d.conf.out", files[i], edge);
+            snprintf(outfile, PATH_MAX, "./%s_%d.conf.2.out", files[i], edge);
+
+            error = test_one_file(infile, outfile, edge);
+            INIOUT(printf("Test for file: %s returned %d\n", files[i], error));
+            if (error) break;
+            snprintf(command, PATH_MAX * 3, "diff -q %s %s", infile, outfile);
+            error = system(command);
+            INIOUT(printf("Comparison of %s %s returned: %d\n",
+                          infile, outfile, error));
+            if ((error) || (WEXITSTATUS(error))) {
+                printf("Failed to run copy command %d %d.\n",  error,
+                       WEXITSTATUS(error));
+                error = -1;
+                break;
+            }
         }
+
         i++;
     }
 
-- 
1.7.1

