Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 513367 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java (-1 / +54 lines)
Lines 65-71 Link Here
65
		String testString = "a\r"; //$NON-NLS-1$
65
		String testString = "a\r"; //$NON-NLS-1$
66
		byte[] testStringBuffer = testString.getBytes(StandardCharsets.UTF_8);
66
		byte[] testStringBuffer = testString.getBytes(StandardCharsets.UTF_8);
67
		TestCase.assertEquals("Test string \"" + testString + "\" should consist of 2 UTF-8 bytes", 2, testStringBuffer.length); //$NON-NLS-1$ //$NON-NLS-2$
67
		TestCase.assertEquals("Test string \"" + testString + "\" should consist of 2 UTF-8 bytes", 2, testStringBuffer.length); //$NON-NLS-1$ //$NON-NLS-2$
68
		MessageConsole console = new MessageConsole("Test Console", //$NON-NLS-1$
68
		MessageConsole console = new MessageConsole("Test Console 2", //$NON-NLS-1$
69
				IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
69
				IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
70
		IDocument document = console.getDocument();
70
		IDocument document = console.getDocument();
71
		TestHelper.waitForJobs();
71
		TestHelper.waitForJobs();
Lines 82-85 Link Here
82
		TestCase.assertEquals("closing the stream should write the pending \\r", testString, document.get()); //$NON-NLS-1$
82
		TestCase.assertEquals("closing the stream should write the pending \\r", testString, document.get()); //$NON-NLS-1$
83
	}
83
	}
84
84
85
	public void testConsoleOutputStreamDocumentClosed() throws IOException {
86
		MessageConsole console = new MessageConsole("Test Console 3", //$NON-NLS-1$
87
				IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
88
		IDocument document = console.getDocument();
89
		try (IOConsoleOutputStream outStream = console.newOutputStream()) {
90
			outStream.write("write1"); //$NON-NLS-1$
91
			document.getDocumentPartitioner().disconnect();
92
			try {
93
				outStream.write("write2"); //$NON-NLS-1$
94
				TestCase.fail("IOException with message \"Document is closed\" expected"); //$NON-NLS-1$
95
			} catch (IOException ioe) {
96
				TestCase.assertEquals("Document is closed", ioe.getMessage()); //$NON-NLS-1$
97
			}
98
		}
99
	}
100
101
	public void testConsoleOutputStreamClosed() throws IOException {
102
		MessageConsole console = new MessageConsole("Test Console 4", //$NON-NLS-1$
103
				IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
104
		try (IOConsoleOutputStream outStream = console.newOutputStream()) {
105
			outStream.write("test1".getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$
106
			outStream.close();
107
			try {
108
				outStream.write("test2".getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$
109
				TestCase.fail("IOException with message \"Output Stream is closed\" expected"); //$NON-NLS-1$
110
			} catch (IOException ioe) {
111
				TestCase.assertEquals("Output Stream is closed", ioe.getMessage()); //$NON-NLS-1$
112
			}
113
		}
114
	}
115
116
	public void testConsoleOutputStreamDocumentStreamClosed() throws IOException {
117
		MessageConsole console = new MessageConsole("Test Console 5", //$NON-NLS-1$
118
				IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
119
		IDocument document = console.getDocument();
120
		try (IOConsoleOutputStream outStream = console.newOutputStream()) {
121
			outStream.write("write1"); //$NON-NLS-1$
122
			document.getDocumentPartitioner().disconnect();
123
			try {
124
				outStream.write("write2"); //$NON-NLS-1$
125
				TestCase.fail("IOException with message \"Document is closed\" expected"); //$NON-NLS-1$
126
			} catch (IOException ioe) {
127
				TestCase.assertEquals("Document is closed", ioe.getMessage()); //$NON-NLS-1$
128
			}
129
			try {
130
				outStream.write("write3"); //$NON-NLS-1$
131
				TestCase.fail("IOException with message \"Output Stream is closed\" expected"); //$NON-NLS-1$
132
			} catch (IOException ioe) {
133
				TestCase.assertEquals("Output Stream is closed", ioe.getMessage()); //$NON-NLS-1$
134
			}
135
		}
136
	}
137
85
}
138
}

Return to bug 513367