diff options
author | Andreas Loth | 2017-02-28 06:04:14 +0000 |
---|---|---|
committer | Sarika Sinha | 2017-03-01 04:21:34 +0000 |
commit | b880d44d7e2ff505bfed40ca37b130b24e60993d (patch) | |
tree | 65a0b01f8dae9a06228135ac78a77cae771b60b9 /org.eclipse.debug.tests | |
parent | 3014f2fdbe89cfb3ab8923d73fc8702ed0fcb4cb (diff) | |
download | eclipse.platform.debug-b880d44d7e2ff505bfed40ca37b130b24e60993d.tar.gz eclipse.platform.debug-b880d44d7e2ff505bfed40ca37b130b24e60993d.tar.xz eclipse.platform.debug-b880d44d7e2ff505bfed40ca37b130b24e60993d.zip |
Bug 507664 - IOConsoleOutputStream does not handle multi-byte charactersI20170301-2000
at buffer boundaries correctly
Change-Id: Ib1651069ab6a1a09d26e0b33bfae2dc3aef2fd77
Signed-off-by: Andreas Loth <andy_2639@justmail.de>
Diffstat (limited to 'org.eclipse.debug.tests')
5 files changed, 131 insertions, 43 deletions
diff --git a/org.eclipse.debug.tests/META-INF/MANIFEST.MF b/org.eclipse.debug.tests/META-INF/MANIFEST.MF index 5f2db82d6..81028df52 100644 --- a/org.eclipse.debug.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.debug.tests/META-INF/MANIFEST.MF @@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.6.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)", org.eclipse.debug.core;bundle-version="[3.9.0,4.0.0)", org.eclipse.ui.externaltools;bundle-version="[3.3.0,4.0.0)", - org.eclipse.ui.console;bundle-version="[3.7.0,4.0.0)" + org.eclipse.ui.console;bundle-version="[3.7.0,4.0.0)", + org.eclipse.text Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-Vendor: %providerName diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java index 2204d97f1..5c3e1f70c 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corporation and others. + * Copyright (c) 2009, 2017 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 @@ -12,11 +12,9 @@ *******************************************************************************/ package org.eclipse.debug.tests; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.eclipse.debug.tests.breakpoint.BreakpointOrderingTests; import org.eclipse.debug.tests.console.ConsoleManagerTests; +import org.eclipse.debug.tests.console.ConsoleTests; import org.eclipse.debug.tests.launching.AcceleratorSubstitutionTests; import org.eclipse.debug.tests.launching.ArgumentParsingTests; import org.eclipse.debug.tests.launching.LaunchConfigurationTests; @@ -41,6 +39,9 @@ import org.eclipse.debug.tests.viewer.model.VirtualViewerSelectionTests; import org.eclipse.debug.tests.viewer.model.VirtualViewerStateTests; import org.eclipse.debug.tests.viewer.model.VirtualViewerUpdateTests; +import junit.framework.Test; +import junit.framework.TestSuite; + /** * Tests for integration and nightly builds. * @@ -104,6 +105,7 @@ public class AutomatedSuite extends TestSuite { // Console view addTest(new TestSuite(ConsoleManagerTests.class)); + addTest(new TestSuite(ConsoleTests.class)); // Launch Groups addTest(new TestSuite(LaunchGroupTests.class)); diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java index 0e3d7fd4d..fb0a025ec 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Andrey Loskutov and others. + * Copyright (c) 2016, 2017 Andrey Loskutov 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 @@ -16,7 +16,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.swt.SWT; @@ -61,7 +60,7 @@ public class ConsoleManagerTests extends TestCase { manager = ConsolePlugin.getDefault().getConsoleManager(); IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); hideWelcomePage(activePage); - processUIEvents(100); + TestHelper.processUIEvents(100); consoles = new ConsoleMock[count]; for (int i = 0; i < count; i++) { final ConsoleMock console = new ConsoleMock(i + 1); @@ -72,7 +71,7 @@ public class ConsoleManagerTests extends TestCase { IViewPart consoleView = activePage.showView("org.eclipse.ui.console.ConsoleView"); //$NON-NLS-1$ activePage.activate(consoleView); - processUIEvents(100); + TestHelper.processUIEvents(100); // The test is unstable ("show" event on the the first console seem to // be not always sent), so make sure console view has shown at least @@ -80,8 +79,8 @@ public class ConsoleManagerTests extends TestCase { firstConsole = new ConsoleMock(0); manager.addConsoles(new ConsoleMock[] { firstConsole }); manager.showConsoleView(firstConsole); - waitForJobs(); - processUIEvents(100); + TestHelper.waitForJobs(); + TestHelper.processUIEvents(100); ConsoleMock.allShownConsoles.set(0); } @@ -90,7 +89,7 @@ public class ConsoleManagerTests extends TestCase { executorService.shutdownNow(); manager.removeConsoles(consoles); manager.removeConsoles(new ConsoleMock[] { firstConsole }); - processUIEvents(100); + TestHelper.processUIEvents(100); super.tearDown(); } @@ -104,7 +103,7 @@ public class ConsoleManagerTests extends TestCase { } if (intro != null) { activePage.hideView(intro); - processUIEvents(100); + TestHelper.processUIEvents(100); } } @@ -124,15 +123,15 @@ public class ConsoleManagerTests extends TestCase { showConsole(console); } System.out.println("All tasks scheduled, processing UI events now..."); //$NON-NLS-1$ - processUIEvents(1000); + TestHelper.processUIEvents(1000); // Console manager starts a job with delay, let wait for him a bit System.out.println("Waiting on jobs now..."); //$NON-NLS-1$ - waitForJobs(); + TestHelper.waitForJobs(); // Give UI a chance to proceed pending console manager jobs System.out.println("Done with jobs, processing UI events again..."); //$NON-NLS-1$ - processUIEvents(3000); + TestHelper.processUIEvents(3000); executorService.shutdown(); @@ -140,7 +139,7 @@ public class ConsoleManagerTests extends TestCase { boolean OK = waitForExecutorService(); if (!OK) { System.out.println("Timed out..."); //$NON-NLS-1$ - processUIEvents(10000); + TestHelper.processUIEvents(10000); // timeout? assertTrue("Timeout occurred while waiting on console to be shown", //$NON-NLS-1$ @@ -157,35 +156,11 @@ public class ConsoleManagerTests extends TestCase { if (executorService.awaitTermination(1, TimeUnit.SECONDS)) { return true; } - processUIEvents(100); + TestHelper.processUIEvents(100); } return false; } - private void processUIEvents(final long millis) { - long start = System.currentTimeMillis(); - while (System.currentTimeMillis() - start < millis) { - while (PlatformUI.getWorkbench().getDisplay().readAndDispatch()) { - // loop untile the queue is empty - } - } - } - - private void waitForJobs() throws InterruptedException { - if (Display.getCurrent() == null) { - Thread.sleep(200); - } else { - processUIEvents(200); - } - while (!Job.getJobManager().isIdle()) { - if (Display.getCurrent() == null) { - Thread.sleep(200); - } else { - processUIEvents(200); - } - } - } - private void showConsole(final ConsoleMock console) { executorService.execute(new Runnable() { @Override @@ -197,7 +172,7 @@ public class ConsoleManagerTests extends TestCase { latch.await(1, TimeUnit.MINUTES); System.out.println("Requesting to show: " + console); //$NON-NLS-1$ manager.showConsoleView(console); - waitForJobs(); + TestHelper.waitForJobs(); } catch (InterruptedException e) { e.printStackTrace(); Thread.interrupted(); @@ -277,4 +252,5 @@ public class ConsoleManagerTests extends TestCase { return "mock #" + number; //$NON-NLS-1$ } } + } diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java new file mode 100644 index 000000000..3939c4d3a --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2017 Andreas Loth 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: + * Andreas Loth - initial API and implementation + *******************************************************************************/ + +package org.eclipse.debug.tests.console; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IOConsoleOutputStream; +import org.eclipse.ui.console.MessageConsole; + +import junit.framework.TestCase; + + +public class ConsoleTests extends TestCase { + + public ConsoleTests() { + super("ConsoleTests"); //$NON-NLS-1$ + } + + public ConsoleTests(String name) { + super(name); + } + + public void testConsoleOutputStreamEncoding() throws IOException, InterruptedException { + String testString = "abc\u00e4\u00f6\u00fcdef"; //$NON-NLS-1$ + // abcdef need 1 byte in UTF-8 each + // äöü (\u00e4\u00f6\u00fc) need 2 bytes each + byte[] testStringBuffer = testString.getBytes(StandardCharsets.UTF_8); + TestCase.assertEquals("Test string \"" + testString + "\" should consist of 12 UTF-8 bytes", 12, testStringBuffer.length); //$NON-NLS-1$ //$NON-NLS-2$ + MessageConsole console = new MessageConsole("Test Console", //$NON-NLS-1$ + IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true); + IDocument document = console.getDocument(); + TestHelper.waitForJobs(); + TestCase.assertEquals("Document should be empty", "", document.get()); //$NON-NLS-1$ //$NON-NLS-2$ + try (IOConsoleOutputStream outStream = console.newOutputStream()) { + outStream.write(testStringBuffer, 0, 6); + // half of ö (\u00f6) is written so we don't expect this char in + // output but all previous chars can be decoded + TestHelper.waitForJobs(); + TestCase.assertEquals("First 4 chars should be written", testString.substring(0, 4), document.get()); //$NON-NLS-1$ + outStream.write(testStringBuffer, 6, 6); + // all remaining bytes are written so we expect the whole string + // including the ö (\u00f6) which was at buffer boundary + TestHelper.waitForJobs(); + TestCase.assertEquals("whole test string should be written", testString, document.get()); //$NON-NLS-1$ + } + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/TestHelper.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/TestHelper.java new file mode 100644 index 000000000..981459a79 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/TestHelper.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2017 Andreas Loth 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: + * Andreas Loth - initial API and implementation + *******************************************************************************/ + +package org.eclipse.debug.tests.console; + +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + + +public final class TestHelper { + + private TestHelper() { + throw new AssertionError("No instances of this utility class!"); //$NON-NLS-1$ + } + + public static void processUIEvents(final long millis) { + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() - start < millis) { + while (PlatformUI.getWorkbench().getDisplay().readAndDispatch()) { + // loop untile the queue is empty + } + } + } + + public static void waitForJobs() throws InterruptedException { + if (Display.getCurrent() == null) { + Thread.sleep(200); + } else { + processUIEvents(200); + } + while (!Job.getJobManager().isIdle()) { + if (Display.getCurrent() == null) { + Thread.sleep(200); + } else { + processUIEvents(200); + } + } + } + +} |