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

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