Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab59222032ec7fa6d9a9f821f82c3890e6ea0c91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*******************************************************************************
 * Copyright (c) 2009, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipe.debug.tests.launching;

import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.internal.core.LaunchManager;

/**
 * 
 * Variety of tests for the {@link org.eclipse.debug.internal.core.LaunchManager}
 * 
 * @since 3.6
 */
public class LaunchManagerTests extends AbstractLaunchTest {

	/**
	 * Constructor
	 * @param name
	 */
	public LaunchManagerTests(String name) {
		super(name);
	}

	/**
	 * Tests generating a valid launch configuration name
	 */
	public void testGenereateConfigName() {
		String configname = "launch_configuration";
		String name = getLaunchManager().generateLaunchConfigurationName(configname);
		assertTrue("the name nust be '"+configname+"'", name.equals(configname));
	}
	
	/**
	 * Tests generating a launch configuration name with an unsupported char using
	 * the deprecated method
	 */
	public void testGenereateConfigNameBadChar() {
		String configname = "config:name";
		String name = getLaunchManager().generateUniqueLaunchConfigurationNameFrom(configname);
		assertEquals("config name should be '"+configname+"'", configname, name);
	}
	
	/**
	 * Tests that a valid name is accepted as is.
	 */
	public void testGenerateValidName() {
		String configname = "thisisavalidname";
		String name = getLaunchManager().generateLaunchConfigurationName(configname);
		assertEquals("Should be the same as the seed", configname, name);
	}
	
	/**
	 * Tests generating a launch configuration name using a name that is an OS reserved
	 * name. Win 32 test only.
	 */
	public void testGenerateConfigNameReservedName() {
		if(Platform.OS_WIN32.equals(Platform.getOS())) {
			String configname = "aux";
			String name = getLaunchManager().generateUniqueLaunchConfigurationNameFrom(configname);
			assertEquals("config name should be 'aux'", configname, name);
		}
	}
	
	/**
	 * Tests generating a configuration name that contains an invalid character
	 */
	public void testGenerateBadConfigName() {
		String configname = "config:name";
		String name = getLaunchManager().generateLaunchConfigurationName(configname);
		assertEquals("config name should be 'config_name'", "config_name", name);
	}
	
	/**
	 * Tests generating a name that conflicts with an OS reserved name. This test is for windows only as there 
	 * are no reserved names on other OS's.
	 */
	public void testGenerateConflictingName() {
		if(Platform.OS_WIN32.equals(Platform.getOS())) {
			String configname = "aux";
			String name = getLaunchManager().generateLaunchConfigurationName(configname);
			assertEquals("config name should be 'launch_configuration'", "launch_configuration", name);
		}
	}
	
	/**
	 * Tests generating a configuration name that contains an invalid character and where there
	 * is another config with the replaced name already
	 */
	public void testGenerateBadCharConflict() throws Exception {
		String configname = "config:name";
		String name = getLaunchManager().generateLaunchConfigurationName(configname);
		assertEquals("config name should be 'config_name'", "config_name", name);
		getLaunchConfiguration(name);
		name = getLaunchManager().generateLaunchConfigurationName(configname);
		assertEquals("config name should be 'config_name (1)'", "config_name (1)", name);
		ILaunchConfiguration config = getLaunchConfiguration("config_name");
		config.delete();
	}
	
	/**
	 * Tests generating a name that conflicts with an OS reserved name and that 
	 * there is a config with the replaced name already. This test is for windows only as there 
	 * are no reserved names on other OS's.
	 */
	public void testGenerateBadNameConflict() throws Exception {
		if(Platform.OS_WIN32.equals(Platform.getOS())) {
			String configname = "com2";
			String name = getLaunchManager().generateLaunchConfigurationName(configname);
			assertEquals("config name should be 'launch_configuration'", "launch_configuration", name);
			getLaunchConfiguration(name);
			name = getLaunchManager().generateLaunchConfigurationName(configname);
			assertEquals("config name should be 'launch_configuration (1)'", "launch_configuration (1)", name);
			ILaunchConfiguration config = getLaunchConfiguration("launch_configuration");
			config.delete();
		}
	}
		
	/**
	 * Tests the {@link org.eclipse.debug.core.ILaunchManager#isValidLaunchConfigurationName(String)} method for correctness
	 */
	public void testValidateConfigGoodName() {
		String configname = "configname";
		try {
			getLaunchManager().isValidLaunchConfigurationName(configname);
		}
		catch(IllegalArgumentException iae) {
			fail("the config name should not have thrown an exception during validation");
		}
	}
	
	/**
	 * Tests the {@link org.eclipse.debug.core.ILaunchManager#isValidLaunchConfigurationName(String)} method for correctness
	 */
	public void testValidateConfigBadCharName() {
		String configname = "config:name";
		try {
			getLaunchManager().isValidLaunchConfigurationName(configname);
		}
		catch(IllegalArgumentException iae) {
			return;
		}
		fail("the config name should have thrown an exception during validation");
	}
	
	/**
	 * Tests the {@link org.eclipse.debug.core.ILaunchManager#isValidLaunchConfigurationName(String)} method for correctness
	 */
	public void testValidateConfigBadName() {
		if(Platform.OS_WIN32.equals(Platform.getOS())) {
			String configname = "com1";
			try {
				getLaunchManager().isValidLaunchConfigurationName(configname);
			}
			catch(IllegalArgumentException iae) {
				return;
			}
			fail("the config name should have thrown an exception during validation");
		}
	}
	
	/**
	 * Tests that generating a configuration name when there exists a configuration with that name
	 * already properly updates a '(N)' counter at the end
	 */
	public void testGenerateNameExistingConfig() throws Exception {
		String configname = "x.y.z.configname";
		getLaunchConfiguration(configname);
		String name = getLaunchManager().generateLaunchConfigurationName(configname);
		assertEquals("the configuration name should have been "+configname+" (1)", configname+" (1)", name);
		getLaunchConfiguration(name);
		name = getLaunchManager().generateLaunchConfigurationName(name);
		assertEquals("the configuration name should have been "+configname+" (2)", configname+" (2)", name);
		ILaunchConfiguration config = getLaunchConfiguration(configname);
		if(config != null) {
			config.delete();
		}
		config = getLaunchConfiguration(configname +" (1)");
		if(config != null) {
			config.delete();
		}
	}
	
	/**
	 * Tests that removing an accelerator properly removes it without affecting the base string (readable) value
	 */
	public void testRemoveAcc() {
		String text = "&Remove";
		String label = LaunchManager.removeAccelerators(text);
		assertEquals("the label should be 'Remove'", "Remove", label);
		text = "Remo&ve";
		label = LaunchManager.removeAccelerators(text);
		assertEquals("the label should be 'Remove'", "Remove", label);
	}
}

Back to the top