adsp 1.0.2 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,166 +1,7 @@
|
|
1
1
|
# Abstract data stream processor.
|
2
2
|
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
require_relative "../../minitest"
|
7
|
-
require_relative "../../mock/stream/raw/compressor"
|
8
|
-
require_relative "../../mock/string"
|
9
|
-
require_relative "../../option"
|
10
|
-
require_relative "../../validation"
|
4
|
+
require "adsp/test/minitest"
|
5
|
+
require "adsp/test/stream/raw/compressor"
|
11
6
|
|
12
|
-
|
13
|
-
module Test
|
14
|
-
module Stream
|
15
|
-
module Raw
|
16
|
-
class Compressor < Abstract
|
17
|
-
Target = Mock::Stream::Raw::Compressor
|
18
|
-
String = Mock::String
|
19
|
-
|
20
|
-
TEXTS = Common::TEXTS
|
21
|
-
LARGE_TEXTS = Common::LARGE_TEXTS
|
22
|
-
PORTION_LENGTHS = Common::PORTION_LENGTHS
|
23
|
-
LARGE_PORTION_LENGTHS = Common::LARGE_PORTION_LENGTHS
|
24
|
-
|
25
|
-
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
26
|
-
BUFFER_LENGTH_MAPPING = { :destination_buffer_length => :destination_buffer_length }.freeze
|
27
|
-
|
28
|
-
def test_invalid_initialize
|
29
|
-
get_invalid_compressor_options do |invalid_options|
|
30
|
-
assert_raises ValidateError do
|
31
|
-
Target.new invalid_options
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_invalid_write
|
37
|
-
compressor = Target.new
|
38
|
-
|
39
|
-
Validation::INVALID_STRINGS.each do |invalid_string|
|
40
|
-
assert_raises ValidateError do
|
41
|
-
compressor.write invalid_string, &NOOP_PROC
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
assert_raises ValidateError do
|
46
|
-
compressor.write ""
|
47
|
-
end
|
48
|
-
|
49
|
-
compressor.close(&NOOP_PROC)
|
50
|
-
|
51
|
-
assert_raises UsedAfterCloseError do
|
52
|
-
compressor.write "", &NOOP_PROC
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_texts
|
57
|
-
parallel_compressor_options do |compressor_options|
|
58
|
-
TEXTS.each do |text|
|
59
|
-
PORTION_LENGTHS.each do |portion_length|
|
60
|
-
compressed_buffer = ::StringIO.new
|
61
|
-
compressed_buffer.set_encoding ::Encoding::BINARY
|
62
|
-
|
63
|
-
writer = proc { |portion| compressed_buffer << portion }
|
64
|
-
compressor = Target.new compressor_options
|
65
|
-
|
66
|
-
begin
|
67
|
-
source = "".b
|
68
|
-
text_offset = 0
|
69
|
-
index = 0
|
70
|
-
|
71
|
-
loop do
|
72
|
-
portion = text.byteslice text_offset, portion_length
|
73
|
-
break if portion.nil?
|
74
|
-
|
75
|
-
text_offset += portion_length
|
76
|
-
source << portion
|
77
|
-
|
78
|
-
bytes_written = compressor.write source, &writer
|
79
|
-
source = source.byteslice bytes_written, source.bytesize - bytes_written
|
80
|
-
|
81
|
-
compressor.flush(&writer) if index.even?
|
82
|
-
index += 1
|
83
|
-
end
|
84
|
-
|
85
|
-
ensure
|
86
|
-
refute_predicate compressor, :closed?
|
87
|
-
compressor.close(&writer)
|
88
|
-
assert_predicate compressor, :closed?
|
89
|
-
end
|
90
|
-
|
91
|
-
compressed_text = compressed_buffer.string
|
92
|
-
|
93
|
-
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
94
|
-
decompressed_text = String.decompress compressed_text, decompressor_options
|
95
|
-
decompressed_text.force_encoding text.encoding
|
96
|
-
|
97
|
-
assert_equal text, decompressed_text
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_large_texts
|
105
|
-
options_generator = OCG.new(
|
106
|
-
:text => LARGE_TEXTS,
|
107
|
-
:portion_length => LARGE_PORTION_LENGTHS
|
108
|
-
)
|
109
|
-
|
110
|
-
Common.parallel_options options_generator do |options|
|
111
|
-
text = options[:text]
|
112
|
-
portion_length = options[:portion_length]
|
113
|
-
|
114
|
-
compressed_buffer = ::StringIO.new
|
115
|
-
compressed_buffer.set_encoding ::Encoding::BINARY
|
116
|
-
|
117
|
-
writer = proc { |portion| compressed_buffer << portion }
|
118
|
-
compressor = Target.new
|
119
|
-
|
120
|
-
begin
|
121
|
-
source = "".b
|
122
|
-
text_offset = 0
|
123
|
-
|
124
|
-
loop do
|
125
|
-
portion = text.byteslice text_offset, portion_length
|
126
|
-
break if portion.nil?
|
127
|
-
|
128
|
-
text_offset += portion_length
|
129
|
-
source << portion
|
130
|
-
|
131
|
-
bytes_written = compressor.write source, &writer
|
132
|
-
source = source.byteslice bytes_written, source.bytesize - bytes_written
|
133
|
-
end
|
134
|
-
ensure
|
135
|
-
compressor.close(&writer)
|
136
|
-
end
|
137
|
-
|
138
|
-
compressed_text = compressed_buffer.string
|
139
|
-
|
140
|
-
decompressed_text = String.decompress compressed_text
|
141
|
-
decompressed_text.force_encoding text.encoding
|
142
|
-
|
143
|
-
assert_equal text, decompressed_text
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# -----
|
148
|
-
|
149
|
-
def get_invalid_compressor_options(&block)
|
150
|
-
Option.get_invalid_compressor_options BUFFER_LENGTH_NAMES, &block
|
151
|
-
end
|
152
|
-
|
153
|
-
def parallel_compressor_options(&block)
|
154
|
-
Common.parallel_options Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
155
|
-
end
|
156
|
-
|
157
|
-
def get_compatible_decompressor_options(compressor_options, &block)
|
158
|
-
Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
Minitest << Compressor
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
7
|
+
Minitest << ADSP::Test::Stream::Raw::Compressor
|
@@ -1,166 +1,7 @@
|
|
1
1
|
# Abstract data stream processor.
|
2
2
|
# Copyright (c) 2021 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
require_relative "../../minitest"
|
7
|
-
require_relative "../../mock/stream/raw/decompressor"
|
8
|
-
require_relative "../../mock/string"
|
9
|
-
require_relative "../../option"
|
10
|
-
require_relative "../../validation"
|
4
|
+
require "adsp/test/minitest"
|
5
|
+
require "adsp/test/stream/raw/decompressor"
|
11
6
|
|
12
|
-
|
13
|
-
module Test
|
14
|
-
module Stream
|
15
|
-
module Raw
|
16
|
-
class Decompressor < Abstract
|
17
|
-
Target = Mock::Stream::Raw::Decompressor
|
18
|
-
String = Mock::String
|
19
|
-
|
20
|
-
TEXTS = Common::TEXTS
|
21
|
-
LARGE_TEXTS = Common::LARGE_TEXTS
|
22
|
-
PORTION_LENGTHS = Common::PORTION_LENGTHS
|
23
|
-
LARGE_PORTION_LENGTHS = Common::LARGE_PORTION_LENGTHS
|
24
|
-
|
25
|
-
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
26
|
-
BUFFER_LENGTH_MAPPING = { :destination_buffer_length => :destination_buffer_length }.freeze
|
27
|
-
|
28
|
-
def test_invalid_initialize
|
29
|
-
get_invalid_decompressor_options do |invalid_options|
|
30
|
-
assert_raises ValidateError do
|
31
|
-
Target.new invalid_options
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_invalid_read
|
37
|
-
decompressor = Target.new
|
38
|
-
|
39
|
-
Validation::INVALID_STRINGS.each do |invalid_string|
|
40
|
-
assert_raises ValidateError do
|
41
|
-
decompressor.read invalid_string, &NOOP_PROC
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
assert_raises ValidateError do
|
46
|
-
decompressor.read ""
|
47
|
-
end
|
48
|
-
|
49
|
-
decompressor.close(&NOOP_PROC)
|
50
|
-
|
51
|
-
assert_raises UsedAfterCloseError do
|
52
|
-
decompressor.read "", &NOOP_PROC
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_texts
|
57
|
-
parallel_compressor_options do |compressor_options|
|
58
|
-
TEXTS.each do |text|
|
59
|
-
compressed_text = String.compress text, compressor_options
|
60
|
-
|
61
|
-
PORTION_LENGTHS.each do |portion_length|
|
62
|
-
get_compatible_decompressor_options compressor_options do |decompressor_options|
|
63
|
-
decompressed_buffer = ::StringIO.new
|
64
|
-
decompressed_buffer.set_encoding ::Encoding::BINARY
|
65
|
-
|
66
|
-
writer = proc { |portion| decompressed_buffer << portion }
|
67
|
-
decompressor = Target.new decompressor_options
|
68
|
-
|
69
|
-
begin
|
70
|
-
source = "".b
|
71
|
-
compressed_text_offset = 0
|
72
|
-
index = 0
|
73
|
-
|
74
|
-
loop do
|
75
|
-
portion = compressed_text.byteslice compressed_text_offset, portion_length
|
76
|
-
break if portion.nil?
|
77
|
-
|
78
|
-
compressed_text_offset += portion_length
|
79
|
-
source << portion
|
80
|
-
|
81
|
-
bytes_read = decompressor.read source, &writer
|
82
|
-
source = source.byteslice bytes_read, source.bytesize - bytes_read
|
83
|
-
|
84
|
-
decompressor.flush(&writer) if index.even?
|
85
|
-
index += 1
|
86
|
-
end
|
87
|
-
|
88
|
-
ensure
|
89
|
-
refute_predicate decompressor, :closed?
|
90
|
-
decompressor.close(&writer)
|
91
|
-
assert_predicate decompressor, :closed?
|
92
|
-
end
|
93
|
-
|
94
|
-
decompressed_text = decompressed_buffer.string
|
95
|
-
decompressed_text.force_encoding text.encoding
|
96
|
-
|
97
|
-
assert_equal text, decompressed_text
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_large_texts
|
105
|
-
options_generator = OCG.new(
|
106
|
-
:text => LARGE_TEXTS,
|
107
|
-
:portion_length => LARGE_PORTION_LENGTHS
|
108
|
-
)
|
109
|
-
|
110
|
-
Common.parallel_options options_generator do |options|
|
111
|
-
text = options[:text]
|
112
|
-
portion_length = options[:portion_length]
|
113
|
-
|
114
|
-
compressed_text = String.compress text
|
115
|
-
|
116
|
-
decompressed_buffer = ::StringIO.new
|
117
|
-
decompressed_buffer.set_encoding ::Encoding::BINARY
|
118
|
-
|
119
|
-
writer = proc { |portion| decompressed_buffer << portion }
|
120
|
-
decompressor = Target.new
|
121
|
-
|
122
|
-
begin
|
123
|
-
source = "".b
|
124
|
-
compressed_text_offset = 0
|
125
|
-
|
126
|
-
loop do
|
127
|
-
portion = compressed_text.byteslice compressed_text_offset, portion_length
|
128
|
-
break if portion.nil?
|
129
|
-
|
130
|
-
compressed_text_offset += portion_length
|
131
|
-
source << portion
|
132
|
-
|
133
|
-
bytes_read = decompressor.read source, &writer
|
134
|
-
source = source.byteslice bytes_read, source.bytesize - bytes_read
|
135
|
-
end
|
136
|
-
ensure
|
137
|
-
decompressor.close(&writer)
|
138
|
-
end
|
139
|
-
|
140
|
-
decompressed_text = decompressed_buffer.string
|
141
|
-
decompressed_text.force_encoding text.encoding
|
142
|
-
|
143
|
-
assert_equal text, decompressed_text
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# -----
|
148
|
-
|
149
|
-
def get_invalid_decompressor_options(&block)
|
150
|
-
Option.get_invalid_decompressor_options BUFFER_LENGTH_NAMES, &block
|
151
|
-
end
|
152
|
-
|
153
|
-
def parallel_compressor_options(&block)
|
154
|
-
Common.parallel_options Option.get_compressor_options_generator(BUFFER_LENGTH_NAMES), &block
|
155
|
-
end
|
156
|
-
|
157
|
-
def get_compatible_decompressor_options(compressor_options, &block)
|
158
|
-
Option.get_compatible_decompressor_options compressor_options, BUFFER_LENGTH_MAPPING, &block
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
Minitest << Decompressor
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
7
|
+
Minitest << ADSP::Test::Stream::Raw::Decompressor
|