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

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