/
socialskk-protocol.t
51 lines (43 loc) · 1.84 KB
/
socialskk-protocol.t
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
package Test::App::SocialSKK::Protocol;
use lib 't/lib';
use App::SocialSKK::Test;
use App::SocialSKK::Protocol;
sub startup : Test(startup) {
my $self = shift;
$self->module = App::SocialSKK::Protocol->new({
on_get_candidates => \&on_get_candidates,
on_get_version => \&on_get_version,
on_get_serverinfo => \&on_get_serverinfo,
});
}
sub accept : Tests {
my $self = shift;
desc 'When accept() called:' => sub {
it 'if request is get_candidates, on_get_candidates event is fired.';
is $self->module->accept('1foo bar'), 'on_get_candidates', spec;
it 'if request is get_serverinfo, on_get_version event is fired.';
is $self->module->accept('2'), 'on_get_version', spec;
it 'if request is get_serverinfo, on_get_serverinfo event is fired.';
is $self->module->accept('3'), 'on_get_serverinfo', spec;
it 'if request is incorrect, undef is returned.';
ok !$self->module->accept('9unknown request'), spec;
};
}
sub dispatch : Tests {
my $self = shift;
desc 'When dispatch() called:' => sub {
it 'if code is 1, on_get_candidates event is fired.';
is $self->module->dispatch(1, 'on_get_candidates()'), 'on_get_candidates', spec;
it 'if code is 2, on_get_version event is fired.';
is $self->module->dispatch(2, 'on_get_version()'), 'on_get_version', spec;
it 'if code is 3, on_get_serverinfo event is fired.';
is $self->module->dispatch(3, 'on_get_serverinfo()'), 'on_get_serverinfo', spec;
it 'if code doesnt match any code, undef is returned.';
ok !$self->module->dispatch(9, 'doesnt match any event'), spec;
};
}
sub on_get_candidates { 'on_get_candidates' }
sub on_get_version { 'on_get_version' }
sub on_get_serverinfo { 'on_get_serverinfo' }
__PACKAGE__->runtests;
1;