[gmime] Consolidate setup/teardown of GnuPG home dir for unit tests



commit 46033f6cf15a80ac96ddb86f6dea5dc6b3e36da4
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Fri Dec 2 09:09:50 2016 -0500

    Consolidate setup/teardown of GnuPG home dir for unit tests
    
    Thanks to Daniel Kahn Gillmor for this patch

 tests/test-pgp.c     |   10 ++--------
 tests/test-pgpmime.c |   10 ++--------
 tests/test-smime.c   |   10 ++--------
 tests/testsuite.c    |   22 ++++++++++++++++++++++
 tests/testsuite.h    |    3 +++
 5 files changed, 31 insertions(+), 24 deletions(-)
---
diff --git a/tests/test-pgp.c b/tests/test-pgp.c
index 3e7a2a4..928f7f1 100644
--- a/tests/test-pgp.c
+++ b/tests/test-pgp.c
@@ -283,13 +283,7 @@ int main (int argc, char **argv)
        
        testsuite_init (argc, argv);
        
-       /* reset .gnupg config directory */
-       if (system ("/bin/rm -rf ./tmp") != 0)
-               return EXIT_FAILURE;
-       if (system ("/bin/mkdir ./tmp") != 0)
-               return EXIT_FAILURE;
-       setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+       if (testsuite_setup_gpghome () != 0)
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -404,7 +398,7 @@ int main (int argc, char **argv)
        
        g_mime_shutdown ();
        
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_destroy_gpghome () != 0)
                return EXIT_FAILURE;
        
        return testsuite_exit ();
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index b5a8b21..cdb83e4 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -419,13 +419,7 @@ int main (int argc, char *argv[])
        
        testsuite_init (argc, argv);
        
-       /* reset .gnupg config directory */
-       if (system ("/bin/rm -rf ./tmp") != 0)
-               return EXIT_FAILURE;
-       if (system ("/bin/mkdir ./tmp") != 0)
-               return EXIT_FAILURE;
-       setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+       if (testsuite_setup_gpghome () != 0)
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -489,7 +483,7 @@ int main (int argc, char *argv[])
        
        g_mime_shutdown ();
        
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_destroy_gpghome () != 0)
                return EXIT_FAILURE;
        
        return testsuite_exit ();
diff --git a/tests/test-smime.c b/tests/test-smime.c
index f05e03a..3fe47d1 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -420,13 +420,7 @@ int main (int argc, char *argv[])
        
        testsuite_init (argc, argv);
        
-       /* reset .gnupg config directory */
-       if (system ("/bin/rm -rf ./tmp") != 0)
-               return EXIT_FAILURE;
-       if (system ("/bin/mkdir ./tmp") != 0)
-               return EXIT_FAILURE;
-       g_setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+       if (testsuite_setup_gpghome () != 0)
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -490,7 +484,7 @@ int main (int argc, char *argv[])
        
        g_mime_shutdown ();
        
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_destroy_gpghome () != 0)
                return EXIT_FAILURE;
        
        return testsuite_exit ();
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 2b72301..a575939 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -346,6 +346,28 @@ g_throw (Exception *ex)
        longjmp (env->env, 1);
 }
 
+int
+testsuite_setup_gpghome (void)
+{
+       /* reset .gnupg config directory */
+       if (system ("/bin/rm -rf ./tmp") != 0)
+               return EXIT_FAILURE;
+       if (system ("/bin/mkdir ./tmp") != 0)
+               return EXIT_FAILURE;
+       setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
+       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
+}
+
+int
+testsuite_destroy_gpghome (void)
+{
+       if (system ("/bin/rm -rf ./tmp") != 0)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
+}
+
 
 #ifdef BUILD
 int main (int argc, char **argv)
diff --git a/tests/testsuite.h b/tests/testsuite.h
index ece9014..a5f9392 100644
--- a/tests/testsuite.h
+++ b/tests/testsuite.h
@@ -45,6 +45,9 @@ void testsuite_check_passed (void);
 
 int testsuite_total_errors (void);
 
+/* GnuPG test suite utility functions */
+int testsuite_setup_gpghome (void);
+int testsuite_destroy_gpghome (void);
 
 /*#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 #define G_GNUC_NORETURN __attribute__((noreturn))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]