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

Last change on this file since 235 was 235, checked in by boris, 19 years ago
  • added class type selection retention to the new class wizard dialog, as requested by ze boss !
File size: 29.0 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    private Button cancel;
88   
89
90    @Override
91    protected 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.findButtonByText("&Finish");
144        assertNotNull("Problems finding finish button", finish);
145       
146        cancel = 
147            Utility.findButtonByText("Cancel");
148        assertNotNull("Problems finding cancel button", cancel);
149
150
151        /* find classType combo by tag */
152        classType = 
153            (Combo)
154                Utility.getInstrumentedWidget(NewClassWizard.CLASS_TYPE_TAG);
155        assertNotNull("Problems finding classType widget", classType);
156       
157       
158        /* make some checks on the state of the wizards */
159        assertEquals("Wrong source folder selected", 
160                sourceFolder.getText(), PROJECT_NAME_1);       
161        assertEquals("Junk present in class name field", 
162                className.getText(), "");
163        assertFalse("initial equation unexpectedly selected",
164                initialEquation.getSelection());
165        assertFalse("partial class unexpectedly selected",
166                partialClass.getSelection());
167        assertFalse("Finish button not disabled", 
168                finish.getEnabled());
169       
170
171    }
172   
173    /**
174     * check if the wizard 'remebers' it's class type selection
175     * between different invocations
176     */
177    public void testSelectionRetention()
178    {
179        /*
180         * pop-up wizard, change class restriction type to 'type',
181         * check that check boxes were updated and close wizard
182         */
183        openWizardAndFetchWidgets();       
184        ctester.actionSelectItem(classType, "type");
185        assertFalse("initial equation check box should be disabled",
186                initialEquation.getEnabled());
187        assertFalse("partial class check box should be disabled",
188                    partialClass.getEnabled());
189        assertFalse("external body check box should be disabled",
190                    externalBody.getEnabled());
191        btester.actionClick(cancel);
192       
193        /*
194         * pup-up wizard again and check that the selection is 'type'
195         * and that the satus of other widgets is correctly set
196         */
197        openWizardAndFetchWidgets();
198        assertEquals("wrong class type selection", "type", classType.getText());
199        assertFalse("initial equation check box should be disabled",
200                    initialEquation.getEnabled());
201        assertFalse("partial class check box should be disabled",
202                    partialClass.getEnabled());
203        assertFalse("external body check box should be disabled",
204                    externalBody.getEnabled());
205       
206        /*
207         * change class restriction type to 'model',
208         * check that check boxes were updated and close dialog
209         */
210        ctester.actionSelectItem(classType, "model");
211        assertTrue("initial equation check box should be enabled",
212                initialEquation.getEnabled());
213        assertTrue("partial class check box should be enabled",
214                    partialClass.getEnabled());
215        assertFalse("external body check box should be disabled",
216                    externalBody.getEnabled());
217        btester.actionClick(cancel);       
218       
219        /*
220         * pup-up wizard again and check that the selection is 'model'
221         * and that the satus of other widgets is correctly set
222         */
223        openWizardAndFetchWidgets();
224        assertEquals("wrong class type selection", "model", classType.getText());
225        assertTrue("initial equation check box should be enabled",
226                    initialEquation.getEnabled());
227        assertTrue("partial class check box should be enabled",
228                    partialClass.getEnabled());
229        assertFalse("external body check box should be disabled",
230                    externalBody.getEnabled());
231       
232        /*
233         * change class restriction type to 'connector',
234         * check that check boxes were updated and close dialog
235         */
236        ctester.actionSelectItem(classType, "connector");
237        assertFalse("initial equation check box should be disabled",
238                initialEquation.getEnabled());
239        assertTrue("partial class check box should be enabled",
240                    partialClass.getEnabled());
241        assertFalse("external body check box should be disabled",
242                    externalBody.getEnabled());
243        btester.actionClick(cancel);       
244       
245        /*
246         * pup-up wizard again and check that the selection is 'connector'
247         * and that the satus of other widgets is correctly set
248         */
249        openWizardAndFetchWidgets();
250        assertEquals("wrong class type selection", "connector",
251                    classType.getText());
252        assertFalse("initial equation check box should be disabled",
253                    initialEquation.getEnabled());
254        assertTrue("partial class check box should be enabled",
255                    partialClass.getEnabled());
256        assertFalse("external body check box should be disabled",
257                    externalBody.getEnabled());
258       
259        /*
260         * change class restriction type to 'block',
261         * check that check boxes were updated and close dialog
262         */
263        ctester.actionSelectItem(classType, "block");
264        assertTrue("initial equation check box should be enabled",
265                initialEquation.getEnabled());
266        assertTrue("partial class check box should be enabled",
267                    partialClass.getEnabled());
268        assertFalse("external body check box should be disabled",
269                    externalBody.getEnabled());
270        btester.actionClick(cancel);       
271       
272        /*
273         * pup-up wizard again and check that the selection is 'block'
274         * and that the satus of other widgets is correctly set
275         */
276        openWizardAndFetchWidgets();
277        assertEquals("wrong class type selection", "block",
278                    classType.getText());
279        assertTrue("initial equation check box should be enabled",
280                initialEquation.getEnabled());
281        assertTrue("partial class check box should be enabled",
282                    partialClass.getEnabled());
283        assertFalse("external body check box should be disabled",
284                    externalBody.getEnabled());
285
286        /*
287         * change class restriction type to 'record',
288         * check that check boxes were updated and close dialog
289         */
290        ctester.actionSelectItem(classType, "record");
291        assertFalse("initial equation check box should be disabled",
292                initialEquation.getEnabled());
293        assertTrue("partial class check box should be enabled",
294                    partialClass.getEnabled());
295        assertFalse("external body check box should be disabled",
296                    externalBody.getEnabled());
297        btester.actionClick(cancel);       
298       
299        /*
300         * pup-up wizard again and check that the selection is 'record'
301         * and that the satus of other widgets is correctly set
302         */
303        openWizardAndFetchWidgets();
304        assertEquals("wrong class type selection", "record",
305                    classType.getText());
306        assertFalse("initial equation check box should be disabled",
307                initialEquation.getEnabled());
308        assertTrue("partial class check box should be enabled",
309                    partialClass.getEnabled());
310        assertFalse("external body check box should be disabled",
311                    externalBody.getEnabled());
312
313        /*
314         * change class restriction type to 'class',
315         * check that check boxes were updated and close dialog
316         */
317        ctester.actionSelectItem(classType, "class");
318        assertTrue("initial equation check box should be enabled",
319                initialEquation.getEnabled());
320        assertTrue("partial class check box should be enabled",
321                    partialClass.getEnabled());
322        assertFalse("external body check box should be disabled",
323                    externalBody.getEnabled());
324        btester.actionClick(cancel);
325       
326        /*
327         * pup-up wizard again and check that the selection is 'class',
328         * check that check boxes were updated
329         * and that the satus of other widgets is correctly set
330         */
331        openWizardAndFetchWidgets();
332        assertEquals("wrong class type selection", "class",
333                    classType.getText());
334        assertTrue("initial equation check box should be enabled",
335                initialEquation.getEnabled());
336        assertTrue("partial class check box should be enabled",
337                    partialClass.getEnabled());
338        assertFalse("external body check box should be disabled",
339                    externalBody.getEnabled());
340
341        /*
342         * change class restriction type to 'function', check that
343         * check boxes were updated and close dialog
344         */
345        ctester.actionSelectItem(classType, "function");
346        assertFalse("initial equation check box should be disabled",
347                initialEquation.getEnabled());
348        assertFalse("partial class check box should be disabled",
349                    partialClass.getEnabled());
350        assertTrue("external body check box should be enabled",
351                externalBody.getEnabled());
352        btester.actionClick(cancel);
353
354        /*
355         * pup-up wizard again and check that the selection is 'function'
356         * and that the satus of other widgets is correctly set
357         */
358        openWizardAndFetchWidgets();
359        assertEquals("wrong class type selection", "function",
360                    classType.getText());
361        assertFalse("initial equation check box should be disabled",
362                initialEquation.getEnabled());
363        assertFalse("partial class check box should be disabled",
364                    partialClass.getEnabled());
365        assertTrue("external body check box should be enabled",
366                externalBody.getEnabled());
367
368        /* close dialog */
369        btester.actionClick(cancel);
370    }
371   
372    public void testCreateModel()
373    {
374        openWizardAndFetchWidgets();       
375       
376        String name = "m1";
377        /*
378         * create model
379         */
380        ttester.actionEnterText(className, name);
381        ctester.actionSelectItem(classType, "model");
382        assertTrue(finish.getEnabled());
383
384        /* wait for the name change to propogate to enable the finish button */
385        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
386        btester.actionClick(finish);
387       
388        while(!project.isOpen()){ Utility.sleep(this, 100); }       
389       
390        /*
391         * check that the generated source code is sane
392         */
393        boolean same = 
394            Utility.compareContent(project.getFile(name + ".mo"), 
395                "model " + name + "\n"+
396                "\n"+
397                "equation\n"+
398                "\n"+
399                "end " + name + ";");
400        assertTrue("unexpected conted created in the source file", same);
401   
402    }
403       
404    public void testCreateModelWithInitEquation()
405    {
406        openWizardAndFetchWidgets();
407       
408        String name = "m2"; 
409       
410        /*
411         * create model
412         */
413        ttester.actionEnterText(className, name);
414        ctester.actionSelectItem(classType, "model");
415        assertTrue(finish.getEnabled());
416       
417        btester.actionClick(initialEquation);
418       
419        assertTrue(initialEquation.getSelection());
420
421        /* wait for the name change to propogate to enable the finish button */
422        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
423        btester.actionClick(finish);
424       
425       
426        while(!project.isOpen()){ Utility.sleep(this, 100); }
427       
428        /*
429         * check that the generated source code is sane
430         */
431        boolean same = 
432            Utility.compareContent(project.getFile(name + ".mo"), 
433                "model "+ name +"\n"+
434                "\n"+
435                "equation\n"+
436                "\n"+
437                "initial equation\n"+
438                "\n"+
439                "end " + name + ";");
440        assertTrue("unexpected conted created in the source file", same);
441    }
442
443    public void testCreatePartialModel()
444    {
445        openWizardAndFetchWidgets();       
446       
447        String name = "m3";
448        /*
449         * create model
450         */
451        ttester.actionEnterText(className, name);
452        ctester.actionSelectItem(classType, "model");
453        assertTrue(finish.getEnabled());
454       
455        btester.actionClick(partialClass);
456       
457        assertTrue(partialClass.getSelection());
458
459        /* wait for the name change to propogate to enable the finish button */
460        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
461        btester.actionClick(finish);
462       
463       
464        while(!project.isOpen()){ Utility.sleep(this, 100); }
465       
466        /*
467         * check that the generated source code is sane
468         */
469        boolean same = 
470            Utility.compareContent(project.getFile(name + ".mo"), 
471                "partial model "+ name +"\n"+
472                "\n"+
473                "equation\n"+
474                "\n"+
475                "end "+ name + ";");
476        assertTrue("unexpected conted created in the source file", same);
477   
478    }
479
480    public void testCreatePartialModelWithInitBlock()
481    {
482        openWizardAndFetchWidgets();       
483       
484        String name = "m4";
485        /*
486         * create model
487         */
488        ttester.actionEnterText(className, name);
489        ctester.actionSelectItem(classType, "model");
490        assertTrue(finish.getEnabled());
491       
492        btester.actionClick(partialClass);     
493        assertTrue(partialClass.getSelection());
494
495        btester.actionClick(initialEquation);       
496        assertTrue(initialEquation.getSelection());
497       
498       
499        /* wait for the name change to propogate to enable the finish button */
500        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
501        btester.actionClick(finish);
502       
503       
504        while(!project.isOpen()){ Utility.sleep(this, 100); }
505       
506        /*
507         * check that the generated source code is sane
508         */
509        boolean same = 
510            Utility.compareContent(project.getFile(name + ".mo"), 
511                "partial model "+ name +"\n"+
512                "\n"+
513                "equation\n"+
514                "\n"+
515                "initial equation\n"+
516                "\n"+
517                "end "+ name + ";");
518        assertTrue("unexpected conted created in the source file", same);
519    }
520
521    public void testCreateClass()
522    {
523        openWizardAndFetchWidgets();       
524       
525        String name = "c1";
526       
527        /*
528         * create class
529         */
530        ttester.actionEnterText(className, name);
531        ctester.actionSelectItem(classType, "class");
532       
533       
534        /* wait for the name change to propogate to enable the finish button */
535        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
536        btester.actionClick(finish);
537       
538       
539        while(!project.isOpen()){ Utility.sleep(this, 100); }
540       
541        /*
542         * check that the generated source code is sane
543         */
544        boolean same = 
545            Utility.compareContent(project.getFile(name + ".mo"), 
546                "class "+ name +"\n"+
547                "\n"+
548                "equation\n"+
549                "\n"+
550                "end "+ name + ";");
551        assertTrue("unexpected conted created in the source file", same);
552    }
553
554    public void testCreateClassWithInitBlock()
555    {
556        openWizardAndFetchWidgets();
557       
558        String name = "c2";
559       
560        /*
561         * create class
562         */
563        ttester.actionEnterText(className, name);
564        ctester.actionSelectItem(classType, "class");
565        btester.actionClick(initialEquation);
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                "class "+ 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 testCreatePartialClass()
592    {
593        openWizardAndFetchWidgets();
594       
595        String name = "c3";
596       
597        /*
598         * create class
599         */
600        ttester.actionEnterText(className, name);
601        ctester.actionSelectItem(classType, "class");
602        btester.actionClick(partialClass);
603       
604       
605        /* wait for the name change to propogate to enable the finish button */
606        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
607        btester.actionClick(finish);
608       
609       
610        while(!project.isOpen()){ Utility.sleep(this, 100); }
611       
612        /*
613         * check that the generated source code is sane
614         */
615        boolean same = 
616            Utility.compareContent(project.getFile(name + ".mo"), 
617                "partial class "+ name +"\n"+
618                "\n"+
619                "equation\n"+
620                "\n"+
621                "end "+ name + ";");
622        assertTrue("unexpected conted created in the source file", same);
623    }
624
625    public void testCreatePartialClassWithInitBlock()
626    {
627        openWizardAndFetchWidgets();
628       
629        String name = "c4";
630       
631        /*
632         * create class
633         */
634        ttester.actionEnterText(className, name);
635        ctester.actionSelectItem(classType, "class");
636        btester.actionClick(partialClass);
637        btester.actionClick(initialEquation);
638       
639       
640        /* wait for the name change to propogate to enable the finish button */
641        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
642        btester.actionClick(finish);
643       
644       
645        while(!project.isOpen()){ Utility.sleep(this, 100); }
646       
647        /*
648         * check that the generated source code is sane
649         */
650        boolean same = 
651            Utility.compareContent(project.getFile(name + ".mo"), 
652                "partial class "+ name +"\n"+
653                "\n"+
654                "equation\n"+
655                "\n"+
656                "initial equation\n"+
657                "\n"+               
658                "end "+ name + ";");
659        assertTrue("unexpected conted created in the source file", same);
660       
661    }
662   
663   
664    public void testCreateConnector()
665    {
666        openWizardAndFetchWidgets();
667       
668        String name = "con1";
669       
670        /*
671         * create class
672         */
673        ttester.actionEnterText(className, name);
674        ctester.actionSelectItem(classType, "connector");
675       
676       
677        /* wait for the name change to propogate to enable the finish button */
678        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
679        btester.actionClick(finish);
680       
681       
682        while(!project.isOpen()){ Utility.sleep(this, 100); }
683       
684        /*
685         * check that the generated source code is sane
686         */
687        boolean same = 
688            Utility.compareContent(project.getFile(name + ".mo"), 
689                "connector "+ name +"\n" +
690                "\n" +
691                "end "+ name + ";");
692        assertTrue("unexpected conted created in the source file", same);
693    }
694
695    public void testCreatePartialConnector()
696    {
697        openWizardAndFetchWidgets();
698       
699        String name = "con2";
700       
701        /*
702         * create class
703         */
704        ttester.actionEnterText(className, name);
705        ctester.actionSelectItem(classType, "connector");
706        btester.actionClick(partialClass);     
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                "partial connector "+ name +"\n" +
722                "\n" +
723                "end "+ name + ";");
724        assertTrue("unexpected conted created in the source file", same);
725       
726    }
727   
728    public void testCreateRecord()
729    {
730        openWizardAndFetchWidgets();
731       
732        String name = "rec1";
733       
734        /*
735         * create class
736         */
737        ttester.actionEnterText(className, name);
738        ctester.actionSelectItem(classType, "record");
739
740       
741       
742        /* wait for the name change to propogate to enable the finish button */
743        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
744        btester.actionClick(finish);
745       
746       
747        while(!project.isOpen()){ Utility.sleep(this, 100); }
748       
749        /*
750         * check that the generated source code is sane
751         */
752        boolean same = 
753            Utility.compareContent(project.getFile(name + ".mo"), 
754                "record "+ name +"\n" +
755                "\n" +
756                "end "+ name + ";");
757        assertTrue("unexpected conted created in the source file", same);
758       
759    }
760   
761    public void testCreatePartialRecord()
762    {
763        openWizardAndFetchWidgets();
764       
765        String name = "rec2";
766       
767        /*
768         * create class
769         */
770        ttester.actionEnterText(className, name);
771        ctester.actionSelectItem(classType, "record");
772        btester.actionClick(partialClass);
773       
774       
775        /* wait for the name change to propogate to enable the finish button */
776        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
777        btester.actionClick(finish);
778       
779       
780        while(!project.isOpen()){ Utility.sleep(this, 100); }
781       
782        /*
783         * check that the generated source code is sane
784         */
785        boolean same = 
786            Utility.compareContent(project.getFile(name + ".mo"), 
787                "partial record "+ name +"\n" +
788                "\n" +
789                "end "+ name + ";");
790        assertTrue("unexpected conted created in the source file", same);
791    }
792
793    public void testCreateBlock()
794    {
795        openWizardAndFetchWidgets();
796       
797        String name = "b1";
798       
799        /*
800         * create class
801         */
802        ttester.actionEnterText(className, name);
803        ctester.actionSelectItem(classType, "block");
804
805       
806       
807        /* wait for the name change to propogate to enable the finish button */
808        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
809        btester.actionClick(finish);
810       
811       
812        while(!project.isOpen()){ Utility.sleep(this, 100); }
813       
814        /*
815         * check that the generated source code is sane
816         */
817        boolean same = 
818            Utility.compareContent(project.getFile(name + ".mo"), 
819                "block "+ name +"\n" +
820                "\n" +
821                "equation\n"+
822                "\n"+
823                "end "+ name + ";");
824        assertTrue("unexpected conted created in the source file", same);
825       
826    }
827    public void testCreateBlockWithInitBlock()
828    {
829        openWizardAndFetchWidgets();
830       
831        String name = "b2";
832       
833        /*
834         * create class
835         */
836        ttester.actionEnterText(className, name);
837        ctester.actionSelectItem(classType, "block");
838        btester.actionClick(initialEquation);       
839
840       
841       
842        /* wait for the name change to propogate to enable the finish button */
843        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
844        btester.actionClick(finish);
845       
846       
847        while(!project.isOpen()){ Utility.sleep(this, 100); }
848       
849        /*
850         * check that the generated source code is sane
851         */
852        boolean same = 
853            Utility.compareContent(project.getFile(name + ".mo"), 
854                "block "+ name +"\n" +
855                "\n" +
856                "equation\n"+
857                "\n"+
858                "initial equation\n"+
859                "\n"+                               
860                "end "+ name + ";");
861        assertTrue("unexpected conted created in the source file", same);
862       
863    }
864
865    public void testCreatePartialBlock()
866    {
867        openWizardAndFetchWidgets();
868       
869        String name = "b3";
870       
871        /*
872         * create class
873         */
874        ttester.actionEnterText(className, name);
875        ctester.actionSelectItem(classType, "block");
876        btester.actionClick(partialClass);     
877
878       
879       
880        /* wait for the name change to propogate to enable the finish button */
881        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
882        btester.actionClick(finish);
883       
884       
885        while(!project.isOpen()){ Utility.sleep(this, 100); }
886       
887        /*
888         * check that the generated source code is sane
889         */
890        boolean same = 
891            Utility.compareContent(project.getFile(name + ".mo"), 
892                "partial block "+ name +"\n" +
893                "\n" +
894                "equation\n"+
895                "\n"+                               
896                "end "+ name + ";");
897        assertTrue("unexpected conted created in the source file", same);
898   
899    }
900    public void testCreatePartialBlockWithInitBlock()
901    {
902        openWizardAndFetchWidgets();
903       
904        String name = "b4";
905       
906        /*
907         * create class
908         */
909        ttester.actionEnterText(className, name);
910        ctester.actionSelectItem(classType, "block");
911        btester.actionClick(partialClass);
912        btester.actionClick(initialEquation);       
913
914       
915       
916        /* wait for the name change to propogate to enable the finish button */
917        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
918        btester.actionClick(finish);
919       
920       
921        while(!project.isOpen()){ Utility.sleep(this, 100); }
922       
923        /*
924         * check that the generated source code is sane
925         */
926        boolean same = 
927            Utility.compareContent(project.getFile(name + ".mo"), 
928                "partial block "+ name +"\n" +
929                "\n" +
930                "equation\n"+
931                "\n"+
932                "initial equation\n"+
933                "\n"+               
934                "end "+ name + ";");
935        assertTrue("unexpected conted created in the source file", same);
936    }
937
938    public void testCreateType()
939    {
940        openWizardAndFetchWidgets();
941       
942        String name = "t1";
943       
944        /*
945         * create class
946         */
947        ttester.actionEnterText(className, name);
948        ctester.actionSelectItem(classType, "type");
949
950       
951       
952        /* wait for the name change to propogate to enable the finish button */
953        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
954        btester.actionClick(finish);
955       
956       
957        while(!project.isOpen()){ Utility.sleep(this, 100); }
958       
959        /*
960         * check that the generated source code is sane
961         */
962        boolean same = 
963            Utility.compareContent(project.getFile(name + ".mo"), 
964                "type "+ name +"\n" +
965                ";");
966        assertTrue("unexpected conted created in the source file", same);
967       
968    }
969
970    public void testCreateFunction()
971    {
972        openWizardAndFetchWidgets();
973       
974        String name = "f1";
975       
976        /*
977         * create class
978         */
979        ctester.actionSelectItem(classType, "function");
980        ttester.actionEnterText(className, name);
981       
982       
983        /* wait for the name change to propogate to enable the finish button */
984        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
985        btester.actionClick(finish);
986       
987       
988        while(!project.isOpen()){ Utility.sleep(this, 100); }
989       
990        /*
991         * check that the generated source code is sane
992         */
993        boolean same = 
994            Utility.compareContent(project.getFile(name + ".mo"), 
995                "function "+ name +"\n" +
996                "\n" +
997                "algorithm\n"+
998                "\n"+               
999                "end "+ name + ";");
1000        assertTrue("unexpected conted created in the source file", same);
1001    }
1002
1003    public void testCreateFunctionWithExternalBody()
1004    {
1005        openWizardAndFetchWidgets();
1006       
1007        String name = "f2";
1008       
1009        /*
1010         * create class
1011         */
1012        ctester.actionSelectItem(classType, "function");
1013        ttester.actionEnterText(className, name);
1014
1015        /*
1016         * wait for the class type change to propogate to the
1017         * external body  checkboc
1018         */
1019        while (!externalBody.getEnabled()) { Utility.sleep(this, 100); }
1020
1021        btester.actionClick(externalBody);     
1022       
1023        /* wait for the name change to propogate to enable the finish button */
1024        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
1025        btester.actionClick(finish);
1026       
1027       
1028        while(!project.isOpen()){ Utility.sleep(this, 100); }
1029       
1030        /*
1031         * check that the generated source code is sane
1032         */
1033        boolean same = 
1034            Utility.compareContent(project.getFile(name + ".mo"), 
1035                "function "+ name +"\n" +
1036                "\n" +
1037                "external\n"+
1038                "end "+ name + ";");
1039        assertTrue("unexpected conted created in the source file", same);
1040       
1041    }
1042
1043     //some ideas for more tests
1044        /*
1045         * TODO enter some text into source folder field and
1046         * check the error/warning messages
1047         */
1048       
1049        /*
1050         * TODO test to create a class in a sub-directory
1051         */
1052}
Note: See TracBrowser for help on using the repository browser.