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

Last change on this file since 1813 was 1813, checked in by masberg, 11 years ago

Fix formatting. Also fixed the two remaining warnings.

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