empathy r1548 - trunk/tests



Author: xclaesse
Date: Mon Oct 13 07:54:02 2008
New Revision: 1548
URL: http://svn.gnome.org/viewvc/empathy?rev=1548&view=rev

Log:
factor out get_xml_file, get_user_xml_file and copy_xml_file

Modified:
   trunk/tests/check-empathy-chatroom-manager.c
   trunk/tests/check-empathy-irc-network-manager.c
   trunk/tests/check-helpers.c
   trunk/tests/check-helpers.h

Modified: trunk/tests/check-empathy-chatroom-manager.c
==============================================================================
--- trunk/tests/check-empathy-chatroom-manager.c	(original)
+++ trunk/tests/check-empathy-chatroom-manager.c	Mon Oct 13 07:54:02 2008
@@ -12,47 +12,12 @@
 #define CHATROOM_SAMPLE "chatrooms-sample.xml"
 #define CHATROOM_FILE "chatrooms.xml"
 
-static gchar *
-get_xml_file (const gchar *filename)
-{
-  return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
-      filename, NULL);
-}
-
-static gchar *
-get_user_xml_file (const gchar *filename)
-{
-  return g_build_filename (g_get_tmp_dir (), filename, NULL);
-}
-
-static void
-copy_chatroom_file (void)
-{
-  gboolean result;
-  gchar *buffer;
-  gsize length;
-  gchar *sample;
-  gchar *file;
-
-  sample = get_xml_file (CHATROOM_SAMPLE);
-  result = g_file_get_contents (sample, &buffer, &length, NULL);
-  fail_if (!result);
-
-  file = get_user_xml_file (CHATROOM_FILE);
-  result = g_file_set_contents (file, buffer, length, NULL);
-  fail_if (!result);
-
-  g_free (sample);
-  g_free (file);
-  g_free (buffer);
-}
-
 START_TEST (test_empathy_chatroom_manager_new)
 {
   EmpathyChatroomManager *mgr;
   gchar *file;
 
-  copy_chatroom_file ();
+  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
   file = get_xml_file (CHATROOM_FILE);
   mgr = empathy_chatroom_manager_new (file);
 

Modified: trunk/tests/check-empathy-irc-network-manager.c
==============================================================================
--- trunk/tests/check-empathy-irc-network-manager.c	(original)
+++ trunk/tests/check-empathy-irc-network-manager.c	Mon Oct 13 07:54:02 2008
@@ -14,18 +14,6 @@
 #define USER_SAMPLE "user-irc-networks-sample.xml"
 #define USER_FILE "user-irc-networks.xml"
 
-static gchar *
-get_xml_file (const gchar *filename)
-{
-  return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml", filename, NULL);
-}
-
-static gchar *
-get_user_xml_file (const gchar *filename)
-{
-  return g_build_filename (g_get_tmp_dir (), filename, NULL);
-}
-
 START_TEST (test_empathy_irc_network_manager_add)
 {
   EmpathyIrcNetworkManager *mgr;
@@ -251,28 +239,6 @@
 }
 END_TEST
 
-static void
-copy_user_file (void)
-{
-  gboolean result;
-  gchar *buffer;
-  gsize length;
-  gchar *user_sample;
-  gchar *user_file;
-
-  user_sample = get_xml_file (USER_SAMPLE);
-  result = g_file_get_contents (user_sample, &buffer, &length, NULL);
-  fail_if (!result);
-
-  user_file = get_user_xml_file (USER_FILE);
-  result = g_file_set_contents (user_file, buffer, length, NULL);
-  fail_if (!result);
-
-  g_free (user_sample);
-  g_free (user_file);
-  g_free (buffer);
-}
-
 START_TEST (test_load_user_file)
 {
   EmpathyIrcNetworkManager *mgr;
@@ -289,7 +255,7 @@
   gboolean network_checked[3];
   gchar *user_file_orig;
 
-  copy_user_file ();
+  copy_xml_file (USER_SAMPLE, USER_FILE);
   user_file_orig = get_user_xml_file (USER_FILE);
   mgr = empathy_irc_network_manager_new (NULL, user_file_orig);
 
@@ -453,7 +419,7 @@
   gboolean network_checked[3];
   gchar *user_file_orig;
 
-  copy_user_file ();
+  copy_xml_file (USER_SAMPLE, USER_FILE);
   user_file_orig = get_user_xml_file (USER_FILE);
   mgr = empathy_irc_network_manager_new (NULL, user_file_orig);
 
@@ -622,7 +588,7 @@
   gboolean network_checked[4];
   gchar *global_file_orig, *user_file_orig;
 
-  copy_user_file ();
+  copy_xml_file (USER_SAMPLE, USER_FILE);
   global_file_orig = get_xml_file (GLOBAL_SAMPLE);
   user_file_orig = get_user_xml_file (USER_FILE);
   mgr = empathy_irc_network_manager_new (global_file_orig, user_file_orig);

Modified: trunk/tests/check-helpers.c
==============================================================================
--- trunk/tests/check-helpers.c	(original)
+++ trunk/tests/check-helpers.c	Mon Oct 13 07:54:02 2008
@@ -61,3 +61,39 @@
   g_log_set_handler (NULL, G_LOG_LEVEL_CRITICAL,
       check_helper_log_critical_func, NULL);
 }
+
+gchar *
+get_xml_file (const gchar *filename)
+{
+  return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
+      filename, NULL);
+}
+
+gchar *
+get_user_xml_file (const gchar *filename)
+{
+  return g_build_filename (g_get_tmp_dir (), filename, NULL);
+}
+
+void
+copy_xml_file (const gchar *orig,
+               const gchar *dest)
+{
+  gboolean result;
+  gchar *buffer;
+  gsize length;
+  gchar *sample;
+  gchar *file;
+
+  sample = get_xml_file (orig);
+  result = g_file_get_contents (sample, &buffer, &length, NULL);
+  fail_if (!result);
+
+  file = get_user_xml_file (dest);
+  result = g_file_set_contents (file, buffer, length, NULL);
+  fail_if (!result);
+
+  g_free (sample);
+  g_free (file);
+  g_free (buffer);
+}

Modified: trunk/tests/check-helpers.h
==============================================================================
--- trunk/tests/check-helpers.h	(original)
+++ trunk/tests/check-helpers.h	Mon Oct 13 07:54:02 2008
@@ -40,4 +40,8 @@
   expect_critical (FALSE);                                        \
 } G_STMT_END;
 
+gchar * get_xml_file (const gchar *filename);
+gchar * get_user_xml_file (const gchar *filename);
+void copy_xml_file (const gchar *orig, const gchar *dest);
+
 #endif /* #ifndef __CHECK_HELPERS_H__ */



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