#!/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)
        self.startNrd()
        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"
