1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PipedConnection_Test.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.comp
.connections
;
33 import complexlib
.ComplexTestCase
;
35 public final class PipedConnection_Test
extends ComplexTestCase
{
36 public String
getTestObjectName() {
37 return getClass().getName();
40 public String
[] getTestMethodNames() {
41 return new String
[] { "test" };
44 public void test() throws Exception
{
45 PipedConnection rightSide
= new PipedConnection(new Object
[0]);
46 PipedConnection leftSide
= new PipedConnection(new Object
[]{rightSide
});
48 byte theByte
[] = new byte[1];
50 Reader reader
= new Reader(rightSide
, theByte
);
51 Writer writer
= new Writer(leftSide
, theByte
, reader
);
63 assure("", writer
._state
&& reader
._state
);
66 static class Reader
extends Thread
{
67 PipedConnection _pipedConnection
;
70 boolean _state
= false;
72 Reader(PipedConnection pipedConnection
, byte theByte
[]) {
73 _pipedConnection
= pipedConnection
;
79 byte bytes
[][] = new byte[1][];
82 int read
= _pipedConnection
.read(bytes
, 1);
85 // System.err.println("read :" + bytes[0][0]);
87 if(_theByte
[0] != bytes
[0][0])
88 throw new NullPointerException();
98 _pipedConnection
.close();
101 catch(com
.sun
.star
.io
.IOException ioException
) {
102 System
.err
.println("#### Reader - unexpected:" + ioException
);
108 static class Writer
extends Thread
{
109 PipedConnection _pipedConnection
;
113 boolean _state
= false;
115 Writer(PipedConnection pipedConnection
, byte theByte
[], Reader reader
) {
116 _pipedConnection
= pipedConnection
;
124 synchronized(_reader
) {
125 _pipedConnection
.write(_theByte
);
126 _pipedConnection
.flush();
127 // System.err.println("written :" + _theByte[0]);
134 _pipedConnection
.close();
138 catch(com
.sun
.star
.io
.IOException ioException
) {
139 System
.err
.println("#### Writer:" + ioException
);
141 catch(InterruptedException interruptedException
) {
142 System
.err
.println("#### Writer:" + interruptedException
);