X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=test%2Ftest_main.rb;h=817b59fbb6859784a04d0f2a4d8ad2a46afff5b6;hb=de09557fdbeb5648cc66ea5fca28b3d769003ee8;hp=da3621cc3ef3c159164ea2d811775a6ac9bca0dd;hpb=310e91e26bebf168b6081e91da123b4a8cfb9b67;p=ruby-vorbistagger.git diff --git a/test/test_main.rb b/test/test_main.rb index da3621c..817b59f 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 @@ -206,4 +214,90 @@ EOF b["artist"] = "Foo" assert_equal(-1, a <=> b) end + + def test_modify_existing_key + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + assert_raises(TypeError) do + t.comments.keys.first.replace("new") + end + end + end + + def test_modify_added_key + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + t.comments["Foo"] = "Bar" + + assert_raises(TypeError) do + t.comments.keys.last.replace("new") + 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_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