2 require "ogg/vorbis/tagger"
7 class MainTest < Test::Unit::TestCase
8 OGG_FILE = "test/test.ogg"
12 -c "artist=Bolt Thrower" -c "album=...For Victory" -c "date=1994"
15 @ogg_buf = StringIO.new
16 cmd = "oggenc -q 0 #{tmp.strip} -r -"
18 Open3.popen3(cmd) do |sin, sout, _|
25 end while !tmp.length.zero?
36 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
37 # make sure the keys are returned in the correct order
38 assert_equal(["artist", "album", "date"], t.comments.keys)
39 assert_equal(["Bolt Thrower", "...For Victory", "1994"],
42 assert_equal(3, t.comments.length)
43 assert_equal(3, t.comments.size)
45 assert_equal("Bolt Thrower", t.comments["artist"])
46 assert_equal("...For Victory", t.comments["album"])
47 assert_equal("1994", t.comments["date"])
51 def test_write_stable_order
52 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
53 assert_equal(3, t.write)
58 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
59 assert_equal(["artist", "album", "date"], t.comments.keys)
63 def test_write_stable_order_change
64 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
65 t.comments["artist"] = "Ballista"
66 assert_equal(3, t.write)
71 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
72 assert_equal(["artist", "album", "date"], t.comments.keys)
77 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
78 t.comments["genre"] = "Death Metal"
79 assert_equal(4, t.write)
84 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
85 assert_equal("Death Metal", t.comments["genre"])
90 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
91 assert_equal("...For Victory", t.comments.delete("album"))
92 assert_nil(t.comments.delete("foo"))
93 assert_equal(2, t.write)
98 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
99 assert_equal(["artist", "date"], t.comments.keys)
104 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
106 assert_equal(0, t.write)
111 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
112 assert(t.comments.empty?)
117 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
118 assert(!t.comments.empty?)
120 t.comments.delete("artist")
121 t.comments.delete("album")
122 t.comments.delete("date")
124 assert_equal(0, t.write)
129 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
130 assert(t.comments.empty?)
135 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
137 "artist" => "Bolt Thrower",
138 "album" => "...For Victory",
143 t.comments.each do |k, v|
152 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
155 t.comments.each_key do |k|
159 assert_equal(["artist", "album", "date"], b)
164 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
167 t.comments.each_value do |v|
171 assert_equal(["Bolt Thrower", "...For Victory", "1994"], b)
176 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
178 {"artist"=>"Bolt Thrower", "album"=>"...For Victory", "date"=>"1994"}
180 assert_equal(tmp.strip, t.comments.inspect)
185 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
186 assert(t.comments.has_key?("artist"))
187 assert(!t.comments.has_key?("foo"))
189 assert(t.comments.key?("artist"))
190 assert(t.comments.include?("artist"))
191 assert(t.comments.member?("artist"))
199 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
205 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
209 assert_equal(0, a <=> b)
211 assert_equal(-1, a <=> b)
214 def test_modify_existing_key
215 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
216 assert_raises(TypeError) do
217 t.comments.keys.first.replace("new")
222 def test_modify_added_key
223 Ogg::Vorbis::Tagger.open(@ogg_buf) do |t|
224 t.comments["Foo"] = "Bar"
226 assert_raises(TypeError) do
227 t.comments.keys.last.replace("new")