[gnome-keyring/trust-store] [testing] Add function for putting test files in scratch dir.



commit 948cff128bf4b2ebb801266d6756984e33ba69c6
Author: Stef Walter <stef memberwebs com>
Date:   Tue Sep 21 03:57:40 2010 +0000

    [testing] Add function for putting test files in scratch dir.
    
    Add testing_data_to_scratch() function for use in tests.

 pkcs11/secret-store/tests/test-secret-module.c |   25 +----------------------
 testing/testing.c                              |   19 ++++++++++++++++++
 testing/testing.h                              |    3 ++
 3 files changed, 24 insertions(+), 23 deletions(-)
---
diff --git a/pkcs11/secret-store/tests/test-secret-module.c b/pkcs11/secret-store/tests/test-secret-module.c
index 30dd342..3215c81 100644
--- a/pkcs11/secret-store/tests/test-secret-module.c
+++ b/pkcs11/secret-store/tests/test-secret-module.c
@@ -42,27 +42,6 @@ static GMutex *mutex = NULL;
 GkmModule*  _gkm_secret_store_get_module_for_testing (void);
 GMutex* _gkm_module_get_scary_mutex_that_you_should_not_touch (GkmModule *module);
 
-static void
-copy_scratch_file (const gchar *basename)
-{
-	gchar *filename;
-	gchar *data;
-	gsize n_data;
-
-	filename = testing_data_filename (basename);
-	if (!g_file_get_contents (filename, &data, &n_data, NULL)) {
-		g_warning ("couldn't read: %s", filename);
-		g_return_if_reached ();
-	}
-	g_free (filename);
-
-	filename = testing_scratch_filename (basename);
-	if (!g_file_set_contents (filename, data, n_data, NULL))
-		g_return_if_reached ();
-	g_free (filename);
-	g_free (data);
-}
-
 GkmModule*
 test_secret_module_initialize_and_enter (void)
 {
@@ -79,8 +58,8 @@ test_secret_module_initialize_and_enter (void)
 	args.flags = CKF_OS_LOCKING_OK;
 
 	/* Copy files from test-data to scratch */
-	copy_scratch_file ("encrypted.keyring");
-	copy_scratch_file ("plain.keyring");
+	testing_data_to_scratch ("encrypted.keyring", NULL);
+	testing_data_to_scratch ("plain.keyring", NULL);
 
 	funcs = gkm_secret_store_get_functions ();
 	rv = (funcs->C_Initialize) (&args);
diff --git a/testing/testing.c b/testing/testing.c
index 7dd4116..119b8d2 100644
--- a/testing/testing.c
+++ b/testing/testing.c
@@ -156,6 +156,25 @@ testing_data_read (const gchar *basename, gsize *n_result)
 	return (guchar*)result;
 }
 
+void
+testing_data_to_scratch (const gchar *basename, const gchar *newname)
+{
+	gchar *filename;
+	gchar *data;
+	gsize n_data;
+
+	filename = testing_data_filename (basename);
+	if (!g_file_get_contents (filename, &data, &n_data, NULL))
+		g_error ("couldn't read: %s", filename);
+	g_free (filename);
+
+	filename = testing_scratch_filename (newname ? newname : basename);
+	if (!g_file_set_contents (filename, data, n_data, NULL))
+		g_error ("couldn't write: %s", filename);
+	g_free (filename);
+	g_free (data);
+}
+
 #if WITH_P11_TESTS
 
 static void
diff --git a/testing/testing.h b/testing/testing.h
index 6d1a204..1bc2c5f 100644
--- a/testing/testing.h
+++ b/testing/testing.h
@@ -46,6 +46,9 @@ const gchar*     testing_scratch_directory        (void);
 guchar*          testing_data_read                (const gchar *basename,
                                                    gsize *n_data);
 
+void             testing_data_to_scratch          (const gchar *basename,
+                                                   const gchar *newname);
+
 gchar*           testing_scratch_filename         (const gchar *basename);
 
 gchar*           testing_data_filename            (const gchar *basename);



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