1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
require 'minitest/autorun'
require 'beefcake/buffer'
class BufferDecodeTest < Minitest::Test
B = Beefcake::Buffer
def setup
@buf = B.new
end
def test_read_info
@buf.append_info(1, 2)
assert_equal [1, 2], @buf.read_info
@buf.append_info(2, 5)
assert_equal [2, 5], @buf.read_info
end
def test_read_string
@buf.append_string("testing")
decoded = @buf.read_string
assert_equal "testing", decoded
assert_equal Encoding.find('utf-8'), decoded.encoding
end
def test_read_fixed32
@buf.append_fixed32(123)
assert_equal 123, @buf.read_fixed32
end
def test_read_fixed64
@buf.append_fixed64(456)
assert_equal 456, @buf.read_fixed64
end
def test_read_uint32
@buf.append_uint32(1)
assert_equal 1, @buf.read_uint32
end
def test_read_int32
@buf.append_int32(999)
assert_equal 999, @buf.read_int32
@buf.append_int32(-999)
assert_equal -999, @buf.read_int32
end
def test_read_int64
@buf.append_int64(999)
assert_equal 999, @buf.read_int64
@buf.append_int64(-999)
assert_equal -999, @buf.read_int64
end
def test_read_uint64
@buf.append_uint64(1)
assert_equal 1, @buf.read_uint64
end
def test_read_float
@buf.append_float(0.5)
assert_equal 0.5, @buf.read_float
end
def test_read_double
@buf.append_double(Math::PI)
assert_equal Math::PI, @buf.read_double
end
def test_read_bool
@buf.append_bool(true)
assert_equal true, @buf.read_bool
@buf.append_bool(false)
assert_equal false, @buf.read_bool
end
def test_read_sint32
@buf.append_sint32(B::MinInt32)
assert_equal B::MinInt32, @buf.read_sint32
@buf.buf = ""
@buf.append_sint32(B::MaxInt32)
assert_equal B::MaxInt32, @buf.read_sint32
end
def test_read_sfixed32
@buf.append_sfixed32(B::MinInt32)
assert_equal B::MinInt32, @buf.read_sfixed32
@buf.buf = ""
@buf.append_sfixed32(B::MaxInt32)
assert_equal B::MaxInt32, @buf.read_sfixed32
end
def test_read_sint64
@buf.append_sint64(B::MinInt64)
assert_equal B::MinInt64, @buf.read_sint64
@buf.buf = ""
@buf.append_sint64(B::MaxInt64)
assert_equal B::MaxInt64, @buf.read_sint64
end
def test_read_sfixed64
@buf.append_sfixed64(B::MinInt64)
assert_equal B::MinInt64, @buf.read_sfixed64
@buf.buf = ""
@buf.append_sfixed64(B::MaxInt64)
assert_equal B::MaxInt64, @buf.read_sfixed64
end
end
|