class TestCodec

Main class for testing Stomp::HeadreCodec methods.

Public Instance Methods

setup() click to toggle source
# File test/test_codec.rb, line 14
def setup
  @conn = get_connection()
  # Data for multi_thread tests
  @max_threads = 20
  @max_msgs = 100
end
teardown() click to toggle source
# File test/test_codec.rb, line 21
def teardown
  @conn.disconnect if @conn.open? # allow tests to disconnect
end
test_1000_check_notneeded() click to toggle source

Test that the codec does nothing to strings that do not need encoding.

# File test/test_codec.rb, line 26
def test_1000_check_notneeded
  test_data = [
    "a",
    "abcdefghijklmnopqrstuvwxyz",
    "ªºÀÁ",
    "AÇBØCꞇDẼ",
    "ªºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ" + 
              "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġDŽDždžLJLjǼǽǾǿȀȁȂȃȌȍȒɰɵɲɮᴘᴤᴭᴥᵻᶅ" +
              "ᶑṆṌṕṽẄẂỚỘⅱⅲꜨꝐꞂ",
    ]
  #
  test_data.each do |s|
    #
    s_decoded = Stomp::HeaderCodec::decode(s)
    assert_equal s, s_decoded, "Sanity check decode: #{s} | #{s_decoded}"
    s_reencoded = Stomp::HeaderCodec::encode(s_decoded)
    assert_equal s_decoded, s_reencoded, "Sanity check reencode: #{s_decoded} | #{s_reencoded}"
    #
  end
end
test_1010_basic_encode_decode() click to toggle source

Test the basic encoding / decoding requirements.

# File test/test_codec.rb, line 48
def test_1010_basic_encode_decode
  test_data = [
      [ "\\\\", "\\" ],
      ["\\n", "\n"],
      ["\\r", "\r"],
          ["\\c", ":"],
          ["\\\\\\n\\c", "\\\n:"],
          ["\\\\\\r\\c", "\\\r:"],
          ["\\c\\n\\\\", ":\n\\"],
          ["\\c\\r\\\\", ":\r\\"],
          ["\\\\\\c", "\\:"],
          ["c\\cc", "c:c"],
          ["n\\nn", "n\nn"],
          ["r\\rr", "r\rr"],
    ]
  #
  test_data.each do |s|
    #
    s_decoded = Stomp::HeaderCodec::encode(s[0])
    assert_equal s[1], s_decoded, "Sanity check encode: #{s[1]} | #{s_decoded}"
    #
    s_encoded = Stomp::HeaderCodec::decode(s[1])
    assert_equal s[0], s_encoded, "Sanity check decode: #{s[0]} | #{s_encoded}"
  end
end
test_1020_fancier() click to toggle source

Test more complex strings with the codec.

# File test/test_codec.rb, line 75
def test_1020_fancier
  test_data = [
      [ "a\\\\b", "a\\b" ],
    [ "\\\\\\n\\c", "\\\n:" ],
    [ "\\\\\\r\\c", "\\\r:" ],
    [ "\\rr\\\\\\n\\c", "\rr\\\n:" ],
    ]
  #
  test_data.each do |s|
    #
    s_decoded = Stomp::HeaderCodec::encode(s[0])
    assert_equal s[1], s_decoded, "Sanity check encode: #{s[1]} | #{s_decoded}"
    #
    s_encoded = Stomp::HeaderCodec::decode(s[1])
    assert_equal s[0], s_encoded, "Sanity check decode: #{s[0]} | #{s_encoded}"
  end
end