#!/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_ndnpeekpoke(unittest.TestCase, process_manager.ProcessManager):
    """Test case for testing ndnpeek and ndnpoke applications"""

    def setUp(self):
        print "\nTesting ndnpeek & ndnpoke"
        print "***********************************"
        os.system("mkdir -p test_ndnpeekpoke/logs/")

    def tearDown(self):
        self.killNfd()
        self.killProcess("ndnpoke")
        self.killProcess("ndnpeek")
        self.cleanupProcesses()

    def test_peekpoke(self):
        self.startNfd()
        time.sleep(1)
        pokeInputFile = os.path.abspath("test_ndnpeekpoke/test-poke-input.txt")
        self.startProcess("ndnpoke",
            ["ndnpoke", "ndn:/test/peekpoke"],
            "-> Starting Poke",
            inputFile=pokeInputFile)
        time.sleep(1)
        peekOutputFile = os.path.abspath("test_ndnpeekpoke/logs/test-peek-output.txt")
        self.startProcess("ndnpeek",
            ["ndnpeek", "ndn:/test/peekpoke"],
            "-> Starting Peek",
            outputFile=peekOutputFile)
        time.sleep(1)
        self.waitForProcessCompletion("ndnpeek", 10)
        self.waitForProcessCompletion("ndnpoke", 10)
        if self.hasProcessCompleted("ndnpeek"):
            if self.getProcessReturnCode("ndnpeek") != 0:
                print self.getProcessReturnCode("ndnpeek")
                print self.getProcessError("ndnpeek")
                print self.getProcessOutput("ndnpeek")
                self.fail(">> TEST FAILED - received non-zero return code from ndnpeek")
        else:
            self.fail(">> TEST FAILED - ndnpeek failed to complete")
        if self.hasProcessCompleted("ndnpoke"):
            if self.getProcessReturnCode("ndnpoke") != 0:
                print self.getProcessError("ndnpoke")
                self.fail(">> TEST FAILED - received non-zero return code from ndnpoke")
        else:
            self.fail(">> TEST FAILED - ndnpoke failed to complete")
        print ">> TEST SUCCESSFUL"
