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

Last change on this file since 295 was 291, checked in by boris, 19 years ago
  • moved the modelica project creation code where it belongs IMHO
  • wraped the call to modelica project creation operation from new project wizard into IWorkspaceRunnable to improve batching of change events
File size: 30.5 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.modelica.mdt.core.IModelicaProject;
52import org.modelica.mdt.core.ModelicaCore;
53import org.modelica.mdt.test.util.Utility;
54import org.modelica.mdt.ui.wizards.NewClassWizard;
55import org.modelica.mdt.ui.wizards.NewTypePage;
56
57import abbot.tester.swt.ButtonTester;
58import abbot.tester.swt.ComboTester;
59import abbot.tester.swt.TextTester;
60
61import junit.framework.Assert;
62import junit.framework.TestCase;
63
64/**
65 * @author Elmir Jagudin
66 *
67 * Test the New Class Wizard functionality
68 */
69public class TestNewClassWizard extends TestCase
70{
71    private static final String PROJECT_NAME_1 = 
72            TestNewClassWizard.class.getName() + "1";
73   
74    /* a project name that is garanteed to be nonexistent */
75    private static final String NON_EXSITING_PROJECT_NAME = 
76        TestNewClassWizard.class.getName() + "non_existing_project";
77
78    private StructuredSelection fileDestination; 
79   
80    private IProject project;
81   
82    private TextTester ttester;
83    private ButtonTester btester;
84    private ComboTester ctester;
85
86    private Text sourceFolder;
87    private Text className;
88    private Combo classType;
89    private Button initialEquation;
90    private Button partialClass;
91    private Button externalBody;
92   
93    private Button finish;
94    private Button cancel;
95   
96
97    @Override
98    protected void setUp() throws Exception
99    {
100        /*
101         * setup project
102         */
103        project = 
104            ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME_1);
105       
106        /* create project only if it does not exist yet */
107        if (!project.exists())
108        {
109            IModelicaProject mproj = 
110                ModelicaCore.getModelicaRoot().createProject(PROJECT_NAME_1);
111            Assert.assertNotNull("failed to create project", mproj);
112           
113            project = mproj.getProject();
114        }
115           
116        /*
117         * create the selection that points at the root of the created project
118         */
119        fileDestination = new StructuredSelection(project);
120       
121        /*
122         * setup testing support objects
123         */
124        ttester = TextTester.getTextTester();
125        btester = ButtonTester.getButtonTester();
126        ctester = new ComboTester();
127               
128    }
129   
130    public void openWizardAndFetchWidgets()
131    {
132        /*
133         * pop-up the wizard
134         */
135        IWizard wizard = 
136            Utility.openWizard("org.modelica.mdt.NewClassWizard",
137                    fileDestination);       
138        assertFalse(wizard.canFinish());
139
140       
141       
142        /* fetch widgets */
143        className = 
144            TextTester.getInstrumentedText(NewClassWizard.CLASS_NAME_TAG);
145        sourceFolder = 
146            TextTester.getInstrumentedText(NewTypePage.SOURCE_FOLDER_TAG);
147        initialEquation = 
148            ButtonTester.getInstrumentedButton(NewClassWizard.INITIAL_EQUATION_TAG);
149        externalBody =
150            ButtonTester.getInstrumentedButton(NewClassWizard.EXTERNAL_BODY_TAG);
151        partialClass = 
152            ButtonTester.getInstrumentedButton(NewClassWizard.PARTIAL_CLASS_TAG);
153        finish = 
154            Utility.findButtonByText("&Finish");
155        assertNotNull("Problems finding finish button", finish);
156       
157        cancel = 
158            Utility.findButtonByText("Cancel");
159        assertNotNull("Problems finding cancel button", cancel);
160
161
162        /* find classType combo by tag */
163        classType = 
164            (Combo)
165                Utility.getInstrumentedWidget(NewClassWizard.CLASS_TYPE_TAG);
166        assertNotNull("Problems finding classType widget", classType);
167       
168        /* make some checks on the state of the wizards */
169        assertEquals("Wrong source folder selected", 
170                PROJECT_NAME_1, sourceFolder.getText());       
171        assertEquals("Junk present in class name field", 
172                "", className.getText());
173        assertFalse("initial equation unexpectedly selected",
174                initialEquation.getSelection());
175        assertFalse("partial class unexpectedly selected",
176                partialClass.getSelection());
177        assertFalse("Finish button not disabled", 
178                finish.getEnabled());
179    }
180   
181    /**
182     * This test makes wizard to display a warning  and error messages
183     * by entering invalid data into the fields.
184     *
185     * The test checks that the state of finish button is right,
186     * it should be enabled for warnings and disabled for errors.
187     *
188     * Test for BUG #1, se bugs database
189     */
190    public void testFinishButtonState()
191    {
192        /*
193         * open dialog and set a legal source folder and an illegal class name,
194         * which should display a warning
195         */
196        openWizardAndFetchWidgets();
197       
198        ttester.actionEnterText(sourceFolder, PROJECT_NAME_1);
199        ttester.actionEnterText(className, "#�%&");
200        assertFalse("Finish button should be disabled when an illegal class " +
201                "name is entered", finish.getEnabled());
202       
203        /*
204         * set legal class name and non-existing source folder,
205         * which should display an error
206         */
207        ttester.actionEnterText(className, "legal_class_name");
208        ttester.actionEnterText(sourceFolder, NON_EXSITING_PROJECT_NAME);       
209        assertFalse("Finish button should not be enabled for an error",
210                finish.getEnabled());
211       
212        /* close the dialog */
213        btester.actionClick(cancel);       
214    }
215   
216    /**
217     * check if the wizard 'remebers' it's class type selection
218     * between different invocations
219     */
220    public void testSelectionRetention()
221    {
222        /*
223         * pop-up wizard, change class restriction type to 'type',
224         * check that check boxes were updated and close wizard
225         */
226        openWizardAndFetchWidgets();       
227        ctester.actionSelectItem(classType, "type");
228        assertFalse("initial equation check box should be disabled",
229                initialEquation.getEnabled());
230        assertFalse("partial class check box should be disabled",
231                    partialClass.getEnabled());
232        assertFalse("external body check box should be disabled",
233                    externalBody.getEnabled());
234        btester.actionClick(cancel);
235       
236        /*
237         * pup-up wizard again and check that the selection is 'type'
238         * and that the satus of other widgets is correctly set
239         */
240        openWizardAndFetchWidgets();
241        assertEquals("wrong class type selection", "type", classType.getText());
242        assertFalse("initial equation check box should be disabled",
243                    initialEquation.getEnabled());
244        assertFalse("partial class check box should be disabled",
245                    partialClass.getEnabled());
246        assertFalse("external body check box should be disabled",
247                    externalBody.getEnabled());
248       
249        /*
250         * change class restriction type to 'model',
251         * check that check boxes were updated and close dialog
252         */
253        ctester.actionSelectItem(classType, "model");
254        assertTrue("initial equation check box should be enabled",
255                initialEquation.getEnabled());
256        assertTrue("partial class check box should be enabled",
257                    partialClass.getEnabled());
258        assertFalse("external body check box should be disabled",
259                    externalBody.getEnabled());
260        btester.actionClick(cancel);       
261       
262        /*
263         * pup-up wizard again and check that the selection is 'model'
264         * and that the satus of other widgets is correctly set
265         */
266        openWizardAndFetchWidgets();
267        assertEquals("wrong class type selection", "model", classType.getText());
268        assertTrue("initial equation check box should be enabled",
269                    initialEquation.getEnabled());
270        assertTrue("partial class check box should be enabled",
271                    partialClass.getEnabled());
272        assertFalse("external body check box should be disabled",
273                    externalBody.getEnabled());
274       
275        /*
276         * change class restriction type to 'connector',
277         * check that check boxes were updated and close dialog
278         */
279        ctester.actionSelectItem(classType, "connector");
280        assertFalse("initial equation check box should be disabled",
281                initialEquation.getEnabled());
282        assertTrue("partial class check box should be enabled",
283                    partialClass.getEnabled());
284        assertFalse("external body check box should be disabled",
285                    externalBody.getEnabled());
286        btester.actionClick(cancel);       
287       
288        /*
289         * pup-up wizard again and check that the selection is 'connector'
290         * and that the satus of other widgets is correctly set
291         */
292        openWizardAndFetchWidgets();
293        assertEquals("wrong class type selection", "connector",
294                    classType.getText());
295        assertFalse("initial equation check box should be disabled",
296                    initialEquation.getEnabled());
297        assertTrue("partial class check box should be enabled",
298                    partialClass.getEnabled());
299        assertFalse("external body check box should be disabled",
300                    externalBody.getEnabled());
301       
302        /*
303         * change class restriction type to 'block',
304         * check that check boxes were updated and close dialog
305         */
306        ctester.actionSelectItem(classType, "block");
307        assertTrue("initial equation check box should be enabled",
308                initialEquation.getEnabled());
309        assertTrue("partial class check box should be enabled",
310                    partialClass.getEnabled());
311        assertFalse("external body check box should be disabled",
312                    externalBody.getEnabled());
313        btester.actionClick(cancel);       
314       
315        /*
316         * pup-up wizard again and check that the selection is 'block'
317         * and that the satus of other widgets is correctly set
318         */
319        openWizardAndFetchWidgets();
320        assertEquals("wrong class type selection", "block",
321                    classType.getText());
322        assertTrue("initial equation check box should be enabled",
323                initialEquation.getEnabled());
324        assertTrue("partial class check box should be enabled",
325                    partialClass.getEnabled());
326        assertFalse("external body check box should be disabled",
327                    externalBody.getEnabled());
328
329        /*
330         * change class restriction type to 'record',
331         * check that check boxes were updated and close dialog
332         */
333        ctester.actionSelectItem(classType, "record");
334        assertFalse("initial equation check box should be disabled",
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        btester.actionClick(cancel);       
341       
342        /*
343         * pup-up wizard again and check that the selection is 'record'
344         * and that the satus of other widgets is correctly set
345         */
346        openWizardAndFetchWidgets();
347        assertEquals("wrong class type selection", "record",
348                    classType.getText());
349        assertFalse("initial equation check box should be disabled",
350                initialEquation.getEnabled());
351        assertTrue("partial class check box should be enabled",
352                    partialClass.getEnabled());
353        assertFalse("external body check box should be disabled",
354                    externalBody.getEnabled());
355
356        /*
357         * change class restriction type to 'class',
358         * check that check boxes were updated and close dialog
359         */
360        ctester.actionSelectItem(classType, "class");
361        assertTrue("initial equation check box should be enabled",
362                initialEquation.getEnabled());
363        assertTrue("partial class check box should be enabled",
364                    partialClass.getEnabled());
365        assertFalse("external body check box should be disabled",
366                    externalBody.getEnabled());
367        btester.actionClick(cancel);
368       
369        /*
370         * pup-up wizard again and check that the selection is 'class',
371         * check that check boxes were updated
372         * and that the satus of other widgets is correctly set
373         */
374        openWizardAndFetchWidgets();
375        assertEquals("wrong class type selection", "class",
376                    classType.getText());
377        assertTrue("initial equation check box should be enabled",
378                initialEquation.getEnabled());
379        assertTrue("partial class check box should be enabled",
380                    partialClass.getEnabled());
381        assertFalse("external body check box should be disabled",
382                    externalBody.getEnabled());
383
384        /*
385         * change class restriction type to 'function', check that
386         * check boxes were updated and close dialog
387         */
388        ctester.actionSelectItem(classType, "function");
389        assertFalse("initial equation check box should be disabled",
390                initialEquation.getEnabled());
391        assertFalse("partial class check box should be disabled",
392                    partialClass.getEnabled());
393        assertTrue("external body check box should be enabled",
394                externalBody.getEnabled());
395        btester.actionClick(cancel);
396
397        /*
398         * pup-up wizard again and check that the selection is 'function'
399         * and that the satus of other widgets is correctly set
400         */
401        openWizardAndFetchWidgets();
402        assertEquals("wrong class type selection", "function",
403                    classType.getText());
404        assertFalse("initial equation check box should be disabled",
405                initialEquation.getEnabled());
406        assertFalse("partial class check box should be disabled",
407                    partialClass.getEnabled());
408        assertTrue("external body check box should be enabled",
409                externalBody.getEnabled());
410
411        /* close dialog */
412        btester.actionClick(cancel);
413    }
414   
415    public void testCreateModel()
416    {
417        openWizardAndFetchWidgets();       
418       
419        String name = "m1";
420        /*
421         * create model
422         */
423        ttester.actionEnterText(className, name);
424        ctester.actionSelectItem(classType, "model");
425        assertTrue(finish.getEnabled());
426
427        /* wait for the name change to propogate to enable the finish button */
428        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
429        btester.actionClick(finish);
430       
431        while(!project.isOpen()){ Utility.sleep(this, 100); }       
432       
433        /*
434         * check that the generated source code is sane
435         */
436        boolean same = 
437            Utility.compareContent(project.getFile(name + ".mo"), 
438                "model " + name + "\n"+
439                "\n"+
440                "equation\n"+
441                "\n"+
442                "end " + name + ";");
443        assertTrue("unexpected conted created in the source file", same);
444   
445    }
446       
447    public void testCreateModelWithInitEquation()
448    {
449        openWizardAndFetchWidgets();
450       
451        String name = "m2"; 
452       
453        /*
454         * create model
455         */
456        ttester.actionEnterText(className, name);
457        ctester.actionSelectItem(classType, "model");
458        assertTrue(finish.getEnabled());
459       
460        btester.actionClick(initialEquation);
461       
462        assertTrue(initialEquation.getSelection());
463
464        /* wait for the name change to propogate to enable the finish button */
465        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
466        btester.actionClick(finish);
467       
468       
469        while(!project.isOpen()){ Utility.sleep(this, 100); }
470       
471        /*
472         * check that the generated source code is sane
473         */
474        boolean same = 
475            Utility.compareContent(project.getFile(name + ".mo"), 
476                "model "+ name +"\n"+
477                "\n"+
478                "equation\n"+
479                "\n"+
480                "initial equation\n"+
481                "\n"+
482                "end " + name + ";");
483        assertTrue("unexpected conted created in the source file", same);
484    }
485
486    public void testCreatePartialModel()
487    {
488        openWizardAndFetchWidgets();       
489       
490        String name = "m3";
491        /*
492         * create model
493         */
494        ttester.actionEnterText(className, name);
495        ctester.actionSelectItem(classType, "model");
496        assertTrue(finish.getEnabled());
497       
498        btester.actionClick(partialClass);
499       
500        assertTrue(partialClass.getSelection());
501
502        /* wait for the name change to propogate to enable the finish button */
503        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
504        btester.actionClick(finish);
505       
506       
507        while(!project.isOpen()){ Utility.sleep(this, 100); }
508       
509        /*
510         * check that the generated source code is sane
511         */
512        boolean same = 
513            Utility.compareContent(project.getFile(name + ".mo"), 
514                "partial model "+ name +"\n"+
515                "\n"+
516                "equation\n"+
517                "\n"+
518                "end "+ name + ";");
519        assertTrue("unexpected conted created in the source file", same);
520   
521    }
522
523    public void testCreatePartialModelWithInitBlock()
524    {
525        openWizardAndFetchWidgets();       
526       
527        String name = "m4";
528        /*
529         * create model
530         */
531        ttester.actionEnterText(className, name);
532        ctester.actionSelectItem(classType, "model");
533        assertTrue(finish.getEnabled());
534       
535        btester.actionClick(partialClass);     
536        assertTrue(partialClass.getSelection());
537
538        btester.actionClick(initialEquation);       
539        assertTrue(initialEquation.getSelection());
540       
541       
542        /* wait for the name change to propogate to enable the finish button */
543        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
544        btester.actionClick(finish);
545       
546       
547        while(!project.isOpen()){ Utility.sleep(this, 100); }
548       
549        /*
550         * check that the generated source code is sane
551         */
552        boolean same = 
553            Utility.compareContent(project.getFile(name + ".mo"), 
554                "partial model "+ name +"\n"+
555                "\n"+
556                "equation\n"+
557                "\n"+
558                "initial equation\n"+
559                "\n"+
560                "end "+ name + ";");
561        assertTrue("unexpected conted created in the source file", same);
562    }
563
564    public void testCreateClass()
565    {
566        openWizardAndFetchWidgets();       
567       
568        String name = "c1";
569       
570        /*
571         * create class
572         */
573        ttester.actionEnterText(className, name);
574        ctester.actionSelectItem(classType, "class");
575       
576       
577        /* wait for the name change to propogate to enable the finish button */
578        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
579        btester.actionClick(finish);
580       
581       
582        while(!project.isOpen()){ Utility.sleep(this, 100); }
583       
584        /*
585         * check that the generated source code is sane
586         */
587        boolean same = 
588            Utility.compareContent(project.getFile(name + ".mo"), 
589                "class "+ name +"\n"+
590                "\n"+
591                "equation\n"+
592                "\n"+
593                "end "+ name + ";");
594        assertTrue("unexpected conted created in the source file", same);
595    }
596
597    public void testCreateClassWithInitBlock()
598    {
599        openWizardAndFetchWidgets();
600       
601        String name = "c2";
602       
603        /*
604         * create class
605         */
606        ttester.actionEnterText(className, name);
607        ctester.actionSelectItem(classType, "class");
608        btester.actionClick(initialEquation);
609       
610       
611        /* wait for the name change to propogate to enable the finish button */
612        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
613        btester.actionClick(finish);
614       
615       
616        while(!project.isOpen()){ Utility.sleep(this, 100); }
617       
618        /*
619         * check that the generated source code is sane
620         */
621        boolean same = 
622            Utility.compareContent(project.getFile(name + ".mo"), 
623                "class "+ name +"\n"+
624                "\n"+
625                "equation\n"+
626                "\n"+
627                "initial equation\n"+
628                "\n"+
629                "end "+ name + ";");
630        assertTrue("unexpected conted created in the source file", same);
631       
632    }
633
634    public void testCreatePartialClass()
635    {
636        openWizardAndFetchWidgets();
637       
638        String name = "c3";
639       
640        /*
641         * create class
642         */
643        ttester.actionEnterText(className, name);
644        ctester.actionSelectItem(classType, "class");
645        btester.actionClick(partialClass);
646       
647       
648        /* wait for the name change to propogate to enable the finish button */
649        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
650        btester.actionClick(finish);
651       
652       
653        while(!project.isOpen()){ Utility.sleep(this, 100); }
654       
655        /*
656         * check that the generated source code is sane
657         */
658        boolean same = 
659            Utility.compareContent(project.getFile(name + ".mo"), 
660                "partial class "+ name +"\n"+
661                "\n"+
662                "equation\n"+
663                "\n"+
664                "end "+ name + ";");
665        assertTrue("unexpected conted created in the source file", same);
666    }
667
668    public void testCreatePartialClassWithInitBlock()
669    {
670        openWizardAndFetchWidgets();
671       
672        String name = "c4";
673       
674        /*
675         * create class
676         */
677        ttester.actionEnterText(className, name);
678        ctester.actionSelectItem(classType, "class");
679        btester.actionClick(partialClass);
680        btester.actionClick(initialEquation);
681       
682       
683        /* wait for the name change to propogate to enable the finish button */
684        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
685        btester.actionClick(finish);
686       
687       
688        while(!project.isOpen()){ Utility.sleep(this, 100); }
689       
690        /*
691         * check that the generated source code is sane
692         */
693        boolean same = 
694            Utility.compareContent(project.getFile(name + ".mo"), 
695                "partial class "+ name +"\n"+
696                "\n"+
697                "equation\n"+
698                "\n"+
699                "initial equation\n"+
700                "\n"+               
701                "end "+ name + ";");
702        assertTrue("unexpected conted created in the source file", same);
703       
704    }
705   
706   
707    public void testCreateConnector()
708    {
709        openWizardAndFetchWidgets();
710       
711        String name = "con1";
712       
713        /*
714         * create class
715         */
716        ttester.actionEnterText(className, name);
717        ctester.actionSelectItem(classType, "connector");
718       
719       
720        /* wait for the name change to propogate to enable the finish button */
721        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
722        btester.actionClick(finish);
723       
724       
725        while(!project.isOpen()){ Utility.sleep(this, 100); }
726       
727        /*
728         * check that the generated source code is sane
729         */
730        boolean same = 
731            Utility.compareContent(project.getFile(name + ".mo"), 
732                "connector "+ name +"\n" +
733                "\n" +
734                "end "+ name + ";");
735        assertTrue("unexpected conted created in the source file", same);
736    }
737
738    public void testCreatePartialConnector()
739    {
740        openWizardAndFetchWidgets();
741       
742        String name = "con2";
743       
744        /*
745         * create class
746         */
747        ttester.actionEnterText(className, name);
748        ctester.actionSelectItem(classType, "connector");
749        btester.actionClick(partialClass);     
750       
751       
752        /* wait for the name change to propogate to enable the finish button */
753        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
754        btester.actionClick(finish);
755       
756       
757        while(!project.isOpen()){ Utility.sleep(this, 100); }
758       
759        /*
760         * check that the generated source code is sane
761         */
762        boolean same = 
763            Utility.compareContent(project.getFile(name + ".mo"), 
764                "partial connector "+ name +"\n" +
765                "\n" +
766                "end "+ name + ";");
767        assertTrue("unexpected conted created in the source file", same);
768       
769    }
770   
771    public void testCreateRecord()
772    {
773        openWizardAndFetchWidgets();
774       
775        String name = "rec1";
776       
777        /*
778         * create class
779         */
780        ttester.actionEnterText(className, name);
781        ctester.actionSelectItem(classType, "record");
782
783       
784       
785        /* wait for the name change to propogate to enable the finish button */
786        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
787        btester.actionClick(finish);
788       
789       
790        while(!project.isOpen()){ Utility.sleep(this, 100); }
791       
792        /*
793         * check that the generated source code is sane
794         */
795        boolean same = 
796            Utility.compareContent(project.getFile(name + ".mo"), 
797                "record "+ name +"\n" +
798                "\n" +
799                "end "+ name + ";");
800        assertTrue("unexpected conted created in the source file", same);
801       
802    }
803   
804    public void testCreatePartialRecord()
805    {
806        openWizardAndFetchWidgets();
807       
808        String name = "rec2";
809       
810        /*
811         * create class
812         */
813        ttester.actionEnterText(className, name);
814        ctester.actionSelectItem(classType, "record");
815        btester.actionClick(partialClass);
816       
817       
818        /* wait for the name change to propogate to enable the finish button */
819        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
820        btester.actionClick(finish);
821       
822       
823        while(!project.isOpen()){ Utility.sleep(this, 100); }
824       
825        /*
826         * check that the generated source code is sane
827         */
828        boolean same = 
829            Utility.compareContent(project.getFile(name + ".mo"), 
830                "partial record "+ name +"\n" +
831                "\n" +
832                "end "+ name + ";");
833        assertTrue("unexpected conted created in the source file", same);
834    }
835
836    public void testCreateBlock()
837    {
838        openWizardAndFetchWidgets();
839       
840        String name = "b1";
841       
842        /*
843         * create class
844         */
845        ttester.actionEnterText(className, name);
846        ctester.actionSelectItem(classType, "block");
847
848       
849       
850        /* wait for the name change to propogate to enable the finish button */
851        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
852        btester.actionClick(finish);
853       
854       
855        while(!project.isOpen()){ Utility.sleep(this, 100); }
856       
857        /*
858         * check that the generated source code is sane
859         */
860        boolean same = 
861            Utility.compareContent(project.getFile(name + ".mo"), 
862                "block "+ name +"\n" +
863                "\n" +
864                "equation\n"+
865                "\n"+
866                "end "+ name + ";");
867        assertTrue("unexpected conted created in the source file", same);
868       
869    }
870    public void testCreateBlockWithInitBlock()
871    {
872        openWizardAndFetchWidgets();
873       
874        String name = "b2";
875       
876        /*
877         * create class
878         */
879        ttester.actionEnterText(className, name);
880        ctester.actionSelectItem(classType, "block");
881        btester.actionClick(initialEquation);       
882
883       
884       
885        /* wait for the name change to propogate to enable the finish button */
886        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
887        btester.actionClick(finish);
888       
889       
890        while(!project.isOpen()){ Utility.sleep(this, 100); }
891       
892        /*
893         * check that the generated source code is sane
894         */
895        boolean same = 
896            Utility.compareContent(project.getFile(name + ".mo"), 
897                "block "+ name +"\n" +
898                "\n" +
899                "equation\n"+
900                "\n"+
901                "initial equation\n"+
902                "\n"+                               
903                "end "+ name + ";");
904        assertTrue("unexpected conted created in the source file", same);
905       
906    }
907
908    public void testCreatePartialBlock()
909    {
910        openWizardAndFetchWidgets();
911       
912        String name = "b3";
913       
914        /*
915         * create class
916         */
917        ttester.actionEnterText(className, name);
918        ctester.actionSelectItem(classType, "block");
919        btester.actionClick(partialClass);     
920
921       
922       
923        /* wait for the name change to propogate to enable the finish button */
924        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
925        btester.actionClick(finish);
926       
927       
928        while(!project.isOpen()){ Utility.sleep(this, 100); }
929       
930        /*
931         * check that the generated source code is sane
932         */
933        boolean same = 
934            Utility.compareContent(project.getFile(name + ".mo"), 
935                "partial block "+ name +"\n" +
936                "\n" +
937                "equation\n"+
938                "\n"+                               
939                "end "+ name + ";");
940        assertTrue("unexpected conted created in the source file", same);
941   
942    }
943    public void testCreatePartialBlockWithInitBlock()
944    {
945        openWizardAndFetchWidgets();
946       
947        String name = "b4";
948       
949        /*
950         * create class
951         */
952        ttester.actionEnterText(className, name);
953        ctester.actionSelectItem(classType, "block");
954        btester.actionClick(partialClass);
955        btester.actionClick(initialEquation);       
956
957       
958       
959        /* wait for the name change to propogate to enable the finish button */
960        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
961        btester.actionClick(finish);
962       
963       
964        while(!project.isOpen()){ Utility.sleep(this, 100); }
965       
966        /*
967         * check that the generated source code is sane
968         */
969        boolean same = 
970            Utility.compareContent(project.getFile(name + ".mo"), 
971                "partial block "+ name +"\n" +
972                "\n" +
973                "equation\n"+
974                "\n"+
975                "initial equation\n"+
976                "\n"+               
977                "end "+ name + ";");
978        assertTrue("unexpected conted created in the source file", same);
979    }
980
981    public void testCreateType()
982    {
983        openWizardAndFetchWidgets();
984       
985        String name = "t1";
986       
987        /*
988         * create class
989         */
990        ttester.actionEnterText(className, name);
991        ctester.actionSelectItem(classType, "type");
992
993       
994       
995        /* wait for the name change to propogate to enable the finish button */
996        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
997        btester.actionClick(finish);
998       
999       
1000        while(!project.isOpen()){ Utility.sleep(this, 100); }
1001       
1002        /*
1003         * check that the generated source code is sane
1004         */
1005        boolean same = 
1006            Utility.compareContent(project.getFile(name + ".mo"), 
1007                "type "+ name +"\n" +
1008                ";");
1009        assertTrue("unexpected conted created in the source file", same);
1010       
1011    }
1012
1013    public void testCreateFunction()
1014    {
1015        openWizardAndFetchWidgets();
1016       
1017        String name = "f1";
1018       
1019        /*
1020         * create class
1021         */
1022        ctester.actionSelectItem(classType, "function");
1023        ttester.actionEnterText(className, name);
1024       
1025       
1026        /* wait for the name change to propogate to enable the finish button */
1027        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
1028        btester.actionClick(finish);
1029       
1030       
1031        while(!project.isOpen()){ Utility.sleep(this, 100); }
1032       
1033        /*
1034         * check that the generated source code is sane
1035         */
1036        boolean same = 
1037            Utility.compareContent(project.getFile(name + ".mo"), 
1038                "function "+ name +"\n" +
1039                "\n" +
1040                "algorithm\n"+
1041                "\n"+               
1042                "end "+ name + ";");
1043        assertTrue("unexpected conted created in the source file", same);
1044    }
1045
1046    public void testCreateFunctionWithExternalBody()
1047    {
1048        openWizardAndFetchWidgets();
1049       
1050        String name = "f2";
1051       
1052        /*
1053         * create class
1054         */
1055        ctester.actionSelectItem(classType, "function");
1056        ttester.actionEnterText(className, name);
1057
1058        /*
1059         * wait for the class type change to propogate to the
1060         * external body  checkboc
1061         */
1062        while (!externalBody.getEnabled()) { Utility.sleep(this, 100); }
1063
1064        btester.actionClick(externalBody);     
1065       
1066        /* wait for the name change to propogate to enable the finish button */
1067        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
1068        btester.actionClick(finish);
1069       
1070       
1071        while(!project.isOpen()){ Utility.sleep(this, 100); }
1072       
1073        /*
1074         * check that the generated source code is sane
1075         */
1076        boolean same = 
1077            Utility.compareContent(project.getFile(name + ".mo"), 
1078                "function "+ name +"\n" +
1079                "\n" +
1080                "external\n"+
1081                "end "+ name + ";");
1082        assertTrue("unexpected conted created in the source file", same);
1083       
1084    }
1085
1086     //some ideas for more tests
1087        /*
1088         * TODO enter some text into source folder field and
1089         * check the error/warning messages
1090         */
1091       
1092        /*
1093         * TODO test to create a class in a sub-directory
1094         */
1095}
Note: See TracBrowser for help on using the repository browser.