Changeset 216

Show
Ignore:
Timestamp:
08/07/08 22:49:56 (4 months ago)
Author:
pwh
Message:
  • Reworked testing, split some functions from application_controller in to lib/nethorus_functions.rb
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nethorus/test/functional/common_functions_test.rb

    • Property svn:mergeinfo set
    r182 r216  
    2222=begin rdoc 
    2323 
    24 Unit tests for application common functions. 
     24Functional tests for common functions. 
    2525 
    2626=end 
    2727 
    2828require File.dirname(__FILE__) + '/../test_helper' 
     29require 'nethorus_functions.rb' 
    2930 
    30 class ApplicationCommonFunctionsTest < ActiveSupport::TestCase 
     31class CommonFunctionsTest < ActiveSupport::TestCase 
    3132 
    3233  # Test the purify_mac_address function, which should convert a hexadecimal 
    3334  # string, perhaps padded with spaces, dots or dashes, in to a 12-character 
    3435  # upper-case hexadecimal string. 
    35    
    36   def purify_mac_address_test 
     36 
     37  def test_purify_mac_address 
    3738 
    3839    test_address = purify_mac_address("000000000000") 
     
    7475  end 
    7576 
     77 
     78  # Test the validate_ip_address function. 
     79   
     80  def test_validate_ip_address 
     81   
     82    assert(validate_ip_address("0.0.0.0"), "The IPv4 address 0.0.0.0 should be valid") 
     83    assert(validate_ip_address("0.0.0.1"), "The IPv4 address 0.0.0.1 should be valid") 
     84    assert(validate_ip_address("255.255.255.254"), "The IPv4 address 255.255.255.254 should be valid") 
     85    assert(validate_ip_address("255.255.255.255"), "The IPv4 address 255.255.255.255 should be valid") 
     86 
     87    assert(!validate_ip_address("0.0.0.-1"), "The IPv4 address 0.0.0.-1 should not be valid") 
     88    assert(!validate_ip_address("0.0.-1.0"), "The IPv4 address 0.0.-1.0 should not be valid") 
     89    assert(!validate_ip_address("0.-1.0.0"), "The IPv4 address 0.-1.0.0 should not be valid") 
     90    assert(!validate_ip_address("-1.0.0.0"), "The IPv4 address -1.0.0.0 should not be valid") 
     91     
     92    assert(validate_ip_address("0"), "The IPv4 address 0 should be valid") 
     93    assert(!validate_ip_address("0.0"), "The IPv4 address 0.0 should not be valid") 
     94    assert(!validate_ip_address("0.0.0"), "The IPv4 address 0.0.0 should not be valid") 
     95    assert(!validate_ip_address("0.0.0.0.0"), "The IPv4 address 0.0.0.0.0 should not be valid") 
     96     
     97  end 
     98   
    7699end 
  • nethorus/test/unit/bridge_test.rb

    r183 r216  
    254254 
    255255 
     256  # Test the bridge hack for devices which return values in seconds rather than centi-seconds 
     257   
     258  def test_bridge_values_in_seconds_not_centiseconds_hack 
     259   
     260    bridge = @device.create_bridge 
     261 
     262    bridge.dot1d_base_bridge_address = "80001234567890AB" 
     263    bridge.dot1d_base_num_ports = 1 
     264    bridge.dot1d_base_type = "transparent-only" 
     265    bridge.dot1d_stp_protocol_specification = "ieee8021d" 
     266    bridge.dot1d_stp_priority = 32768 
     267    bridge.dot1d_stp_designated_root = "80001234567890AB" 
     268    bridge.dot1d_stp_root_cost = 100 
     269    bridge.dot1d_stp_root_port = 50 
     270    bridge.dot1d_stp_max_age = 2000 
     271    bridge.dot1d_stp_hello_time = 200 
     272    bridge.dot1d_stp_hold_time = 200 
     273    bridge.dot1d_stp_forward_delay = 1500 
     274    bridge.dot1d_stp_bridge_max_age = 2000 
     275    bridge.dot1d_stp_bridge_hello_time = 200 
     276    bridge.dot1d_stp_bridge_forward_delay = 1500 
     277 
     278    assert(bridge.valid?, "A new Bridge should be valid with the minimum required attributes set") 
     279     
     280     
     281    # Test recalculation for low values of dot1d_stp_max_age 
     282     
     283    bridge.dot1d_stp_max_age = 1 
     284    assert(bridge.valid? && bridge_dot1d_stp_max_age = 100, "Specifying dot1d_stp_max_age =< 50 should multiply the value by 100 (centisecond hack) - we used 1") 
     285 
     286    bridge.dot1d_stp_max_age = 50 
     287    assert(bridge.valid? && bridge_dot1d_stp_max_age = 5000, "Specifying dot1d_stp_max_age =< 50 should multiply the value by 100 (centisecond hack) - we used 50") 
     288   
     289    bridge.dot1d_stp_max_age = 51 
     290    assert(bridge.valid? && bridge_dot1d_stp_max_age = 51, "Specifying dot1d_stp_max_age =< 50 should multiply the value by 100 (centisecond hack) - we used 51") 
     291 
     292 
     293    # Test recalculation for low values of dot1d_stp_hello_time 
     294 
     295    bridge.dot1d_stp_hello_time = 1 
     296    assert(bridge.valid? && bridge_dot1d_stp_hello_time = 100, "Specifying dot1d_stp_hello_time =< 50 should multiply the value by 100 (centisecond hack) - we used 1") 
     297 
     298    bridge.dot1d_stp_hello_time = 50 
     299    assert(bridge.valid? && bridge_dot1d_stp_hello_time = 5000, "Specifying dot1d_stp_hello_time =< 50 should multiply the value by 100 (centisecond hack) - we used 50") 
     300   
     301    bridge.dot1d_stp_hello_time = 51 
     302    assert(bridge.valid? && bridge_dot1d_stp_hello_time = 51, "Specifying dot1d_stp_hello_time =< 50 should multiply the value by 100 (centisecond hack) - we used 51") 
     303 
     304  end 
     305 
     306 
    256307  # Test the device/bridge relationship 
    257308   
  • nethorus/test/unit/device_test.rb

    r168 r216  
    210210 
    211211    device = Device.new 
    212     device.hostname = "xample" 
     212    device.hostname = "example" 
    213213    device.ipv4_address = "127.0.0.1" 
    214214 
     
    225225    assert(device.valid?, "A device should be valid with a nil SNMP version") 
    226226 
     227    device.snmp_version = 4 
     228    assert(!device.valid?, "A device should not be valid with an SNMP version of 4") 
     229 
     230    device.snmp_version = "garbage" 
     231    assert(!device.valid?, "A device should not be valid with an SNMP version of 'garbage'") 
     232 
    227233  end 
    228234