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

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