testdev/ite/test/com.nokia.testfw.launch.test/src/com/nokia/testfw/launch/STFEmulationLaunchTest.java
changeset 1 96906a986c3b
equal deleted inserted replaced
0:f1112f777ce9 1:96906a986c3b
       
     1 package com.nokia.testfw.launch;
       
     2 
       
     3 import java.io.File;
       
     4 
       
     5 import junit.framework.TestCase;
       
     6 
       
     7 import org.eclipse.core.resources.IProject;
       
     8 import org.eclipse.core.runtime.CoreException;
       
     9 import org.eclipse.debug.core.DebugPlugin;
       
    10 import org.eclipse.debug.core.ILaunchConfigurationType;
       
    11 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
       
    12 import org.eclipse.debug.core.ILaunchManager;
       
    13 import org.eclipse.debug.internal.ui.DebugUIPlugin;
       
    14 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager;
       
    15 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
       
    16 import org.eclipse.debug.ui.ILaunchConfigurationTab;
       
    17 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
       
    18 import org.eclipse.jface.viewers.StructuredSelection;
       
    19 import org.eclipse.swt.widgets.Display;
       
    20 import org.eclipse.swt.widgets.Shell;
       
    21 import org.junit.Before;
       
    22 import org.junit.Test;
       
    23 
       
    24 import com.nokia.testfw.test.utils.ProjectUtils;
       
    25 import com.nokia.testfw.test.utils.TestUtils;
       
    26 
       
    27 @SuppressWarnings("restriction")
       
    28 public class STFEmulationLaunchTest extends TestCase {
       
    29 
       
    30 	IProject targetProject;
       
    31 	ILaunchConfigurationWorkingCopy iLaunchConfigurationWorkingCopy;
       
    32 
       
    33 	@Before
       
    34 	public void setUp() throws Exception {
       
    35 		targetProject = ProjectUtils.getTargetProject("TestModule");
       
    36 		if (targetProject == null) {
       
    37 			String projectPath = (new File("resource/TestModule"))
       
    38 					.getCanonicalPath();
       
    39 			String bldInfPath = "group/bld.inf";
       
    40 			targetProject = ProjectUtils.createTargetProject("TestModule",
       
    41 					projectPath, bldInfPath);
       
    42 		}
       
    43 		ProjectUtils.selectProject(targetProject);
       
    44 		ILaunchManager lLaunchManager = DebugPlugin.getDefault()
       
    45 				.getLaunchManager();
       
    46 		ILaunchConfigurationType type = lLaunchManager
       
    47 				.getLaunchConfigurationType("com.nokia.testfw.launch.STFEmulationLaunch");
       
    48 		iLaunchConfigurationWorkingCopy = type.newInstance(null,
       
    49 				"STFEmulationLaunchTest");
       
    50 	}
       
    51 
       
    52 	@Test
       
    53 	public void testSUTEmulationLaunch() {
       
    54 		Shell shell = Display.getDefault().getShells()[0];
       
    55 		String groupIdentifier = "org.eclipse.debug.ui.launchGroup.run";
       
    56 
       
    57 		org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension ext = DebugUIPlugin
       
    58 				.getDefault().getLaunchConfigurationManager().getLaunchGroup(
       
    59 						groupIdentifier);
       
    60 		TestUtils.delay(1000);
       
    61 		if (ext != null) {
       
    62 			try {
       
    63 				ILaunchConfigurationTabGroup tabGroup = LaunchConfigurationPresentationManager
       
    64 						.getDefault().getTabGroup(
       
    65 								iLaunchConfigurationWorkingCopy,
       
    66 								ILaunchManager.RUN_MODE);
       
    67 				LaunchConfigurationsDialog dialog = new LaunchConfigurationsDialog(
       
    68 						shell, ext);
       
    69 				dialog.setInitialSelection(new StructuredSelection(
       
    70 						iLaunchConfigurationWorkingCopy.getType()));
       
    71 				dialog.setInitialStatus(null);
       
    72 				dialog.setOpenMode(3);
       
    73 				dialog.setBlockOnOpen(false);
       
    74 				dialog.open();
       
    75 
       
    76 				tabGroup.createTabs(dialog, dialog.getMode());
       
    77 				ILaunchConfigurationTab tabs[] = tabGroup.getTabs();
       
    78 				for (int i = 0; i < tabs.length; i++)
       
    79 					tabs[i].setLaunchConfigurationDialog(dialog);
       
    80 
       
    81 				tabGroup.setDefaults(iLaunchConfigurationWorkingCopy);
       
    82 				iLaunchConfigurationWorkingCopy.doSave();
       
    83 				tabGroup.dispose();
       
    84 				TestUtils.delay(1000);
       
    85 				try {
       
    86 					dialog.getTabGroup().performApply(
       
    87 							iLaunchConfigurationWorkingCopy);
       
    88 					String script = iLaunchConfigurationWorkingCopy
       
    89 							.getAttribute(LaunchConfigurationConstants.SCRIPT_DEVICE_PATH,
       
    90 									(String) null);
       
    91 					assertNotNull(script);
       
    92 					assertEquals(script, "c:\\TestFramework\\TestModuleTests.cfg");
       
    93 				} catch (CoreException e) {
       
    94 					e.printStackTrace();
       
    95 				}
       
    96 				dialog.close();
       
    97 				TestUtils.delay(1000);
       
    98 			} catch (CoreException e) {
       
    99 				e.printStackTrace();
       
   100 			}
       
   101 
       
   102 		}
       
   103 	}
       
   104 }