annotate plugins/perl/scripts/conversation.pl @ 13253:87a7c3077c19

[gaim-migrate @ 15619] More cleaning up of oscar. Renamed some functions to be more clear. Got rid of some stuff that wasn't used. Inlined some small things in conn.c that were only used once. The goals of all this are 1. Non-blocking I/O for all connections 2. p2p stuff won't use the same struct as oscar connections, because that's stupid 3. The oscar PRPL should be less scary committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 12 Feb 2006 21:27:04 +0000
parents 6fd82071a7b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
1 $MODULE_NAME = "Conversation Test";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
2
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
3 use Gaim;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
4
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
5 # All the information Gaim gets about our nifty plugin
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
6 %PLUGIN_INFO = (
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
7 perl_api_version => 2,
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
8 name => "Perl: $MODULE_NAME",
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
9 version => "0.1",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
10 summary => "Test plugin for the Perl interpreter.",
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
11 description => "Implements a set of test proccedures to ensure all " .
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
12 "functions that work in the C API still work in the " .
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
13 "Perl plugin interface. As XSUBs are added, this " .
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
14 "*should* be updated to test the changes. " .
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
15 "Furthermore, this will function as the tutorial perl " .
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
16 "plugin.",
11457
4d9686e7c234 [gaim-migrate @ 13696]
Richard Laager <rlaager@wiktel.com>
parents: 11170
diff changeset
17 author => "John H. Kelm <johnhkelm\@gmail.com>",
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
18 url => "http://sourceforge.net/users/johnhkelm/",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
19
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
20 load => "plugin_load",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
21 unload => "plugin_unload"
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
22 );
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
23
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
24
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
25 # These names must already exist
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
26 my $GROUP = "UIUC Buddies";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
27 my $USERNAME = "johnhkelm2";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
28
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
29 # We will create these on load then destroy them on unload
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
30 my $TEST_GROUP = "UConn Buddies";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
31 my $TEST_NAME = "johnhkelm";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
32 my $TEST_ALIAS = "John Kelm";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
33 my $PROTOCOL_ID = "prpl-oscar";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
34
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
35
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
36 sub plugin_init {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
37 return %PLUGIN_INFO;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
38 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
39
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
40
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
41 # This is the sub defined in %PLUGIN_INFO to be called when the plugin is loaded
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
42 # Note: The plugin has a reference to itself on top of the argument stack.
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
43 sub plugin_load {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
44 my $plugin = shift;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
45 print "#" x 80 . "\n\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
46
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
47 print "PERL: Finding account.\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
48 $account = Gaim::Accounts::find($USERNAME, $PROTOCOL_ID);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
49
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
50 ######### TEST CODE HERE ##########
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
51 # First we create two new conversations.
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
52 print "Testing Gaim::Conversation::new()...";
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
53 $conv1 = Gaim::Conversation->new(1, $account, "Test Conversation 1");
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
54 if ($conv1) { print "ok.\n"; } else { print "fail.\n"; }
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
55
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
56 print "Testing Gaim::Conversation::new()...";
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
57 $conv2 = Gaim::Conversation->new(1, $account, "Test Conversation 2");
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
58 if ($conv2) { print "ok.\n"; } else { print "fail.\n"; }
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
59
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
60 # Second we create a window to display the conversations in.
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
61 # Note that the package here is Gaim::Conversation::Window
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
62 print "Testing Gaim::Conversation::Window::new()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
63 $win = Gaim::Conversation::Window::new();
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
64
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
65 # The third thing to do is to add the two conversations to the windows.
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
66 # The subroutine add_conversation() returns the number of conversations
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
67 # present in the window.
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
68 print "Testing Gaim::Conversation::Window::add_conversation()...";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
69 $conv_count = $conv1->add_conversation();
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
70 if ($conv_count) {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
71 print "ok..." . $conv_count . " conversations...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
72 } else {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
73 print "fail.\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
74 }
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
75
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
76 print "Testing Gaim::Conversation::Window::add_conversation()...";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
77 $conv_count = $win->add_conversation($conv2);
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
78 if ($conv_count) {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
79 print "ok..." . $conv_count . " conversations...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
80 } else {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
81 print "fail.\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
82 }
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
83
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
84 # Now the window is displayed to the user.
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
85 print "Testing Gaim::Conversation::Window::show()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
86 $win->show();
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
87
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
88 # Use get_im_data() to get a handle for the conversation
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
89 print "Testing Gaim::Conversation::get_im_data()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
90 $im = $conv1->get_im_data();
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
91 if ($im) { print "ok.\n"; } else { print "fail.\n"; }
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
92
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
93 # Here we send messages to the conversation
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
94 print "Testing Gaim::Conversation::IM::send()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
95 $im->send("Message Test.");
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
96
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
97 print "Testing Gaim::Conversation::IM::write()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
98 $im->write("SENDER", "<b>Message</b> Test.", 0, 0);
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
99
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
100 print "#" x 80 . "\n\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
101 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
102
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
103 sub plugin_unload {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
104 my $plugin = shift;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
105
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
106 print "#" x 80 . "\n\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
107 ######### TEST CODE HERE ##########
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
108
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
109 print "Testing Gaim::Conversation::Window::get_conversation_count()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
110 $conv_count = $win->get_conversation_count();
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
111 print "...and it returned $conv_count.\n";
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
112 if ($conv_count > 0) {
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
113 print "Testing Gaim::Conversation::Window::destroy()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11457
diff changeset
114 $win->destroy();
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
115 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
116
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
117 print "\n\n" . "#" x 80 . "\n\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
118 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
119