about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-12-14 16:16:46 +0000
committerJames Booth <boothj5@gmail.com>2013-12-14 16:16:46 +0000
commit3a403046ff241381e0f9750dfe39f1e05c73fd63 (patch)
treeda06b12e14d2a6e63bdd73ba0467d35960113e9a
parent7f7973f9a72b2b6c7fe39cc39929f779d1662a69 (diff)
downloadprofani-tty-3a403046ff241381e0f9750dfe39f1e05c73fd63.tar.gz
Moved autocomplete tests to cmocka
-rw-r--r--Makefile.am1
-rw-r--r--src/roster_list.c22
-rw-r--r--tests/test_autocomplete.c58
-rw-r--r--tests/testsuite.c16
4 files changed, 48 insertions, 49 deletions
diff --git a/Makefile.am b/Makefile.am
index 8ca2123c..e52fe8bd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -80,6 +80,7 @@ test_sources = \
 	src/config/accounts.c src/config/accounts.h \
 	src/config/preferences.c src/config/preferences.h \
 	src/config/theme.c src/config/theme.h \
+    tests/test_autocomplete.c \
     tests/test_common.c \
 	tests/test_command.c \
     tests/testsuite.c
diff --git a/src/roster_list.c b/src/roster_list.c
index 37031ca4..fa00437b 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -156,19 +156,19 @@ roster_free(void)
     autocomplete_free(groups_ac);
 }
 
-void                                                                                  
+void
 roster_change_name(const char * const barejid, const char * const new_name)
 {
-    PContact contact = g_hash_table_lookup(contacts, barejid);                   
-    const char * current_name = NULL;                                            
-    if (p_contact_name(contact) != NULL) {                                       
-        current_name = strdup(p_contact_name(contact));                          
-    }                                                                            
-                                                                                 
-    if (contact != NULL) {                                                       
-        p_contact_set_name(contact, new_name);                                   
-        _replace_name(current_name, new_name, barejid);                          
-                                                                                 
+    PContact contact = g_hash_table_lookup(contacts, barejid);
+    const char * current_name = NULL;
+    if (p_contact_name(contact) != NULL) {
+        current_name = strdup(p_contact_name(contact));
+    }
+
+    if (contact != NULL) {
+        p_contact_set_name(contact, new_name);
+        _replace_name(current_name, new_name, barejid);
+
         GSList *groups = p_contact_groups(contact);
         roster_send_name_change(barejid, new_name, groups);
     }
diff --git a/tests/test_autocomplete.c b/tests/test_autocomplete.c
index 58a0e596..3eea639b 100644
--- a/tests/test_autocomplete.c
+++ b/tests/test_autocomplete.c
@@ -1,66 +1,67 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <head-unit.h>
 #include <glib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <stdlib.h>
 
 #include "contact.h"
 #include "tools/autocomplete.h"
 
-static void clear_empty(void)
+void clear_empty(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_clear(ac);
 }
 
-static void reset_after_create(void)
+void reset_after_create(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_reset(ac);
     autocomplete_clear(ac);
 }
 
-static void find_after_create(void)
+void find_after_create(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_complete(ac, "hello");
     autocomplete_clear(ac);
 }
 
-static void get_after_create_returns_null(void)
+void get_after_create_returns_null(void **state)
 {
     Autocomplete ac = autocomplete_new();
     GSList *result = autocomplete_get_list(ac);
 
-    assert_is_null(result);
+    assert_null(result);
 
     autocomplete_clear(ac);
 }
 
-static void add_one_and_complete(void)
+void add_one_and_complete(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_add(ac, "Hello");
     char *result = autocomplete_complete(ac, "Hel");
 
-    assert_string_equals("Hello", result);
+    assert_string_equal("Hello", result);
 
     autocomplete_clear(ac);
 }
 
-static void add_two_and_complete_returns_first(void)
+void add_two_and_complete_returns_first(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_add(ac, "Hello");
     autocomplete_add(ac, "Help");
     char *result = autocomplete_complete(ac, "Hel");
 
-    assert_string_equals("Hello", result);
+    assert_string_equal("Hello", result);
 
     autocomplete_clear(ac);
 }
 
-static void add_two_and_complete_returns_second(void)
+void add_two_and_complete_returns_second(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_add(ac, "Hello");
@@ -68,36 +69,36 @@ static void add_two_and_complete_returns_second(void)
     char *result1 = autocomplete_complete(ac, "Hel");
     char *result2 = autocomplete_complete(ac, result1);
 
-    assert_string_equals("Help", result2);
+    assert_string_equal("Help", result2);
 
     autocomplete_clear(ac);
 }
 
-static void add_two_adds_two(void)
+void add_two_adds_two(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_add(ac, "Hello");
     autocomplete_add(ac, "Help");
     GSList *result = autocomplete_get_list(ac);
 
-    assert_int_equals(2, g_slist_length(result));
+    assert_int_equal(2, g_slist_length(result));
 
     autocomplete_clear(ac);
 }
 
-static void add_two_same_adds_one(void)
+void add_two_same_adds_one(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_add(ac, "Hello");
     autocomplete_add(ac, "Hello");
     GSList *result = autocomplete_get_list(ac);
 
-    assert_int_equals(1, g_slist_length(result));
+    assert_int_equal(1, g_slist_length(result));
 
     autocomplete_clear(ac);
 }
 
-static void add_two_same_updates(void)
+void add_two_same_updates(void **state)
 {
     Autocomplete ac = autocomplete_new();
     autocomplete_add(ac, "Hello");
@@ -108,22 +109,7 @@ static void add_two_same_updates(void)
 
     char *str = first->data;
 
-    assert_string_equals("Hello", str);
+    assert_string_equal("Hello", str);
 
     autocomplete_clear(ac);
 }
-
-void register_autocomplete_tests(void)
-{
-    TEST_MODULE("autocomplete tests");
-    TEST(clear_empty);
-    TEST(reset_after_create);
-    TEST(find_after_create);
-    TEST(get_after_create_returns_null);
-    TEST(add_one_and_complete);
-    TEST(add_two_and_complete_returns_first);
-    TEST(add_two_and_complete_returns_second);
-    TEST(add_two_adds_two);
-    TEST(add_two_same_adds_one);
-    TEST(add_two_same_updates);
-}
diff --git a/tests/testsuite.c b/tests/testsuite.c
index b12bacd5..6215b761 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -3,6 +3,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 
+#include "test_autocomplete.h"
 #include "test_common.h"
 #include "test_command.h"
 
@@ -41,7 +42,18 @@ int main(int argc, char* argv[]) {
         unit_test(next_available_9_in_first_gap),
         unit_test(next_available_0_in_first_gap),
         unit_test(next_available_11_in_first_gap),
-        unit_test(next_available_24_first_big_gap)
-    };
+        unit_test(next_available_24_first_big_gap),
+
+        unit_test(clear_empty),
+        unit_test(reset_after_create),
+        unit_test(find_after_create),
+        unit_test(get_after_create_returns_null),
+        unit_test(add_one_and_complete),
+        unit_test(add_two_and_complete_returns_first),
+        unit_test(add_two_and_complete_returns_second),
+        unit_test(add_two_adds_two),
+        unit_test(add_two_same_adds_one),
+        unit_test(add_two_same_updates)
+     };
     return run_tests(tests);
 }