source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewClassWizard.java @ 189

Last change on this file since 189 was 189, checked in by boris, 19 years ago
  • added missing test for creating records from new class wizard
File size: 21.2 KB
Line 
1/*
2 * This file is part of Modelica Development Tooling.
3 *
4 * Copyright (c) 2005, Link�pings universitet, Department of
5 * Computer and Information Science, PELAB
6 *
7 * All rights reserved.
8 *
9 * (The new BSD license, see also
10 * http://www.opensource.org/licenses/bsd-license.php)
11 *
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are
15 * met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 *   notice, this list of conditions and the following disclaimer.
19 *
20 * * Redistributions in binary form must reproduce the above copyright
21 *   notice, this list of conditions and the following disclaimer in
22 *   the documentation and/or other materials provided with the
23 *   distribution.
24 *
25 * * Neither the name of Link�pings universitet nor the names of its
26 *   contributors may be used to endorse or promote products derived from
27 *   this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42package org.modelica.mdt.test;
43
44import org.eclipse.core.resources.IProject;
45import org.eclipse.core.resources.ResourcesPlugin;
46import org.eclipse.jface.viewers.StructuredSelection;
47import org.eclipse.jface.wizard.IWizard;
48import org.eclipse.swt.widgets.Button;
49import org.eclipse.swt.widgets.Combo;
50import org.eclipse.swt.widgets.Text;
51import org.eclipse.ui.PlatformUI;
52import org.modelica.mdt.core.ModelicaCore;
53import org.modelica.mdt.test.util.Utility;
54import org.modelica.mdt.ui.wizards.NewClassWizard;
55
56import abbot.tester.swt.ButtonTester;
57import abbot.tester.swt.ComboTester;
58import abbot.tester.swt.TextTester;
59
60import junit.framework.TestCase;
61
62/**
63 * @author Elmir Jagudin
64 *
65 * Test the New Class Wizard functionality
66 */
67public class TestNewClassWizard extends TestCase
68{
69    private static final String PROJECT_NAME_1 = 
70            TestNewClassWizard.class.getName() + "1";
71    private StructuredSelection fileDestination; 
72   
73    private IProject project;
74   
75    private TextTester ttester;
76    private ButtonTester btester;
77    private ComboTester ctester;
78
79    private Text sourceFolder;
80    private Text className;
81    private Combo classType;
82    private Button initialEquation;
83    private Button partialClass;
84    private Button externalBody;
85   
86    private Button finish;
87   
88
89    @Override
90    //protected void setUp() throws Exception
91    public void setUp() throws Exception
92    {
93        /*
94         * setup project
95         */
96        project = 
97            ModelicaCore.createProject(PROJECT_NAME_1,
98                    PlatformUI.getWorkbench().getActiveWorkbenchWindow());
99        assertNotNull("failed to create project", project);
100       
101        /*
102         * create the selection that points at the root of the created project
103         */
104        fileDestination = 
105            new StructuredSelection(ResourcesPlugin.getWorkspace().getRoot().
106                    getProject(PROJECT_NAME_1));
107       
108        /*
109         * setup testing support objects
110         */
111        ttester = TextTester.getTextTester();
112        btester = ButtonTester.getButtonTester();
113        ctester = new ComboTester();
114               
115    }
116   
117
118   
119    public void openWizardAndFetchWidgets()
120    {
121        /*
122         * pop-up the wizard
123         */
124        IWizard wizard = 
125            Utility.openWizard("org.modelica.mdt.NewClassWizard",
126                    fileDestination);       
127        assertFalse(wizard.canFinish());
128
129       
130       
131        /* fetch widgets */
132        className = 
133            TextTester.getInstrumentedText(NewClassWizard.CLASS_NAME_TAG);
134        sourceFolder = 
135            TextTester.getInstrumentedText(NewClassWizard.SOURCE_FOLDER_TAG);
136        initialEquation = 
137            ButtonTester.getInstrumentedButton(NewClassWizard.INITIAL_EQUATION_TAG);
138        externalBody =
139            ButtonTester.getInstrumentedButton(NewClassWizard.EXTERNAL_BODY_TAG);
140        partialClass = 
141            ButtonTester.getInstrumentedButton(NewClassWizard.PARTIAL_CLASS_TAG);
142        finish = 
143            Utility.findFinishButton();
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       
151       
152        /* make some checks on the state of the wizards */
153        assertEquals("Wrong source folder selected", 
154                sourceFolder.getText(), PROJECT_NAME_1);       
155        assertEquals("Junk present in class name field", 
156                className.getText(), "");
157        assertFalse("initial equation unexpectedly selected",
158                initialEquation.getSelection());
159        assertFalse("partial class unexpectedly selected",
160                partialClass.getSelection());
161        assertFalse("Finish button not disabled", 
162                finish.getEnabled());
163       
164
165    }
166   
167    public void testCreateModel()
168    {
169        openWizardAndFetchWidgets();       
170       
171        String name = "m1";
172        /*
173         * create model
174         */
175        ttester.actionEnterText(className, name);
176        assertTrue(finish.getEnabled());
177
178        /* wait for the name change to propogate to enable the finish button */
179        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
180        btester.actionClick(finish);
181       
182        while(!project.isOpen()){ Utility.sleep(this, 100); }       
183       
184        /*
185         * check that the generated source code is sane
186         */
187        boolean same = 
188            Utility.compareContent(project.getFile(name + ".mo"), 
189                "model " + name + "\n"+
190                "\n"+
191                "equation\n"+
192                "\n"+
193                "end " + name + ";");
194        assertTrue("unexpected conted created in the source file", same);
195   
196    }
197       
198    public void testCreateModelWithInitEquation()
199    {
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    {
238        openWizardAndFetchWidgets();       
239       
240        String name = "m3";
241        /*
242         * create model
243         */
244        ttester.actionEnterText(className, name);
245        assertTrue(finish.getEnabled());
246       
247        btester.actionClick(partialClass);
248       
249        assertTrue(partialClass.getSelection());
250
251        /* wait for the name change to propogate to enable the finish button */
252        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
253        btester.actionClick(finish);
254       
255       
256        while(!project.isOpen()){ Utility.sleep(this, 100); }
257       
258        /*
259         * check that the generated source code is sane
260         */
261        boolean same = 
262            Utility.compareContent(project.getFile(name + ".mo"), 
263                "partial model "+ name +"\n"+
264                "\n"+
265                "equation\n"+
266                "\n"+
267                "end "+ name + ";");
268        assertTrue("unexpected conted created in the source file", same);
269   
270    }
271
272    public void testCreatePartialModelWithInitBlock()
273    {
274        openWizardAndFetchWidgets();       
275       
276        String name = "m4";
277        /*
278         * create model
279         */
280        ttester.actionEnterText(className, name);
281        assertTrue(finish.getEnabled());
282       
283        btester.actionClick(partialClass);     
284        assertTrue(partialClass.getSelection());
285
286        btester.actionClick(initialEquation);       
287        assertTrue(initialEquation.getSelection());
288       
289       
290        /* wait for the name change to propogate to enable the finish button */
291        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
292        btester.actionClick(finish);
293       
294       
295        while(!project.isOpen()){ Utility.sleep(this, 100); }
296       
297        /*
298         * check that the generated source code is sane
299         */
300        boolean same = 
301            Utility.compareContent(project.getFile(name + ".mo"), 
302                "partial model "+ name +"\n"+
303                "\n"+
304                "equation\n"+
305                "\n"+
306                "initial equation\n"+
307                "\n"+
308                "end "+ name + ";");
309        assertTrue("unexpected conted created in the source file", same);
310    }
311
312    public void testCreateClass()
313    {
314        openWizardAndFetchWidgets();       
315       
316        String name = "c1";
317       
318        /*
319         * create class
320         */
321        ttester.actionEnterText(className, name);
322        ctester.actionSelectItem(classType, "class");
323       
324       
325        /* wait for the name change to propogate to enable the finish button */
326        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
327        btester.actionClick(finish);
328       
329       
330        while(!project.isOpen()){ Utility.sleep(this, 100); }
331       
332        /*
333         * check that the generated source code is sane
334         */
335        boolean same = 
336            Utility.compareContent(project.getFile(name + ".mo"), 
337                "class "+ name +"\n"+
338                "\n"+
339                "equation\n"+
340                "\n"+
341                "end "+ name + ";");
342        assertTrue("unexpected conted created in the source file", same);
343    }
344
345    public void testCreateClassWithInitBlock()
346    {
347        openWizardAndFetchWidgets();
348       
349        String name = "c2";
350       
351        /*
352         * create class
353         */
354        ttester.actionEnterText(className, name);
355        ctester.actionSelectItem(classType, "class");
356        btester.actionClick(initialEquation);
357       
358       
359        /* wait for the name change to propogate to enable the finish button */
360        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
361        btester.actionClick(finish);
362       
363       
364        while(!project.isOpen()){ Utility.sleep(this, 100); }
365       
366        /*
367         * check that the generated source code is sane
368         */
369        boolean same = 
370            Utility.compareContent(project.getFile(name + ".mo"), 
371                "class "+ name +"\n"+
372                "\n"+
373                "equation\n"+
374                "\n"+
375                "initial equation\n"+
376                "\n"+
377                "end "+ name + ";");
378        assertTrue("unexpected conted created in the source file", same);
379       
380    }
381
382    public void testCreatePartialClass()
383    {
384        openWizardAndFetchWidgets();
385       
386        String name = "c3";
387       
388        /*
389         * create class
390         */
391        ttester.actionEnterText(className, name);
392        ctester.actionSelectItem(classType, "class");
393        btester.actionClick(partialClass);
394       
395       
396        /* wait for the name change to propogate to enable the finish button */
397        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
398        btester.actionClick(finish);
399       
400       
401        while(!project.isOpen()){ Utility.sleep(this, 100); }
402       
403        /*
404         * check that the generated source code is sane
405         */
406        boolean same = 
407            Utility.compareContent(project.getFile(name + ".mo"), 
408                "partial class "+ name +"\n"+
409                "\n"+
410                "equation\n"+
411                "\n"+
412                "end "+ name + ";");
413        assertTrue("unexpected conted created in the source file", same);
414    }
415
416    public void testCreatePartialClassWithInitBlock()
417    {
418        openWizardAndFetchWidgets();
419       
420        String name = "c4";
421       
422        /*
423         * create class
424         */
425        ttester.actionEnterText(className, name);
426        ctester.actionSelectItem(classType, "class");
427        btester.actionClick(partialClass);
428        btester.actionClick(initialEquation);
429       
430       
431        /* wait for the name change to propogate to enable the finish button */
432        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
433        btester.actionClick(finish);
434       
435       
436        while(!project.isOpen()){ Utility.sleep(this, 100); }
437       
438        /*
439         * check that the generated source code is sane
440         */
441        boolean same = 
442            Utility.compareContent(project.getFile(name + ".mo"), 
443                "partial class "+ name +"\n"+
444                "\n"+
445                "equation\n"+
446                "\n"+
447                "initial equation\n"+
448                "\n"+               
449                "end "+ name + ";");
450        assertTrue("unexpected conted created in the source file", same);
451       
452    }
453   
454   
455    public void testCreateConnector()
456    {
457        openWizardAndFetchWidgets();
458       
459        String name = "con1";
460       
461        /*
462         * create class
463         */
464        ttester.actionEnterText(className, name);
465        ctester.actionSelectItem(classType, "connector");
466       
467       
468        /* wait for the name change to propogate to enable the finish button */
469        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
470        btester.actionClick(finish);
471       
472       
473        while(!project.isOpen()){ Utility.sleep(this, 100); }
474       
475        /*
476         * check that the generated source code is sane
477         */
478        boolean same = 
479            Utility.compareContent(project.getFile(name + ".mo"), 
480                "connector "+ name +"\n" +
481                "\n" +
482                "end "+ name + ";");
483        assertTrue("unexpected conted created in the source file", same);
484    }
485
486    public void testCreatePartialConnector()
487    {
488        openWizardAndFetchWidgets();
489       
490        String name = "con2";
491       
492        /*
493         * create class
494         */
495        ttester.actionEnterText(className, name);
496        ctester.actionSelectItem(classType, "connector");
497        btester.actionClick(partialClass);     
498       
499       
500        /* wait for the name change to propogate to enable the finish button */
501        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
502        btester.actionClick(finish);
503       
504       
505        while(!project.isOpen()){ Utility.sleep(this, 100); }
506       
507        /*
508         * check that the generated source code is sane
509         */
510        boolean same = 
511            Utility.compareContent(project.getFile(name + ".mo"), 
512                "partial connector "+ name +"\n" +
513                "\n" +
514                "end "+ name + ";");
515        assertTrue("unexpected conted created in the source file", same);
516       
517    }
518   
519    public void testCreateRecord()
520    {
521        openWizardAndFetchWidgets();
522       
523        String name = "rec1";
524       
525        /*
526         * create class
527         */
528        ttester.actionEnterText(className, name);
529        ctester.actionSelectItem(classType, "record");
530
531       
532       
533        /* wait for the name change to propogate to enable the finish button */
534        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
535        btester.actionClick(finish);
536       
537       
538        while(!project.isOpen()){ Utility.sleep(this, 100); }
539       
540        /*
541         * check that the generated source code is sane
542         */
543        boolean same = 
544            Utility.compareContent(project.getFile(name + ".mo"), 
545                "record "+ name +"\n" +
546                "\n" +
547                "end "+ name + ";");
548        assertTrue("unexpected conted created in the source file", same);
549       
550    }
551   
552    public void testCreatePartialRecord()
553    {
554        openWizardAndFetchWidgets();
555       
556        String name = "rec2";
557       
558        /*
559         * create class
560         */
561        ttester.actionEnterText(className, name);
562        ctester.actionSelectItem(classType, "record");
563        btester.actionClick(partialClass);
564       
565       
566        /* wait for the name change to propogate to enable the finish button */
567        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
568        btester.actionClick(finish);
569       
570       
571        while(!project.isOpen()){ Utility.sleep(this, 100); }
572       
573        /*
574         * check that the generated source code is sane
575         */
576        boolean same = 
577            Utility.compareContent(project.getFile(name + ".mo"), 
578                "partial record "+ name +"\n" +
579                "\n" +
580                "end "+ name + ";");
581        assertTrue("unexpected conted created in the source file", same);
582    }
583
584    public void testCreateBlock()
585    {
586        openWizardAndFetchWidgets();
587       
588        String name = "b1";
589       
590        /*
591         * create class
592         */
593        ttester.actionEnterText(className, name);
594        ctester.actionSelectItem(classType, "block");
595
596       
597       
598        /* wait for the name change to propogate to enable the finish button */
599        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
600        btester.actionClick(finish);
601       
602       
603        while(!project.isOpen()){ Utility.sleep(this, 100); }
604       
605        /*
606         * check that the generated source code is sane
607         */
608        boolean same = 
609            Utility.compareContent(project.getFile(name + ".mo"), 
610                "block "+ name +"\n" +
611                "\n" +
612                "equation\n"+
613                "\n"+
614                "end "+ name + ";");
615        assertTrue("unexpected conted created in the source file", same);
616       
617    }
618    public void testCreateBlockWithInitBlock()
619    {
620        openWizardAndFetchWidgets();
621       
622        String name = "b2";
623       
624        /*
625         * create class
626         */
627        ttester.actionEnterText(className, name);
628        ctester.actionSelectItem(classType, "block");
629        btester.actionClick(initialEquation);       
630
631       
632       
633        /* wait for the name change to propogate to enable the finish button */
634        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
635        btester.actionClick(finish);
636       
637       
638        while(!project.isOpen()){ Utility.sleep(this, 100); }
639       
640        /*
641         * check that the generated source code is sane
642         */
643        boolean same = 
644            Utility.compareContent(project.getFile(name + ".mo"), 
645                "block "+ name +"\n" +
646                "\n" +
647                "equation\n"+
648                "\n"+
649                "initial equation\n"+
650                "\n"+                               
651                "end "+ name + ";");
652        assertTrue("unexpected conted created in the source file", same);
653       
654    }
655
656    public void testCreatePartialBlock()
657    {
658        openWizardAndFetchWidgets();
659       
660        String name = "b3";
661       
662        /*
663         * create class
664         */
665        ttester.actionEnterText(className, name);
666        ctester.actionSelectItem(classType, "block");
667        btester.actionClick(partialClass);     
668
669       
670       
671        /* wait for the name change to propogate to enable the finish button */
672        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
673        btester.actionClick(finish);
674       
675       
676        while(!project.isOpen()){ Utility.sleep(this, 100); }
677       
678        /*
679         * check that the generated source code is sane
680         */
681        boolean same = 
682            Utility.compareContent(project.getFile(name + ".mo"), 
683                "partial block "+ name +"\n" +
684                "\n" +
685                "equation\n"+
686                "\n"+                               
687                "end "+ name + ";");
688        assertTrue("unexpected conted created in the source file", same);
689   
690    }
691    public void testCreatePartialBlockWithInitBlock()
692    {
693        openWizardAndFetchWidgets();
694       
695        String name = "b4";
696       
697        /*
698         * create class
699         */
700        ttester.actionEnterText(className, name);
701        ctester.actionSelectItem(classType, "block");
702        btester.actionClick(partialClass);
703        btester.actionClick(initialEquation);       
704
705       
706       
707        /* wait for the name change to propogate to enable the finish button */
708        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
709        btester.actionClick(finish);
710       
711       
712        while(!project.isOpen()){ Utility.sleep(this, 100); }
713       
714        /*
715         * check that the generated source code is sane
716         */
717        boolean same = 
718            Utility.compareContent(project.getFile(name + ".mo"), 
719                "partial block "+ name +"\n" +
720                "\n" +
721                "equation\n"+
722                "\n"+
723                "initial equation\n"+
724                "\n"+               
725                "end "+ name + ";");
726        assertTrue("unexpected conted created in the source file", same);
727    }
728
729    public void testCreateType()
730    {
731        openWizardAndFetchWidgets();
732       
733        String name = "t1";
734       
735        /*
736         * create class
737         */
738        ttester.actionEnterText(className, name);
739        ctester.actionSelectItem(classType, "type");
740
741       
742       
743        /* wait for the name change to propogate to enable the finish button */
744        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
745        btester.actionClick(finish);
746       
747       
748        while(!project.isOpen()){ Utility.sleep(this, 100); }
749       
750        /*
751         * check that the generated source code is sane
752         */
753        boolean same = 
754            Utility.compareContent(project.getFile(name + ".mo"), 
755                "type "+ name +"\n" +
756                ";");
757        assertTrue("unexpected conted created in the source file", same);
758       
759    }
760
761    public void testCreateFunction()
762    {
763        openWizardAndFetchWidgets();
764       
765        String name = "f1";
766       
767        /*
768         * create class
769         */
770        ctester.actionSelectItem(classType, "function");
771        ttester.actionEnterText(className, name);
772       
773       
774        /* wait for the name change to propogate to enable the finish button */
775        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
776        btester.actionClick(finish);
777       
778       
779        while(!project.isOpen()){ Utility.sleep(this, 100); }
780       
781        /*
782         * check that the generated source code is sane
783         */
784        boolean same = 
785            Utility.compareContent(project.getFile(name + ".mo"), 
786                "function "+ name +"\n" +
787                "\n" +
788                "algorithm\n"+
789                "\n"+               
790                "end "+ name + ";");
791        assertTrue("unexpected conted created in the source file", same);
792    }
793
794    public void testCreateFunctionWithExternalBody()
795    {
796        openWizardAndFetchWidgets();
797       
798        String name = "f2";
799       
800        /*
801         * create class
802         */
803        ctester.actionSelectItem(classType, "function");
804        ttester.actionEnterText(className, name);
805
806        /*
807         * wait for the class type change to propogate to the
808         * external body  checkboc
809         */
810        while (!externalBody.getEnabled()) { Utility.sleep(this, 100); }
811
812        btester.actionClick(externalBody);     
813       
814        /* wait for the name change to propogate to enable the finish button */
815        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
816        btester.actionClick(finish);
817       
818       
819        while(!project.isOpen()){ Utility.sleep(this, 100); }
820       
821        /*
822         * check that the generated source code is sane
823         */
824        boolean same = 
825            Utility.compareContent(project.getFile(name + ".mo"), 
826                "function "+ name +"\n" +
827                "\n" +
828                "external\n"+
829                "end "+ name + ";");
830        assertTrue("unexpected conted created in the source file", same);
831       
832    }
833
834     //some ideas for more tests
835        /*
836         * TODO enter some text into source folder field and
837         * check the error/warning messages
838         */
839       
840        /*
841         * TODO test to create a class in a sub-directory
842         */
843}
Note: See TracBrowser for help on using the repository browser.