""" 
<Program Name>
  z_test_connection_send.repy

<Started>
  February 9, 2009

<Author>
  Richard Jordan

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

  Passes quietly
"""
include connection.repy
include dummies.repy

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

def test_send():
  conn = Connection()
  conn.conn = True
  conn.localip = IP
  conn.localport = PORT
  conn.remoteip = IP
  conn.remoteport = PORT
  conn.client = TcpClient(conn)
  bytes = conn.send(MESS)
  assert bytes

def test_send_not_bound():
  conn = Connection()
  try:
    conn.send(MESS)
  except NotBoundError:
    pass
  else:
    raise Exception("should have raised error")

def test_send_not_established():
  conn = Connection()
  conn.localip = IP
  conn.localport = PORT
  conn.conn = True
  try:
    conn.send(MESS)
  except NotEstablishedError:
    pass
  else:
    raise Exception("should have raised error")

def test_send_not_connected():
  conn = Connection()
  conn.localip = IP
  conn.localport = PORT
  try:
    conn.send(MESS)
  except NotConnectedError:
    pass
  else:
    raise Exception("should have raised error")


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

def main():
  # setup
  
  # Run tests
  test_send()
  test_send_not_established()
  test_send_not_bound()
  test_send_not_connected()

  # teardown
  exitall()

if callfunc == 'initialize':
  main()
