#!/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 ndn-tlv-peek and ndn-tlv-poke applications"""

    def setUp(self):
        print "\nTesting ndn-tlv-peek & ndn-tlv-poke"
        print "***********************************"
        os.system("mkdir test_ndnpeekpoke/logs/")

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