Class: ZipFileSplitTest

Inherits:
MiniTest::Test
  • Object
show all
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb

Constant Summary collapse

TEST_ZIP =
TestZipFile::TEST_ZIP2.clone
EXTRACTED_FILENAME =
"test/data/generated/extEntrySplit"
UNSPLITTED_FILENAME =
"test/data/generated/unsplitted.zip"
ENTRY_TO_EXTRACT =
TEST_ZIP.entry_names.first

Instance Method Summary collapse

Instance Method Details

#setupObject



10
11
12
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb', line 10

def setup
  FileUtils.cp(TestZipFile::TEST_ZIP2.zip_name, TEST_ZIP.zip_name)
end

#teardownObject



14
15
16
17
18
19
20
21
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb', line 14

def teardown
  File.delete(TEST_ZIP.zip_name)
  File.delete(UNSPLITTED_FILENAME) if File.exist?(UNSPLITTED_FILENAME)

  Dir["#{TEST_ZIP.zip_name}.*"].each do |zip_file_name|
    File.delete(zip_file_name) if File.exist?(zip_file_name)
  end
end

#test_splitObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb', line 27

def test_split
  result = ::Zip::File.split(TEST_ZIP.zip_name, 65536, false)

  unless result.nil?
    Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index|
      File.open(zip_file_name, 'rb') do |zip_file|
        zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0
        File.open(UNSPLITTED_FILENAME, 'ab') do |file|
          file << zip_file.read
        end
      end
    end

    ::Zip::File.open(UNSPLITTED_FILENAME) do |zf|
      zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)

      assert(File.exist?(EXTRACTED_FILENAME))
      AssertEntry::assert_contents(EXTRACTED_FILENAME,
                                   zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read })


      File.unlink(EXTRACTED_FILENAME)

      entry = zf.get_entry(ENTRY_TO_EXTRACT)
      entry.extract(EXTRACTED_FILENAME)

      assert(File.exist?(EXTRACTED_FILENAME))
      AssertEntry::assert_contents(EXTRACTED_FILENAME,
                                   entry.get_input_stream() { |is| is.read })

    end
  end
end

#test_split_method_respondObject



23
24
25
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb', line 23

def test_split_method_respond
  assert_respond_to ::Zip::File, :split, "Does not have split class method"
end