File: 03-test_connectivity.t

package info (click to toggle)
libnet-jabber-bot-perl 2.1.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 276 kB
  • sloc: perl: 1,279; makefile: 2; sh: 1
file content (52 lines) | stat: -rw-r--r-- 1,914 bytes parent folder | download
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
#!perl -T

BEGIN {
    use Test::More;

    # Author tests - requires Config::Std
    plan skip_all => "\$ENV{AUTHOR_TESTING} required for these tests" if(!$ENV{AUTHOR_TESTING});
    eval "use Config::Std";
    plan skip_all => "Optional Module Config::Std Required for these tests" if($@);
}

use Net::Jabber::Bot;
use Log::Log4perl qw(:easy);
use Test::NoWarnings;  # This breaks the skips in CPAN.
# Otherwise it's 7 tests
plan tests => 7;

# Load config file.
use Config::Std; # Uses read_config to pull info from a config files. enhanced INI format.
my $config_file = 't/test_config.cfg';
my %config_file_hash;
ok((read_config($config_file => %config_file_hash)), "Load config file")
    or die("Can't test without config file $config_file");

my $alias = 'make_test_bot';
my $loop_sleep_time = 5;
my $server_info_timeout = 5;

my %forums_and_responses;
$forums_and_responses{$config_file_hash{'main'}{'test_forum1'}} = ["jbot:", ""];
$forums_and_responses{$config_file_hash{'main'}{'test_forum2'}} = ["notjbot:"];

my $bot = Net::Jabber::Bot->new(
    server => $config_file_hash{'main'}{'server'}
    , conference_server => $config_file_hash{'main'}{'conference'}
    , port => $config_file_hash{'main'}{'port'}
    , username => $config_file_hash{'main'}{'username'}
    , password => $config_file_hash{'main'}{'password'}
    , alias => $alias
    , forums_and_responses => \%forums_and_responses
    );

isa_ok($bot, "Net::Jabber::Bot");

ok(defined $bot->Process(), "Bot connected to server");
sleep 5;
ok($bot->Disconnect() > 0, "Bot successfully disconnects"); # Disconnects
is($bot->Disconnect(), undef,  "Bot fails to disconnect cause it already is"); # If already disconnected, we get a negative number

eval{Net::Jabber::Bot->Disconnect()};
like($@, qr/^\QCan't use string ("Net::Jabber::Bot") as a HASH ref while "strict refs" in use\E/, "Error when trying to disconnect not as an object");