diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2008-10-13 15:54:02 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2008-10-13 15:54:02 +0800 |
commit | f0762d3d556c168c9ec1d85d69cf10cdf2fef97a (patch) | |
tree | 6aabff5ab9b31bc0885b3b8c6e0b530313f6c833 | |
parent | 70730f587cae7c323d2c6d58384b8c628c62c5ad (diff) | |
download | gsoc2013-empathy-f0762d3d556c168c9ec1d85d69cf10cdf2fef97a.tar gsoc2013-empathy-f0762d3d556c168c9ec1d85d69cf10cdf2fef97a.tar.gz gsoc2013-empathy-f0762d3d556c168c9ec1d85d69cf10cdf2fef97a.tar.bz2 gsoc2013-empathy-f0762d3d556c168c9ec1d85d69cf10cdf2fef97a.tar.lz gsoc2013-empathy-f0762d3d556c168c9ec1d85d69cf10cdf2fef97a.tar.xz gsoc2013-empathy-f0762d3d556c168c9ec1d85d69cf10cdf2fef97a.tar.zst gsoc2013-empathy-f0762d3d556c168c9ec1d85d69cf10cdf2fef97a.zip |
factor out get_xml_file, get_user_xml_file and copy_xml_file
svn path=/trunk/; revision=1548
-rw-r--r-- | tests/check-empathy-chatroom-manager.c | 37 | ||||
-rw-r--r-- | tests/check-empathy-irc-network-manager.c | 40 | ||||
-rw-r--r-- | tests/check-helpers.c | 36 | ||||
-rw-r--r-- | tests/check-helpers.h | 4 |
4 files changed, 44 insertions, 73 deletions
diff --git a/tests/check-empathy-chatroom-manager.c b/tests/check-empathy-chatroom-manager.c index 25014da1f..fbeb9bae1 100644 --- a/tests/check-empathy-chatroom-manager.c +++ b/tests/check-empathy-chatroom-manager.c @@ -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); diff --git a/tests/check-empathy-irc-network-manager.c b/tests/check-empathy-irc-network-manager.c index 3244a8e2f..47601f5f3 100644 --- a/tests/check-empathy-irc-network-manager.c +++ b/tests/check-empathy-irc-network-manager.c @@ -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 @@ START_TEST (test_empathy_irc_network_manager_remove) } 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 @@ START_TEST (test_load_user_file) 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 @@ START_TEST (test_modify_user_file) 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 @@ START_TEST (test_modify_both_files) 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); diff --git a/tests/check-helpers.c b/tests/check-helpers.c index 7a7663fce..8cd46388c 100644 --- a/tests/check-helpers.c +++ b/tests/check-helpers.c @@ -61,3 +61,39 @@ check_helpers_init (void) 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); +} diff --git a/tests/check-helpers.h b/tests/check-helpers.h index b71b3b65b..85cebc1b3 100644 --- a/tests/check-helpers.h +++ b/tests/check-helpers.h @@ -40,4 +40,8 @@ G_STMT_START { \ 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__ */ |