Ignore:
Timestamp:
11/09/05 11:03:31 (19 years ago)
Author:
boris
Message:
  • new package wizard finished
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/util/Utility.java

    r121 r126  
    4242package org.modelica.mdt.test.util;
    4343
     44import java.io.IOException;
     45import java.io.InputStream;
    4446import java.util.concurrent.Semaphore;
    4547
    4648import junit.framework.Assert;
    4749
     50import org.eclipse.core.resources.IFile;
    4851import org.eclipse.core.runtime.CoreException;
    4952import org.eclipse.jface.viewers.IStructuredSelection;
     
    5154import org.eclipse.jface.wizard.WizardDialog;
    5255import org.eclipse.swt.widgets.Button;
     56import org.eclipse.swt.widgets.Widget;
    5357import org.eclipse.ui.IWorkbench;
    5458import org.eclipse.ui.IWorkbenchWizard;
     
    6064import abbot.finder.matchers.swt.TextMatcher;
    6165import abbot.finder.swt.BasicFinder;
     66import abbot.finder.swt.Matcher;
    6267import abbot.finder.swt.MultipleWidgetsFoundException;
    6368import abbot.finder.swt.TestHierarchy;
     
    216221        return null; /* this is not happening */
    217222    }
     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
    218301}
Note: See TracChangeset for help on using the changeset viewer.