Class: CPIOArchiveWriterTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/excavate/extractors/cpio/cpio_old_format.rb

Instance Method Summary collapse

Instance Method Details

#test_adding_a_file_with_an_excessively_long_name_should_raiseObject



398
399
400
401
402
403
404
405
406
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 398

def test_adding_a_file_with_an_excessively_long_name_should_raise
  archiver = CPIO::ArchiveWriter.new(StringIO.new)
  assert_raise(CPIO::ArchiveFormatError) do
    archiver.open do |arch|
      name = "fffff" * (CPIO::ArchiveHeader::FieldMaxValues[:namesize])
      arch.add_file(name) { |sio| }
    end
  end
end

#test_adding_a_non_executable_file_should_preserve_said_modeObject



408
409
410
411
412
413
414
415
416
417
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 408

def test_adding_a_non_executable_file_should_preserve_said_mode
  io = StringIO.new
  archiver = CPIO::ArchiveWriter.new(io)
  archiver.open do |arch|
    arch.add_file("barfoo", 0444) { |sio| }
  end
  CPIO::ArchiveReader.new(io).each_entry do |ent|
    assert !ent.executable? && ent.file?
  end
end

#test_adding_an_executable_file_should_preserve_said_modeObject



419
420
421
422
423
424
425
426
427
428
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 419

def test_adding_an_executable_file_should_preserve_said_mode
  io = StringIO.new
  archiver = CPIO::ArchiveWriter.new(io)
  archiver.open do |arch|
    arch.add_file("barfoo", 0500) { |sio| }
  end
  CPIO::ArchiveReader.new(io).each_entry do |ent|
    assert ent.executable? && ent.file?
  end
end

#test_adding_empty_files_should_workObject



387
388
389
390
391
392
393
394
395
396
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 387

def test_adding_empty_files_should_work
  expected = 1
  io = StringIO.new
  archiver = CPIO::ArchiveWriter.new(io)
  archiver.open do |arch|
    arch.add_file("barfoo", 0111) { |sio| }
  end
  CPIO::ArchiveReader.new(io).each_entry { |ent| expected -= 1 if ent.file? }
  assert_equal 0, expected
end

#test_making_directories_should_workObject



349
350
351
352
353
354
355
356
357
358
359
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 349

def test_making_directories_should_work
  expected = 2
  io = StringIO.new
  archiver = CPIO::ArchiveWriter.new(io)
  archiver.open do |arch|
    arch.mkdir "foo"
    arch.mkdir "bar"
  end
  CPIO::ArchiveReader.new(io).each_entry { |ent| expected -= 1 if ent.directory? }
  assert_equal 0, expected
end

#test_making_files_and_directories_should_workObject



373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 373

def test_making_files_and_directories_should_work
  expected = 4
  io = StringIO.new
  archiver = CPIO::ArchiveWriter.new(io)
  archiver.open do |arch|
    arch.mkdir "blah"
    arch.add_file("foo") { |sio| sio.write("foobar") }
    arch.add_file("barfoo") { |sio| sio.write("barfoo") }
    arch.add_file("barfoobaz", 0111) { |sio| sio.write("wee") }
  end
  CPIO::ArchiveReader.new(io).each_entry { |ent| expected -= 1 }
  assert_equal 0, expected
end

#test_making_files_should_workObject



361
362
363
364
365
366
367
368
369
370
371
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 361

def test_making_files_should_work
  expected = 2
  io = StringIO.new
  archiver = CPIO::ArchiveWriter.new(io)
  archiver.open do |arch|
    arch.add_file("foo") { |sio| sio.write("foobar") }
    arch.add_file("barfoo") { |sio| sio.write("barfoo") }
  end
  CPIO::ArchiveReader.new(io).each_entry { |ent| expected -= 1 if ent.file? }
  assert_equal 0, expected
end