From 4b29f098adfaa900dc7c293163eb914f6725d800 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 9 Sep 2013 04:12:28 +0000 Subject: tracklist: preliminary tracklist class This should allow us to eventually implement a MPRIS 2.0-compliant tracklist. --- test/test_tracklist.rb | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/test_tracklist.rb (limited to 'test') diff --git a/test/test_tracklist.rb b/test/test_tracklist.rb new file mode 100644 index 0000000..cc462c5 --- /dev/null +++ b/test/test_tracklist.rb @@ -0,0 +1,75 @@ +# Copyright (C) 2013, Eric Wong and all contributors +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require_relative 'helper' +require 'dtas/tracklist' +class TestTracklist < Testcase + def test_tl_add_tracks + tl = DTAS::Tracklist.new + tl.add_track("/foo.flac") + assert_equal(%w(/foo.flac), tl.instance_variable_get(:@list)) + + oids = tl.tracks + assert_kind_of Array, oids + assert_equal 1, oids.size + assert_equal [ [ oids[0], "/foo.flac" ] ], tl.get_tracks(oids) + + tl.add_track("/bar.flac") + assert_equal(%w(/bar.flac /foo.flac), tl.instance_variable_get(:@list)) + + tl.add_track("/after.flac", oids[0]) + assert_equal(%w(/bar.flac /foo.flac /after.flac), + tl.instance_variable_get(:@list)) + end + + def test_add_current + tl = DTAS::Tracklist.new + tl.instance_variable_get(:@list).replace(%w(a b c d e f g)) + tl.add_track('/foo.flac', nil, true) + assert_equal '/foo.flac', tl.cur_track + end + + def test_next_track + tl = DTAS::Tracklist.new + tl.instance_variable_get(:@list).replace(%w(a b c d e f g)) + %w(a b c d e f g).each do |t| + assert_equal t, tl.next_track + end + assert_nil tl.next_track + tl.repeat = true + assert_equal 'a', tl.next_track + end + + def _build_mapping(tl) + tracks = tl.get_tracks(tl.tracks) + Hash[tracks.map { |(oid,name)| [ name, oid ] }] + end + + def test_goto + tl = DTAS::Tracklist.new + tl.instance_variable_get(:@list).replace(%w(a b c d e f g)) + mapping = _build_mapping(tl) + assert_equal 'f', tl.go_to(mapping['f']) + assert_nil tl.go_to(1 << 128) + assert_equal 'g', tl.next_track + end + + def test_remove_track + tl = DTAS::Tracklist.new + tl.instance_variable_get(:@list).replace(%w(a b c d e f g)) + mapping = _build_mapping(tl) + %w(a b c d e f g).each { |t| assert_kind_of Integer, mapping[t] } + + tl.remove_track(mapping['a']) + assert_equal %w(b c d e f g), tl.instance_variable_get(:@list) + + tl.remove_track(mapping['d']) + assert_equal %w(b c e f g), tl.instance_variable_get(:@list) + + tl.remove_track(mapping['g']) + assert_equal %w(b c e f), tl.instance_variable_get(:@list) + + # it'll be a while before OIDs require >128 bits, right? + tl.remove_track(1 << 128) + assert_equal %w(b c e f), tl.instance_variable_get(:@list), "no change" + end +end -- cgit v1.2.3-24-ge0c7