aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-01-21 22:17:11 +0100
committerJelmer Vernooij <jelmer@samba.org>2007-01-21 22:17:11 +0100
commited5df815732d311b228993627f5d8b8c8e3eb4e0 (patch)
tree1f5c4963491914f8efbcdf2838ff2cb716e89267 /tests
parent7bee5af91e56f1e58232b895fd40c367aec67e8a (diff)
Add unit testing for user code
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile2
-rw-r--r--tests/check.c14
-rw-r--r--tests/check_user.c75
-rw-r--r--tests/testsuite.h1
4 files changed, 91 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 3ddd1570..b9da83c9 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -10,7 +10,7 @@ clean:
main_objs = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o storage_text.o user.o
-test_objs = check.o check_util.o check_nick.o check_md5.o check_irc.o check_help.o
+test_objs = check.o check_util.o check_nick.o check_md5.o check_irc.o check_help.o check_user.o
check: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o
@echo '*' Linking $@
diff --git a/tests/check.c b/tests/check.c
index 069b3c57..9fee07e3 100644
--- a/tests/check.c
+++ b/tests/check.c
@@ -20,6 +20,16 @@ gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2)
return TRUE;
}
+irc_t *torture_irc(void)
+{
+ irc_t *irc;
+ GIOChannel *ch1, *ch2;
+ if (!g_io_channel_pair(&ch1, &ch2))
+ return NULL;
+ irc = irc_new(g_io_channel_unix_get_fd(ch1));
+ return irc;
+}
+
double gettime()
{
struct timeval time[1];
@@ -43,6 +53,9 @@ Suite *irc_suite(void);
/* From check_help.c */
Suite *help_suite(void);
+/* From check_user.c */
+Suite *user_suite(void);
+
int main (int argc, char **argv)
{
int nf;
@@ -84,6 +97,7 @@ int main (int argc, char **argv)
srunner_add_suite(sr, md5_suite());
srunner_add_suite(sr, irc_suite());
srunner_add_suite(sr, help_suite());
+ srunner_add_suite(sr, user_suite());
if (no_fork)
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL);
diff --git a/tests/check_user.c b/tests/check_user.c
new file mode 100644
index 00000000..79248049
--- /dev/null
+++ b/tests/check_user.c
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <glib.h>
+#include <gmodule.h>
+#include <check.h>
+#include <string.h>
+#include "bitlbee.h"
+#include "user.h"
+#include "testsuite.h"
+
+START_TEST(test_user_add)
+ irc_t *irc = torture_irc();
+ user_t *user;
+ user = user_add(irc, "foo");
+ fail_if(user == NULL);
+ fail_if(strcmp(user->nick, "foo") != 0);
+ fail_unless(user_find(irc, "foo") == user);
+END_TEST
+
+START_TEST(test_user_add_exists)
+ irc_t *irc = torture_irc();
+ user_t *user;
+ user = user_add(irc, "foo");
+ fail_if(user == NULL);
+ user = user_add(irc, "foo");
+ fail_unless(user == NULL);
+END_TEST
+
+START_TEST(test_user_add_invalid)
+ irc_t *irc = torture_irc();
+ user_t *user;
+ user = user_add(irc, ":foo");
+ fail_unless(user == NULL);
+END_TEST
+
+START_TEST(test_user_del_invalid)
+ irc_t *irc = torture_irc();
+ fail_unless(user_del(irc, ":foo") == 0);
+END_TEST
+
+START_TEST(test_user_del)
+ irc_t *irc = torture_irc();
+ user_t *user;
+ user = user_add(irc, "foo");
+ fail_unless(user_del(irc, "foo") == 1);
+ fail_unless(user_find(irc, "foo") == NULL);
+END_TEST
+
+START_TEST(test_user_del_nonexistant)
+ irc_t *irc = torture_irc();
+ fail_unless(user_del(irc, "foo") == 0);
+END_TEST
+
+START_TEST(test_user_rename)
+ irc_t *irc = torture_irc();
+ user_t *user;
+ user = user_add(irc, "foo");
+ user_rename(irc, "foo", "bar");
+ fail_unless(user_find(irc, "foo") == NULL);
+ fail_if(user_find(irc, "bar") == NULL);
+END_TEST
+
+Suite *user_suite (void)
+{
+ Suite *s = suite_create("User");
+ TCase *tc_core = tcase_create("Core");
+ suite_add_tcase (s, tc_core);
+ tcase_add_test (tc_core, test_user_add);
+ tcase_add_test (tc_core, test_user_add_invalid);
+ tcase_add_test (tc_core, test_user_add_exists);
+ tcase_add_test (tc_core, test_user_del_invalid);
+ tcase_add_test (tc_core, test_user_del_nonexistant);
+ tcase_add_test (tc_core, test_user_del);
+ tcase_add_test (tc_core, test_user_rename);
+ return s;
+}
diff --git a/tests/testsuite.h b/tests/testsuite.h
index dacaf8a3..79227041 100644
--- a/tests/testsuite.h
+++ b/tests/testsuite.h
@@ -1,6 +1,7 @@
#ifndef __BITLBEE_CHECK_H__
#define __BITLBEE_CHECK_H__
+irc_t *torture_irc(void);
gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2);
#endif /* __BITLBEE_CHECK_H__ */