1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#!/usr/bin/perl
use Filter::Template;
const PCJx POE::Component::Jabber
use warnings;
use strict;
use Test::More tests => 29;
use POE;
BEGIN
{
use_ok('PCJx');
use_ok('PCJx::Error');
use_ok('PCJx::Status');
use_ok('PCJx::ProtocolFactory');
}
sub test_new_pcj_fail
{
my ($name, @args) = @_;
eval { PCJx->new(@args); };
ok($@ ne '', $name);
}
sub test_new_pcj_succeed
{
my ($name, @args) = @_;
eval { PCJx->new(@args); };
ok($@ eq '', $name);
}
# Lets start by testing constants
can_ok('PCJx::Error',
qw/PCJ_SOCKETFAIL PCJ_SOCKETDISCONNECT PCJ_AUTHFAIL PCJ_BINDFAIL
PCJ_SESSIONFAIL PCJ_SSLFAIL PCJ_CONNECTFAIL/);
can_ok('PCJx::Status',
qw/ PCJ_CONNECT PCJ_CONNECTING PCJ_CONNECTED PCJ_STREAMSTART
PCJ_SSLNEGOTIATE PCJ_SSLSUCCESS PCJ_AUTHNEGOTIATE PCJ_AUTHSUCCESS
PCJ_BINDNEGOTIATE PCJ_BINDSUCCESS PCJ_SESSIONNEGOTIATE PCJ_SESSIONSUCCESS
PCJ_RECONNECT PCJ_NODESENT PCJ_NODERECEIVED PCJ_NODEQUEUED PCJ_RTS_START
PCJ_RTS_FINISH PCJ_INIT_FINISHED PCJ_STREAMEND PCJ_SHUTDOWN_START
PCJ_SHUTDOWN_FINISH /);
can_ok('PCJx::ProtocolFactory',
qw/ JABBERD14_COMPONENT JABBERD20_COMPONENT LEGACY XMPP /);
#now lets test ProtocolFactory
my $guts = PCJx::ProtocolFactory::get_guts(+XMPP);
isa_ok($guts, 'PCJx::XMPP');
isa_ok($guts, 'PCJx::Protocol');
$guts = PCJx::ProtocolFactory::get_guts(+LEGACY);
isa_ok($guts, 'PCJx::Legacy');
isa_ok($guts, 'PCJx::Protocol');
$guts = PCJx::ProtocolFactory::get_guts(+JABBERD14_COMPONENT);
isa_ok($guts, 'PCJx::J14');
isa_ok($guts, 'PCJx::Protocol');
$guts = PCJx::ProtocolFactory::get_guts(+JABBERD20_COMPONENT);
isa_ok($guts, 'PCJx::J2');
isa_ok($guts, 'PCJx::Protocol');
#now lets test constructing PCJ
my $config =
{
IP => 'jabber.org',
Port => '5222',
Hostname => 'jabber.org',
Username => 'PCJTester',
Password => 'PCJTester',
ConnectionType => +XMPP,
States => {
StatusEvent => 'status_event',
InputEvent => 'input_event',
ErrorEvent => 'error_event',
}
};
my $scratch_space = {};
test_new_pcj_fail('No current session', %{$config});
POE::Session->create
(
'inline_states' =>
{
'_start' =>
sub
{
$_[KERNEL]->alias_set('basic_testing');
$_[KERNEL]->yield('continue');
$_[HEAP] = $config;
},
'continue' =>
sub
{
test_new_pcj_fail('No arguments');
my @keys = keys(%{$_[HEAP]});
foreach my $key (@keys)
{
my %hash = %{$_[HEAP]};
delete($hash{$key});
test_new_pcj_fail('No ' . $key, %hash);
}
my %hash = %{$_[HEAP]};
$hash{'ConnectionType'} = 12983;
test_new_pcj_fail('Invalid ConnectionType', %hash);
test_new_pcj_succeed('Correct construction XMPP', %{$_[HEAP]});
$hash{'ConnectionType'} = +LEGACY;
test_new_pcj_succeed('Correct construction LEGACY', %hash);
$hash{'ConnectionType'} = +JABBERD14_COMPONENT;
test_new_pcj_succeed('Correct construction J14', %hash);
$hash{'ConnectionType'} = +JABBERD20_COMPONENT;
test_new_pcj_succeed('Correct construction J2', %hash);
},
}
);
POE::Kernel->run();
exit 1;
|