TeensyMud - 'A ruby mud server.'

Browse repository
back

test_telnetfilter.rb

# Code Generated by ZenTest v. 2.3.0
# classname: asrt / meth = ratio%
# TelnetFilter: 9 / 22 = 40.91%

unless defined? $ZENTEST and $ZENTEST
require 'test/unit'
require 'utility/log'
require 'network/protocol/telnetfilter'
require 'flexmock'
require 'ostruct'
require 'strscan'
require 'mocksocket'
end

class TestTelnetFilter < Test::Unit::TestCase
def setup
@serv = FlexMock.new
@serv.mock_handle(:service_type) { :server }
@serv.mock_handle(:service_io) { :sockio }
@serv.mock_handle(:service_filters) { [:telnetfilter, :debugfilter] }
@serv.mock_handle(:service_negotiation) { [:supga, :zmp, :echo] }
@sock = MockSocket.new("hello world\r\nfoobar")
@sockio = SockIO.new(@sock, 5)
@conn = FlexMock.new
@conn.mock_handle(:sendmsg) { true }
@conn.mock_handle(:sock) { @sock }
@conn.mock_handle(:sockio) { @sockio }
@pstack = FlexMock.new
@pstack.mock_handle(:conn) { @conn }
@pstack.mock_handle(:echo_on) { false }
@pstack.mock_handle(:binary_on) { false }
@pstack.mock_handle(:urgent_on) { false }
@filter = TelnetFilter.new(@pstack, @serv)
end

def test_desired_eh
assert_equal(true, @filter.desired?(TelnetCodes::ECHO))
assert_equal(false, @filter.desired?(TelnetCodes::BINARY))
end

def test_echo
assert(true, @filter.echo("foobar"))
end

def test_enabled_eh
assert_equal(false, @filter.enabled?(TelnetCodes::ECHO, :us))
end

def test_filter_in
assert_equal("Hello World\n",
@filter.filter_in("Hello "+TelnetCodes::IAC.chr+TelnetCodes::AYT.chr+"World\r\n"))
end

def test_filter_out
assert_equal("Hello World\r\n",
@filter.filter_out("Hello World\n"))
end

def test_init
assert_equal(true, @filter.init([:server, :filter, :echo, :zmp]))
end

def test_init_subneg
assert(true, @filter.init_subneg)
end

def test_send_naws
assert(true, @filter.send_naws)
end
end