// CSC 152 Class Project:  Scheme Testing Program
// Version 2
// Class to run individual test cases in Scheme
// Author: Henry M. Walker
// Created:  March 4, 2001
// File:  /home/walker/152/project.s01/RunSchemeTest2.java

/*
   Compile the C program and this Java program with commands

   /net/jdk1.2.2/bin/javac RunSchemeTest2.java
   /net/jdk1.2.2/bin/javah RunSchemeTest2
   gcc -c -fPIC -I/net/jdk1.2.2/include -I/net/jdk1.2.2/include/linux runTestCase.c
   gcc -shared -Wl,-soname,libRunTestCase.so -o libRunTestCase.so runTestCase.o 
   /net/jdk1.2.2/bin/javac Coordinator2.java-v1

   Set Java library path and run program with commands
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH.:
   /net/jdk1.2.2/bin/java Coordinator2
*/

public class RunSchemeTest2 {

    String progName;
    static long msToWait;
    static long uSecToWait;
    static long maxChar;
    static boolean DEBUG = true;

    public static native String runTestCase(String prog, String testCmd,
                                            long uSecToWait, long maxCharOut);
        // interface to Linux and Scheme environments

    static {
        System.loadLibrary("RunTestCase");
    }

    public RunSchemeTest2 (String nameSchemeProg, int maxSec, int maxCharOut) {
        // constructor
        // nameSchemeProg specifies the full path name of the Scheme program
        //     to be tested
        // timeLimit gives the number of seconds a test can run before it
        //     is terminated and assumed to be in an infinite loop
        // maxCharOut gives an upper bound on the number of characters
        //     allowed in the output for a test case

        progName = nameSchemeProg;
        msToWait = 1000 * (long)(maxSec);
        uSecToWait = 1000 * (long)(msToWait);
        maxChar = maxCharOut;
    }

    public RunSchemeTest2 (String nameSchemeProg) {
        // constructor for use after class has first been initialized
        // time and output limits were set at first initialization and not needed here
        // nameSchemeProg specifies the full path name of the Scheme program
        //     to be tested
        progName = nameSchemeProg;
    }

    public String runTest (String testCase) {
        // run test case for given Scheme program
        // Pre-condition: testCase gives the full Scheme command for testing
        // Post-conditions:  
        //   if test completes within the time limit
        //      then method returns results of the test as a string
        //      else method returns "test timed out" 

        return runTestCase (progName, testCase, uSecToWait, maxChar);  
    }

}
