source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/Utility.java @ 62

Last change on this file since 62 was 62, checked in by boris, 19 years ago
  • changed new project wizard test to actually click on the finish button, not just invoke 'performFinish()'
File size: 3.7 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 java.util.concurrent.Semaphore;
45
46import junit.framework.Assert;
47
48import org.eclipse.core.runtime.CoreException;
49import org.eclipse.jface.viewers.StructuredSelection;
50import org.eclipse.jface.wizard.WizardDialog;
51import org.eclipse.ui.IWorkbench;
52import org.eclipse.ui.IWorkbenchWizard;
53import org.eclipse.ui.PlatformUI;
54import org.eclipse.ui.wizards.IWizardDescriptor;
55
56/**
57 * @author Elmir Jagudin
58 *
59 * This class contains some utility code for assisting the testcases
60 */
61public class Utility 
62{
63
64    /**
65     * opens (runs dialog.open() method ) a dialog in UI thread and waits until it
66     * is open before returning
67     *
68     * @param dialog the dialog to open, it is assumed that dialog is fully initialized
69     *
70     */
71    public static IWorkbenchWizard openWizard(String wizardID)
72    {
73       
74        IWorkbench workbench = PlatformUI.getWorkbench();
75        IWizardDescriptor wizDesc = 
76            workbench.getNewWizardRegistry().findWizard(wizardID); 
77        Assert.assertNotNull("wizard " + wizardID + " not found", wizDesc);
78       
79        IWorkbenchWizard wizard = null;
80        try
81        {
82            wizard = wizDesc.createWizard();
83        }
84        catch (CoreException e)
85        {
86            Assert.fail("Could not create " + wizardID + 
87                    " wizard, CoreException thrown\n" + e.getMessage());
88        }
89        Assert.assertNotNull(wizard);
90       
91        wizard.init(workbench, StructuredSelection.EMPTY);
92        final WizardDialog dialog = 
93            new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
94        dialog.create();
95
96        final Semaphore sem = new Semaphore(0);
97       
98        dialog.getShell().getDisplay().syncExec(new Runnable()
99        {
100            public void run()
101            {
102                dialog.setBlockOnOpen(false);
103                dialog.open();
104                sem.release();
105            }
106        });
107       
108        try
109        {
110            sem.acquire();
111        } 
112        catch (InterruptedException e)
113        {
114            Assert.fail("interruped while waiting for dialog to open");
115        }
116       
117        return wizard;
118    }   
119}
Note: See TracBrowser for help on using the repository browser.