]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/c_glib/test/test-mutable-buffer.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / c_glib / test / test-mutable-buffer.rb
CommitLineData
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
18class TestMutableBuffer < Test::Unit::TestCase
19 def setup
20 @data = "Hello"
21 @buffer = Arrow::MutableBuffer.new(@data)
22 end
23
24 def test_new_bytes
25 bytes_data = GLib::Bytes.new(@data)
26 buffer = Arrow::MutableBuffer.new(bytes_data)
27 if GLib.check_binding_version?(3, 2, 2)
28 assert_equal(bytes_data.pointer, buffer.mutable_data.pointer)
29 else
30 assert_equal(@data, buffer.mutable_data.to_s)
31 end
32 end
33
34 def test_mutable?
35 assert do
36 @buffer.mutable?
37 end
38 end
39
40 def test_mutable_data
41 assert_equal(@data, @buffer.mutable_data.to_s)
42 end
43
44 def test_slice
45 sliced_buffer = @buffer.slice(1, 3)
46 assert_equal(@data[1, 3], sliced_buffer.data.to_s)
47 end
48
49 sub_test_case("#set_data") do
50 test("offset") do
51 @buffer.set_data(1, "EL")
52 assert_equal("HELlo", @buffer.data.to_s)
53 end
54
55 test("replace") do
56 @buffer.set_data(0, "World")
57 assert_equal("World", @buffer.data.to_s)
58 end
59
60 test("offset: too large") do
61 message = "[mutable-buffer][set-data]: Data is too large: <(5 + 1) > (5)>"
62 assert_raise(Arrow::Error::Invalid.new(message)) do
63 @buffer.set_data(5, "X")
64 end
65 end
66
67 test("data too large") do
68 message = "[mutable-buffer][set-data]: Data is too large: <(0 + 6) > (5)>"
69 assert_raise(Arrow::Error::Invalid.new(message)) do
70 @buffer.set_data(0, @data + "!")
71 end
72 end
73 end
74end