diff options
Diffstat (limited to 'tools/iap/device-ipod.t')
-rw-r--r-- | tools/iap/device-ipod.t | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tools/iap/device-ipod.t b/tools/iap/device-ipod.t new file mode 100644 index 0000000000..607184e331 --- /dev/null +++ b/tools/iap/device-ipod.t | |||
@@ -0,0 +1,74 @@ | |||
1 | use Test::More qw( no_plan ); | ||
2 | use strict; | ||
3 | |||
4 | BEGIN { use_ok('Device::iPod'); } | ||
5 | require_ok('Device::iPod'); | ||
6 | |||
7 | my $ipod = Device::iPod->new(); | ||
8 | my $m; | ||
9 | my ($l, $c, $p); | ||
10 | |||
11 | isa_ok($ipod, 'Device::iPod'); | ||
12 | |||
13 | # Frame a short command | ||
14 | $m = $ipod->_frame_cmd("\x00\x02\x00\x06"); | ||
15 | ok(defined($m) && ($m eq "\xFF\x55\x04\x00\x02\x00\x06\xF4"), "Framed command valid"); | ||
16 | |||
17 | # Frame a long command | ||
18 | $m = $ipod->_frame_cmd("\x00" x 1024); | ||
19 | ok(defined($m) && ($m eq "\xFF\x55\x00\x04\x00" . ("\x00" x 1024) . "\xFC"), "Long framed command valid"); | ||
20 | |||
21 | # Frame an overly long command | ||
22 | $m = $ipod->_frame_cmd("\x00" x 65537); | ||
23 | ok(!defined($m) && ($ipod->error() =~ 'Command too long'), "Overly long command failed"); | ||
24 | |||
25 | # Unframe a short command | ||
26 | ($l, $c, $p) = $ipod->_unframe_cmd("\xFF\x55\x04\x00\x02\x00\x06\xF4"); | ||
27 | ok(defined($l) && ($l == 0x00) && ($c == 0x02) && ($p eq "\x00\x06"), "Unframed short command"); | ||
28 | |||
29 | # Unframe a long command | ||
30 | ($l, $c, $p) = $ipod->_unframe_cmd("\xFF\x55\x00\x04\x00" . ("\x00" x 1024) . "\xFC"); | ||
31 | ok(defined($l) && ($l == 0x00) && ($c == 0x00) && ($p eq "\x00" x 1022), "Unframed long command"); | ||
32 | |||
33 | # Frame without sync byte | ||
34 | ($l, $c, $p) = $ipod->_unframe_cmd("\x00"); | ||
35 | ok(!defined($l) && ($ipod->error() =~ /Could not unframe data/), "Frame without sync byte failed"); | ||
36 | |||
37 | # Frame without SOP byte | ||
38 | ($l, $c, $p) = $ipod->_unframe_cmd("\xFF"); | ||
39 | ok(!defined($l) && ($ipod->error() =~ /Could not unframe data/), "Frame without SOP byte failed"); | ||
40 | |||
41 | # Frame with length 0 | ||
42 | ($l, $c, $p) = $ipod->_unframe_cmd("\xFF\x55\x00\x00\x00"); | ||
43 | ok(!defined($l) && ($ipod->error() =~ /Length is 0/), "Frame with length 0 failed"); | ||
44 | |||
45 | # Too short frame | ||
46 | ($l, $c, $p) = $ipod->_unframe_cmd("\xFF\x55\x03\x00\x00"); | ||
47 | ok(!defined($l) && ($ipod->error() =~ /Could not unframe data/), "Too short frame failed"); | ||
48 | |||
49 | # Invalid checksum | ||
50 | ($l, $c, $p) = $ipod->_unframe_cmd("\xFF\x55\x03\x00\x00\x00\x00"); | ||
51 | ok(!defined($l) && ($ipod->error() =~ /Invalid checksum/), "Invalid checksum failed"); | ||
52 | |||
53 | # Find a message in a string | ||
54 | $ipod->{-inbuf} = "\x00\xFF\x55\x00\xFF\xFF\xFF\x55\x04\x00\x02\x00\x06\xF4"; | ||
55 | ($c, $l) = $ipod->_message_in_buffer(); | ||
56 | ok(defined($l) && ($c == 6) && ($l == 8), "Found message in buffer"); | ||
57 | |||
58 | # Return message from a string | ||
59 | $ipod->{-inbuf} = "\x00\xFF\x55\x00\xFF\xFF\xFF\x55\x04\x00\x02\x00\x06\xF4\x00"; | ||
60 | $m = $ipod->_message(); | ||
61 | ok(defined($m) && ($ipod->{-inbuf} eq "\x00"), "Retrieved message from buffer"); | ||
62 | |||
63 | # Return two messages from buffer | ||
64 | $ipod->{-inbuf} = "\xffU\x04\x00\x02\x00\x13\xe7\xffU\x02\x00\x14\xea"; | ||
65 | $m = $ipod->_message(); | ||
66 | subtest "First message" => sub { | ||
67 | ok(defined($m), "Message received"); | ||
68 | is($m, "\xffU\x04\x00\x02\x00\x13\xe7"); | ||
69 | }; | ||
70 | $m = $ipod->_message(); | ||
71 | subtest "Second message" => sub { | ||
72 | ok(defined($m), "Message received"); | ||
73 | is($m, "\xffU\x02\x00\x14\xea"); | ||
74 | }; | ||