adsp 1.0.2 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{test → lib/adsp/test}/common.rb +4 -1
- data/{test → lib/adsp/test}/coverage_helper.rb +0 -0
- data/lib/adsp/test/file.rb +120 -0
- data/{test → lib/adsp/test}/minitest.rb +1 -0
- data/{test → lib/adsp/test}/mock/common.rb +1 -0
- data/{test → lib/adsp/test}/mock/file.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/compressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/decompressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/native_compressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/raw/native_decompressor.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/reader.rb +1 -0
- data/{test → lib/adsp/test}/mock/stream/writer.rb +1 -0
- data/{test → lib/adsp/test}/mock/string.rb +1 -0
- data/{test → lib/adsp/test}/option.rb +1 -0
- data/{test → lib/adsp/test}/stream/abstract.rb +1 -0
- data/lib/adsp/test/stream/minitar.rb +50 -0
- data/{test → lib/adsp/test}/stream/raw/abstract.rb +1 -0
- data/lib/adsp/test/stream/raw/compressor.rb +165 -0
- data/lib/adsp/test/stream/raw/decompressor.rb +165 -0
- data/lib/adsp/test/stream/reader.rb +642 -0
- data/lib/adsp/test/stream/reader_helpers.rb +421 -0
- data/lib/adsp/test/stream/writer.rb +609 -0
- data/lib/adsp/test/stream/writer_helpers.rb +267 -0
- data/lib/adsp/test/string.rb +95 -0
- data/{test → lib/adsp/test}/validation.rb +7 -0
- data/lib/adsp/test/version.rb +18 -0
- data/lib/adsp/version.rb +1 -1
- data/test/file.test.rb +3 -116
- data/test/stream/minitar.test.rb +3 -46
- data/test/stream/raw/compressor.test.rb +3 -162
- data/test/stream/raw/decompressor.test.rb +3 -162
- data/test/stream/reader.test.rb +3 -639
- data/test/stream/reader_helpers.test.rb +3 -417
- data/test/stream/writer.test.rb +3 -606
- data/test/stream/writer_helpers.test.rb +3 -263
- data/test/string.test.rb +3 -91
- data/test/version.test.rb +3 -14
- metadata +28 -19
@@ -0,0 +1,267 @@
|
|
1
|
+
# Abstract data stream processor.
|
2
|
+
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
require "English"
|
5
|
+
require "stringio"
|
6
|
+
|
7
|
+
require_relative "../common"
|
8
|
+
require_relative "../minitest"
|
9
|
+
require_relative "../option"
|
10
|
+
require_relative "../validation"
|
11
|
+
require_relative "../mock/stream/writer"
|
12
|
+
require_relative "../mock/string"
|
13
|
+
|
14
|
+
module ADSP
|
15
|
+
module Test
|
16
|
+
# ADSP::Test::Stream module.
|
17
|
+
module Stream
|
18
|
+
# ADSP::Test::Stream::WriterHelpers class.
|
19
|
+
class WriterHelpers < Minitest::Test
|
20
|
+
Target = Mock::Stream::Writer
|
21
|
+
String = Mock::String
|
22
|
+
|
23
|
+
ARCHIVE_PATH = Common::ARCHIVE_PATH
|
24
|
+
TEXTS = Common::TEXTS
|
25
|
+
LARGE_TEXTS = Common::LARGE_TEXTS
|
26
|
+
PORTION_LENGTHS = Common::PORTION_LENGTHS
|
27
|
+
LARGE_PORTION_LENGTHS = Common::LARGE_PORTION_LENGTHS
|
28
|
+
|
29
|
+
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
30
|
+
BUFFER_LENGTH_MAPPING = { :destination_buffer_length => :destination_buffer_length }.freeze
|
31
|
+
|
32
|
+
def test_write
|
33
|
+
parallel_compressor_options do |compressor_options, worker_index|
|
34
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
35
|
+
|
36
|
+
TEXTS.each do |text|
|
37
|
+
PORTION_LENGTHS.each do |portion_length|
|
38
|
+
sources = get_sources text, portion_length
|
39
|
+
|
40
|
+
Target.open archive_path, compressor_options do |instance|
|
41
|
+
sources.each { |current_source| instance << current_source }
|
42
|
+
end
|
43
|
+
|
44
|
+
compressed_text = ::File.read archive_path, :mode => "rb"
|
45
|
+
|
46
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
47
|
+
check_text text, compressed_text, decompressor_options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_print
|
55
|
+
parallel_compressor_options do |compressor_options, worker_index|
|
56
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
57
|
+
|
58
|
+
TEXTS.reject(&:empty?).each do |text|
|
59
|
+
PORTION_LENGTHS.each do |portion_length|
|
60
|
+
sources = get_sources text, portion_length
|
61
|
+
field_separator = " ".encode text.encoding
|
62
|
+
record_separator = "\n".encode text.encoding
|
63
|
+
|
64
|
+
target_text = "".encode text.encoding
|
65
|
+
sources.each { |source| target_text << (source + field_separator) }
|
66
|
+
target_text << record_separator
|
67
|
+
|
68
|
+
Target.open archive_path, compressor_options do |instance|
|
69
|
+
keyword_args = { :field_separator => field_separator, :record_separator => record_separator }
|
70
|
+
instance.print(*sources, **keyword_args)
|
71
|
+
end
|
72
|
+
|
73
|
+
compressed_text = ::File.read archive_path, :mode => "rb"
|
74
|
+
|
75
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
76
|
+
check_text target_text, compressed_text, decompressor_options
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_printf
|
84
|
+
parallel_compressor_options do |compressor_options, worker_index|
|
85
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
86
|
+
|
87
|
+
TEXTS.each do |text|
|
88
|
+
PORTION_LENGTHS.each do |portion_length|
|
89
|
+
sources = get_sources text, portion_length
|
90
|
+
|
91
|
+
Target.open archive_path, compressor_options do |instance|
|
92
|
+
sources.each { |source| instance.printf "%s", source }
|
93
|
+
end
|
94
|
+
|
95
|
+
compressed_text = ::File.read archive_path, :mode => "rb"
|
96
|
+
|
97
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
98
|
+
check_text text, compressed_text, decompressor_options
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_invalid_putc
|
106
|
+
instance = target.new ::StringIO.new
|
107
|
+
|
108
|
+
Validation::INVALID_CHARS.each do |invalid_char|
|
109
|
+
assert_raises ValidateError do
|
110
|
+
instance.putc invalid_char
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_putc
|
116
|
+
parallel_compressor_options do |compressor_options, worker_index|
|
117
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
118
|
+
|
119
|
+
TEXTS.each do |text|
|
120
|
+
Target.open archive_path, compressor_options do |instance|
|
121
|
+
# Putc should process numbers and strings.
|
122
|
+
text.chars.each.with_index do |char, index|
|
123
|
+
if index.even?
|
124
|
+
instance.putc char.ord, :encoding => text.encoding
|
125
|
+
else
|
126
|
+
instance.putc char
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
compressed_text = ::File.read archive_path, :mode => "rb"
|
132
|
+
|
133
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
134
|
+
check_text text, compressed_text, decompressor_options
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_puts
|
141
|
+
parallel_compressor_options do |compressor_options, worker_index|
|
142
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
143
|
+
|
144
|
+
TEXTS.each do |text|
|
145
|
+
PORTION_LENGTHS.each do |portion_length|
|
146
|
+
newline = "\n".encode text.encoding
|
147
|
+
|
148
|
+
sources = get_sources text, portion_length
|
149
|
+
sources = sources.map do |source|
|
150
|
+
source.delete_suffix! newline while source.end_with? newline
|
151
|
+
source
|
152
|
+
end
|
153
|
+
|
154
|
+
target_text = "".encode text.encoding
|
155
|
+
sources.each { |source| target_text << (source + newline) }
|
156
|
+
|
157
|
+
Target.open archive_path, compressor_options do |instance|
|
158
|
+
# Puts should ignore additional newlines and process arrays.
|
159
|
+
args = sources.map.with_index do |source, index|
|
160
|
+
if index.even?
|
161
|
+
source + newline
|
162
|
+
else
|
163
|
+
[source]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
instance.puts(*args)
|
168
|
+
end
|
169
|
+
|
170
|
+
compressed_text = ::File.read archive_path, :mode => "rb"
|
171
|
+
|
172
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
173
|
+
check_text target_text, compressed_text, decompressor_options
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_invalid_open
|
181
|
+
Validation::INVALID_STRINGS.each do |invalid_string|
|
182
|
+
assert_raises ValidateError do
|
183
|
+
Target.open(invalid_string) {} # no-op
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Proc is required.
|
188
|
+
assert_raises ValidateError do
|
189
|
+
Target.open ARCHIVE_PATH
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_open
|
194
|
+
parallel_compressor_options do |compressor_options, worker_index|
|
195
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
196
|
+
|
197
|
+
TEXTS.each do |text|
|
198
|
+
Target.open(archive_path, compressor_options) { |instance| instance.write text }
|
199
|
+
|
200
|
+
compressed_text = ::File.read archive_path, :mode => "rb"
|
201
|
+
|
202
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
203
|
+
check_text text, compressed_text, decompressor_options
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_open_with_large_texts
|
210
|
+
options_generator = OCG.new(
|
211
|
+
:text => LARGE_TEXTS,
|
212
|
+
:portion_length => LARGE_PORTION_LENGTHS
|
213
|
+
)
|
214
|
+
|
215
|
+
Common.parallel_options options_generator do |options, worker_index|
|
216
|
+
text = options[:text]
|
217
|
+
portion_length = options[:portion_length]
|
218
|
+
|
219
|
+
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
220
|
+
|
221
|
+
sources = get_sources text, portion_length
|
222
|
+
|
223
|
+
Target.open archive_path do |instance|
|
224
|
+
sources.each { |source| instance.write source }
|
225
|
+
end
|
226
|
+
|
227
|
+
compressed_text = ::File.read archive_path, :mode => "rb"
|
228
|
+
|
229
|
+
check_text text, compressed_text, {}
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# -----
|
234
|
+
|
235
|
+
protected def get_sources(text, portion_length)
|
236
|
+
sources = text
|
237
|
+
.chars
|
238
|
+
.each_slice(portion_length)
|
239
|
+
.map(&:join)
|
240
|
+
|
241
|
+
return [""] if sources.empty?
|
242
|
+
|
243
|
+
sources
|
244
|
+
end
|
245
|
+
|
246
|
+
protected def check_text(text, compressed_text, decompressor_options)
|
247
|
+
decompressed_text = String.decompress compressed_text, decompressor_options
|
248
|
+
decompressed_text.force_encoding text.encoding
|
249
|
+
|
250
|
+
assert_equal text, decompressed_text
|
251
|
+
end
|
252
|
+
|
253
|
+
def parallel_compressor_options(&block)
|
254
|
+
Common.parallel_options Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
255
|
+
end
|
256
|
+
|
257
|
+
def get_compatible_decompressor_options(compressor_options, &block)
|
258
|
+
Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
259
|
+
end
|
260
|
+
|
261
|
+
protected def target
|
262
|
+
self.class::Target
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# Abstract data stream processor.
|
2
|
+
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
require "adsp/string"
|
5
|
+
|
6
|
+
require_relative "common"
|
7
|
+
require_relative "minitest"
|
8
|
+
require_relative "mock/string"
|
9
|
+
require_relative "option"
|
10
|
+
require_relative "validation"
|
11
|
+
|
12
|
+
module ADSP
|
13
|
+
# ADSP::Test module.
|
14
|
+
module Test
|
15
|
+
# ADSP::Test::String class.
|
16
|
+
class String < Minitest::Test
|
17
|
+
Option = Test::Option
|
18
|
+
Target = Mock::String
|
19
|
+
|
20
|
+
TEXTS = Common::TEXTS
|
21
|
+
LARGE_TEXTS = Common::LARGE_TEXTS
|
22
|
+
|
23
|
+
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
24
|
+
BUFFER_LENGTH_MAPPING = { :destination_buffer_length => :destination_buffer_length }.freeze
|
25
|
+
|
26
|
+
def test_invalid_arguments
|
27
|
+
Validation::INVALID_STRINGS.each do |invalid_string|
|
28
|
+
assert_raises ValidateError do
|
29
|
+
Target.compress invalid_string
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_raises ValidateError do
|
33
|
+
Target.decompress invalid_string
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
get_invalid_compressor_options do |invalid_options|
|
38
|
+
assert_raises ValidateError do
|
39
|
+
Target.compress "", invalid_options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
get_invalid_decompressor_options do |invalid_options|
|
44
|
+
assert_raises ValidateError do
|
45
|
+
Target.decompress "", invalid_options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_texts
|
51
|
+
parallel_compressor_options do |compressor_options|
|
52
|
+
TEXTS.each do |text|
|
53
|
+
compressed_text = Target.compress text, compressor_options
|
54
|
+
|
55
|
+
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
56
|
+
decompressed_text = Target.decompress compressed_text, decompressor_options
|
57
|
+
decompressed_text.force_encoding text.encoding
|
58
|
+
|
59
|
+
assert_equal text, decompressed_text
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_large_texts
|
66
|
+
Common.parallel LARGE_TEXTS do |text|
|
67
|
+
compressed_text = Target.compress text
|
68
|
+
|
69
|
+
decompressed_text = Target.decompress compressed_text
|
70
|
+
decompressed_text.force_encoding text.encoding
|
71
|
+
|
72
|
+
assert_equal text, decompressed_text
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# -----
|
77
|
+
|
78
|
+
def get_invalid_compressor_options(&block)
|
79
|
+
self.class::Option.get_invalid_compressor_options BUFFER_LENGTH_NAMES, &block
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_invalid_decompressor_options(&block)
|
83
|
+
self.class::Option.get_invalid_decompressor_options BUFFER_LENGTH_NAMES, &block
|
84
|
+
end
|
85
|
+
|
86
|
+
def parallel_compressor_options(&block)
|
87
|
+
Common.parallel_options self.class::Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_compatible_decompressor_options(compressor_options, &block)
|
91
|
+
self.class::Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -5,6 +5,7 @@ require "stringio"
|
|
5
5
|
|
6
6
|
module ADSP
|
7
7
|
module Test
|
8
|
+
# ADSP::Test::Validation module.
|
8
9
|
module Validation
|
9
10
|
NOOP_PROC = proc {} # no-op
|
10
11
|
|
@@ -43,26 +44,32 @@ module ADSP
|
|
43
44
|
]
|
44
45
|
.freeze
|
45
46
|
|
47
|
+
# ADSP::Test::Validation::StringIOWithoutEOF class.
|
46
48
|
class StringIOWithoutEOF < ::StringIO
|
47
49
|
undef :eof?
|
48
50
|
end
|
49
51
|
|
52
|
+
# ADSP::Test::Validation::StringIOWithoutRead class.
|
50
53
|
class StringIOWithoutRead < ::StringIO
|
51
54
|
undef :read
|
52
55
|
end
|
53
56
|
|
57
|
+
# ADSP::Test::Validation::StringIOWithoutReadNonblock class.
|
54
58
|
class StringIOWithoutReadNonblock < ::StringIO
|
55
59
|
undef :read_nonblock
|
56
60
|
end
|
57
61
|
|
62
|
+
# ADSP::Test::Validation::StringIOWithoutReadpartial class.
|
58
63
|
class StringIOWithoutReadpartial < ::StringIO
|
59
64
|
undef :readpartial
|
60
65
|
end
|
61
66
|
|
67
|
+
# ADSP::Test::Validation::StringIOWithoutWrite class.
|
62
68
|
class StringIOWithoutWrite < ::StringIO
|
63
69
|
undef :write
|
64
70
|
end
|
65
71
|
|
72
|
+
# ADSP::Test::Validation::StringIOWithoutWriteNonblock class.
|
66
73
|
class StringIOWithoutWriteNonblock < ::StringIO
|
67
74
|
undef :write_nonblock
|
68
75
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Abstract data stream processor.
|
2
|
+
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
require "adsp"
|
5
|
+
|
6
|
+
require_relative "minitest"
|
7
|
+
|
8
|
+
module ADSP
|
9
|
+
# ADSP::Test module.
|
10
|
+
module Test
|
11
|
+
# ADSP::Test::Version class.
|
12
|
+
class Version < Minitest::Test
|
13
|
+
def test_version
|
14
|
+
refute_nil ADSP::VERSION
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/adsp/version.rb
CHANGED
data/test/file.test.rb
CHANGED
@@ -1,120 +1,7 @@
|
|
1
1
|
# Abstract data stream processor.
|
2
2
|
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
require "adsp/
|
4
|
+
require "adsp/test/minitest"
|
5
|
+
require "adsp/test/file"
|
5
6
|
|
6
|
-
|
7
|
-
require_relative "minitest"
|
8
|
-
require_relative "mock/file"
|
9
|
-
require_relative "option"
|
10
|
-
require_relative "validation"
|
11
|
-
|
12
|
-
module ADSP
|
13
|
-
module Test
|
14
|
-
class File < Minitest::Test
|
15
|
-
Option = Test::Option
|
16
|
-
Target = Mock::File
|
17
|
-
|
18
|
-
SOURCE_PATH = Common::SOURCE_PATH
|
19
|
-
ARCHIVE_PATH = Common::ARCHIVE_PATH
|
20
|
-
TEXTS = Common::TEXTS
|
21
|
-
LARGE_TEXTS = Common::LARGE_TEXTS
|
22
|
-
|
23
|
-
BUFFER_LENGTH_NAMES = %i[source_buffer_length destination_buffer_length].freeze
|
24
|
-
BUFFER_LENGTH_MAPPING = {
|
25
|
-
:source_buffer_length => :destination_buffer_length,
|
26
|
-
:destination_buffer_length => :source_buffer_length
|
27
|
-
}
|
28
|
-
.freeze
|
29
|
-
|
30
|
-
def test_invalid_arguments
|
31
|
-
Validation::INVALID_STRINGS.each do |invalid_path|
|
32
|
-
assert_raises ValidateError do
|
33
|
-
Target.compress invalid_path, ARCHIVE_PATH
|
34
|
-
end
|
35
|
-
|
36
|
-
assert_raises ValidateError do
|
37
|
-
Target.compress SOURCE_PATH, invalid_path
|
38
|
-
end
|
39
|
-
|
40
|
-
assert_raises ValidateError do
|
41
|
-
Target.decompress invalid_path, SOURCE_PATH
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_raises ValidateError do
|
45
|
-
Target.decompress ARCHIVE_PATH, invalid_path
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
get_invalid_compressor_options do |invalid_options|
|
50
|
-
assert_raises ValidateError do
|
51
|
-
Target.compress SOURCE_PATH, ARCHIVE_PATH, invalid_options
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
get_invalid_decompressor_options do |invalid_options|
|
56
|
-
assert_raises ValidateError do
|
57
|
-
Target.decompress ARCHIVE_PATH, SOURCE_PATH, invalid_options
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_texts
|
63
|
-
parallel_compressor_options do |compressor_options, worker_index|
|
64
|
-
source_path = Common.get_path SOURCE_PATH, worker_index
|
65
|
-
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
66
|
-
|
67
|
-
TEXTS.each do |text|
|
68
|
-
::File.write source_path, text, :mode => "wb"
|
69
|
-
Target.compress source_path, archive_path, compressor_options
|
70
|
-
|
71
|
-
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
72
|
-
Target.decompress archive_path, source_path, decompressor_options
|
73
|
-
|
74
|
-
decompressed_text = ::File.read source_path, :mode => "rb"
|
75
|
-
decompressed_text.force_encoding text.encoding
|
76
|
-
|
77
|
-
assert_equal text, decompressed_text
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_large_texts
|
84
|
-
Common.parallel LARGE_TEXTS do |text, worker_index|
|
85
|
-
source_path = Common.get_path SOURCE_PATH, worker_index
|
86
|
-
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
87
|
-
|
88
|
-
::File.write source_path, text, :mode => "wb"
|
89
|
-
Target.compress source_path, archive_path
|
90
|
-
Target.decompress archive_path, source_path
|
91
|
-
|
92
|
-
decompressed_text = ::File.read source_path, :mode => "rb"
|
93
|
-
decompressed_text.force_encoding text.encoding
|
94
|
-
|
95
|
-
assert_equal text, decompressed_text
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# -----
|
100
|
-
|
101
|
-
def get_invalid_compressor_options(&block)
|
102
|
-
self.class::Option.get_invalid_compressor_options BUFFER_LENGTH_NAMES, &block
|
103
|
-
end
|
104
|
-
|
105
|
-
def get_invalid_decompressor_options(&block)
|
106
|
-
self.class::Option.get_invalid_decompressor_options BUFFER_LENGTH_NAMES, &block
|
107
|
-
end
|
108
|
-
|
109
|
-
def parallel_compressor_options(&block)
|
110
|
-
Common.parallel_options self.class::Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
111
|
-
end
|
112
|
-
|
113
|
-
def get_compatible_decompressor_options(compressor_options, &block)
|
114
|
-
self.class::Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
Minitest << File
|
119
|
-
end
|
120
|
-
end
|
7
|
+
Minitest << ADSP::Test::File
|
data/test/stream/minitar.test.rb
CHANGED
@@ -1,50 +1,7 @@
|
|
1
1
|
# Abstract data stream processor.
|
2
2
|
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
require "
|
4
|
+
require "adsp/test/minitest"
|
5
|
+
require "adsp/test/stream/minitar"
|
5
6
|
|
6
|
-
|
7
|
-
require_relative "../minitest"
|
8
|
-
require_relative "../mock/stream/reader"
|
9
|
-
require_relative "../mock/stream/writer"
|
10
|
-
|
11
|
-
module ADSP
|
12
|
-
module Test
|
13
|
-
module Stream
|
14
|
-
class MinitarTest < Minitest::Test
|
15
|
-
Reader = Mock::Stream::Reader
|
16
|
-
Writer = Mock::Stream::Writer
|
17
|
-
|
18
|
-
ARCHIVE_PATH = Common::ARCHIVE_PATH
|
19
|
-
LARGE_TEXTS = Common::LARGE_TEXTS
|
20
|
-
|
21
|
-
def test_tar
|
22
|
-
Common.parallel LARGE_TEXTS do |text, worker_index|
|
23
|
-
archive_path = Common.get_path ARCHIVE_PATH, worker_index
|
24
|
-
|
25
|
-
Writer.open archive_path do |writer|
|
26
|
-
Minitar::Writer.open writer do |tar|
|
27
|
-
tar.add_file_simple "file", :data => text
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Reader.open archive_path do |reader|
|
32
|
-
Minitar::Reader.open reader do |tar|
|
33
|
-
tar.each_entry do |entry|
|
34
|
-
assert_equal "file", entry.name
|
35
|
-
|
36
|
-
decompressed_text = entry.read
|
37
|
-
decompressed_text.force_encoding text.encoding
|
38
|
-
|
39
|
-
assert_equal text, decompressed_text
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
Minitest << MinitarTest
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
7
|
+
Minitest << ADSP::Test::Stream::MinitarTest
|