X-Git-Url: http://git.code-monkey.de/?p=ruby-vorbistagger.git;a=blobdiff_plain;f=test%2Ftest_main.rb;h=fe622e674a70fd2e1517f595023c40ffc370b04f;hp=5c6457b8c54a181fff35c680428767f5f9b3f440;hb=HEAD;hpb=023eb2d385346cfbcc1ac21d5428e88a042df1f9 diff --git a/test/test_main.rb b/test/test_main.rb index 5c6457b..fe622e6 100644 --- a/test/test_main.rb +++ b/test/test_main.rb @@ -1,39 +1,21 @@ require "test/unit" require "ogg/vorbis/tagger" require "fileutils" -require "stringio" -require "open3" +require "digest/md5" class MainTest < Test::Unit::TestCase OGG_FILE = "test/test.ogg" def setup - tmp =< "Bolt Thrower", "album" => "...For Victory", @@ -149,7 +155,7 @@ EOF end def test_each_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| b = [] t.comments.each_key do |k| @@ -161,7 +167,7 @@ EOF end def test_each_value - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| b = [] t.comments.each_value do |v| @@ -173,7 +179,7 @@ EOF end def test_inspect - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| tmp=<"Bolt Thrower", "album"=>"...For Victory", "date"=>"1994"} EOF @@ -182,9 +188,13 @@ EOF end def test_has_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| assert(t.comments.has_key?("artist")) assert(!t.comments.has_key?("foo")) + + assert(t.comments.key?("artist")) + assert(t.comments.include?("artist")) + assert(t.comments.member?("artist")) end end @@ -192,13 +202,11 @@ EOF a = nil b = nil - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| a = t.comments end - @ogg_buf.seek(0) - - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| b = t.comments end @@ -208,7 +216,7 @@ EOF end def test_modify_existing_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| assert_raises(TypeError) do t.comments.keys.first.replace("new") end @@ -216,7 +224,7 @@ EOF end def test_modify_added_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| t.comments["Foo"] = "Bar" assert_raises(TypeError) do @@ -224,4 +232,80 @@ EOF end end end + + def test_merge + repl = { + "artist" => "Ballista", + "genre" => "Death Metal", + } + + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + t.comments.merge!(repl) + + assert_equal(["artist", "album", "date", "genre"], + t.comments.keys) + assert_equal(["Ballista", "...For Victory", "1994", + "Death Metal"], + t.comments.values) + end + end + + def test_merge_bad_arg + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + assert_raises(ArgumentError) do + t.comments.merge!(42) + end + end + end + + def test_shift + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + assert_equal(["artist", "Bolt Thrower"], t.comments.shift) + assert_equal(["album", "...For Victory"], t.comments.shift) + assert_equal(["date", "1994"], t.comments.shift) + assert_equal(nil, t.comments.shift) + end + end + + def test_close + Ogg::Vorbis::Tagger.new(OGG_FILE).close + end + + def test_close2 + t = Ogg::Vorbis::Tagger.new(OGG_FILE) + t.close + + assert_raise(Ogg::Vorbis::Tagger::ClosedStreamError) do + t.close + end + + assert_raise(Ogg::Vorbis::Tagger::ClosedStreamError) do + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + t.close + end + end + end + + def test_open_non_existing_file + assert_raises(Ogg::Vorbis::Tagger::OpenError) do + Ogg::Vorbis::Tagger.new("foo.bar") + end + end + + def test_open_non_ogg_file + File.open("test/foo.bar", "w") do |f| + f << "foobarbazxyzzy" + end + + assert_raises(Ogg::Vorbis::Tagger::InvalidDataError) do + Ogg::Vorbis::Tagger.new("test/foo.bar") + end + ensure + FileUtils.rm_f("test/foo.bar") + end + + def test_standalone_comments_object + o = Ogg::Vorbis::Comments.new + assert_equal(o.length, 0); + end end