- Timestamp:
- 11/09/05 11:03:31 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewClassWizard.java
r123 r126 42 42 package org.modelica.mdt.test; 43 43 44 import java.io.IOException;45 import java.io.InputStream;46 47 import org.eclipse.core.resources.IFile;48 44 import org.eclipse.core.resources.IProject; 49 45 import org.eclipse.core.resources.ResourcesPlugin; 50 import org.eclipse.core.runtime.CoreException;51 46 import org.eclipse.jface.viewers.StructuredSelection; 52 47 import org.eclipse.jface.wizard.IWizard; … … 54 49 import org.eclipse.swt.widgets.Combo; 55 50 import org.eclipse.swt.widgets.Text; 56 import org.eclipse.swt.widgets.Widget;57 51 import org.eclipse.ui.PlatformUI; 58 52 import org.modelica.mdt.core.ModelicaCore; … … 60 54 import org.modelica.mdt.ui.wizards.NewClassWizard; 61 55 62 import abbot.finder.swt.BasicFinder;63 import abbot.finder.swt.Matcher;64 import abbot.finder.swt.MultipleWidgetsFoundException;65 import abbot.finder.swt.TestHierarchy;66 import abbot.finder.swt.WidgetNotFoundException;67 56 import abbot.tester.swt.ButtonTester; 68 57 import abbot.tester.swt.ComboTester; … … 83 72 84 73 private IProject project; 74 85 75 private TextTester ttester; 86 76 private ButtonTester btester; … … 125 115 } 126 116 127 /**128 * Compares the content of a file with a provided string129 * @param file130 * @param expectedContent131 * @return true if file's content exactly matches the expectedContent132 * string133 */134 private boolean compareContent(IFile file, String expectedContent)135 {136 InputStream fileContent = null;137 138 try139 {140 fileContent = file.getContents();141 }142 catch (CoreException e)143 {144 fail("could not fetch contents of the created class");145 }146 147 byte[] buf = new byte[expectedContent.length()];148 149 try150 {151 fileContent.read(buf);152 int i = fileContent.read();153 154 assertEquals("file is to long", i, -1);155 }156 catch (IOException e)157 {158 fail("could not read contents of the file");159 }160 161 return expectedContent.equals(new String(buf));162 }163 117 164 118 … … 170 124 IWizard wizard = 171 125 Utility.openWizard("org.modelica.mdt.NewClassWizard", 172 fileDestination); 173 126 fileDestination); 174 127 assertFalse(wizard.canFinish()); 175 128 … … 189 142 finish = 190 143 Utility.findFinishButton(); 191 192 193 /* 194 * find classType combo by tag 195 */ 196 BasicFinder finder = new BasicFinder(new TestHierarchy 197 (PlatformUI.getWorkbench().getDisplay())); 198 199 try 200 { 201 classType = (Combo)finder.find(new Matcher() 202 { 203 public boolean matches(Widget w) 204 { 205 Object tag = w.getData("name"); 206 if (tag == null || !(tag instanceof String)) 207 { 208 return false; 209 } 210 211 return ((String)tag).equals(NewClassWizard.CLASS_TYPE_TAG); 212 } 213 214 }); 215 } 216 catch (WidgetNotFoundException e) 217 { 218 fail("multiple classType combos found " + e.getMessage()); 219 } 220 catch (MultipleWidgetsFoundException e) 221 { 222 fail("classType combo widget not found " + e.getMessage()); 223 } 144 145 /* find classType combo by tag */ 146 classType = 147 (Combo) 148 Utility.getInstrumentedWidget(NewClassWizard.CLASS_TYPE_TAG); 149 assertNotNull("Problems finding classType widget", classType); 150 224 151 225 152 /* make some checks on the state of the wizards */ … … 242 169 openWizardAndFetchWidgets(); 243 170 171 String name = "m1"; 244 172 /* 245 173 * create model 246 174 */ 247 ttester.actionEnterText(className, "m1");175 ttester.actionEnterText(className, name); 248 176 assertTrue(finish.getEnabled()); 249 177 … … 258 186 */ 259 187 boolean same = 260 compareContent(project.getFile("m1.mo"),261 "model m1\n"+262 "\n"+ 263 "equation\n"+ 264 "\n"+ 265 "end m1;");188 Utility.compareContent(project.getFile(name + ".mo"), 189 "model " + name + "\n"+ 190 "\n"+ 191 "equation\n"+ 192 "\n"+ 193 "end " + name + ";"); 266 194 assertTrue("unexpected conted created in the source file", same); 267 195 … … 270 198 public void testCreateModelWithInitEquation() 271 199 { 200 openWizardAndFetchWidgets(); 201 202 String name = "m2"; 203 204 /* 205 * create model 206 */ 207 ttester.actionEnterText(className, name); 208 assertTrue(finish.getEnabled()); 209 210 btester.actionClick(initialEquation); 211 212 assertTrue(initialEquation.getSelection()); 213 214 /* wait for the name change to propogate to enable the finish button */ 215 while (!finish.getEnabled()) { Utility.sleep(this, 100); } 216 btester.actionClick(finish); 217 218 219 while(!project.isOpen()){ Utility.sleep(this, 100); } 220 221 /* 222 * check that the generated source code is sane 223 */ 224 boolean same = 225 Utility.compareContent(project.getFile(name + ".mo"), 226 "model "+ name +"\n"+ 227 "\n"+ 228 "equation\n"+ 229 "\n"+ 230 "initial equation\n"+ 231 "\n"+ 232 "end " + name + ";"); 233 assertTrue("unexpected conted created in the source file", same); 234 } 235 236 public void testCreatePartialModel() 237 { 272 238 openWizardAndFetchWidgets(); 273 239 240 String name = "m3"; 274 241 /* 275 242 * create model 276 243 */ 277 ttester.actionEnterText(className, "m2");244 ttester.actionEnterText(className, name); 278 245 assertTrue(finish.getEnabled()); 279 246 280 btester.actionClick(initialEquation);281 282 assertTrue(initialEquation.getSelection());283 284 /* wait for the name change to propogate to enable the finish button */285 while (!finish.getEnabled()) { Utility.sleep(this, 100); }286 btester.actionClick(finish);287 288 289 while(!project.isOpen()){ Utility.sleep(this, 100); }290 291 /*292 * check that the generated source code is sane293 */294 boolean same =295 compareContent(project.getFile("m2.mo"),296 "model m2\n"+297 "\n"+298 "equation\n"+299 "\n"+300 "initial equation\n"+301 "\n"+302 "end m2;");303 assertTrue("unexpected conted created in the source file", same);304 }305 306 public void testCreatePartialModel()307 {308 openWizardAndFetchWidgets();309 310 String name = "m3";311 /*312 * create model313 */314 ttester.actionEnterText(className, name);315 assertTrue(finish.getEnabled());316 317 247 btester.actionClick(partialClass); 318 248 … … 330 260 */ 331 261 boolean same = 332 compareContent(project.getFile(name + ".mo"),262 Utility.compareContent(project.getFile(name + ".mo"), 333 263 "partial model "+ name +"\n"+ 334 264 "\n"+ … … 369 299 */ 370 300 boolean same = 371 compareContent(project.getFile(name + ".mo"),301 Utility.compareContent(project.getFile(name + ".mo"), 372 302 "partial model "+ name +"\n"+ 373 303 "\n"+ … … 404 334 */ 405 335 boolean same = 406 compareContent(project.getFile(name + ".mo"),336 Utility.compareContent(project.getFile(name + ".mo"), 407 337 "class "+ name +"\n"+ 408 338 "\n"+ … … 438 368 */ 439 369 boolean same = 440 compareContent(project.getFile(name + ".mo"),370 Utility.compareContent(project.getFile(name + ".mo"), 441 371 "class "+ name +"\n"+ 442 372 "\n"+ … … 475 405 */ 476 406 boolean same = 477 compareContent(project.getFile(name + ".mo"),407 Utility.compareContent(project.getFile(name + ".mo"), 478 408 "partial class "+ name +"\n"+ 479 409 "\n"+ … … 510 440 */ 511 441 boolean same = 512 compareContent(project.getFile(name + ".mo"),442 Utility.compareContent(project.getFile(name + ".mo"), 513 443 "partial class "+ name +"\n"+ 514 444 "\n"+ … … 547 477 */ 548 478 boolean same = 549 compareContent(project.getFile(name + ".mo"),479 Utility.compareContent(project.getFile(name + ".mo"), 550 480 "connector "+ name +"\n" + 551 481 "\n" + … … 579 509 */ 580 510 boolean same = 581 compareContent(project.getFile(name + ".mo"),511 Utility.compareContent(project.getFile(name + ".mo"), 582 512 "partial connector "+ name +"\n" + 583 513 "\n" + … … 612 542 */ 613 543 boolean same = 614 compareContent(project.getFile(name + ".mo"),544 Utility.compareContent(project.getFile(name + ".mo"), 615 545 "block "+ name +"\n" + 616 546 "\n" + … … 647 577 */ 648 578 boolean same = 649 compareContent(project.getFile(name + ".mo"),579 Utility.compareContent(project.getFile(name + ".mo"), 650 580 "block "+ name +"\n" + 651 581 "\n" + … … 685 615 */ 686 616 boolean same = 687 compareContent(project.getFile(name + ".mo"),617 Utility.compareContent(project.getFile(name + ".mo"), 688 618 "partial block "+ name +"\n" + 689 619 "\n" + … … 721 651 */ 722 652 boolean same = 723 compareContent(project.getFile(name + ".mo"),653 Utility.compareContent(project.getFile(name + ".mo"), 724 654 "partial block "+ name +"\n" + 725 655 "\n" + … … 757 687 */ 758 688 boolean same = 759 compareContent(project.getFile(name + ".mo"),689 Utility.compareContent(project.getFile(name + ".mo"), 760 690 "type "+ name +"\n" + 761 691 ";"); … … 788 718 */ 789 719 boolean same = 790 compareContent(project.getFile(name + ".mo"),720 Utility.compareContent(project.getFile(name + ".mo"), 791 721 "function "+ name +"\n" + 792 722 "\n" + … … 828 758 */ 829 759 boolean same = 830 compareContent(project.getFile(name + ".mo"),760 Utility.compareContent(project.getFile(name + ".mo"), 831 761 "function "+ name +"\n" + 832 762 "\n" +
Note: See TracChangeset
for help on using the changeset viewer.