summaryrefslogtreecommitdiff
path: root/tools/iap/ipod-001-general.t
diff options
context:
space:
mode:
Diffstat (limited to 'tools/iap/ipod-001-general.t')
-rw-r--r--tools/iap/ipod-001-general.t133
1 files changed, 133 insertions, 0 deletions
diff --git a/tools/iap/ipod-001-general.t b/tools/iap/ipod-001-general.t
new file mode 100644
index 0000000000..f2b5451dbc
--- /dev/null
+++ b/tools/iap/ipod-001-general.t
@@ -0,0 +1,133 @@
1use Test::More qw( no_plan );
2use strict;
3
4BEGIN { use_ok('Device::iPod'); }
5require_ok('Device::iPod');
6
7my $ipod = Device::iPod->new();
8my $m;
9my ($l, $c, $p);
10
11isa_ok($ipod, 'Device::iPod');
12
13$ipod->{-debug} = 1;
14$ipod->open("/dev/ttyUSB0");
15
16$m = $ipod->sendraw("\xFF" x 16); # Wake up and sync
17ok($m == 1, "Wakeup sent");
18
19# Empty the buffer
20$ipod->emptyrecv();
21
22# Send a command with wrong checksum
23# We expect no response (Timeout)
24$m = $ipod->sendraw("\xff\x55\x02\x00\x03\x00");
25ok($m == 1, "Broken checksum sent");
26($l, $c, $p) = $ipod->recvmsg();
27subtest "Timeout" => sub {
28 ok(!defined($l), "No response received");
29 like($ipod->error(), '/Timeout/', "Timeout reading response");
30};
31
32# Empty the buffer
33$ipod->emptyrecv();
34
35# Send a too short command
36# We expect an ACK Bad Parameter as response
37$m = $ipod->sendmsg(0x00, 0x13, "");
38ok($m == 1, "Short command sent");
39($l, $c, $p) = $ipod->recvmsg();
40subtest "ACK Bad Parameter" => sub {
41 ok(defined($l), "Response received");
42 is($l, 0x00, "Response lingo");
43 is($c, 0x02, "Response command");
44 is($p, "\x04\x13", "Response payload");
45};
46
47# Empty the buffer
48$ipod->emptyrecv();
49
50# Send an undefined lingo
51# We expect a timeout
52$m = $ipod->sendmsg(0x1F, 0x00);
53ok($m == 1, "Undefined lingo sent");
54($l, $c, $p) = $ipod->recvmsg();
55subtest "Timeout" => sub {
56 ok(!defined($l), "No response received");
57 like($ipod->error(), '/Timeout/', "Timeout reading response");
58};
59
60# Empty the buffer
61$ipod->emptyrecv();
62
63# IdentifyDeviceLingoes(lingos=0x80000011, options=0x00, deviceid=0x00)
64# We expect an ACK Command Failed message as response
65$m = $ipod->sendmsg(0x00, 0x13, "\x80\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x00");
66ok($m == 1, "IdentifyDeviceLingoes(lingos=0x80000011, options=0x00, deviceid=0x00) sent");
67($l, $c, $p) = $ipod->recvmsg();
68subtest "ACK Command Failed" => sub {
69 ok(defined($l), "Response received");
70 is($l, 0x00, "Response lingo");
71 is($c, 0x02, "Response command");
72 is($p, "\x02\x13", "Response payload");
73};
74
75# Empty the buffer
76$ipod->emptyrecv();
77
78# Identify(lingo=0xFF)
79# We expect no response (timeout)
80$m = $ipod->sendmsg(0x00, 0x01, "\xFF");
81ok($m == 1, "Identify(lingo=0xFF) sent");
82($l, $c, $p) = $ipod->recvmsg();
83subtest "Timeout" => sub {
84 ok(!defined($l), "No response received");
85 like($ipod->error(), '/Timeout/', "Timeout reading response");
86};
87
88# Empty the buffer
89$ipod->emptyrecv();
90
91# IdentifyDeviceLingoes(lingos=0x10, options=0x00, deviceid=0x00)
92# We expect an ACK Command Failed message as response
93$m = $ipod->sendmsg(0x00, 0x13, "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00");
94ok($m == 1, "IdentifyDeviceLingoes(lingos=0x10, options=0x00, deviceid=0x00) sent");
95($l, $c, $p) = $ipod->recvmsg();
96subtest "ACK Command Failed" => sub {
97 ok(defined($l), "Response received");
98 is($l, 0x00, "Response lingo");
99 is($c, 0x02, "Response command");
100 is($p, "\x02\x13", "Response payload");
101};
102
103# Empty the buffer
104$ipod->emptyrecv();
105# IdentifyDeviceLingoes(lingos=0x00, options=0x00, deviceid=0x00)
106# We expect an ACK Command Failed message as response
107$m = $ipod->sendmsg(0x00, 0x13, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
108ok($m == 1, "IdentifyDeviceLingoes(lingos=0x00, options=0x00, deviceid=0x00) sent");
109($l, $c, $p) = $ipod->recvmsg();
110subtest "ACK Command Failed" => sub {
111 ok(defined($l), "Response received");
112 is($l, 0x00, "Response lingo");
113 is($c, 0x02, "Response command");
114 is($p, "\x02\x13", "Response payload");
115};
116
117# Empty the buffer
118$ipod->emptyrecv();
119
120# RequestLingoProtocolVersion(lingo=0xFF)
121# We expect an ACK Bad Parameter message as response
122$m = $ipod->sendmsg(0x00, 0x0F, "\xFF");
123ok($m == 1, "RequestLingoProtocolVersion(lingo=0xFF) sent");
124($l, $c, $p) = $ipod->recvmsg();
125subtest "ACK Bad Parameter" => sub {
126 ok(defined($l), "Response received");
127 is($l, 0x00, "Response lingo");
128 is($c, 0x02, "Response command");
129 is($p, "\x04\x0F", "Response payload");
130};
131
132# Empty the buffer
133$ipod->emptyrecv();