#!/usr/bin/python2
# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
#
# Copyright (C) 2014 University of Arizona
# Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
# See COPYING for copyright and distribution information.
#

import os
import time
import unittest
import process_manager

class test_ndntraffic(unittest.TestCase, process_manager.ProcessManager):
    """Test case for testing ndn-traffic-generator application"""

    def setUp(self):
        print "\nTesting ndn-traffic-generator"
        print "*****************************"

    def tearDown(self):
        self.killNfd()
        self.killProcess("ndn-traffic-server")
        self.killProcess("ndn-traffic")
        self.cleanupProcesses()

    def test_traffic(self):
        self.startNfd()
        time.sleep(1)
        self.startNrd()
        time.sleep(1)
        serverConfigurationFile = os.path.abspath("test_ndntraffic/test-traffic-server.conf")
        self.startProcess("ndn-traffic-server",
            ["ndn-traffic-server", "-c 1", serverConfigurationFile],
            "-> Starting Traffic Server")
        time.sleep(1)
        clientConfigurationFile = os.path.abspath("test_ndntraffic/test-traffic-client.conf")
        self.startProcess("ndn-traffic",
            ["ndn-traffic", "-c 1", clientConfigurationFile],
            "-> Starting Traffic Client")
        time.sleep(1)
        self.waitForProcessCompletion("ndn-traffic", 10)
        self.waitForProcessCompletion("ndn-traffic-server", 10)
        if self.hasProcessCompleted("ndn-traffic"):
            if self.getProcessReturnCode("ndn-traffic") != 0:
                print self.getProcessError("ndn-traffic")
                self.fail(">> TEST FAILED - received non-zero return code from ndn-traffic")
        else:
            self.fail(">> TEST FAILED - ndn-traffic failed to complete")
        if self.hasProcessCompleted("ndn-traffic-server"):
            if self.getProcessReturnCode("ndn-traffic-server") != 0:
                print self.getProcessError("ndn-traffic-server")
                self.fail(">> TEST FAILED - received non-zero return code from ndn-traffic-server")
        else:
            self.fail(">> TEST FAILED - ndn-traffic-server failed to complete")
        print ">> TEST SUCCESSFUL"
