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

    def tearDown(self):
        self.killNfd()
        self.killProcess("ndn-tlv-poke")
        self.killProcess("ndn-tlv-peek")
        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("/tmp/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"
