Changeset 657 in tmcsimulator for trunk


Ignore:
Timestamp:
09/12/2022 01:30:08 PM (4 years ago)
Author:
jdalbey
Message:

Update unit tests to run on Windows (path and line separators), remove obsolete paramics test.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/Coordinator.java

    r560 r657  
    609609            Path source = Paths.get(selectedFile); 
    610610            Files.copy(source, destination,REPLACE_EXISTING); 
    611             Logger.getLogger(Coordinator.class.getName()).log(Level.INFO,   
    612                     "Loaded script copied to " + destination); 
     611            //Logger.getLogger(Coordinator.class.getName()).log(Level.INFO,   
     612            //        "Loaded script copied to " + destination); 
    613613        } catch (IOException ex) { 
    614614            Logger.getLogger(Coordinator.class.getName()).log(Level.SEVERE, null, ex); 
  • trunk/test/tmcsim/cadsimulator/CADSimulatorConsoleTest.java

    r656 r657  
    8585    private void verify(String errmsg, String expect) 
    8686    { 
    87         String[] results = sw.toString().trim().split("\n");   // split into lines 
     87         
     88        String result = sw.toString().trim().replace("\r","");  // Remove windows line feed characters 
     89        String[] results = result.split("\n"); //System.getProperty("line.separator"));   // split into lines 
    8890        String[] expecteds = expect.trim().split("\n"); 
    8991        int rIdx = results.length-1;  // index to results array 
     
    234236                + "Network Loaded              : None\n" 
    235237                + "-- Info Messages --\n" 
    236                 + ". = Console Info Message." 
    237                 + "tmcsim.cadsimulator.Coordinator.copyXMLfile = Loaded script copied to webapps/dynamicdata/incident_script.xml\n" 
     238                + ". = Console Info Message.\n" 
    238239                + "-- Error Messages --\n" 
    239240                + "Someclass.Somemethod = Sample error message.\n"; 
     
    247248                + "Network Loaded              : None\n" 
    248249                + "-- Info Messages --\n" 
    249                 + ". = Console Info Message." 
    250                 + "tmcsim.cadsimulator.Coordinator.copyXMLfile = Loaded script copied to webapps/dynamicdata/incident_script.xml\n" 
     250                + ". = Console Info Message.\n" 
    251251                + "-- Error Messages --\n" 
    252252                + "Someclass.Somemethod = Sample error message.\n"; 
  • trunk/test/tmcsim/cadsimulator/SystemTest.java

    r653 r657  
    6262        }); 
    6363 
    64         // Check CAD Simulator appears with no script and nothing connected 
     64        // Check CAD Server appears with no script and nothing connected 
    6565        assertTrue("Title bar incorrect", cadwindow.getTitle().trim().startsWith("CAD Server")); 
    6666        Panel mainPanel = cadwindow.getPanel("contentPane"); 
     
    7272        assertEquals("network id should be None", "None", mainPanel.getTextBox("networkLoadedTF").getText().trim()); 
    7373 
    74         ParamicsCommunicator pc = null; 
    75         pc = new ParamicsCommunicator("config/paramics_communicator_config.properties"); 
    76         ParamicsCommunicatorGUI theGUI = new ParamicsCommunicatorGUI(); 
    77         pc.setGUI(theGUI); 
     74 
    7875        // Note: Can't set visible ANY windows during UISpec test 
    79  
    80         // expect pcomm to say "sleeping" 
    8176 
    8277        Window simMgrWindow = null; 
     
    10095        TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText"); 
    10196        assertEquals("No Script", txtSimStatus.getText()); 
    102         TextBox txtParamStatus = contentPanel.getTextBox("paramicsStatusInfoLabel"); 
    103         assertEquals("Unknown", txtParamStatus.getText()); 
    104         Button loadNetworkBtn = simMgrWindow.getButton("Load Network"); 
    105         assertFalse(loadNetworkBtn.isEnabled()); 
    106  
    107         Button paramicsBtn = simMgrWindow.getButton("Connect to Paramics"); 
    108         paramicsBtn.click(); 
    109         try 
    110         { 
    111             Thread.sleep(200); 
    112         } catch (Exception ex) 
    113         { 
    114         } 
    115         assertEquals("Disconnect from Paramics", paramicsBtn.getLabel()); 
    116  
    117         assertEquals("Connected", txtParamStatus.getText()); 
    118         pc.startReading(); 
    119  
    120         loadNetworkBtn.click(); 
    121         try 
    122         { 
    123             Thread.sleep(200); 
    124         } catch (Exception ex) 
    125         { 
    126         } 
    127         assertEquals("Sending Network ID", txtParamStatus.getText()); 
    128         System.out.println("Sending Network ID"); 
    129         assertFalse(loadNetworkBtn.isEnabled()); 
    130         String warmingXML = "<Paramics>\n" 
    131                 + "<Network_Status>WARMING</Network_Status>\n" 
    132                 + "<Network_ID>1</Network_ID>\n" 
    133                 + "</Paramics>"; 
    134         writedata("paramics_status.xml", warmingXML); 
    135         try 
    136         { 
    137             Thread.sleep(2100); 
    138         } catch (Exception ex) 
    139         { 
    140         } 
    141         assertEquals("Warming Up", txtParamStatus.getText()); 
    142         System.out.println("Warming Up Passed"); 
    143  
    144         try 
    145         { 
    146             Thread.sleep(2100); 
    147         } catch (Exception ex) 
    148         { 
    149         } 
    150         String loadedXML = "<Paramics>\n" 
    151                 + "<Network_Status>LOADED</Network_Status>" 
    152                 + "<Network_ID>1</Network_ID>" 
    153                 + "</Paramics>"; 
    154         writedata("paramics_status.xml", loadedXML); 
    155         try 
    156         { 
    157             Thread.sleep(2100); 
    158         } catch (Exception ex) 
    159         { 
    160         } 
    161         //assertEquals("Network 1 Loaded", txtParamStatus.getText()); 
    162         //assertEquals("network id should be 1", "1", mainPanel.getTextBox("networkLoadedTF").getText().trim()); 
    16397 
    16498 
  • trunk/test/tmcsim/cadsimulator/viewer/CADConsoleViewerTest.java

    r455 r657  
    3434        console.setWriter(sw); 
    3535    } 
    36     /** 
    37      * compare StringWriter contents against expected 
     36    /** compare StringWriter contents against expected 
     37     *  @param expected contains just the most recent lines of output 
     38     *  @param errmsg message to be displayed if test fails 
     39     *  improved to verify line by line 
    3840     */ 
    39     private void verify(String msg, String expect) 
    40     { 
    41         String result = sw.toString().trim(); 
    42         result = result.replaceAll("\n", ","); 
    43         String fullExpect = expect.trim(); 
    44         fullExpect = fullExpect.replaceAll("\n", ","); 
    45         assertTrue(msg + ": " + result, result.endsWith(fullExpect)); 
    46     } 
     41    private void verify(String errmsg, String expect) 
     42    { 
     43         
     44        String result = sw.toString().trim().replace("\r","");  // Remove windows line feed characters 
     45        String[] results = result.split("\n"); //System.getProperty("line.separator"));   // split into lines 
     46        String[] expecteds = expect.trim().split("\n"); 
     47        int rIdx = results.length-1;  // index to results array 
     48        // Work backwards from the most recent line of output  
     49        for (int eIdx=expecteds.length-1; eIdx >= 0; eIdx--) 
     50        { 
     51            //System.out.println("Verifying "+eIdx+". "+expecteds[eIdx]+" against "+results[rIdx]); 
     52            assertEquals(errmsg + " line "+eIdx, expecteds[eIdx], results[rIdx]); 
     53            rIdx--; 
     54        }     
     55    }   
    4756 
    4857    public static void pause(int millis) 
     
    233242    } 
    234243 
    235     public void testNetworkID() 
    236     { 
    237         String expected10 = 
    238                 "--- CAD Simulator ---\n" 
    239                 + "Elapsed Simulation Time     : 0:00:00\n" 
    240                 + "Status                      : No Script\n" 
    241                 + "Connected CAD Terminals     : 0\n" 
    242                 + "Simulation Manager Connected: No\n" 
    243                 + "Connected to Paramics       : No\n" 
    244                 + "Network Loaded              : 17\n" 
    245                 + "-- Info Messages --\n\n" 
    246                 + "-- Error Messages --\n\n"; 
    247         // this will tell the model it has a new network ID 
    248         cadmodel.setParamicsNetworkLoaded("17"); 
    249         cadmodel.setParamicsStatus(CADEnums.PARAMICS_STATUS.LOADED); 
    250         pause(500); 
    251         verify("network id should be 17", expected10); 
    252     } 
     244     
    253245} 
  • trunk/test/tmcsim/highwaymodel/LoadHighwaysTest.java

    r653 r657  
    1818 */ 
    1919public class LoadHighwaysTest extends TestCase { 
     20    // Setup a path for temp files 
     21    static String tmpPath = "/tmp/";// default path is for linux 
     22    static 
     23    { 
     24        String myOs = System.getProperty("os.name").toLowerCase(); 
     25        if (myOs.indexOf("win") >= 0)  
     26        { 
     27          tmpPath = "C:/TEMP/";  // alt path for Windows 
     28        } 
     29    } 
    2030 
    2131    public LoadHighwaysTest(String testName) { 
     
    2838        PrintWriter writer = null; 
    2939        try { 
    30             writer = new PrintWriter(new FileWriter("/tmp/postmiles1.txt")); 
     40            writer = new PrintWriter(new FileWriter(tmpPath + "postmiles1.txt")); 
    3141            writer.println("5 S 0.9,33.408425,-117.599923,CALAFIA,0,0"); 
    3242            writer.println("5 N 1.24,33.413051,-117.601964,MAGDALENA,0,0"); 
    3343            writer.println("5 S 1.49,33.416348,-117.603827,EL CAMINO REAL,0,0"); 
    3444            writer.close(); 
    35             writer = new PrintWriter(new FileWriter("/tmp/postmiles3.txt")); 
     45            writer = new PrintWriter(new FileWriter(tmpPath + "postmiles3.txt")); 
    3646            writer.println("73 N 23.9,33.643656,-117.859875,BISON 2,0.976131,0.217185"); 
    3747            writer.println("55 S 6.88,33.697495,-117.862677,MACARTHU1,-0.710326,0.703873"); 
     
    4959    protected void tearDown() throws Exception { 
    5060        super.tearDown(); 
    51         Path path = FileSystems.getDefault().getPath("/tmp", "postmiles1.txt"); 
     61        Path path = FileSystems.getDefault().getPath(tmpPath, "postmiles1.txt"); 
    5262        Files.delete(path); 
    53         path = FileSystems.getDefault().getPath("/tmp", "postmiles3.txt"); 
     63        path = FileSystems.getDefault().getPath(tmpPath, "postmiles3.txt"); 
    5464        Files.delete(path); 
    5565    } 
     
    6171        System.out.println("testLoadHighways"); 
    6272        Highways highways = new Highways( 
    63                 "/tmp/postmiles1.txt"); 
     73                tmpPath + "postmiles1.txt"); 
    6474 
    6575        // Test for correct number of highways 
     
    97107        System.out.println("testLoadHighways2"); 
    98108        Highways highways = new Highways( 
    99                 "/tmp/postmiles3.txt"); 
     109                tmpPath + "postmiles3.txt"); 
    100110 
    101111        // Test for correct number of highways 
Note: See TracChangeset for help on using the changeset viewer.