"""
<Program Name>
  z_test_connection_bind.repy

<Started>
  February 9, 2009

<Author>
  Richard Jordan

<Purpose>
  To test that Connection.bind() function works.

  Passes quietly
"""
include connection.repy

if callfunc == "initialize":
  IP = getmyip()
  PORT = 12345

def test_bind():
  conn = Connection()
  conn.bind(IP, PORT)
  assert conn.localip == IP
  assert conn.localport == PORT
  assert not conn.conn
  assert not conn.remoteip
  assert not conn.remoteport

def test_rebind():
  conn = Connection()
  conn.bind(IP, PORT)
  conn.bind(IP, PORT)
  assert conn.localip == IP
  assert conn.localport == PORT
  assert not conn.conn
  assert not conn.remoteip
  assert not conn.remoteport

def test_bind_already_connected():
  conn = Connection()
  conn.bind(IP, PORT)
  conn.conn = True
  try:
    conn.bind(IP, PORT)
  except AlreadyConnectedError:
    pass
  else:
    raise Exception("should have raised error")

####################
# Test Helper Functions
####################

def main():
  # setup
  
  # Run tests
  test_bind()
  test_rebind()
  test_bind_already_connected()

  # teardown
  exitall()

if callfunc == 'initialize':
  main()
