Parent

Class/Module Index [+]

Quicksearch

Rex::IO::RingBuffer::UnitTest

TODO: Mock up the socket so this test doesn't take so long

Public Instance Methods

setup() click to toggle source
# File lib/rex/io/ring_buffer.rb.ut.rb, line 13
def setup
        server = Rex::Socket.create_tcp_server('LocalPort' => 0)
        lport  = server.getsockname[2]
        @client = Rex::Socket.create_tcp('PeerHost' => '127.0.0.1', 'PeerPort' => lport)
        conn   = server.accept
        #server.close

        @r = Rex::IO::RingBuffer.new(conn, {:size => 64})
        @r.start_monitor
end
teardown() click to toggle source
# File lib/rex/io/ring_buffer.rb.ut.rb, line 24
def teardown
        begin
                @client.close
                @r.stop_monitor
        rescue ::Exception
        end
end
test_sequential_read_data() click to toggle source
# File lib/rex/io/ring_buffer.rb.ut.rb, line 40
def test_sequential_read_data
        @r.clear_data

        s = nil
        0.upto(10) do |num|
                @client.put(num.to_s)
                @r.wait(s)
                s,d = @r.read_data(s)
                assert_equal(num.to_s, d)
        end
end
test_single_read_data() click to toggle source
# File lib/rex/io/ring_buffer.rb.ut.rb, line 32
def test_single_read_data
        @client.put("123")
        @r.wait(0)
        s,d = @r.read_data

        assert_equal("123", d)
end
test_wrap() click to toggle source
# File lib/rex/io/ring_buffer.rb.ut.rb, line 52
def test_wrap
        @r.clear_data
        0.upto(@r.size - 1) {
                @client.put("a")
                # Need to sleep so the socket doesn't get all the data in one read()
                sleep 0.05
        }
        s,d = @r.read_data

        @client.put("b")
        sleep 0.01
        s,d = @r.read_data(s)

        assert_equal("b", d)

end

[Validate]

Generated with the Darkfish Rdoc Generator 2.