spec/frames_spec.rb in aviglitch-0.1.6 vs spec/frames_spec.rb in aviglitch-0.2.0

- old
+ new

@@ -3,32 +3,27 @@ describe AviGlitch::Frames do before :all do AviGlitch::Frames.class_eval do define_method(:get_real_id_with) do |frame| - pos = @io.pos - @io.pos -= frame.data.size - @io.pos -= 8 - id = @io.read 4 - @io.pos = pos + movi = @avi.get_movi + pos = movi.pos + movi.pos -= frame.data.size + movi.pos -= 8 + id = movi.read 4 + movi.pos = pos id end end - FileUtils.mkdir OUTPUT_DIR unless File.exist? OUTPUT_DIR - @in = FILES_DIR + 'sample.avi' - @out = OUTPUT_DIR + 'out.avi' + AviGlitch::Avi.class_eval do + define_method(:get_movi) do + @movi + end + end end - after :each do - FileUtils.rm Dir.glob((OUTPUT_DIR + '*').to_s) - end - - after :all do - FileUtils.rmdir OUTPUT_DIR - end - it 'should save the same file when nothing is changed' do avi = AviGlitch.open @in avi.frames.each do |f| ; end @@ -83,19 +78,10 @@ f.data.should_not == nil end avi.close end - it 'should hide the inner variables' do - avi = AviGlitch.open @in - frames = avi.frames - lambda { frames.meta }.should raise_error(NoMethodError) - lambda { frames.io }.should raise_error(NoMethodError) - lambda { frames.frames_data_as_io }.should raise_error(NoMethodError) - avi.close - end - it 'should save video frames count in header' do avi = AviGlitch.open @in c = 0 avi.frames.each do |f| c += 1 if f.is_videoframe? @@ -553,8 +539,31 @@ expect(vc1).to eq(vc) expect(vc2).to eq(vc) expect(ac1).to eq(ac) expect(ac2).to eq(ac) + end + + it 'should pick the first / last frame with a method' do + a = AviGlitch.open @in + fkidx = -1 + lkidx = -1 + faidx = -1 + laidx = -1 + a.frames.each_with_index do |f, i| + if f.is_keyframe? + fkidx = i if fkidx == -1 + lkidx = i + end + if f.is_audioframe? + faidx = i if faidx == -1 + laidx = i + end + end + a.frames.index(a.frames.first_of(:keyframe)).should eq(fkidx) + a.frames.rindex(a.frames.last_of(:keyframe)).should eq(lkidx) + a.frames.index(a.frames.first_of(:audioframe)).should eq(faidx) + a.frames.rindex(a.frames.last_of(:audioframe)).should eq(laidx) + a.close end end