summaryrefslogtreecommitdiff
path: root/tools/iap/device-ipod.t
diff options
context:
space:
mode:
authorRalf Ertzinger <rockbox@camperquake.de>2013-06-22 10:08:23 +0100
committerFrank Gevaerts <frank@gevaerts.be>2013-11-10 18:41:24 +0100
commitb170c73f922e3457b923b4e7fcbec794a8885c77 (patch)
tree89fbdbd8c25af5101a29a1ede3b896332a4e205c /tools/iap/device-ipod.t
parent500b137308a6ee5c2aba873734a8956d70472f56 (diff)
downloadrockbox-b170c73f922e3457b923b4e7fcbec794a8885c77.tar.gz
rockbox-b170c73f922e3457b923b4e7fcbec794a8885c77.zip
Updated IAP commands.
Originally written and uploaded by Lalufu (Ralf Ertzinger) in Feb 2012. They have been condensed into a single patch and some further additions by Andy Potter. Currently includes Authentication V2 support from iPod to Accessory, RF/BlueTooth transmitter support, selecting a playlist and selecting a track from the current playlist. Does not support uploading Album Art or podcasts. Has been tested on the following iPods, 4th Gen Grayscale, 4th Gen Color/Photo, Mini 2nd Gen, Nano 1st Gen and Video 5.5Gen. Change-Id: Ie8fc098361844132f0228ecbe3c48da948726f5e Co-Authored by: Andy Potter <liveboxandy@gmail.com> Reviewed-on: http://gerrit.rockbox.org/533 Reviewed-by: Frank Gevaerts <frank@gevaerts.be>
Diffstat (limited to 'tools/iap/device-ipod.t')
-rw-r--r--tools/iap/device-ipod.t74
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 @@
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# Frame a short command
14$m = $ipod->_frame_cmd("\x00\x02\x00\x06");
15ok(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);
19ok(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);
23ok(!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");
27ok(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");
31ok(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");
35ok(!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");
39ok(!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");
43ok(!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");
47ok(!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");
51ok(!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();
56ok(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();
61ok(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();
66subtest "First message" => sub {
67 ok(defined($m), "Message received");
68 is($m, "\xffU\x04\x00\x02\x00\x13\xe7");
69};
70$m = $ipod->_message();
71subtest "Second message" => sub {
72 ok(defined($m), "Message received");
73 is($m, "\xffU\x02\x00\x14\xea");
74};