[folks] Add a key-file test library



commit db13eb9b9d8788d58ef4ad102337ea315202c03c
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu Sep 16 14:29:03 2010 +0100

    Add a key-file test library
    
    This contains some of the boilerplate code necessary to test the key-file
    backend with arbitrary key files.
    
    Helps bgo#629862.

 configure.ac                    |    1 +
 tests/lib/Makefile.am           |    1 +
 tests/lib/key-file/Makefile.am  |   31 +++++++++++++++++++++
 tests/lib/key-file/backend.vala |   57 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 30e60fa..1233342 100644
--- a/configure.ac
+++ b/configure.ac
@@ -223,6 +223,7 @@ AC_CONFIG_FILES([
     tests/telepathy/Makefile
     tests/lib/Makefile
     tests/lib/folks-test-uninstalled.pc
+    tests/lib/key-file/Makefile
     tests/lib/telepathy/Makefile
     tests/lib/telepathy/contactlist/Makefile
     tests/lib/telepathy/contactlist/session.conf
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index a4508b6..5bd8edc 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -1,4 +1,5 @@
 SUBDIRS = \
+	key-file \
 	telepathy \
 	$(NULL)
 
diff --git a/tests/lib/key-file/Makefile.am b/tests/lib/key-file/Makefile.am
new file mode 100644
index 0000000..880f34b
--- /dev/null
+++ b/tests/lib/key-file/Makefile.am
@@ -0,0 +1,31 @@
+VALAFLAGS += \
+	--library=kf-test \
+	--header=kf-test.h \
+	--vapidir=. \
+	$(NULL)
+
+noinst_LTLIBRARIES = libkf-test.la
+
+libkf_test_la_SOURCES = \
+	backend.vala \
+	$(NULL)
+
+libkf_test_la_CFLAGS = \
+	$(GLIB_CFLAGS) \
+	$(NULL)
+
+libkf_test_la_LIBADD = \
+	$(GLIB_LIBS) \
+	$(NULL)
+
+MAINTAINERCLEANFILES = \
+	kf-test.vapi \
+	kf-test.h \
+	$(NULL)
+
+GITIGNOREFILES = \
+	$(libkf_test_la_SOURCES:.vala=.c) \
+	libkf_test_la_vala.stamp \
+	$(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/lib/key-file/backend.vala b/tests/lib/key-file/backend.vala
new file mode 100644
index 0000000..0b241fe
--- /dev/null
+++ b/tests/lib/key-file/backend.vala
@@ -0,0 +1,57 @@
+public class KfTest.Backend
+{
+  private string key_file_name;
+
+  public void set_up (string key_file_contents)
+    {
+      int fd;
+
+      /* Create a temporary file */
+      try
+        {
+          fd = FileUtils.open_tmp ("folks-kf-test-XXXXXX",
+              out this.key_file_name);
+        }
+      catch (FileError e)
+        {
+          error ("Error opening temporary file: %s", e.message);
+        }
+
+      /* Populate it with the given content */
+      IOChannel channel = new IOChannel.unix_new (fd);
+      try
+        {
+          channel.write_chars ((char[]) key_file_contents, null);
+        }
+      catch (ConvertError e)
+        {
+          error ("Error converting for writing to temporary file '%s': %s\n%s",
+              this.key_file_name, e.message, key_file_contents);
+        }
+      catch (IOChannelError e)
+        {
+          error ("Error writing to temporary file '%s': %s", this.key_file_name,
+              e.message);
+        }
+
+      try
+        {
+          channel.shutdown (true);
+        }
+      catch (IOChannelError e) {}
+      FileUtils.close (fd);
+
+      /* Set the environment variable for the key file path to the temporary
+       * file, causing the key-file backend to use it next time it's loaded */
+      Environment.set_variable ("FOLKS_BACKEND_KEY_FILE_PATH",
+          this.key_file_name, true);
+    }
+
+  public void tear_down ()
+    {
+      /* Remove the temporary file */
+      if (this.key_file_name != null)
+        FileUtils.remove (this.key_file_name);
+      this.key_file_name = null;
+    }
+}



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