update emoji autocorrect entries from po-files
[LibreOffice.git] / jurt / test / com / sun / star / comp / connections / PipedConnection_Test.java
blob6d9027a4423e13b4b4b8a35de71e999dd915a065
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com.sun.star.comp.connections;
21 import com.sun.star.io.IOException;
22 import org.junit.Test;
23 import static org.junit.Assert.*;
25 public final class PipedConnection_Test {
26 private static final int ROUNDS = 2000;
28 @Test public void test() throws Exception {
29 PipedConnection rightSide = new PipedConnection(new Object[0]);
30 PipedConnection leftSide = new PipedConnection(new Object[]{rightSide});
32 Reader reader = new Reader(rightSide);
33 Writer writer = new Writer(leftSide);
35 reader.start();
36 writer.start();
38 writer.join();
39 reader.join();
41 assertTrue(writer._state);
42 assertTrue(reader._state);
43 assertEquals(ROUNDS, reader._rounds);
46 private static class Reader extends Thread {
47 PipedConnection _pipedConnection;
48 boolean _state = false;
49 int _rounds = 0;
51 Reader(PipedConnection pipedConnection) {
52 _pipedConnection = pipedConnection;
55 @Override
56 public void run() {
57 try {
58 for (byte v = 0;; v++) {
59 byte[][] b = new byte[1][];
60 int n = _pipedConnection.read(b, 1);
61 if (n == 0) {
62 break;
64 assertEquals(1, n);
65 assertEquals(1, b[0].length);
66 assertEquals(v, b[0][0]);
67 ++_rounds;
69 _pipedConnection.close();
70 _state = true;
71 } catch (IOException e) {
72 throw new RuntimeException(e);
77 private static class Writer extends Thread {
78 PipedConnection _pipedConnection;
79 boolean _state = false;
81 Writer(PipedConnection pipedConnection) {
82 _pipedConnection = pipedConnection;
85 @Override
86 public void run() {
87 try {
88 byte v = 0;
89 for (int i = 0; i != ROUNDS; ++i) {
90 byte[] b = new byte[] { v++ };
91 _pipedConnection.write(b);
92 _pipedConnection.flush();
94 _pipedConnection.close();
95 _state = true;
96 } catch (IOException e) {
97 throw new RuntimeException(e);