libgaim/plugins/perl/scripts/buddy_list.pl

Wed, 12 Nov 2008 05:14:03 +0000

author
Richard Laager <rlaager@pidgin.im>
date
Wed, 12 Nov 2008 05:14:03 +0000
branch
gaim
changeset 20471
1966704b3e42
parent 11457
plugins/perl/scripts/buddy_list.pl@e787f1445e64
parent 20470
plugins/perl/scripts/buddy_list.pl@77693555855f
permissions
-rw-r--r--

merge of '77693555855fe9cd3215414f79964dba346cc5fa'
and '19a87e98e5857ad0289f2c760d460f7f1dbbb42d'

11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
1 $MODULE_NAME = "Buddy List Test";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
2
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
3 use Gaim;
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
4
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
5 # All the information Gaim gets about our nifty plugin
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
6 %PLUGIN_INFO = (
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
7 perl_api_version => 2,
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
8 name => "Perl: $MODULE_NAME",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
9 version => "0.1",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
10 summary => "Test plugin for the Perl interpreter.",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
11 description => "Implements a set of test proccedures to ensure all functions that work in the C API still work in the Perl plugin interface. As XSUBs are added, this *should* be updated to test the changes. Furthermore, this will function as the tutorial perl plugin.",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
12 author => "John H. Kelm <johnhkelm\@gmail.com>",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
13 url => "http://sourceforge.net/users/johnhkelm/",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
14
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
15 load => "plugin_load",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
16 unload => "plugin_unload"
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
17 );
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
18
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
19
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
20 # These names must already exist
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
21 my $USERNAME = "johnhkelm2";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
22
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
23 # We will create these on load then destroy them on unload
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
24 my $TEST_GROUP = "UConn Buddies";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
25 my $TEST_NAME = "johnhkelm";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
26 my $TEST_ALIAS = "John Kelm";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
27 my $PROTOCOL_ID = "prpl-oscar";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
28
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
29
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
30 sub plugin_init {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
31 return %PLUGIN_INFO;
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
32 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
33
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
34
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
35 # This is the sub defined in %PLUGIN_INFO to be called when the plugin is loaded
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
36 # Note: The plugin has a reference to itself on top of the argument stack.
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
37 sub plugin_load {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
38 my $plugin = shift;
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
39
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
40 # This is how we get an account to use in the following tests. You should replace the username
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
41 # with an existing user
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
42 $account = Gaim::Accounts::find($USERNAME, $PROTOCOL_ID);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
43
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
44 # Testing a find function: Note Gaim::Find not Gaim::Buddy:find!
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
45 # Furthermore, this should work the same for chats and groups
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
46 Gaim::Debug::info($MODULE_NAME, "Testing: Gaim::Find::buddy()...");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
47 $buddy = Gaim::Find::buddy($account, $TEST_NAME);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
48 Gaim::Debug::info("", ($buddy ? "ok." : "fail.") . "\n");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
49
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
50 # If you should need the handle for some reason, here is how you do it
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
51 Gaim::Debug::info($MODULE_NAME, "Testing: Gaim::BuddyList::get_handle()...");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
52 $handle = Gaim::BuddyList::get_handle();
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
53 Gaim::Debug::info("", ($handle ? "ok." : "fail.") . "\n");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
54
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
55 # This gets the Gaim::BuddyList and references it by $blist
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
56 Gaim::Debug::info($MODULE_NAME, "Testing: Gaim::get_blist()...");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
57 $blist = Gaim::get_blist();
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
58 Gaim::Debug::info("", ($blist ? "ok." : "fail.") . "\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
59
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
60 # This is how you would add a buddy named $TEST_NAME" with the alias $TEST_ALIAS
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
61 Gaim::Debug::info($MODULE_NAME, "Testing: Gaim::BuddyList::Buddy::new...");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
62 $buddy = Gaim::BuddyList::Buddy::new($account, $TEST_NAME, $TEST_ALIAS);
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
63 Gaim::Debug::info("", ($buddy ? "ok." : "fail.") . "\n");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
64
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
65 # Here we add the new buddy '$buddy' to the group $TEST_GROUP
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
66 # so first we must find the group
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
67 Gaim::Debug::info($MODULE_NAME, "Testing: Gaim::Find::group...");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
68 $group = Gaim::Find::group($TEST_GROUP);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
69 Gaim::Debug::info("", ($group ? "ok." : "fail.") . "\n");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
70
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
71 # To add the buddy we need to have the buddy, contact, group and node for insertion.
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
72 # For this example we can let contact be undef and set the insertion node as the group
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
73 Gaim::Debug::info($MODULE_NAME, "Testing: Gaim::BuddyList::add_buddy...\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
74 Gaim::BuddyList::add_buddy($buddy, undef, $group, $group);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
75
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
76 # The example that follows gives an indication of how an API call that returns a list is handled.
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
77 # In this case the buddies of the account found earlier are retrieved and put in an array '@buddy_array'
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
78 # Further down an accessor method is used, 'get_name()' -- see source for details on the full set of methods
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
79 Gaim::Debug::info($MODULE_NAME, "Testing: Gaim::Find::buddies...\n");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
80 @buddy_array = Gaim::Find::buddies($account, undef);
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
81 if (@buddy_array) {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
82 Gaim::Debug::info($MODULE_NAME, "Buddies in list (" . @buddy_array . "): \n");
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
83 foreach $bud (@buddy_array) {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
84 Gaim::Debug::info($MODULE_NAME, Gaim::BuddyList::Buddy::get_name($bud) . "\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
85 }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
86 }
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
87 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
88
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
89 sub plugin_unload {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
90 my $plugin = shift;
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
91
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
92 print "#" x 80 . "\n\n";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
93 ######### TEST CODE HERE ##########
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
94
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
95 print "Testing: Gaim::Find::buddy()...";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
96 $buddy = Gaim::Find::buddy($account, $TEST_NAME . TEST);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
97 if ($buddy) {
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
98 print "ok.\n";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
99 print "Testing: Gaim::BuddyList::remove_buddy()...";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
100 Gaim::BuddyList::remove_buddy($buddy);
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
101 if (Gaim::Find::buddy($account, $TEST_NAME . TEST)) { print "fail.\n"; } else { print "ok.\n"; }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
102 } else { print "fail.\n"; }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
103
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
104
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
105 print "\n\n" . "#" x 80 . "\n\n";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
106 }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
107

mercurial