[gnome-keyring/trust-store] [testing] Add function to clear scratch directory.



commit 5488f4ac054906a5b8ab53bdecca83865d672858
Author: Stef Walter <stefw collabora co uk>
Date:   Fri Nov 26 19:49:55 2010 +0000

    [testing] Add function to clear scratch directory.
    
    testing_scratch_remove_all()

 pkcs11/xdg-store/tests/test-xdg-module.c |    3 +++
 testing/testing.c                        |   18 ++++++++++++++++++
 testing/testing.h                        |    2 ++
 3 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/pkcs11/xdg-store/tests/test-xdg-module.c b/pkcs11/xdg-store/tests/test-xdg-module.c
index a3cd72d..d254173 100644
--- a/pkcs11/xdg-store/tests/test-xdg-module.c
+++ b/pkcs11/xdg-store/tests/test-xdg-module.c
@@ -55,6 +55,9 @@ test_xdg_module_initialize_and_enter (void)
 	args.pReserved = string;
 	args.flags = CKF_OS_LOCKING_OK;
 
+	/* Delete all files in this directory */
+	testing_scratch_remove_all ();
+
 	/* Copy files from test-data to scratch */
 	testing_data_to_scratch ("test-refer-1.trust", NULL);
 	testing_data_to_scratch ("test-certificate-1.cer", NULL);
diff --git a/testing/testing.c b/testing/testing.c
index 1ebee17..5aa522d 100644
--- a/testing/testing.c
+++ b/testing/testing.c
@@ -222,6 +222,24 @@ testing_scratch_remove (const gchar *basename)
 	g_free (filename);
 }
 
+void
+testing_scratch_remove_all (void)
+{
+	GError *err = NULL;
+	const gchar *basename;
+	GDir *dir;
+
+	/* WARNING: Don't change path without changing remove below */
+	dir = g_dir_open (testing_scratch_directory (), 0, &err);
+	if (dir == NULL)
+		g_error ("couldn't open directory: %s",
+		         err && err->message ? err->message : "");
+
+	while ((basename = g_dir_read_name (dir)) != NULL)
+		testing_scratch_remove (basename);
+
+	g_dir_close (dir);
+}
 
 #if WITH_P11_TESTS
 
diff --git a/testing/testing.h b/testing/testing.h
index dfaafbb..71a3d50 100644
--- a/testing/testing.h
+++ b/testing/testing.h
@@ -62,6 +62,8 @@ void             testing_scratch_touch            (const gchar *basename,
 
 void             testing_scratch_remove           (const gchar *basename);
 
+void             testing_scratch_remove_all       (void);
+
 gchar*           testing_data_filename            (const gchar *basename);
 
 #ifdef CRYPTOKI_VERSION_MAJOR



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