spec/spotify_spec.rb in spotify-9.0.1 vs spec/spotify_spec.rb in spotify-9.1.0

- old
+ new

@@ -179,6 +179,28 @@ attached_members.must_include member end end end end + + describe Spotify::Subscribers do + it "should create the subscribers array using count" do + # Memory looks like this: + # + # 00 00 00 00 <- count of subscribers + # 00 00 00 00 <- pointer to subscriber 1 + # …… …… …… …… + # 00 00 00 00 <- pointer to subscriber n + real_struct = FFI::MemoryPointer.new(:char, 24) + real_struct.put_uint(0, 2) + subscribers = %w[a bb].map { |x| FFI::MemoryPointer.from_string(x) } + real_struct.put_array_of_pointer(8, subscribers) + + struct = Spotify::Subscribers.new(real_struct) + struct[:count].must_equal 2 + struct[:subscribers].size.must_equal 2 + struct[:subscribers][0].read_string.must_equal "a" + struct[:subscribers][1].read_string.must_equal "bb" + proc { struct[:subscribers][2] }.must_raise IndexError + end + end end