Added a sample Ogg Vorbis file, so we don't depend on oggenc in the tests.
[ruby-vorbistagger.git] / test / test_main.rb
index 21c4edf662f5ec5056088a63fb5363876a860aa7..3003783554337a3bd3b2b05722ea3d29d414038a 100644 (file)
@@ -1,30 +1,12 @@
 require "test/unit"
 require "ogg/vorbis/tagger"
 require "fileutils"
-require "open3"
 
 class MainTest < Test::Unit::TestCase
        OGG_FILE = "test/test.ogg"
 
        def setup
-               tmp =<<EOF
--c "artist=Bolt Thrower" -c "album=...For Victory" -c "date=1994"
-EOF
-
-               f = File.open(OGG_FILE, "w")
-               cmd = "oggenc -q 0 #{tmp.strip} -r -"
-
-               Open3.popen3(cmd) do |sin, sout, _|
-                       sin.write("\0\0\0\0")
-                       sin.close
-
-                       begin
-                               tmp = sout.read
-                               f << tmp
-                       end while !tmp.length.zero?
-               end
-
-               f.close
+               FileUtils.cp("test/sample.ogg", OGG_FILE)
        end
 
        def teardown
@@ -213,4 +195,34 @@ 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_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
 end