Changeset 57 in tmcsimulator-scriptbuilder for trunk/test/scriptbuilder/structures


Ignore:
Timestamp:
08/14/2017 02:46:52 PM (9 years ago)
Author:
bmcguffin
Message:

Added test cases for TimeSlice? class. Added a reference file containing a single timeslice.

Location:
trunk/test/scriptbuilder/structures
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/scriptbuilder/structures/TimeSliceTest.java

    r56 r57  
    11package scriptbuilder.structures; 
    22 
     3import java.io.File; 
     4import java.io.IOException; 
     5import java.nio.file.Files; 
     6import java.util.logging.Level; 
     7import java.util.logging.Logger; 
    38import junit.framework.TestCase; 
     9import scriptbuilder.structures.events.AudioEvent; 
     10import scriptbuilder.structures.events.CHPRadioEvent; 
    411import scriptbuilder.structures.events.I_ScriptEvent; 
    512 
     
    815 * @author Bryan McGuffin 
    916 */ 
    10 public class TimeSliceTest extends TestCase { 
    11      
    12     public TimeSliceTest(String testName) { 
     17public class TimeSliceTest extends TestCase 
     18{ 
     19 
     20    public TimeSliceTest(String testName) 
     21    { 
    1322        super(testName); 
    1423    } 
     
    2029    { 
    2130        System.out.println("addEvent"); 
    22         I_ScriptEvent event = null; 
    23         TimeSlice instance = null; 
     31        I_ScriptEvent event = new CHPRadioEvent(); 
     32        TimeSlice instance = new TimeSlice(0, null); 
     33 
     34        assertEquals(0, instance.events.size()); 
    2435        instance.addEvent(event); 
    25         // TODO review the generated test code and remove the default call to fail. 
    26         fail("The test case is a prototype."); 
     36        assertEquals(1, instance.events.size()); 
    2737    } 
    2838 
     
    3343    { 
    3444        System.out.println("getX"); 
    35         TimeSlice instance = null; 
     45        TimeSlice instance = new TimeSlice(0, null); 
    3646        int expResult = 0; 
    3747        int result = instance.getX(); 
    3848        assertEquals(expResult, result); 
    39         // TODO review the generated test code and remove the default call to fail. 
    40         fail("The test case is a prototype."); 
    4149    } 
    4250 
     
    4755    { 
    4856        System.out.println("getTime"); 
    49         TimeSlice instance = null; 
    50         int expResult = 0; 
     57        TimeSlice instance = new TimeSlice(100, null); 
     58        int expResult = 100; 
    5159        int result = instance.getTime(); 
    5260        assertEquals(expResult, result); 
    53         // TODO review the generated test code and remove the default call to fail. 
    54         fail("The test case is a prototype."); 
    5561    } 
    5662 
     
    6167    { 
    6268        System.out.println("shift"); 
    63         int amnt = 0; 
    64         TimeSlice instance = null; 
     69        int amnt = 25; 
     70        TimeSlice instance = new TimeSlice(100, null); 
     71        assertEquals(100, instance.getTime()); 
    6572        instance.shift(amnt); 
    66         // TODO review the generated test code and remove the default call to fail. 
    67         fail("The test case is a prototype."); 
     73        assertEquals(125, instance.getTime()); 
    6874    } 
    6975 
     
    7480    { 
    7581        System.out.println("getEffectiveDuration"); 
    76         TimeSlice instance = null; 
    77         int expResult = 0; 
    78         int result = instance.getEffectiveDuration(); 
    79         assertEquals(expResult, result); 
    80         // TODO review the generated test code and remove the default call to fail. 
    81         fail("The test case is a prototype."); 
     82        TimeSlice instance = new TimeSlice(0, null); 
     83        assertEquals(0, instance.getEffectiveDuration()); 
     84 
     85        ScriptEvent ev1 = new AudioEvent(); 
     86        assertEquals(1, ev1.getLength()); 
     87        instance.addEvent(ev1); 
     88        assertEquals(1, instance.getEffectiveDuration()); 
     89 
     90        ScriptEvent ev2 = new AudioEvent(); 
     91        ev2.length = 25; 
     92        assertEquals(25, ev2.getLength()); 
     93        instance.addEvent(ev2); 
     94        assertEquals(25, instance.getEffectiveDuration()); 
    8295    } 
    8396 
     
    89102        System.out.println("getToolTipText"); 
    90103        int y = 0; 
    91         TimeSlice instance = null; 
     104        TimeSlice instance = new TimeSlice(0, null); 
    92105        String expResult = ""; 
    93         String result = instance.getToolTipText(y); 
    94         assertEquals(expResult, result); 
    95         // TODO review the generated test code and remove the default call to fail. 
    96         fail("The test case is a prototype."); 
     106        String result = instance.getToolTipText(0); 
     107        assertEquals(null, result); 
     108 
     109        result = instance.getToolTipText(56); 
     110        assertEquals(null, result); 
     111 
     112        result = instance.getToolTipText(50); 
     113        assertEquals(null, result); 
     114 
     115        result = instance.getToolTipText(80); 
     116        assertEquals(null, result); 
     117 
     118        AudioEvent ev = new AudioEvent(); 
     119        instance.addEvent(ev); 
     120        expResult = "<html>" + ev.toString() + "<br/></html>"; 
     121 
     122        result = instance.getToolTipText(56); 
     123        assertEquals(ev.toString(), result); 
     124 
     125        result = instance.getToolTipText(70); 
     126        assertEquals(ev.toString(), result); 
     127 
     128        result = instance.getToolTipText(85); 
     129        assertEquals(null, result); 
     130 
     131        result = instance.getToolTipText(50); 
     132        assertEquals(expResult, result); 
     133 
     134        result = instance.getToolTipText(0); 
     135        assertEquals(null, result); 
    97136    } 
    98137 
     
    103142    { 
    104143        System.out.println("toString"); 
    105         TimeSlice instance = null; 
     144        TimeSlice instance = new TimeSlice(0, null); 
    106145        String expResult = ""; 
    107146        String result = instance.toString(); 
    108147        assertEquals(expResult, result); 
    109         // TODO review the generated test code and remove the default call to fail. 
    110         fail("The test case is a prototype."); 
     148 
     149        AudioEvent ev1 = new AudioEvent(); 
     150        CHPRadioEvent ev2 = new CHPRadioEvent(); 
     151 
     152        instance.addEvent(ev1); 
     153        instance.addEvent(ev2); 
     154 
     155        expResult = ev1.toString() + "\n" + ev2.toString() + "\n"; 
     156        result = instance.toString(); 
     157        assertEquals(expResult, result); 
    111158    } 
    112159 
     
    117164    { 
    118165        System.out.println("compareTo"); 
    119         Object o = null; 
    120         TimeSlice instance = null; 
    121         int expResult = 0; 
     166        Object o = new SimulationScript(); 
     167 
     168        TimeSlice other = new TimeSlice(10, null); 
     169 
     170        TimeSlice instance = new TimeSlice(0, null); 
    122171        int result = instance.compareTo(o); 
    123         assertEquals(expResult, result); 
    124         // TODO review the generated test code and remove the default call to fail. 
    125         fail("The test case is a prototype."); 
     172        assertEquals(0, result); 
     173 
     174        result = instance.compareTo(other); 
     175        assertEquals(-1, result); 
     176 
     177        result = other.compareTo(instance); 
     178        assertEquals(1, result); 
     179 
     180        result = instance.compareTo(instance); 
     181        assertEquals(0, result); 
     182 
    126183    } 
    127184 
     
    131188    public void testToXML() 
    132189    { 
    133         System.out.println("toXML"); 
    134         TimeSlice instance = null; 
    135         String expResult = ""; 
    136         String result = instance.toXML(); 
    137         assertEquals(expResult, result); 
    138         // TODO review the generated test code and remove the default call to fail. 
    139         fail("The test case is a prototype."); 
     190        try 
     191        { 
     192            System.out.println("toXML"); 
     193            SimulationScript script = new SimulationScript(); 
     194            script.loadScriptFromFile(new File("test/scriptbuilder/structures/single_timeslice_output_expected.xml")); 
     195            TimeSlice instance = script.incidents.get(0).slices.get(0); 
     196 
     197            byte[] data = Files.readAllBytes( 
     198                    new File("test/scriptbuilder/structures/single_timeslice_output_expected.xml").toPath()); 
     199 
     200            String expResult = new String(data); 
     201 
     202            String result = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" 
     203                    + "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">\n" 
     204                    + XMLWriter.openTag(ELEMENT.TMC_SCRIPT.tag + " title=\"" + script.title + "\"") 
     205                    + instance.toXML() 
     206                    + XMLWriter.closeTag(ELEMENT.TMC_SCRIPT.tag); 
     207 
     208            assertEquals(expResult, result); 
     209 
     210        } 
     211        catch (IOException ex) 
     212        { 
     213            Logger.getLogger(TimeSliceTest.class.getName()).log(Level.SEVERE, null, ex); 
     214        } 
    140215    } 
    141216 
Note: See TracChangeset for help on using the changeset viewer.