#!/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)
        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"
