- 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/util/Utility.java
r121 r126 42 42 package org.modelica.mdt.test.util; 43 43 44 import java.io.IOException; 45 import java.io.InputStream; 44 46 import java.util.concurrent.Semaphore; 45 47 46 48 import junit.framework.Assert; 47 49 50 import org.eclipse.core.resources.IFile; 48 51 import org.eclipse.core.runtime.CoreException; 49 52 import org.eclipse.jface.viewers.IStructuredSelection; … … 51 54 import org.eclipse.jface.wizard.WizardDialog; 52 55 import org.eclipse.swt.widgets.Button; 56 import org.eclipse.swt.widgets.Widget; 53 57 import org.eclipse.ui.IWorkbench; 54 58 import org.eclipse.ui.IWorkbenchWizard; … … 60 64 import abbot.finder.matchers.swt.TextMatcher; 61 65 import abbot.finder.swt.BasicFinder; 66 import abbot.finder.swt.Matcher; 62 67 import abbot.finder.swt.MultipleWidgetsFoundException; 63 68 import abbot.finder.swt.TestHierarchy; … … 216 221 return null; /* this is not happening */ 217 222 } 223 224 public static Widget getInstrumentedWidget(final String tag) 225 { 226 /* 227 * find classType combo by tag 228 */ 229 Widget widget; 230 BasicFinder finder = new BasicFinder(new TestHierarchy 231 (PlatformUI.getWorkbench().getDisplay())); 232 233 try 234 { 235 widget = finder.find(new Matcher() 236 { 237 public boolean matches(Widget w) 238 { 239 Object widgetTag = w.getData("name"); 240 241 if (widgetTag == null || !(widgetTag instanceof String)) 242 { 243 return false; 244 } 245 return ((String)widgetTag).equals(tag); 246 } 247 248 }); 249 250 return widget; 251 } 252 catch (WidgetNotFoundException e) 253 { 254 /* fall through */ 255 } 256 catch (MultipleWidgetsFoundException e) 257 { 258 /* fall through */ 259 } 260 261 /* exception thrown, no/more than one widgets found */ 262 return null; 263 } 264 265 /** 266 * Compares the content of a file with a provided string 267 * @param file 268 * @param expectedContent 269 * @return true if file's content exactly matches the expectedContent 270 * string 271 */ 272 public static boolean compareContent(IFile file, String expectedContent) 273 { 274 InputStream fileContent = null; 275 276 try 277 { 278 fileContent = file.getContents(); 279 } 280 catch (CoreException e) 281 { 282 Assert.fail("could not fetch contents of the created class"); 283 } 284 285 byte[] buf = new byte[expectedContent.length()]; 286 287 try 288 { 289 fileContent.read(buf); 290 int i = fileContent.read(); 291 292 Assert.assertEquals("file is to long", -1, i); 293 } 294 catch (IOException e) 295 { 296 Assert.fail("could not read contents of the file"); 297 } 298 return expectedContent.equals(new String(buf)); 299 } 300 218 301 }
Note: See TracChangeset
for help on using the changeset viewer.