source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewPackageWizard.java @ 160

Last change on this file since 160 was 152, checked in by boris, 19 years ago
  • added a test for problem marker creator (aka the builder)
File size: 8.9 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.IFile;
45import org.eclipse.core.resources.IFolder;
46import org.eclipse.core.resources.IProject;
47import org.eclipse.core.resources.ResourcesPlugin;
48import org.eclipse.jface.viewers.StructuredSelection;
49import org.eclipse.jface.wizard.IWizard;
50import org.eclipse.swt.widgets.Button;
51import org.eclipse.swt.widgets.Text;
52import org.eclipse.ui.PlatformUI;
53import org.modelica.mdt.core.ModelicaCore;
54import org.modelica.mdt.test.util.Utility;
55import org.modelica.mdt.ui.wizards.NewPackageWizard;
56
57import abbot.tester.swt.ButtonTester;
58import abbot.tester.swt.TextTester;
59
60import junit.framework.TestCase;
61
62/**
63 * @author Elmir Jagudin
64 */
65
66public class TestNewPackageWizard extends TestCase
67{
68    private static final String PROJECT_NAME_1 = 
69        TestNewPackageWizard.class.getName() + "1";
70
71    private TextTester ttester;
72    private ButtonTester btester;
73   
74    private Text packageName;
75    private Text packageDesc;
76    private Text sourceFolder;
77    private Button isEncapsulated;
78    private Button finish;
79   
80    private IProject project;
81    private StructuredSelection fileDestination; 
82
83    @Override
84    protected void setUp() throws Exception
85    {
86        /*
87         * setup project
88         */
89        project = 
90            ModelicaCore.createProject(PROJECT_NAME_1,
91                    PlatformUI.getWorkbench().getActiveWorkbenchWindow());
92        assertNotNull("failed to create project", project);
93       
94        /*
95         * create the selection that points at the root of the created project
96         */
97        fileDestination = 
98            new StructuredSelection(ResourcesPlugin.getWorkspace().getRoot().
99                    getProject(PROJECT_NAME_1));       
100        /*
101         * setup testing support objects
102         */
103        ttester = TextTester.getTextTester();
104        btester = ButtonTester.getButtonTester();
105
106    }
107   
108    public void openWizardAndFetchWidgets()
109    {
110        /*
111         * pop-up the wizard
112         */
113        IWizard wizard = 
114            Utility.openWizard("org.modelica.mdt.NewPackageWizard",
115                    fileDestination);       
116        assertFalse(wizard.canFinish());
117
118       
119       
120        /* fetch widgets */
121        packageName = 
122            TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_NAME_TAG);
123        packageDesc = 
124            TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_DESC_TAG);
125        sourceFolder = 
126            TextTester.getInstrumentedText(NewPackageWizard.SOURCE_FOLDER_TAG);
127        isEncapsulated = 
128            ButtonTester.getInstrumentedButton(NewPackageWizard.IS_ENCAPSULATED_TAG);
129        finish = 
130            Utility.findFinishButton();
131
132       
133        /* make some checks on the state of the wizards */
134        assertEquals("Wrong source folder selected", 
135                sourceFolder.getText(), PROJECT_NAME_1);       
136        assertEquals("Junk present in package name field", 
137                packageName.getText(), "");
138        assertFalse("is encapsulated unexpectedly selected",
139                isEncapsulated.getSelection());
140        assertFalse("Finish button not disabled", 
141                finish.getEnabled());
142       
143
144    }
145
146    /**
147     * create a plain package
148     */
149    public void testCreatePackge()
150    {
151        openWizardAndFetchWidgets();
152       
153        String name = "pkg1";
154       
155        /*
156         * fill in the wizard fields
157         */
158        ttester.actionEnterText(packageName, name);
159
160        /* wait for the name change to propogate to enable the finish button */
161        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
162        btester.actionClick(finish);
163
164        /* check if the package folder was created */
165        IFolder folder = project.getFolder(name);
166        assertTrue("no package folder was created", folder.exists());
167
168        /*
169         * check that the generated package.mo exists and is sane
170         */
171        IFile packageMo = folder.getFile("package.mo");
172        assertTrue("package.mo was not created", packageMo.exists());
173       
174        boolean same = 
175            Utility.compareContent(packageMo, 
176                "package " + name + "\n"+
177                "\n"+
178                "end " + name + ";");
179        assertTrue("unexpected conted created in the package.mo", same);
180    }
181   
182    /**
183     * create a plain package with description
184     */
185    public void testCreatePackgeWithDesc()
186    {
187        openWizardAndFetchWidgets();
188       
189        String name = "pkg2";
190        String description = "jolly good package";
191       
192        /*
193         * fill in the wizard fields
194         */
195        ttester.actionEnterText(packageName, name);
196        ttester.actionEnterText(packageDesc, description);
197   
198
199        /* wait for the name change to propogate to enable the finish button */
200        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
201        btester.actionClick(finish);
202
203        /* check if the package folder was created */
204        IFolder folder = project.getFolder(name);
205        assertTrue("no package folder was created", folder.exists());
206
207        /*
208         * check that the generated package.mo exists and is sane
209         */
210        IFile packageMo = folder.getFile("package.mo");
211        assertTrue("package.mo was not created", packageMo.exists());
212       
213        boolean same = 
214            Utility.compareContent(packageMo, 
215                "package " + name + " \"" + description + "\"" + "\n"+
216                "\n"+
217                "end " + name + ";");
218        assertTrue("unexpected conted created in the package.mo", same);
219    }
220   
221    /**
222     * create a encapsulated package
223     */
224    public void testEncapsulatedCreatePackge()
225    {
226        openWizardAndFetchWidgets();
227       
228        String name = "pkg3";
229       
230        /*
231         * fill in the wizard fields
232         */
233        ttester.actionEnterText(packageName, name);
234        btester.actionClick(isEncapsulated);
235
236        /* wait for the name change to propogate to enable the finish button */
237        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
238        btester.actionClick(finish);
239
240        /* check if the package folder was created */
241        IFolder folder = project.getFolder(name);
242        assertTrue("no package folder was created", folder.exists());
243
244        /*
245         * check that the generated package.mo exists and is sane
246         */
247        IFile packageMo = folder.getFile("package.mo");
248        assertTrue("package.mo was not created", packageMo.exists());
249       
250        boolean same = 
251            Utility.compareContent(packageMo, 
252                "encapsulated package " + name + "\n"+
253                "\n"+
254                "end " + name + ";");
255        assertTrue("unexpected conted created in the package.mo", same);
256       
257    }
258   
259    /**
260     * create a encapsulated package with description
261     */
262    public void testEncapsulatedCreatePackgeWithDesc()
263    {
264        openWizardAndFetchWidgets();
265       
266        String name = "pkg4";
267        String description = "lebensmittelverpackung mit butter";
268       
269        /*
270         * fill in the wizard fields
271         */
272        ttester.actionEnterText(packageName, name);
273        btester.actionClick(isEncapsulated);
274        ttester.actionEnterText(packageDesc, description);
275   
276
277        /* wait for the name change to propogate to enable the finish button */
278        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
279        btester.actionClick(finish);
280
281        /* check if the package folder was created */
282        IFolder folder = project.getFolder(name);
283        assertTrue("no package folder was created", folder.exists());
284
285        /*
286         * check that the generated package.mo exists and is sane
287         */
288        IFile packageMo = folder.getFile("package.mo");
289        assertTrue("package.mo was not created", packageMo.exists());
290       
291        boolean same = 
292            Utility.compareContent(packageMo, 
293                "encapsulated package " + name + " \"" + description + "\"" + "\n"+
294                "\n"+
295                "end " + name + ";");
296        assertTrue("unexpected conted created in the package.mo", same);
297       
298    }
299}
Note: See TracBrowser for help on using the repository browser.