-
Notifications
You must be signed in to change notification settings - Fork 1
/
hsms_message_test.rb
50 lines (45 loc) · 1.2 KB
/
hsms_message_test.rb
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
require "test/unit"
require "hsms_message"
class TestHSMSMessage < Test::Unit::TestCase
def test_length_one_feed
h = HSMSMessage.new
assert_equal(0, h.length)
h.feed("\x10\x02\x30\x04\x50\x06")
assert_equal(0x10023004, h.length)
end
def test_length_fractional_feeds
h = HSMSMessage.new
h.feed(0xFF)
assert_equal(0, h.length)
h.feed(0x00)
assert_equal(0, h.length)
h.feed(0x00)
assert_equal(0, h.length)
h.feed(0x11)
assert_equal(0xFF000011, h.length)
h.feed(0xFF)
assert_equal(0xFF000011, h.length)
end
def test_remain_buffer_size
h = HSMSMessage.new
assert_equal(HSMSMessage::MAX_BUFFER_SIZE, h.remain_buffer_size)
3.times { h.feed(0) }
h.feed(20)
assert_equal(20, h.remain_buffer_size)
data = "0" * 10
h.feed(data)
assert_equal(10, h.remain_buffer_size)
h.feed(data)
assert_equal(0, h.remain_buffer_size)
h.feed(data)
assert_equal(0, h.remain_buffer_size)
end
def test_select_rsp
h = HSMSMessage.new
s_type = "\x02"
select_rsp = "\x00\x00\x00\x0A" + "\x00" * 5 + s_type + "\x00" * 4
h.feed(select_rsp)
assert_equal(10, h.length)
assert_equal(2, h.s_type)
end
end