[Ruburple-submits] [19] trunk/ruburple: much more thorough tests, and methods to support it
nobody at rubyforge.org
nobody at rubyforge.org
Mon May 7 04:36:25 EDT 2007
Revision: 19
Author: zond
Date: 2007-05-07 04:36:24 -0400 (Mon, 07 May 2007)
Log Message:
-----------
much more thorough tests, and methods to support it
Modified Paths:
--------------
trunk/ruburple/ext/ruburple_ext.c
trunk/ruburple/tests/ruburple_test.rb
trunk/ruburple/tests/test_accounts.rb.template
Modified: trunk/ruburple/ext/ruburple_ext.c
===================================================================
--- trunk/ruburple/ext/ruburple_ext.c 2007-05-06 22:40:09 UTC (rev 18)
+++ trunk/ruburple/ext/ruburple_ext.c 2007-05-07 08:36:24 UTC (rev 19)
@@ -55,10 +55,13 @@
static VALUE rb_ruburple_protocol_account_savedstatus;
static VALUE rb_ruburple_protocol_connection;
static VALUE rb_ruburple_blist_status;
+static VALUE rb_ruburple_blist_presence;
static VALUE rb_ruburple_blist;
static VALUE rb_ruburple_blist_buddy_icon;
static VALUE rb_ruburple_blist_buddy;
static VALUE rb_ruburple_blist_node;
+static VALUE rb_ruburple_blist_contact;
+static VALUE rb_ruburple_blist_chat;
static VALUE rb_ruburple_blist_group;
static VALUE rb_ruburple_handle;
static VALUE rb_ruburple_cipher;
@@ -112,6 +115,7 @@
#define RB_RUBURPLE_PLUGIN(purple_plugin_pointer) Data_Wrap_Struct(rb_ruburple_plugin, NULL, NULL, purple_plugin_pointer)
#define RB_RUBURPLE_PROTOCOL_INFO(purple_plugin_info_pointer) Data_Wrap_Struct(rb_ruburple_protocol_info, NULL, NULL, purple_plugin_info_pointer)
#define RB_RUBURPLE_BLIST_STATUS(purple_status_pointer) Data_Wrap_Struct(rb_ruburple_blist_status, NULL, NULL, purple_status_pointer)
+#define RB_RUBURPLE_BLIST_PRESENCE(purple_presence_pointer) Data_Wrap_Struct(rb_ruburple_blist_presence, NULL, NULL, purple_presence_pointer)
#define RB_RUBURPLE_BLIST(purple_blist_pointer) Data_Wrap_Struct(rb_ruburple_blist, NULL, NULL, purple_blist_pointer)
#define RB_RUBURPLE_BLIST_BUDDY(purple_buddy_pointer) Data_Wrap_Struct(rb_ruburple_blist_buddy, NULL, NULL, purple_buddy_pointer)
#define RB_RUBURPLE_BLIST_NODE(purple_blist_node_pointer) Data_Wrap_Struct(rb_ruburple_blist_node, NULL, NULL, purple_blist_node_pointer)
@@ -136,6 +140,9 @@
#define PURPLE_SAVEDSTATUS(rb_ruburple_protocol_account_savedstatus,purple_saved_status_pointer) Data_Get_Struct(rb_ruburple_protocol_account_savedstatus, PurpleSavedStatus, purple_saved_status_pointer)
#define RUBURPLE_SIGNAL_HANDLER(rb_ruburple_subscription,ruburple_signal_handler_pointer) Data_Get_Struct(rb_ruburple_subscription, RuburpleSignalHandler, ruburple_signal_handler_pointer)
#define PURPLE_CONNECTION(rb_ruburple_protocol_connection,purple_connection_pointer) Data_Get_Struct(rb_ruburple_protocol_connection, PurpleConnection, purple_connection_pointer)
+#define PURPLE_BUDDY(rb_ruburple_blist_buddy,purple_buddy_pointer) Data_Get_Struct(rb_ruburple_blist_buddy, PurpleBuddy, purple_buddy_pointer)
+#define PURPLE_PRESENCE(rb_ruburple_blist_presence,purple_presence_pointer) Data_Get_Struct(rb_ruburple_blist_presence, PurplePresence, purple_presence_pointer)
+#define PURPLE_STATUS(rb_ruburple_blist_status,purple_status_pointer) Data_Get_Struct(rb_ruburple_blist_status, PurpleStatus, purple_status_pointer)
#define GPOINTER(rb_ruburple_pointer,gpointer) Data_Get_Struct(rb_ruburple_pointer, void, gpointer)
/*
@@ -685,26 +692,6 @@
}
static gpointer
-ruburple_protocol_account_set_alias(gpointer data)
-{
- gpointer *args = (gpointer *) data;
- purple_account_set_alias((PurpleAccount *) args[0], (char *) args[1]);
- return NULL;
-}
-
-static VALUE
-rb_ruburple_protocol_account_set_alias(VALUE self, VALUE alias)
-{
- gpointer args[2];
- PurpleAccount *account;
- PURPLE_ACCOUNT(self, account);
- args[0] = (gpointer) account;
- args[1] = (gpointer) RSTRING(alias)->ptr;
- call_and_get_result(ruburple_protocol_account_set_alias, args);
- return Qnil;
-}
-
-static gpointer
ruburple_protocol_account_set_savedstatus(gpointer data)
{
gpointer *args = (gpointer *) data;
@@ -1231,6 +1218,143 @@
return RB_RUBURPLE_PROTOCOL_ACCOUNT((PurpleAccount *) call_and_get_result(ruburple_protocol_connection_get_account, (gpointer) plugin));
}
+static gpointer
+ruburple_protocol_account_get_buddy(gpointer data)
+{
+ gpointer *args = (gpointer *) data;
+ return purple_find_buddy((PurpleAccount *) args[0], (char *) args[1]);
+}
+
+static VALUE
+rb_ruburple_protocol_account_has_buddy(VALUE self, VALUE name)
+{
+ PurpleAccount *account;
+ gpointer args[2];
+ PurpleBuddy *buddy;
+ PURPLE_ACCOUNT(self, account);
+ args[0] = (gpointer) account;
+ args[1] = (gpointer) RSTRING(name)->ptr;
+ buddy = (PurpleBuddy *) call_and_get_result(ruburple_protocol_account_get_buddy, args);
+ return buddy == NULL ? Qfalse : Qtrue;
+}
+
+static VALUE
+rb_ruburple_protocol_account_get_buddy(VALUE self, VALUE name)
+{
+ PurpleAccount *account;
+ gpointer args[2];
+ PurpleBuddy *buddy;
+ PURPLE_ACCOUNT(self, account);
+ args[0] = (gpointer) account;
+ args[1] = (gpointer) RSTRING(name)->ptr;
+ buddy = (PurpleBuddy *) call_and_get_result(ruburple_protocol_account_get_buddy, args);
+ RETURN_QNIL_IF_NULL(buddy);
+ return RB_RUBURPLE_BLIST_BUDDY(buddy);
+}
+
+static gpointer
+ruburple_protocol_account_get_buddies(gpointer data)
+{
+ gpointer *args = (gpointer *) data;
+ return purple_find_buddies((PurpleAccount *) args[0], (char *) args[1]);
+}
+
+static VALUE
+rb_ruburple_protocol_account_get_buddies(int argc, VALUE *argv, VALUE self)
+{
+ PurpleAccount *account;
+ GList *iter;
+ VALUE return_value = rb_ary_new();
+ gpointer args[2];
+
+ PURPLE_ACCOUNT(self, account);
+ args[0] = (gpointer) account;
+ if (argc > 1)
+ rb_raise(rb_eRuntimeError, "Ruburple::Protocol::Account#buddies(USERNAME = nil) takes at most 1 argument");
+ else if (argc == 1)
+ args[1] = RSTRING(argv[0])->ptr;
+ else
+ args[1] = NULL;
+
+ for (iter = (GList *) call_and_get_result(ruburple_protocol_account_get_buddies, args); iter; iter = iter->next) {
+ rb_ary_push(return_value, RB_RUBURPLE_BLIST_BUDDY(iter->data));
+ }
+
+ return return_value;
+}
+
+static gpointer
+ruburple_blist_buddy_get_account(gpointer data)
+{
+ return (gpointer) purple_buddy_get_account((PurpleBuddy *) data);
+}
+
+static VALUE
+rb_ruburple_blist_buddy_get_account(VALUE self)
+{
+ PurpleBuddy *buddy;
+ PURPLE_BUDDY(self, buddy);
+ return RB_RUBURPLE_PROTOCOL_ACCOUNT((PurpleAccount *) call_and_get_result(ruburple_blist_buddy_get_account, (gpointer) buddy));
+}
+
+static gpointer
+ruburple_blist_buddy_get_name(gpointer data)
+{
+ return (gpointer) purple_buddy_get_name((PurpleBuddy *) data);
+}
+
+static VALUE
+rb_ruburple_blist_buddy_get_name(VALUE self)
+{
+ PurpleBuddy *buddy;
+ PURPLE_BUDDY(self, buddy);
+ return rb_str_new2((char *) call_and_get_result(ruburple_blist_buddy_get_name, (gpointer) buddy));
+}
+
+static gpointer
+ruburple_blist_buddy_get_presence(gpointer data)
+{
+ return (gpointer) purple_buddy_get_presence((PurpleBuddy *) data);
+}
+
+static VALUE
+rb_ruburple_blist_buddy_get_presence(VALUE self)
+{
+ PurpleBuddy *buddy;
+ PURPLE_BUDDY(self, buddy);
+ return RB_RUBURPLE_BLIST_PRESENCE((PurplePresence *) call_and_get_result(ruburple_blist_buddy_get_presence, (gpointer) buddy));
+}
+
+static gpointer
+ruburple_blist_presence_get_active_status(gpointer data)
+{
+ PurplePresence *presence = (PurplePresence *) data;
+ return purple_presence_get_active_status(presence);
+}
+
+static VALUE
+rb_ruburple_blist_presence_get_active_status(VALUE self)
+{
+ PurplePresence *presence;
+ PURPLE_PRESENCE(self, presence);
+ return RB_RUBURPLE_BLIST_STATUS((PurpleStatus *) call_and_get_result(ruburple_blist_presence_get_active_status, (gpointer) presence));
+}
+
+static gpointer
+ruburple_blist_status_get_name(gpointer data)
+{
+ PurpleStatus *status = (PurpleStatus *) data;
+ return (gpointer) purple_status_get_name(status);
+}
+
+static VALUE
+rb_ruburple_blist_status_get_name(VALUE self)
+{
+ PurpleStatus *status;
+ PURPLE_STATUS(self, status);
+ return rb_str_new2((char *) call_and_get_result(ruburple_blist_status_get_name, (gpointer) status));
+}
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -1323,7 +1447,9 @@
rb_define_method(rb_ruburple_protocol_account, "username", rb_ruburple_protocol_account_get_username, 0);
rb_define_method(rb_ruburple_protocol_account, "password", rb_ruburple_protocol_account_get_password, 0);
rb_define_method(rb_ruburple_protocol_account, "alias", rb_ruburple_protocol_account_get_alias, 0);
- rb_define_method(rb_ruburple_protocol_account, "alias=", rb_ruburple_protocol_account_set_alias, 1);
+ rb_define_method(rb_ruburple_protocol_account, "has_buddy?", rb_ruburple_protocol_account_has_buddy, 1);
+ rb_define_method(rb_ruburple_protocol_account, "get_buddy", rb_ruburple_protocol_account_get_buddy, 1);
+ rb_define_method(rb_ruburple_protocol_account, "buddies", rb_ruburple_protocol_account_get_buddies, -1);
rb_ruburple_protocol_account_conversation = rb_define_class_under(rb_ruburple_protocol_account, "Conversation", rb_cObject);
@@ -1334,6 +1460,7 @@
rb_ruburple_blist = rb_define_class_under(rb_ruburple, "BuddyList", rb_cObject);
rb_ruburple_blist_status = rb_define_class_under(rb_ruburple_blist, "Status", rb_cObject);
+ rb_define_method(rb_ruburple_blist_status, "name", rb_ruburple_blist_status_get_name, 0);
rb_define_const(rb_ruburple_blist_status, "STATUS_UNSET", INT2NUM(PURPLE_STATUS_UNSET));
rb_define_const(rb_ruburple_blist_status, "STATUS_OFFLINE", INT2NUM(PURPLE_STATUS_OFFLINE));
rb_define_const(rb_ruburple_blist_status, "STATUS_AVAILABLE", INT2NUM(PURPLE_STATUS_AVAILABLE));
@@ -1352,10 +1479,20 @@
rb_ruburple_blist_node = rb_define_class_under(rb_ruburple_blist, "Node", rb_cObject);
- rb_ruburple_blist_buddy = rb_define_class_under(rb_ruburple_blist, "Buddy", rb_cObject);
+ rb_ruburple_blist_buddy = rb_define_class_under(rb_ruburple_blist, "Buddy", rb_ruburple_blist_node);
+ rb_define_method(rb_ruburple_blist_buddy, "account", rb_ruburple_blist_buddy_get_account, 0);
+ rb_define_method(rb_ruburple_blist_buddy, "name", rb_ruburple_blist_buddy_get_name, 0);
+ rb_define_method(rb_ruburple_blist_buddy, "presence", rb_ruburple_blist_buddy_get_presence, 0);
- rb_ruburple_blist_group = rb_define_class_under(rb_ruburple_blist, "Group", rb_cObject);
+ rb_ruburple_blist_presence = rb_define_class_under(rb_ruburple_blist, "Presence", rb_cObject);
+ rb_define_method(rb_ruburple_blist_presence, "active_status", rb_ruburple_blist_presence_get_active_status, 0);
+ rb_ruburple_blist_group = rb_define_class_under(rb_ruburple_blist, "Group", rb_ruburple_blist_node);
+
+ rb_ruburple_blist_contact = rb_define_class_under(rb_ruburple_blist, "Contact", rb_ruburple_blist_node);
+
+ rb_ruburple_blist_chat = rb_define_class_under(rb_ruburple_blist, "Chat", rb_ruburple_blist_node);
+
rb_ruburple_blist_buddy_icon = rb_define_class_under(rb_ruburple_blist, "BuddyIcon", rb_cObject);
rb_ruburple_handle = rb_define_class_under(rb_ruburple, "Handle", rb_cObject);
Modified: trunk/ruburple/tests/ruburple_test.rb
===================================================================
--- trunk/ruburple/tests/ruburple_test.rb 2007-05-06 22:40:09 UTC (rev 18)
+++ trunk/ruburple/tests/ruburple_test.rb 2007-05-07 08:36:24 UTC (rev 19)
@@ -10,7 +10,9 @@
@@events = {}
+ puts "testing init..."
Ruburple::init
+ puts "testing subscribe..."
Ruburple::subscribe(:signed_on, (Proc.new do |c|
puts "got signed_on from #{c.account.username}"
@@events[:signed_on] << c
@@ -27,29 +29,52 @@
}
end
- def test_msn
- test_operations("MSN")
+ def test_protocols
+ $TEST_ACCOUNTS.keys.each do |key|
+ test_operations(key)
+ end
end
private
def test_operations(protocol)
+ puts "testing #{protocol}..."
test_accounts = $TEST_ACCOUNTS[protocol]
p = Ruburple::get_protocol(protocol)
+ puts "testing sign on..."
a1 = p.get_account(test_accounts.first.username, test_accounts.first.password)
+ a2 = p.get_account(test_accounts.last.username, test_accounts.last.password)
a1.connect
- a2 = p.get_account(test_accounts.last.username, test_accounts.last.password)
+ assert_within(30) do
+ @@events[:signed_on].find do |e|
+ e.account.username == a1.username
+ end
+ end
+ puts "testing buddies..."
+ assert(a1.has_buddy?(a2.username))
+ assert(buddy2 = a1.buddies.find do |b|
+ b.name == a2.username
+ end)
+ puts "testing presence..."
+ assert_equal("Offline", buddy2.presence.active_status.name)
a2.connect
- puts "testing sign on..."
assert_within(30) do
- a1_signed_on = @@events[:signed_on].find do |e|
- e.account.username == test_accounts.first.username
+ @@events[:signed_on].find do |e|
+ e.account.username == a2.username
end
- a2_signed_on = @@events[:signed_on].find do |e|
- e.account.username == test_accounts.last.username
- end
- a1_signed_on && a2_signed_on
end
+ puts "testing buddies..."
+ assert(a2.has_buddy?(a1.username))
+ assert(buddy1 = a2.buddies.find do |b|
+ b.name == a1.username
+ end)
+ puts "testing presence..."
+ assert_within(30) do
+ buddy1.presence.active_status.name == "Available"
+ end
+ assert_within(30) do
+ buddy2.presence.active_status.name == "Available"
+ end
puts "testing send im..."
a1.connection.send_im(a2.username, "hello a2")
a2.connection.send_im(a1.username, "hello a1")
@@ -62,6 +87,14 @@
end
a1_got_message && a2_got_message
end
+ puts "testing close..."
+ a1.connection.close
+ puts "testing presence..."
+ assert_within(30) do
+ buddy1.presence.active_status.name == "Offline"
+ end
+ puts "testing close..."
+ a2.connection.close
end
Modified: trunk/ruburple/tests/test_accounts.rb.template
===================================================================
--- trunk/ruburple/tests/test_accounts.rb.template 2007-05-06 22:40:09 UTC (rev 18)
+++ trunk/ruburple/tests/test_accounts.rb.template 2007-05-07 08:36:24 UTC (rev 19)
@@ -1,4 +1,7 @@
+#
+# These accounts should be on each others buddy lists for the tests to run.
+#
$TEST_ACCOUNTS = {
"MSN" => [
TestAccount.new("MSN", "some at msn.account", "some_msn_password"),
More information about the Ruburple-submits
mailing list