Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b3732bbfc4edf4a08668c1ea5b7efd9326ba5557 (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
/*******************************************************************************
 * Copyright (c) 2011 SAP AG
 * 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:
 *    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 {
        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 {
        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