Blame SOURCES/0168-testsuite-add-a-test-for-AlwaysExcludedElements.patch

562801
From 9a90a05c9000dc7d21afcfab6efbd26715aa3f08 Mon Sep 17 00:00:00 2001
562801
From: Jakub Filak <jfilak@redhat.com>
562801
Date: Mon, 8 Jun 2015 11:32:23 +0200
562801
Subject: [PATCH] testsuite: add a test for AlwaysExcludedElements
562801
562801
Related: #362
562801
562801
Signed-off-by: Jakub Filak <jfilak@redhat.com>
562801
562801
Conflicts:
562801
	tests/Makefile.am
562801
---
562801
 tests/Makefile.am      |   3 +-
562801
 tests/global_config.at | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
562801
 tests/testsuite.at     |   1 +
562801
 3 files changed, 107 insertions(+), 1 deletion(-)
562801
 create mode 100644 tests/global_config.at
562801
562801
diff --git a/tests/Makefile.am b/tests/Makefile.am
562801
index eaf1ac2..5ed7af6 100644
562801
--- a/tests/Makefile.am
562801
+++ b/tests/Makefile.am
562801
@@ -43,7 +43,8 @@ TESTSUITE_AT = \
562801
   xfuncs.at \
562801
   string_list.at \
562801
   ureport.at \
562801
-  dump_dir.at
562801
+  dump_dir.at \
562801
+  global_config.at
562801
 
562801
 EXTRA_DIST += $(TESTSUITE_AT)
562801
 TESTSUITE = $(srcdir)/testsuite
562801
diff --git a/tests/global_config.at b/tests/global_config.at
562801
new file mode 100644
562801
index 0000000..a6f5423
562801
--- /dev/null
562801
+++ b/tests/global_config.at
562801
@@ -0,0 +1,104 @@
562801
+# -*- Autotest -*-
562801
+
562801
+AT_BANNER([global_config])
562801
+
562801
+## ------------------------ ##
562801
+## always_excluded_elements ##
562801
+## ------------------------ ##
562801
+
562801
+AT_TESTFUN([always_excluded_elements],
562801
+[[
562801
+#include "internal_libreport.h"
562801
+#include <errno.h>
562801
+#include <assert.h>
562801
+
562801
+int main(int argc, char **argv)
562801
+{
562801
+    g_verbose = 3;
562801
+    char cwd_buf[PATH_MAX + 1];
562801
+
562801
+    static const char *dirs[] = {
562801
+        NULL,
562801
+        NULL,
562801
+    };
562801
+    dirs[0] = getcwd(cwd_buf, sizeof(cwd_buf));
562801
+
562801
+    static int dir_flags[] = {
562801
+        CONF_DIR_FLAG_NONE,
562801
+        -1,
562801
+    };
562801
+
562801
+    unlink("libreport.conf");
562801
+    FILE *lrf = fopen("libreport.conf", "wx");
562801
+    assert(lrf != NULL);
562801
+    fclose(lrf);
562801
+
562801
+    assert(load_global_configuration_from_dirs(dirs, dir_flags));
562801
+
562801
+    {
562801
+        unsetenv("EXCLUDE_FROM_REPORT");
562801
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
562801
+
562801
+        assert(excluded != NULL);
562801
+        assert(excluded[0] == NULL);
562801
+
562801
+        string_vector_free(excluded);
562801
+    }
562801
+
562801
+    {
562801
+        setenv("EXCLUDE_FROM_REPORT", "hostname, environ, uid", 1);
562801
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
562801
+
562801
+        assert(excluded != NULL);
562801
+        assert(strcmp(excluded[0], "hostname") == 0);
562801
+        assert(strcmp(excluded[1], "environ") == 0);
562801
+        assert(strcmp(excluded[2], "uid") == 0);
562801
+        assert(excluded[3] == NULL);
562801
+
562801
+        string_vector_free(excluded);
562801
+    }
562801
+
562801
+    free_global_configuration();
562801
+
562801
+    unlink("libreport.conf");
562801
+    lrf = fopen("libreport.conf", "wx");
562801
+    assert(lrf != NULL);
562801
+    fprintf(lrf, "AlwaysExcludedElements = maps, var_log_messages, proc_pid_status");
562801
+    fclose(lrf);
562801
+
562801
+    assert(load_global_configuration_from_dirs(dirs, dir_flags));
562801
+
562801
+    {
562801
+        unsetenv("EXCLUDE_FROM_REPORT");
562801
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
562801
+
562801
+        assert(excluded != NULL);
562801
+        assert(strcmp(excluded[0], "maps") == 0);
562801
+        assert(strcmp(excluded[1], "var_log_messages") == 0);
562801
+        assert(strcmp(excluded[2], "proc_pid_status") == 0);
562801
+        assert(excluded[3] == NULL);
562801
+
562801
+        string_vector_free(excluded);
562801
+    }
562801
+
562801
+    {
562801
+        setenv("EXCLUDE_FROM_REPORT", "hostname, environ, uid", 1);
562801
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
562801
+
562801
+        assert(excluded != NULL);
562801
+        assert(strcmp(excluded[0], "hostname") == 0);
562801
+        assert(strcmp(excluded[1], "environ") == 0);
562801
+        assert(strcmp(excluded[2], "uid") == 0);
562801
+        assert(strcmp(excluded[3], "maps") == 0);
562801
+        assert(strcmp(excluded[4], "var_log_messages") == 0);
562801
+        assert(strcmp(excluded[5], "proc_pid_status") == 0);
562801
+        assert(excluded[6] == NULL);
562801
+
562801
+        string_vector_free(excluded);
562801
+    }
562801
+
562801
+    unlink("libreport.conf");
562801
+
562801
+    return EXIT_SUCCESS;
562801
+}
562801
+]])
562801
diff --git a/tests/testsuite.at b/tests/testsuite.at
562801
index 41107e7..91f0823 100644
562801
--- a/tests/testsuite.at
562801
+++ b/tests/testsuite.at
562801
@@ -18,3 +18,4 @@ m4_include([report_python.at])
562801
 m4_include([string_list.at])
562801
 m4_include([ureport.at])
562801
 m4_include([dump_dir.at])
562801
+m4_include([global_config.at])
562801
-- 
562801
1.8.3.1
562801