| 1 |
# |
| 2 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
# or more contributor license agreements. See the NOTICE file |
| 4 |
# distributed with this work for additional information |
| 5 |
# regarding copyright ownership. The ASF licenses this file |
| 6 |
# to you under the Apache License, Version 2.0 (the |
| 7 |
# "License"); you may not use this file except in compliance |
| 8 |
# with the License. You may obtain a copy of the License at |
| 9 |
# |
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
# |
| 12 |
# Unless required by applicable law or agreed to in writing, |
| 13 |
# software distributed under the License is distributed on an |
| 14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
# KIND, either express or implied. See the License for the |
| 16 |
# specific language governing permissions and limitations |
| 17 |
# under the License. |
| 18 |
# |
| 19 |
|
| 20 |
require 'spec_helper' |
| 21 |
|
| 22 |
describe "The extended array type" do |
| 23 |
|
| 24 |
before :each do |
| 25 |
@data = Qpid::Proton::Codec::Data.new |
| 26 |
@list = random_list(rand(100)) |
| 27 |
@undescribed = random_array(rand(100)) |
| 28 |
@description = random_string(128) |
| 29 |
@described = random_array(rand(100), true, @description) |
| 30 |
end |
| 31 |
|
| 32 |
it "can be created like a normal array" do |
| 33 |
value = [] |
| 34 |
|
| 35 |
value.must_respond_to(:proton_put) |
| 36 |
value.must_respond_to(:proton_array_header) |
| 37 |
value.class.must_respond_to(:proton_get) |
| 38 |
end |
| 39 |
|
| 40 |
it "raises an error when the current object is not a list" do |
| 41 |
@data.string = random_string(128) |
| 42 |
@data.rewind |
| 43 |
proc { @data.list }.must_raise(TypeError) |
| 44 |
end |
| 45 |
|
| 46 |
it "can be put into a Data object as a list" do |
| 47 |
@data.list= @list |
| 48 |
result = @data.list |
| 49 |
result.must_equal(@list) |
| 50 |
end |
| 51 |
|
| 52 |
it "raises an error when the elements of an Array are dissimilar and is put into a Data object" do |
| 53 |
value = Qpid::Proton::Types::UniformArray.new(Qpid::Proton::Codec::INT) |
| 54 |
value << random_string(16) |
| 55 |
proc { @data << value }.must_raise(TypeError) |
| 56 |
end |
| 57 |
|
| 58 |
it "can be put into a Data object as an undescribed array" do |
| 59 |
@data << @undescribed |
| 60 |
result = @data.array |
| 61 |
result.must_be_kind_of Qpid::Proton::Types::UniformArray |
| 62 |
@undescribed.must_equal(result) |
| 63 |
end |
| 64 |
|
| 65 |
it "can be put into a Data object as a described array" do |
| 66 |
@data << @described |
| 67 |
result = @data.array |
| 68 |
@described.must_equal(result) |
| 69 |
result.must_be_kind_of Qpid::Proton::Types::UniformArray |
| 70 |
end |
| 71 |
|
| 72 |
end |