libgaim/plugins/perl/scripts/account.pl

Mon, 04 Dec 2006 04:52:46 +0000

author
Daniel Atallah <datallah@pidgin.im>
date
Mon, 04 Dec 2006 04:52:46 +0000
changeset 15166
8febc283dead
parent 14254
77edc7a6191a
child 20470
77693555855f
permissions
-rw-r--r--

[gaim-migrate @ 17890]
Fix up some of the example perl plugins. They still could use some work, but these will at least load now.

11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
1 $MODULE_NAME = "Account Functions 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.",
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
11 description => "Implements a set of test proccedures to ensure all " .
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
12 "functions that work in the C API still work in the " .
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
13 "Perl plugin interface. As XSUBs are added, this " .
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
14 "*should* be updated to test the changes. " .
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
15 "Furthermore, this will function as the tutorial perl " .
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
16 "plugin.",
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
17 author => "John H. Kelm <johnhkelm\@gmail.com>",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
18 url => "http://sourceforge.net/users/johnhkelm/",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
19
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
20 load => "plugin_load",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
21 unload => "plugin_unload"
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
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
24
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
25 # These names must already exist
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
26 my $USERNAME = "johnhkelm2";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
27
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
28 # We will create these on load then destroy them on unload
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
29 my $TEST_NAME = "perlTestName";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
30 my $PROTOCOL_ID = "prpl-oscar";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
31
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
32
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
33 sub plugin_init {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
34 return %PLUGIN_INFO;
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
35 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
36
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
37
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
38 # 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
39 # 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
40 sub plugin_load {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
41 my $plugin = shift;
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
42 print "#" x 80 . "\n\n";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
43 Gaim::Debug::info($MODULE_NAME, "plugin_load() - Testing $MODULE_NAME Started.");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
44 print "\n\n";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
45
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
46
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
47 #################################
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
48 # #
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
49 # Gaim::Account::Option #
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
50 # #
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
51 #################################
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
52
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
53 print "Testing: Gaim::Account::Option::new()...\n";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
54 $acc_opt = Gaim::Account::Option->new(1, "TEXT", "pref_name");
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
55 $acc_opt2 = Gaim::Account::Option->bool_new("TeXt", "MYprefName", 1);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
56
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
57 #################################
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
58 # #
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
59 # Gaim::Account #
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
60 # #
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
61 #################################
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
62
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
63
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
64 print "Testing: Gaim::Account::new()... ";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
65 $account = Gaim::Account->new($TEST_NAME, $PROTOCOL_ID);
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
66 if ($account) { print "ok.\n"; } else { print "fail.\n"; }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
67
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
68 print "Testing: Gaim::Accounts::add()...";
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
69 Gaim::Accounts::add($account);
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
70 print "pending find...\n";
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
71
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
72 print "Testing: Gaim::Accounts::find()...";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
73 $account = Gaim::Accounts::find($TEST_NAME, $PROTOCOL_ID);
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
74 if ($account) { print "ok.\n"; } else { print "fail.\n"; }
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
75
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
76 print "Testing: Gaim::Account::get_username()... ";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
77 $user_name = $account->get_username();
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
78 if ($user_name) {
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
79 print "Success: $user_name.\n";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
80 } else {
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
81 print "Failed!\n";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
82 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
83
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
84 print "Testing: Gaim::Account::is_connected()... ";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
85 if ($account->is_connected()) {
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
86 print " Connected.\n";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
87 } else {
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
88 print " Disconnected.\n";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
89 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
90
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
91 print "Testing: Gaim::Accounts::get_active_status()... ";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
92 if ($account->get_active_status()) {
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
93 print "Okay.\n";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
94 } else {
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
95 print "Failed!\n";
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
96 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
97
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
98 $account = Gaim::Accounts::find($USERNAME, $PROTOCOL_ID);
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
99 print "Testing: Gaim::Accounts::connect()...pending...\n";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
100
12364
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
101 $account->set_status("available", TRUE);
42b44fed7423 [gaim-migrate @ 14668]
Will Thompson <resiak@pidgin.im>
parents: 11457
diff changeset
102 $account->connect();
11170
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 print "\n\n";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
105 Gaim::Debug::info($MODULE_NAME, "plugin_load() - Testing $MODULE_NAME Completed.\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
106 print "\n\n" . "#" x 80 . "\n\n";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
107 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
108
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
109 sub plugin_unload {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
110 my $plugin = shift;
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
111
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
112 print "#" x 80 . "\n\n";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
113 Gaim::Debug::info($MODULE_NAME, "plugin_unload() - Testing $MODULE_NAME Started.\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
114 print "\n\n";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
115
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
116 ######### TEST CODE HERE ##########
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
117
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
118 print "\n\n";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
119 Gaim::Debug::info($MODULE_NAME, "plugin_unload() - Testing $MODULE_NAME Completed.\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
120 print "\n\n" . "#" x 80 . "\n\n";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
121 }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
122

mercurial