diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java index 855d6656535..485396437a4 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java @@ -535,6 +535,78 @@ public class LaunchConfigurationAndRestartTest extends BaseTestCase { testSettingArguments(); } + /** + * This test will tell the launch to set some arguments for the program. We will + * then check that the program has the same arguments. + * See bug 381804 + */ + @Test + public void testSettingArgumentsWithSymbols() throws Throwable { + // Set a argument with double quotes and spaces, which should be considered a single argument + String argumentToPreserveSpaces = "--c=\"c < s: 'a' t: 'b'>\""; + String argumentUsedByGDB = "\"--c=c < s: 'a' t: 'b'>\""; + + setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, argumentToPreserveSpaces); + doLaunch(); + + MIStoppedEvent stoppedEvent = getInitialStoppedEvent(); + + // Check that argc is correct + final IExpressionDMContext argcDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc"); + Query query = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fExpService.getFormattedExpressionValue( + fExpService.getFormattedValueContext(argcDmc, MIExpressions.DETAILS_FORMAT), rm); + } + }; + try { + fExpService.getExecutor().execute(query); + FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS); + + // Argc should be 2: the program name and the one arguments + assertTrue("Expected 2 but got " + value.getFormattedValue(), + value.getFormattedValue().trim().equals("2")); + } catch (InterruptedException e) { + fail(e.getMessage()); + } catch (ExecutionException e) { + fail(e.getCause().getMessage()); + } catch (TimeoutException e) { + fail(e.getMessage()); + } + + // Check that argv is also correct. + final IExpressionDMContext argvDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argv[argc-1]"); + Query query2 = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fExpService.getFormattedExpressionValue( + fExpService.getFormattedValueContext(argvDmc, MIExpressions.DETAILS_FORMAT), rm); + } + }; + try { + fExpService.getExecutor().execute(query2); + FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS); + assertTrue("Expected \"" + argumentUsedByGDB + "\" but got " + value.getFormattedValue(), + value.getFormattedValue().trim().endsWith(argumentUsedByGDB)); + } catch (InterruptedException e) { + fail(e.getMessage()); + } catch (ExecutionException e) { + fail(e.getCause().getMessage()); + } catch (TimeoutException e) { + fail(e.getMessage()); + } + } + + /** + * Repeat the test testSettingArguments, but after a restart. + */ + @Test + public void testSettingArgumentsWithSymbolsRestart() throws Throwable { + fRestart = true; + testSettingArgumentsWithSymbols(); + } + /** * This test will tell the launch to "stop on main" at method main(), which we will verify. */