Added two tests that ensure that writing comments doesn't corrupt files.
[ruby-vorbistagger.git] / test / test_main.rb
index 3003783554337a3bd3b2b05722ea3d29d414038a..bbc5b0023a2987e31af883c4573dde96f4605dd5 100644 (file)
@@ -1,6 +1,7 @@
 require "test/unit"
 require "ogg/vorbis/tagger"
 require "fileutils"
+require "digest/md5"
 
 class MainTest < Test::Unit::TestCase
        OGG_FILE = "test/test.ogg"
@@ -29,6 +30,32 @@ class MainTest < Test::Unit::TestCase
                end
        end
 
+       def test_write_is_non_destructive
+               a = Digest::MD5.hexdigest(File.read(OGG_FILE))
+
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
+                       t.write
+               end
+
+               b = Digest::MD5.hexdigest(File.read(OGG_FILE))
+
+               assert_equal(a, b)
+       end
+
+       def test_multiple_writes
+               a = Digest::MD5.hexdigest(File.read(OGG_FILE))
+
+               Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
+                       1.upto(10) do
+                               t.write
+                       end
+               end
+
+               b = Digest::MD5.hexdigest(File.read(OGG_FILE))
+
+               assert_equal(a, b)
+       end
+
        def test_write_stable_order
                Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
                        assert_equal(3, t.write)