require "test/unit"
require "ogg/vorbis/tagger"
require "fileutils"
-require "stringio"
require "open3"
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, _|
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"],
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")
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",
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|
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|
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
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"))
+
+ assert(t.comments.key?("artist"))
+ assert(t.comments.include?("artist"))
+ assert(t.comments.member?("artist"))
end
end
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
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
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