]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | # Licensed to the Apache Software Foundation (ASF) under one |
2 | # or more contributor license agreements. See the NOTICE file | |
3 | # distributed with this work for additional information | |
4 | # regarding copyright ownership. The ASF licenses this file | |
5 | # to you under the Apache License, Version 2.0 (the | |
6 | # "License"); you may not use this file except in compliance | |
7 | # with the License. You may obtain a copy of the License at | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, | |
12 | # software distributed under the License is distributed on an | |
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | # KIND, either express or implied. See the License for the | |
15 | # specific language governing permissions and limitations | |
16 | # under the License. | |
17 | ||
18 | class TestBufferInputStream < Test::Unit::TestCase | |
19 | include Helper::Buildable | |
20 | ||
21 | def test_read | |
22 | buffer = Arrow::Buffer.new("Hello World") | |
23 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
24 | read_buffer = buffer_input_stream.read(5) | |
25 | assert_equal("Hello", read_buffer.data.to_s) | |
26 | end | |
27 | ||
28 | def test_read_bytes | |
29 | buffer = Arrow::Buffer.new("Hello World") | |
30 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
31 | read_bytes = buffer_input_stream.read_bytes(5) | |
32 | assert_equal("Hello", read_bytes.to_s) | |
33 | end | |
34 | ||
35 | def test_read_at | |
36 | buffer = Arrow::Buffer.new("Hello World") | |
37 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
38 | read_buffer = buffer_input_stream.read_at(6, 3) | |
39 | assert_equal("Wor", read_buffer.data.to_s) | |
40 | end | |
41 | ||
42 | def test_read_at_bytes | |
43 | buffer = Arrow::Buffer.new("Hello World") | |
44 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
45 | read_bytes = buffer_input_stream.read_at_bytes(6, 3) | |
46 | assert_equal("Wor", read_bytes.to_s) | |
47 | end | |
48 | ||
49 | def test_advance | |
50 | buffer = Arrow::Buffer.new("Hello World") | |
51 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
52 | buffer_input_stream.advance(6) | |
53 | read_buffer = buffer_input_stream.read(5) | |
54 | assert_equal("World", read_buffer.data.to_s) | |
55 | end | |
56 | ||
57 | def test_align | |
58 | buffer = Arrow::Buffer.new("Hello World") | |
59 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
60 | buffer_input_stream.advance(3) | |
61 | buffer_input_stream.align(8) | |
62 | read_buffer = buffer_input_stream.read(3) | |
63 | assert_equal("rld", read_buffer.data.to_s) | |
64 | end | |
65 | ||
66 | def test_peek | |
67 | buffer = Arrow::Buffer.new("Hello World") | |
68 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
69 | peeked_data = buffer_input_stream.peek(5) | |
70 | assert_equal(buffer_input_stream.read(5).data.to_s, | |
71 | peeked_data.to_s) | |
72 | end | |
73 | ||
74 | def test_gio_input_stream | |
75 | # U+3042 HIRAGANA LETTER A | |
76 | data = "\u3042" | |
77 | convert_encoding = "cp932" | |
78 | buffer = Arrow::Buffer.new(data) | |
79 | buffer_input_stream = Arrow::BufferInputStream.new(buffer) | |
80 | converter = Gio::CharsetConverter.new(convert_encoding, "UTF-8") | |
81 | convert_input_stream = | |
82 | Gio::ConverterInputStream.new(buffer_input_stream, converter) | |
83 | gio_input_stream = Arrow::GIOInputStream.new(convert_input_stream) | |
84 | raw_read_data = gio_input_stream.read(10).data.to_s | |
85 | assert_equal(data.encode(convert_encoding), | |
86 | raw_read_data.dup.force_encoding(convert_encoding)) | |
87 | end | |
88 | ||
89 | def test_read_record_batch | |
90 | fields = [ | |
91 | Arrow::Field.new("visible", Arrow::BooleanDataType.new), | |
92 | Arrow::Field.new("valid", Arrow::BooleanDataType.new), | |
93 | ] | |
94 | schema = Arrow::Schema.new(fields) | |
95 | columns = [ | |
96 | build_boolean_array([true]), | |
97 | build_boolean_array([false]), | |
98 | ] | |
99 | record_batch = Arrow::RecordBatch.new(schema, 1, columns) | |
100 | ||
101 | buffer = Arrow::ResizableBuffer.new(0) | |
102 | output_stream = Arrow::BufferOutputStream.new(buffer) | |
103 | output_stream.write_record_batch(record_batch) | |
104 | output_stream.close | |
105 | ||
106 | input_stream = Arrow::BufferInputStream.new(buffer) | |
107 | options = Arrow::ReadOptions.new | |
108 | assert_equal(record_batch, | |
109 | input_stream.read_record_batch(schema, options)) | |
110 | end | |
111 | end |