Class: SOCKS5BytestreamsTest

Inherits:
Test::Unit::TestCase show all
Includes:
ClientTester
Defined in:
lib/gems/xmpp4r-0.4/test/bytestreams/tc_socks5bytestreams.rb

Constant Summary collapse

@@server =
Bytestreams::SOCKS5BytestreamsServer.new(65005)

Instance Method Summary collapse

Methods inherited from Test::Unit::TestCase

#assert_array_equal, expect, #run

Instance Method Details

#create_buffer(size) ⇒ Object



18
19
20
# File 'lib/gems/xmpp4r-0.4/test/bytestreams/tc_socks5bytestreams.rb', line 18

def create_buffer(size)
  ([nil] * size).collect { rand(256).chr }.join
end

#test_pingpongObject



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
# File 'lib/gems/xmpp4r-0.4/test/bytestreams/tc_socks5bytestreams.rb', line 68

def test_pingpong
  target = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '1', '[email protected]/1', '[email protected]/2')
  initiator = Bytestreams::SOCKS5BytestreamsInitiator.new(@client, '1', '[email protected]/1', '[email protected]/2')
  initiator.add_streamhost(@@server)


  Thread.new do
    target.accept

    while buf = target.read(256)
      target.write(buf)
      target.flush
    end

    target.close
  end


  initiator.open

  10.times do
    buf = create_buffer(8192)
    initiator.write(buf)
    initiator.flush

    bufr = ''
    begin
      bufr += initiator.read(256)
    end while bufr.size < buf.size
    assert_equal(buf, bufr)
  end

  initiator.close
end

#test_server2multiObject



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
# File 'lib/gems/xmpp4r-0.4/test/bytestreams/tc_socks5bytestreams.rb', line 22

def test_server2multi
  target1 = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '1', '[email protected]/1', '[email protected]/2')
  target2 = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '2', '[email protected]/1', '[email protected]/2')
  initiator1 = Bytestreams::SOCKS5BytestreamsInitiator.new(@client, '1', '[email protected]/1', '[email protected]/2')
  initiator2 = Bytestreams::SOCKS5BytestreamsInitiator.new(@client, '2', '[email protected]/1', '[email protected]/2')
  initiator1.add_streamhost(@@server)
  initiator2.add_streamhost(@@server)

  buf1 = create_buffer(8192)
  buf2 = create_buffer(8192)

  Thread.new do
    target1.accept
    target1.write(buf1)
    target1.flush
    target1.close
  end

  Thread.new do
    target2.accept
    target2.write(buf2)
    target2.flush
    target2.close
  end

  initiator1.open
  initiator2.open

  recv1 = ''
  recv2 = ''

  while buf = initiator2.read(256)
    recv2 += buf
  end

  while buf = initiator1.read(256)
    recv1 += buf
  end

  initiator1.close
  initiator2.close

  assert_equal(buf1, recv1)
  assert_equal(buf2, recv2)
end

#test_timeoutObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/gems/xmpp4r-0.4/test/bytestreams/tc_socks5bytestreams.rb', line 103

def test_timeout
  target = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '1', '[email protected]/1', '[email protected]/2')

  assert_nothing_raised do
    Timeout::timeout(2) do
      target.connect_timeout = 1
      assert target.accept == false
    end
  end
end