Reworked output file writing.
[ruby-vorbistagger.git] / test / test_main.rb
index ae30dedcb9d54e8c833a2986a668bb0bca469723..21c4edf662f5ec5056088a63fb5363876a860aa7 100644 (file)
@@ -1,7 +1,6 @@
 require "test/unit"
 require "ogg/vorbis/tagger"
 require "fileutils"
-require "stringio"
 require "open3"
 
 class MainTest < Test::Unit::TestCase
@@ -12,7 +11,7 @@ class MainTest < Test::Unit::TestCase
 -c "artist=Bolt Thrower" -c "album=...For Victory" -c "date=1994"
 EOF
 
-               @ogg_buf = StringIO.new
+               f = File.open(OGG_FILE, "w")
                cmd = "oggenc -q 0 #{tmp.strip} -r -"
 
                Open3.popen3(cmd) do |sin, sout, _|
@@ -21,19 +20,19 @@ EOF
 
                        begin
                                tmp = sout.read
-                               @ogg_buf << tmp
+                               f << tmp
                        end while !tmp.length.zero?
                end
 
-               @ogg_buf.seek(0)
+               f.close
        end
 
        def teardown
-               @ogg_buf.close
+               FileUtils.rm_f(OGG_FILE)
        end
 
        def test_read
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        # make sure the keys are returned in the correct order
                        assert_equal(["artist", "album", "date"], t.comments.keys)
                        assert_equal(["Bolt Thrower", "...For Victory", "1994"],
@@ -49,72 +48,62 @@ EOF
        end
 
        def test_write_stable_order
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert_equal(3, t.write)
                end
 
-               @ogg_buf.seek(0)
-
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert_equal(["artist", "album", "date"], t.comments.keys)
                end
        end
 
        def test_write_stable_order_change
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        t.comments["artist"] = "Ballista"
                        assert_equal(3, t.write)
                end
 
-               @ogg_buf.seek(0)
-
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert_equal(["artist", "album", "date"], t.comments.keys)
                end
        end
 
        def test_append
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        t.comments["genre"] = "Death Metal"
                        assert_equal(4, t.write)
                end
 
-               @ogg_buf.seek(0)
-
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert_equal("Death Metal", t.comments["genre"])
                end
        end
 
        def test_delete
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert_equal("...For Victory", t.comments.delete("album"))
                        assert_nil(t.comments.delete("foo"))
                        assert_equal(2, t.write)
                end
 
-               @ogg_buf.seek(0)
-
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert_equal(["artist", "date"], t.comments.keys)
                end
        end
 
        def test_clear
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        t.comments.clear
                        assert_equal(0, t.write)
                end
 
-               @ogg_buf.seek(0)
-
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert(t.comments.empty?)
                end
        end
 
        def test_empty
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert(!t.comments.empty?)
 
                        t.comments.delete("artist")
@@ -124,15 +113,13 @@ EOF
                        assert_equal(0, t.write)
                end
 
-               @ogg_buf.seek(0)
-
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert(t.comments.empty?)
                end
        end
 
        def test_each
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        a = {
                                "artist" => "Bolt Thrower",
                                "album" => "...For Victory",
@@ -149,7 +136,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 +148,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 +160,7 @@ EOF
        end
 
        def test_inspect
-               Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        tmp=<<EOF
 {"artist"=>"Bolt Thrower", "album"=>"...For Victory", "date"=>"1994"}
 EOF
@@ -182,7 +169,7 @@ 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"))
 
@@ -196,13 +183,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
 
@@ -212,7 +197,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
@@ -220,7 +205,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