Sha256: 0e5da1ebae0d5c9cc06b69aa71a8dd9ad955572969af7325a329e77b8205135f

Contents?: true

Size: 1.35 KB

Versions: 43

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))

require 'test/unit'
require 'rex/socket/switch_board'

class Rex::Socket::SwitchBoard::UnitTest < Test::Unit::TestCase

	Klass = Rex::Socket::SwitchBoard

	def test_add
		Klass.flush_routes
		assert_equal(true, Klass.add_route('0.0.0.0', 0, 'foo'))
		assert_equal(false, Klass.add_route('0.0.0.0', 0, 'foo'))
		assert_equal(1, Klass.routes.length)

		assert_equal('0.0.0.0', Klass.routes[0].subnet)
		assert_equal('0.0.0.0', Klass.routes[0].netmask)
		assert_equal(0, Klass.routes[0].bitmask)
		assert_equal('foo', Klass.routes[0].comm)
	end

	def test_remove
		Klass.flush_routes
		assert_equal(true, Klass.add_route('0.0.0.0', 0, 'foo'))
		assert_equal(true, Klass.remove_route('0.0.0.0', 0, 'foo'))
		assert_equal(false, Klass.remove_route('0.0.0.0', 0, 'foo'))
		assert_equal(0, Klass.routes.length)
	end

	def test_best_comm
		Klass.flush_routes
		Klass.add_route('0.0.0.0', 0, 'default')
		Klass.add_route('1.2.3.0', 24, 'spec')

		assert_equal('default', Klass.best_comm('4.5.6.7'))
		assert_equal('spec', Klass.best_comm('1.2.3.7'))
	end

	def test_remove_by_comm
		Klass.flush_routes
		Klass.add_route('1.2.3.0', 24, 'foo')
		Klass.add_route('1.2.4.0', 24, 'dog')

		Klass.remove_by_comm('foo')

		assert_equal('dog', Klass.best_comm('1.2.4.7'))
		assert_nil(Klass.best_comm('1.2.3.7'))
	end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.63 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.54 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.53 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.52 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.51 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.50 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.49 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.48 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.47 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.46 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.44 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.43 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.42 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.41 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.40 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.39 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.38 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.37 lib/rex/socket/switch_board.rb.ut.rb
librex-0.0.36 lib/rex/socket/switch_board.rb.ut.rb