Ignore:
Timestamp:
09/11/2022 04:28:42 PM (4 years ago)
Author:
jdalbey
Message:

Improve unit tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/tmcsim/cadsimulator/CADSimulatorConsoleTest.java

    r653 r655  
    3030    private CADConsoleViewer console; 
    3131    private StringWriter sw; 
    32  
     32    // Setup a path for temp files 
     33    static String tmpPath = "/tmp/";// default path is for linux 
     34    static 
     35    { 
     36        String myOs = System.getProperty("os.name").toLowerCase(); 
     37        if (myOs.indexOf("win") >= 0)  
     38        { 
     39          tmpPath = "C:/TEMP/";  // alt path for Windows 
     40        } 
     41    } 
    3342    public CADSimulatorConsoleTest(String testName) 
    3443    { 
     
    7079 
    7180    /** 
    72      * compare StringWriter contents against expected 
     81     * obsolete: compare StringWriter contents against expected 
    7382     */ 
    74     private void verify(String msg, String expect) 
     83    private void verify0(String msg, String expect) 
    7584    { 
    7685        String result = sw.toString().trim(); 
     
    8594        assertTrue(msg + ": " + result, match); 
    8695    } 
    87  
     96    /** compare StringWriter contents against expected 
     97     *  @param expected contains just the most recent lines of output 
     98     *  @param errmsg message to be displayed if test fails 
     99     *  improved to verify line by line 
     100     */ 
     101    private void verify(String errmsg, String expect) 
     102    { 
     103        String[] results = sw.toString().trim().split("\n");   // split into lines 
     104        String[] expecteds = expect.trim().split("\n"); 
     105        // Work backwards from the most recent line of output  
     106        for (int item=expecteds.length-1; item >= 0; item--) 
     107        { 
     108            //System.out.println("Verifying "+expecteds[item]+" against "+results[item]); 
     109            assertEquals(errmsg + " line "+item, expecteds[item], results[item]); 
     110        }     
     111    }             
    88112    public static void pause(int millis) 
    89113    { 
     
    134158        CADClientInterface ci = mock(CADClientInterface.class); 
    135159        app.theCoordinator.registerForCallback(ci); 
     160        pause(500); 
    136161        verify("connected 1 terminal output incorrect: ", expected2); 
    137162        String expected3 = 
     
    286311            +"FEPSim_IP_addr = localhost\n" 
    287312            +"Output_Destination = Console\n" 
    288             +"Highway_Status_File = /tmp/highway_status.json\n"; 
     313            +"Highway_Status_File = "+tmpPath+"highway_status.json\n"; 
    289314    static final String paramicsData = "ParamicsCommHost = 127.0.0.1\n" 
    290315            + "ParamicsCommPort       = 4450\n" 
Note: See TracChangeset for help on using the changeset viewer.