File: 06notifier-mixin.t

package info (click to toggle)
libio-async-perl 0.51-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,052 kB
  • sloc: perl: 11,110; makefile: 8
file content (47 lines) | stat: -rw-r--r-- 1,088 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
#!/usr/bin/perl -w

use strict;

use Test::More tests => 9;
use Test::Refcount;

use IO::Async::Loop;

my $loop = IO::Async::Loop->new;

is_refcount( $loop, 2, '$loop has refcount 2 initially' );

my $notifier = SomeEventSource::Async->new;
my $in_loop;

isa_ok( $notifier, "SomeEventSource",     '$notifier isa SomeEventSource' );
isa_ok( $notifier, "IO::Async::Notifier", '$notifier isa IO::Async::Notifier' );

$loop->add( $notifier );

is_refcount( $loop, 2, '$loop has refcount 2 adding Notifier' );
is_refcount( $notifier, 2, '$notifier has refcount 2 after adding to Loop' );

is( $notifier->loop, $loop, 'loop $loop' );

ok( $in_loop, 'SomeEventSource::Async added to Loop' );

$loop->remove( $notifier );

is( $notifier->loop, undef, '$notifier->loop is undef' );

ok( !$in_loop, 'SomeEventSource::Async removed from Loop' );

package SomeEventSource;

sub new
{
   my $class = shift;
   return bless {}, $class;
}

package SomeEventSource::Async;
use base qw( SomeEventSource IO::Async::Notifier );

sub _add_to_loop      { $in_loop = 1 }
sub _remove_from_loop { $in_loop = 0 }