2 require "ogg/vorbis/tagger"
6 class MainTest < Test::Unit::TestCase
7 OGG_FILE = "test/test.ogg"
10 FileUtils.cp("test/sample.ogg", OGG_FILE)
14 FileUtils.rm_f(OGG_FILE)
18 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
19 # make sure the keys are returned in the correct order
20 assert_equal(["artist", "album", "date"], t.comments.keys)
21 assert_equal(["Bolt Thrower", "...For Victory", "1994"],
24 assert_equal(3, t.comments.length)
25 assert_equal(3, t.comments.size)
27 assert_equal("Bolt Thrower", t.comments["artist"])
28 assert_equal("...For Victory", t.comments["album"])
29 assert_equal("1994", t.comments["date"])
33 def test_write_is_non_destructive
34 a = Digest::MD5.hexdigest(File.read(OGG_FILE))
36 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
40 b = Digest::MD5.hexdigest(File.read(OGG_FILE))
45 def test_multiple_writes
46 a = Digest::MD5.hexdigest(File.read(OGG_FILE))
48 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
54 b = Digest::MD5.hexdigest(File.read(OGG_FILE))
59 def test_write_stable_order
60 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
61 assert_equal(3, t.write)
64 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
65 assert_equal(["artist", "album", "date"], t.comments.keys)
69 def test_write_stable_order_change
70 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
71 t.comments["artist"] = "Ballista"
72 assert_equal(3, t.write)
75 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
76 assert_equal(["artist", "album", "date"], t.comments.keys)
81 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
82 t.comments["genre"] = "Death Metal"
83 assert_equal(4, t.write)
86 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
87 assert_equal("Death Metal", t.comments["genre"])
92 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
93 assert_equal("...For Victory", t.comments.delete("album"))
94 assert_nil(t.comments.delete("foo"))
95 assert_equal(2, t.write)
98 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
99 assert_equal(["artist", "date"], t.comments.keys)
104 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
106 assert_equal(0, t.write)
109 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
110 assert(t.comments.empty?)
115 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
116 assert(!t.comments.empty?)
118 t.comments.delete("artist")
119 t.comments.delete("album")
120 t.comments.delete("date")
122 assert_equal(0, t.write)
125 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
126 assert(t.comments.empty?)
131 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
133 "artist" => "Bolt Thrower",
134 "album" => "...For Victory",
139 t.comments.each do |k, v|
148 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
151 t.comments.each_key do |k|
155 assert_equal(["artist", "album", "date"], b)
160 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
163 t.comments.each_value do |v|
167 assert_equal(["Bolt Thrower", "...For Victory", "1994"], b)
172 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
174 {"artist"=>"Bolt Thrower", "album"=>"...For Victory", "date"=>"1994"}
176 assert_equal(tmp.strip, t.comments.inspect)
181 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
182 assert(t.comments.has_key?("artist"))
183 assert(!t.comments.has_key?("foo"))
185 assert(t.comments.key?("artist"))
186 assert(t.comments.include?("artist"))
187 assert(t.comments.member?("artist"))
195 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
199 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
203 assert_equal(0, a <=> b)
205 assert_equal(-1, a <=> b)
208 def test_modify_existing_key
209 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
210 assert_raises(TypeError) do
211 t.comments.keys.first.replace("new")
216 def test_modify_added_key
217 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
218 t.comments["Foo"] = "Bar"
220 assert_raises(TypeError) do
221 t.comments.keys.last.replace("new")
228 "artist" => "Ballista",
229 "genre" => "Death Metal",
232 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
233 t.comments.merge!(repl)
235 assert_equal(["artist", "album", "date", "genre"],
237 assert_equal(["Ballista", "...For Victory", "1994",
244 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
245 assert_equal(["artist", "Bolt Thrower"], t.comments.shift)
246 assert_equal(["album", "...For Victory"], t.comments.shift)
247 assert_equal(["date", "1994"], t.comments.shift)
248 assert_equal(nil, t.comments.shift)
253 Ogg::Vorbis::Tagger.new(OGG_FILE).close