fail
""" 
<Program Name>
  z_test_client_accept.repy

<Started>
  February 9, 2009

<Author>
  Richard Jordan

<Purpose>
  To test that the function works.

  Passes quietly
"""
include constants.repy
include client.repy

if callfunc == 'initialize':
  DEST_IP = 'whatever'
  DEST_PORT = 12345
  SRC_IP = 'whateversrc'
  SRC_PORT = 12346
  TIMEOUT = .01
  RETRIES = 4  

def test_accept():
  mycontext['packets'].clear()
  ACK_NUM = 1
  WINDOW= 10
  cli = TcpClient(synack_register)
  SEQ_NUM = cli.last_seq_sent
  cli.recv_window_size= WINDOW
  try:
    cli.accept(ACK_NUM, DEST_IP, DEST_PORT, SRC_IP, SRC_PORT,RETRIES, TIMEOUT)
  except TimeoutError:
    pass
  else:
    raise Exception("should raise timeout")

  assert SEQ_NUM in mycontext['packets'].keys()
  assert mycontext['packets'][SEQ_NUM].is_synack()
  assert cli.last_ack_recv is None
  assert cli.last_seq_sent == SEQ_NUM
  assert mycontext['packet_count'] == RETRIES + 1
  assert mycontext['packets'][SEQ_NUM].srcport == SRC_PORT
  assert mycontext['packets'][SEQ_NUM].destport == DEST_PORT
  assert mycontext['packets'][SEQ_NUM].window == WINDOW
  assert mycontext['packets'][SEQ_NUM].ack_num == ACK_NUM
  assert mycontext['packets'][SEQ_NUM].seq_num == SEQ_NUM

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

def synack_register(destip, destport, message, srcip = None, srcport = None):
    mycontext['packet_count'] +=1
    pack = unpack(message)
    mycontext['packets'][pack.seq_num] = pack
    return len(pack.payload)


def main():
  # setup
  mycontext['packet_count'] = 0
  mycontext['packets'] = {}

  # Run tests
  test_accept()

  # teardown
  exitall()

if callfunc == 'initialize':
  main()
