]> git.0d.be Git - empathy.git/blobdiff - tests/check-empathy-chatroom-manager.c
Updated Basque translation.
[empathy.git] / tests / check-empathy-chatroom-manager.c
index fa0be544d2b10a7da20a4d8cd2885a3e7f4b84e5..ef5c7761853f08136791435c28e93cd8d8800ac5 100644 (file)
@@ -82,40 +82,57 @@ check_chatrooms_list (EmpathyChatroomManager *mgr,
   g_hash_table_destroy (found);
 }
 
-START_TEST (test_empathy_chatroom_manager_new)
+static gboolean
+change_account_name_in_file (McAccount *account,
+                             const gchar *file)
 {
-  EmpathyChatroomManager *mgr;
   gchar *cmd;
+
+  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
+      mc_account_get_unique_name (account), file);
+
+  if (system (cmd) == -1)
+    {
+      g_print ("'%s' call failed\n", cmd);
+      g_free (cmd);
+      return FALSE;
+    }
+
+  g_free (cmd);
+  return TRUE;
+}
+
+START_TEST (test_empathy_chatroom_manager_dup_singleton)
+{
+  EmpathyChatroomManager *mgr;
   gchar *file;
   McAccount *account;
   struct chatroom_t chatrooms[] = {
         { "name1", "room1", TRUE, TRUE },
         { "name2", "room2", FALSE, TRUE }};
 
-  account = create_test_account ();
+  account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
 
   file = get_user_xml_file (CHATROOM_FILE);
+
   /* change the chatrooms XML file to use the account we just created */
-  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
-      mc_account_get_unique_name (account), file);
-  system (cmd);
-  g_free (cmd);
+  if (!change_account_name_in_file (account, file))
+    return;
 
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
   check_chatrooms_list (mgr, account, chatrooms, 2);
 
   g_free (file);
   g_object_unref (mgr);
-  destroy_test_account (account);
+  g_object_unref (account);
 }
 END_TEST
 
 START_TEST (test_empathy_chatroom_manager_add)
 {
   EmpathyChatroomManager *mgr;
-  gchar *cmd;
   gchar *file;
   McAccount *account;
   struct chatroom_t chatrooms[] = {
@@ -125,18 +142,17 @@ START_TEST (test_empathy_chatroom_manager_add)
         { "name4", "room4", FALSE, FALSE }};
   EmpathyChatroom *chatroom;
 
-  account = create_test_account ();
+  account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
 
   file = get_user_xml_file (CHATROOM_FILE);
+
   /* change the chatrooms XML file to use the account we just created */
-  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
-      mc_account_get_unique_name (account), file);
-  system (cmd);
-  g_free (cmd);
+  if (!change_account_name_in_file (account, file))
+    return;
 
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   /* add a favorite chatroom */
   chatroom = empathy_chatroom_new_full (account, "room3", "name3", FALSE);
@@ -148,7 +164,7 @@ START_TEST (test_empathy_chatroom_manager_add)
 
   /* reload chatrooms file */
   g_object_unref (mgr);
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   /* chatroom has been added to the XML file as it's a favorite */
   check_chatrooms_list (mgr, account, chatrooms, 3);
@@ -163,39 +179,37 @@ START_TEST (test_empathy_chatroom_manager_add)
 
   /* reload chatrooms file */
   g_object_unref (mgr);
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   /* chatrooms has not been added to the XML file */
   check_chatrooms_list (mgr, account, chatrooms, 3);
 
   g_object_unref (mgr);
   g_free (file);
-  destroy_test_account (account);
+  g_object_unref (account);
 }
 END_TEST
 
 START_TEST (test_empathy_chatroom_manager_remove)
 {
   EmpathyChatroomManager *mgr;
-  gchar *cmd;
   gchar *file;
   McAccount *account;
   struct chatroom_t chatrooms[] = {
         { "name2", "room2", FALSE, TRUE }};
   EmpathyChatroom *chatroom;
 
-  account = create_test_account ();
+  account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
 
   file = get_user_xml_file (CHATROOM_FILE);
+
   /* change the chatrooms XML file to use the account we just created */
-  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
-      mc_account_get_unique_name (account), file);
-  system (cmd);
-  g_free (cmd);
+  if (!change_account_name_in_file (account, file))
+    return;
 
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   /* remove room1 */
   chatroom = empathy_chatroom_manager_find (mgr, account, "room1");
@@ -206,7 +220,7 @@ START_TEST (test_empathy_chatroom_manager_remove)
 
   /* reload chatrooms file */
   g_object_unref (mgr);
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   check_chatrooms_list (mgr, account, chatrooms, 1);
 
@@ -220,20 +234,19 @@ START_TEST (test_empathy_chatroom_manager_remove)
 
   /* reload chatrooms file */
   g_object_unref (mgr);
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   check_chatrooms_list (mgr, account, chatrooms, 0);
 
   g_object_unref (mgr);
   g_free (file);
-  destroy_test_account (account);
+  g_object_unref (account);
 }
 END_TEST
 
 START_TEST (test_empathy_chatroom_manager_change_favorite)
 {
   EmpathyChatroomManager *mgr;
-  gchar *cmd;
   gchar *file;
   McAccount *account;
   struct chatroom_t chatrooms[] = {
@@ -241,18 +254,17 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
         { "name2", "room2", FALSE, FALSE }};
   EmpathyChatroom *chatroom;
 
-  account = create_test_account ();
+  account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
 
   file = get_user_xml_file (CHATROOM_FILE);
+
   /* change the chatrooms XML file to use the account we just created */
-  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
-      mc_account_get_unique_name (account), file);
-  system (cmd);
-  g_free (cmd);
+  if (!change_account_name_in_file (account, file))
+    return;
 
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   /* room2 is not favorite anymore */
   chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
@@ -263,7 +275,7 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
 
   /* reload chatrooms file */
   g_object_unref (mgr);
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   /* room2 is not present in the XML file anymore as it's not a favorite */
   check_chatrooms_list (mgr, account, chatrooms, 1);
@@ -282,7 +294,7 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
 
   /* reload chatrooms file */
   g_object_unref (mgr);
-  mgr = empathy_chatroom_manager_new (file);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
 
   /* room2 is back in the XML file now */
   check_chatrooms_list (mgr, account, chatrooms, 2);
@@ -290,7 +302,73 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
   g_object_unref (mgr);
   g_object_unref (chatroom);
   g_free (file);
-  destroy_test_account (account);
+  g_object_unref (account);
+}
+END_TEST
+
+START_TEST (test_empathy_chatroom_manager_change_chatroom)
+{
+  EmpathyChatroomManager *mgr;
+  gchar *file;
+  McAccount *account;
+  struct chatroom_t chatrooms[] = {
+        { "name1", "room1", TRUE, TRUE },
+        { "name2", "room2", FALSE, TRUE }};
+  EmpathyChatroom *chatroom;
+
+  account = get_test_account ();
+
+  copy_xml_file (CHATROOM_SAMPLE, "foo.xml");
+
+  file = get_user_xml_file ("foo.xml");
+
+  /* change the chatrooms XML file to use the account we just created */
+  if (!change_account_name_in_file (account, file))
+    return;
+
+  mgr = empathy_chatroom_manager_dup_singleton (file);
+
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* change room2 name */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+  empathy_chatroom_set_name (chatroom, "new_name");
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
+
+  chatrooms[1].name = "new_name";
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* change room2 auto-connect status */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+  empathy_chatroom_set_auto_connect (chatroom, TRUE);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
+
+  chatrooms[1].auto_connect = TRUE;
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* change room2 room */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+  empathy_chatroom_set_room (chatroom, "new_room");
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_dup_singleton (file);
+
+  chatrooms[1].room = "new_room";
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  g_object_unref (mgr);
+  g_free (file);
+  g_object_unref (account);
 }
 END_TEST
 
@@ -298,9 +376,10 @@ TCase *
 make_empathy_chatroom_manager_tcase (void)
 {
     TCase *tc = tcase_create ("empathy-chatroom-manager");
-    tcase_add_test (tc, test_empathy_chatroom_manager_new);
+    tcase_add_test (tc, test_empathy_chatroom_manager_dup_singleton);
     tcase_add_test (tc, test_empathy_chatroom_manager_add);
     tcase_add_test (tc, test_empathy_chatroom_manager_remove);
     tcase_add_test (tc, test_empathy_chatroom_manager_change_favorite);
+    tcase_add_test (tc, test_empathy_chatroom_manager_change_chatroom);
     return tc;
 }