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

    def tearDown(self):
        self.killNfd()
        self.killProcess("ndnpoke")
        self.killProcess("ndnpeek")
        os.system("rm -r test_ndnpeekpoke/logs/")
        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"
