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