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

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