Class: ADSP::Test::File

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/adsp/test/file.rb

Overview

ADSP::Test::File class.

Constant Summary collapse

Target =
Mock::File
Option =
Test::Option
SOURCE_PATH =
Common::SOURCE_PATH
ARCHIVE_PATH =
Common::ARCHIVE_PATH
TEXTS =
Common::TEXTS
LARGE_TEXTS =
Common::LARGE_TEXTS
BUFFER_LENGTH_NAMES =
i[source_buffer_length destination_buffer_length].freeze
BUFFER_LENGTH_MAPPING =
{
  :source_buffer_length      => :destination_buffer_length,
  :destination_buffer_length => :source_buffer_length
}
.freeze

Instance Method Summary collapse

Instance Method Details

#get_compatible_decompressor_options(compressor_options, &block) ⇒ Object



115
116
117
# File 'lib/adsp/test/file.rb', line 115

def get_compatible_decompressor_options(compressor_options, &block)
  option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
end

#get_invalid_compressor_options(&block) ⇒ Object




103
104
105
# File 'lib/adsp/test/file.rb', line 103

def get_invalid_compressor_options(&block)
  option.get_invalid_compressor_options BUFFER_LENGTH_NAMES, &block
end

#get_invalid_decompressor_options(&block) ⇒ Object



107
108
109
# File 'lib/adsp/test/file.rb', line 107

def get_invalid_decompressor_options(&block)
  option.get_invalid_decompressor_options BUFFER_LENGTH_NAMES, &block
end

#parallel_compressor_options(&block) ⇒ Object



111
112
113
# File 'lib/adsp/test/file.rb', line 111

def parallel_compressor_options(&block)
  Common.parallel_options option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
end

#test_invalid_argumentsObject



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
60
61
62
# File 'lib/adsp/test/file.rb', line 32

def test_invalid_arguments
  Validation::INVALID_STRINGS.each do |invalid_path|
    assert_raises ValidateError do
      target.compress invalid_path, ARCHIVE_PATH
    end

    assert_raises ValidateError do
      target.compress SOURCE_PATH, invalid_path
    end

    assert_raises ValidateError do
      target.decompress invalid_path, SOURCE_PATH
    end

    assert_raises ValidateError do
      target.decompress ARCHIVE_PATH, invalid_path
    end
  end

  get_invalid_compressor_options do |invalid_options|
    assert_raises ValidateError do
      target.compress SOURCE_PATH, ARCHIVE_PATH, invalid_options
    end
  end

  get_invalid_decompressor_options do |invalid_options|
    assert_raises ValidateError do
      target.decompress ARCHIVE_PATH, SOURCE_PATH, invalid_options
    end
  end
end

#test_large_textsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/adsp/test/file.rb', line 85

def test_large_texts
  Common.parallel LARGE_TEXTS do |text, worker_index|
    source_path  = Common.get_path SOURCE_PATH, worker_index
    archive_path = Common.get_path ARCHIVE_PATH, worker_index

    ::File.write source_path, text, :mode => "wb"
    target.compress source_path, archive_path
    target.decompress archive_path, source_path

    decompressed_text = ::File.read source_path, :mode => "rb"
    decompressed_text.force_encoding text.encoding

    assert_equal text, decompressed_text
  end
end

#test_textsObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/adsp/test/file.rb', line 64

def test_texts
  parallel_compressor_options do |compressor_options, worker_index|
    source_path  = Common.get_path SOURCE_PATH, worker_index
    archive_path = Common.get_path ARCHIVE_PATH, worker_index

    TEXTS.each do |text|
      ::File.write source_path, text, :mode => "wb"
      target.compress source_path, archive_path, compressor_options

      get_compatible_decompressor_options compressor_options do |decompressor_options|
        target.decompress archive_path, source_path, decompressor_options

        decompressed_text = ::File.read source_path, :mode => "rb"
        decompressed_text.force_encoding text.encoding

        assert_equal text, decompressed_text
      end
    end
  end
end