Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 905b6c2d691e2efb49fbcced1f781541f4eb4f88 (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
/*******************************************************************************
 * Copyright (c) 2011, 2017 SAP AG and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Lazar Kirchev, SAP AG - initial contribution
 ******************************************************************************/

package org.eclipse.equinox.console.common;

import org.junit.Assert;
import org.junit.Test;

import org.eclipse.equinox.console.common.ConsoleInputStream;

public class ConsoleInputStreamTests {

	private static final int DATA_LENGTH = 4;

	@Test
	public void addReadBufferTest() throws Exception {
		try (ConsoleInputStream in = new ConsoleInputStream()) {
			byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' };
			in.add(data);
			byte[] read = new byte[DATA_LENGTH];
			for (int i = 0; i < DATA_LENGTH; i++) {
				in.read(read, i, 1);
				Assert.assertEquals(
						"Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + read[i],
						read[i], data[i]);
			}
		}
	}

	@Test
	public void addReadTest() throws Exception {
		try (ConsoleInputStream in = new ConsoleInputStream()) {
			byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' };
			in.add(data);
			for (int i = 0; i < DATA_LENGTH; i++) {
				byte symbol = (byte) in.read();
				Assert.assertEquals(
						"Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + symbol, symbol,
						data[i]);
			}
		}
	}
}

Back to the top