forked from eventmachine/eventmachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stomp.rb
38 lines (29 loc) · 930 Bytes
/
test_stomp.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
require_relative 'em_test_helper'
class TestStomp < Test::Unit::TestCase
CONTENT_LENGTH_REGEX = /^content-length: (\d+)$/
def bytesize(str)
str = str.to_s
size = str.bytesize if str.respond_to?(:bytesize) # bytesize added in 1.9
size || str.size
end
class TStomp
include EM::P::Stomp
def last_sent_content_length
@sent && Integer(@sent[CONTENT_LENGTH_REGEX, 1])
end
def send_data(string)
@sent = string
end
end
def test_content_length_in_bytes
connection = TStomp.new
queue = "queue"
failure_message = "header content-length is not the byte size of last sent body"
body = "test"
connection.send queue, body
assert_equal bytesize(body), connection.last_sent_content_length, failure_message
body = "test\u221A"
connection.send queue, body
assert_equal bytesize(body), connection.last_sent_content_length, failure_message
end
end