Ignore:
Timestamp:
11/09/05 11:03:31 (19 years ago)
Author:
boris
Message:
  • new package wizard finished
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewClassWizard.java

    r123 r126  
    4242package org.modelica.mdt.test;
    4343
    44 import java.io.IOException;
    45 import java.io.InputStream;
    46 
    47 import org.eclipse.core.resources.IFile;
    4844import org.eclipse.core.resources.IProject;
    4945import org.eclipse.core.resources.ResourcesPlugin;
    50 import org.eclipse.core.runtime.CoreException;
    5146import org.eclipse.jface.viewers.StructuredSelection;
    5247import org.eclipse.jface.wizard.IWizard;
     
    5449import org.eclipse.swt.widgets.Combo;
    5550import org.eclipse.swt.widgets.Text;
    56 import org.eclipse.swt.widgets.Widget;
    5751import org.eclipse.ui.PlatformUI;
    5852import org.modelica.mdt.core.ModelicaCore;
     
    6054import org.modelica.mdt.ui.wizards.NewClassWizard;
    6155
    62 import abbot.finder.swt.BasicFinder;
    63 import abbot.finder.swt.Matcher;
    64 import abbot.finder.swt.MultipleWidgetsFoundException;
    65 import abbot.finder.swt.TestHierarchy;
    66 import abbot.finder.swt.WidgetNotFoundException;
    6756import abbot.tester.swt.ButtonTester;
    6857import abbot.tester.swt.ComboTester;
     
    8372   
    8473    private IProject project;
     74   
    8575    private TextTester ttester;
    8676    private ButtonTester btester;
     
    125115    }
    126116   
    127     /**
    128      * Compares the content of a file with a provided string
    129      * @param file
    130      * @param expectedContent
    131      * @return true if file's content exactly matches the expectedContent
    132      * string
    133      */
    134     private boolean compareContent(IFile file, String expectedContent)
    135     {
    136         InputStream fileContent = null;
    137        
    138         try
    139         {
    140             fileContent = file.getContents();
    141         }
    142         catch (CoreException e)
    143         {
    144             fail("could not fetch contents of the created class");
    145         }
    146 
    147         byte[] buf = new byte[expectedContent.length()];
    148        
    149         try
    150         {
    151             fileContent.read(buf);
    152             int i = fileContent.read();
    153            
    154             assertEquals("file is to long", i, -1);
    155         }
    156         catch (IOException e)
    157         {
    158             fail("could not read contents of the file");
    159         }
    160        
    161         return expectedContent.equals(new String(buf));
    162     }
    163117
    164118   
     
    170124        IWizard wizard =
    171125            Utility.openWizard("org.modelica.mdt.NewClassWizard",
    172                     fileDestination);
    173        
     126                    fileDestination);       
    174127        assertFalse(wizard.canFinish());
    175128
     
    189142        finish =
    190143            Utility.findFinishButton();
    191        
    192    
    193         /*
    194          * find classType combo by tag
    195          */
    196         BasicFinder finder = new BasicFinder(new TestHierarchy
    197                 (PlatformUI.getWorkbench().getDisplay()));
    198        
    199         try
    200         {           
    201             classType = (Combo)finder.find(new Matcher()
    202             {
    203                 public boolean matches(Widget w)
    204                 {
    205                     Object tag = w.getData("name");
    206                     if (tag == null || !(tag instanceof String))
    207                     {
    208                         return false;
    209                     }
    210                                    
    211                     return ((String)tag).equals(NewClassWizard.CLASS_TYPE_TAG);
    212                 }
    213                            
    214             });
    215         }
    216         catch (WidgetNotFoundException e)
    217         {
    218             fail("multiple classType combos found " + e.getMessage());
    219         }
    220         catch (MultipleWidgetsFoundException e)
    221         {
    222             fail("classType combo widget not found " + e.getMessage());
    223         }
     144
     145        /* find classType combo by tag */
     146        classType =
     147            (Combo)
     148                Utility.getInstrumentedWidget(NewClassWizard.CLASS_TYPE_TAG);
     149        assertNotNull("Problems finding classType widget", classType);
     150       
    224151       
    225152        /* make some checks on the state of the wizards */
     
    242169        openWizardAndFetchWidgets();       
    243170       
     171        String name = "m1";
    244172        /*
    245173         * create model
    246174         */
    247         ttester.actionEnterText(className, "m1");
     175        ttester.actionEnterText(className, name);
    248176        assertTrue(finish.getEnabled());
    249177
     
    258186         */
    259187        boolean same =
    260             compareContent(project.getFile("m1.mo"),
    261                 "model m1\n"+
    262                 "\n"+
    263                 "equation\n"+
    264                 "\n"+
    265                 "end m1;");
     188            Utility.compareContent(project.getFile(name + ".mo"),
     189                "model " + name + "\n"+
     190                "\n"+
     191                "equation\n"+
     192                "\n"+
     193                "end " + name + ";");
    266194        assertTrue("unexpected conted created in the source file", same);
    267195   
     
    270198    public void testCreateModelWithInitEquation()
    271199    {
     200        openWizardAndFetchWidgets();
     201       
     202        String name = "m2";
     203       
     204        /*
     205         * create model
     206         */
     207        ttester.actionEnterText(className, name);
     208        assertTrue(finish.getEnabled());
     209       
     210        btester.actionClick(initialEquation);
     211       
     212        assertTrue(initialEquation.getSelection());
     213
     214        /* wait for the name change to propogate to enable the finish button */
     215        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
     216        btester.actionClick(finish);
     217       
     218       
     219        while(!project.isOpen()){ Utility.sleep(this, 100); }
     220       
     221        /*
     222         * check that the generated source code is sane
     223         */
     224        boolean same =
     225            Utility.compareContent(project.getFile(name + ".mo"),
     226                "model "+ name +"\n"+
     227                "\n"+
     228                "equation\n"+
     229                "\n"+
     230                "initial equation\n"+
     231                "\n"+
     232                "end " + name + ";");
     233        assertTrue("unexpected conted created in the source file", same);
     234    }
     235
     236    public void testCreatePartialModel()
     237    {
    272238        openWizardAndFetchWidgets();       
    273239       
     240        String name = "m3";
    274241        /*
    275242         * create model
    276243         */
    277         ttester.actionEnterText(className, "m2");
     244        ttester.actionEnterText(className, name);
    278245        assertTrue(finish.getEnabled());
    279246       
    280         btester.actionClick(initialEquation);
    281        
    282         assertTrue(initialEquation.getSelection());
    283 
    284         /* wait for the name change to propogate to enable the finish button */
    285         while (!finish.getEnabled()) { Utility.sleep(this, 100); }
    286         btester.actionClick(finish);
    287        
    288        
    289         while(!project.isOpen()){ Utility.sleep(this, 100); }
    290        
    291         /*
    292          * check that the generated source code is sane
    293          */
    294         boolean same =
    295             compareContent(project.getFile("m2.mo"),
    296                 "model m2\n"+
    297                 "\n"+
    298                 "equation\n"+
    299                 "\n"+
    300                 "initial equation\n"+
    301                 "\n"+
    302                 "end m2;");
    303         assertTrue("unexpected conted created in the source file", same);
    304     }
    305 
    306     public void testCreatePartialModel()
    307     {
    308         openWizardAndFetchWidgets();       
    309        
    310         String name = "m3";
    311         /*
    312          * create model
    313          */
    314         ttester.actionEnterText(className, name);
    315         assertTrue(finish.getEnabled());
    316        
    317247        btester.actionClick(partialClass);
    318248       
     
    330260         */
    331261        boolean same =
    332             compareContent(project.getFile(name + ".mo"),
     262            Utility.compareContent(project.getFile(name + ".mo"),
    333263                "partial model "+ name +"\n"+
    334264                "\n"+
     
    369299         */
    370300        boolean same =
    371             compareContent(project.getFile(name + ".mo"),
     301            Utility.compareContent(project.getFile(name + ".mo"),
    372302                "partial model "+ name +"\n"+
    373303                "\n"+
     
    404334         */
    405335        boolean same =
    406             compareContent(project.getFile(name + ".mo"),
     336            Utility.compareContent(project.getFile(name + ".mo"),
    407337                "class "+ name +"\n"+
    408338                "\n"+
     
    438368         */
    439369        boolean same =
    440             compareContent(project.getFile(name + ".mo"),
     370            Utility.compareContent(project.getFile(name + ".mo"),
    441371                "class "+ name +"\n"+
    442372                "\n"+
     
    475405         */
    476406        boolean same =
    477             compareContent(project.getFile(name + ".mo"),
     407            Utility.compareContent(project.getFile(name + ".mo"),
    478408                "partial class "+ name +"\n"+
    479409                "\n"+
     
    510440         */
    511441        boolean same =
    512             compareContent(project.getFile(name + ".mo"),
     442            Utility.compareContent(project.getFile(name + ".mo"),
    513443                "partial class "+ name +"\n"+
    514444                "\n"+
     
    547477         */
    548478        boolean same =
    549             compareContent(project.getFile(name + ".mo"),
     479            Utility.compareContent(project.getFile(name + ".mo"),
    550480                "connector "+ name +"\n" +
    551481                "\n" +
     
    579509         */
    580510        boolean same =
    581             compareContent(project.getFile(name + ".mo"),
     511            Utility.compareContent(project.getFile(name + ".mo"),
    582512                "partial connector "+ name +"\n" +
    583513                "\n" +
     
    612542         */
    613543        boolean same =
    614             compareContent(project.getFile(name + ".mo"),
     544            Utility.compareContent(project.getFile(name + ".mo"),
    615545                "block "+ name +"\n" +
    616546                "\n" +
     
    647577         */
    648578        boolean same =
    649             compareContent(project.getFile(name + ".mo"),
     579            Utility.compareContent(project.getFile(name + ".mo"),
    650580                "block "+ name +"\n" +
    651581                "\n" +
     
    685615         */
    686616        boolean same =
    687             compareContent(project.getFile(name + ".mo"),
     617            Utility.compareContent(project.getFile(name + ".mo"),
    688618                "partial block "+ name +"\n" +
    689619                "\n" +
     
    721651         */
    722652        boolean same =
    723             compareContent(project.getFile(name + ".mo"),
     653            Utility.compareContent(project.getFile(name + ".mo"),
    724654                "partial block "+ name +"\n" +
    725655                "\n" +
     
    757687         */
    758688        boolean same =
    759             compareContent(project.getFile(name + ".mo"),
     689            Utility.compareContent(project.getFile(name + ".mo"),
    760690                "type "+ name +"\n" +
    761691                ";");
     
    788718         */
    789719        boolean same =
    790             compareContent(project.getFile(name + ".mo"),
     720            Utility.compareContent(project.getFile(name + ".mo"),
    791721                "function "+ name +"\n" +
    792722                "\n" +
     
    828758         */
    829759        boolean same =
    830             compareContent(project.getFile(name + ".mo"),
     760            Utility.compareContent(project.getFile(name + ".mo"),
    831761                "function "+ name +"\n" +
    832762                "\n" +
Note: See TracChangeset for help on using the changeset viewer.