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

Last change on this file since 126 was 126, checked in by boris, 19 years ago
  • new package wizard finished
File size: 19.7 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 testCreateBlock()
520    {
521        openWizardAndFetchWidgets();
522       
523        String name = "b1";
524       
525        /*
526         * create class
527         */
528        ttester.actionEnterText(className, name);
529        ctester.actionSelectItem(classType, "block");
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                "block "+ name +"\n" +
546                "\n" +
547                "equation\n"+
548                "\n"+
549                "end "+ name + ";");
550        assertTrue("unexpected conted created in the source file", same);
551       
552    }
553    public void testCreateBlockWithInitBlock()
554    {
555        openWizardAndFetchWidgets();
556       
557        String name = "b2";
558       
559        /*
560         * create class
561         */
562        ttester.actionEnterText(className, name);
563        ctester.actionSelectItem(classType, "block");
564        btester.actionClick(initialEquation);       
565
566       
567       
568        /* wait for the name change to propogate to enable the finish button */
569        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
570        btester.actionClick(finish);
571       
572       
573        while(!project.isOpen()){ Utility.sleep(this, 100); }
574       
575        /*
576         * check that the generated source code is sane
577         */
578        boolean same = 
579            Utility.compareContent(project.getFile(name + ".mo"), 
580                "block "+ name +"\n" +
581                "\n" +
582                "equation\n"+
583                "\n"+
584                "initial equation\n"+
585                "\n"+                               
586                "end "+ name + ";");
587        assertTrue("unexpected conted created in the source file", same);
588       
589    }
590
591    public void testCreatePartialBlock()
592    {
593        openWizardAndFetchWidgets();
594       
595        String name = "b3";
596       
597        /*
598         * create class
599         */
600        ttester.actionEnterText(className, name);
601        ctester.actionSelectItem(classType, "block");
602        btester.actionClick(partialClass);     
603
604       
605       
606        /* wait for the name change to propogate to enable the finish button */
607        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
608        btester.actionClick(finish);
609       
610       
611        while(!project.isOpen()){ Utility.sleep(this, 100); }
612       
613        /*
614         * check that the generated source code is sane
615         */
616        boolean same = 
617            Utility.compareContent(project.getFile(name + ".mo"), 
618                "partial block "+ name +"\n" +
619                "\n" +
620                "equation\n"+
621                "\n"+                               
622                "end "+ name + ";");
623        assertTrue("unexpected conted created in the source file", same);
624   
625    }
626    public void testCreatePartialBlockWithInitBlock()
627    {
628        openWizardAndFetchWidgets();
629       
630        String name = "b4";
631       
632        /*
633         * create class
634         */
635        ttester.actionEnterText(className, name);
636        ctester.actionSelectItem(classType, "block");
637        btester.actionClick(partialClass);
638        btester.actionClick(initialEquation);       
639
640       
641       
642        /* wait for the name change to propogate to enable the finish button */
643        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
644        btester.actionClick(finish);
645       
646       
647        while(!project.isOpen()){ Utility.sleep(this, 100); }
648       
649        /*
650         * check that the generated source code is sane
651         */
652        boolean same = 
653            Utility.compareContent(project.getFile(name + ".mo"), 
654                "partial block "+ name +"\n" +
655                "\n" +
656                "equation\n"+
657                "\n"+
658                "initial equation\n"+
659                "\n"+               
660                "end "+ name + ";");
661        assertTrue("unexpected conted created in the source file", same);
662    }
663
664    public void testCreateType()
665    {
666        openWizardAndFetchWidgets();
667       
668        String name = "t1";
669       
670        /*
671         * create class
672         */
673        ttester.actionEnterText(className, name);
674        ctester.actionSelectItem(classType, "type");
675
676       
677       
678        /* wait for the name change to propogate to enable the finish button */
679        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
680        btester.actionClick(finish);
681       
682       
683        while(!project.isOpen()){ Utility.sleep(this, 100); }
684       
685        /*
686         * check that the generated source code is sane
687         */
688        boolean same = 
689            Utility.compareContent(project.getFile(name + ".mo"), 
690                "type "+ name +"\n" +
691                ";");
692        assertTrue("unexpected conted created in the source file", same);
693       
694    }
695
696    public void testCreateFunction()
697    {
698        openWizardAndFetchWidgets();
699       
700        String name = "f1";
701       
702        /*
703         * create class
704         */
705        ctester.actionSelectItem(classType, "function");
706        ttester.actionEnterText(className, name);
707       
708       
709        /* wait for the name change to propogate to enable the finish button */
710        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
711        btester.actionClick(finish);
712       
713       
714        while(!project.isOpen()){ Utility.sleep(this, 100); }
715       
716        /*
717         * check that the generated source code is sane
718         */
719        boolean same = 
720            Utility.compareContent(project.getFile(name + ".mo"), 
721                "function "+ name +"\n" +
722                "\n" +
723                "algorithm\n"+
724                "\n"+               
725                "end "+ name + ";");
726        assertTrue("unexpected conted created in the source file", same);
727    }
728
729    public void testCreateFunctionWithExternalBody()
730    {
731        openWizardAndFetchWidgets();
732       
733        String name = "f2";
734       
735        /*
736         * create class
737         */
738        ctester.actionSelectItem(classType, "function");
739        ttester.actionEnterText(className, name);
740
741        /*
742         * wait for the class type change to propogate to the
743         * external body  checkboc
744         */
745        while (!externalBody.getEnabled()) { Utility.sleep(this, 100); }
746
747        btester.actionClick(externalBody);     
748       
749        /* wait for the name change to propogate to enable the finish button */
750        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
751        btester.actionClick(finish);
752       
753       
754        while(!project.isOpen()){ Utility.sleep(this, 100); }
755       
756        /*
757         * check that the generated source code is sane
758         */
759        boolean same = 
760            Utility.compareContent(project.getFile(name + ".mo"), 
761                "function "+ name +"\n" +
762                "\n" +
763                "external\n"+
764                "end "+ name + ";");
765        assertTrue("unexpected conted created in the source file", same);
766       
767    }
768
769     //some ideas for more tests
770        /*
771         * TODO enter some text into source folder field and
772         * check the error/warning messages
773         */
774       
775        /*
776         * TODO test to create a class in a sub-directory
777         */
778}
Note: See TracBrowser for help on using the repository browser.