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: MarkableInputStream.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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
40 import com
.sun
.star
.io
.XActiveDataSink
;
41 import com
.sun
.star
.io
.XActiveDataSource
;
42 import com
.sun
.star
.io
.XInputStream
;
43 import com
.sun
.star
.io
.XOutputStream
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.io.MarkableInputStream</code>. <p>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::io::XInputStream</code></li>
54 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
55 * <li> <code>com::sun::star::io::XConnectable</code></li>
56 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
58 * @see com.sun.star.io.MarkableInputStream
59 * @see com.sun.star.io.XInputStream
60 * @see com.sun.star.io.XMarkableStream
61 * @see com.sun.star.io.XConnectable
62 * @see com.sun.star.io.XActiveDataSink
63 * @see ifc.io._XInputStream
64 * @see ifc.io._XMarkableStream
65 * @see ifc.io._XConnectable
66 * @see ifc.io._XActiveDataSink
68 public class MarkableInputStream
extends TestCase
{
71 * Creating a Testenvironment for the interfaces to be tested.
72 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
73 * <code>com.sun.star.io.MarkableInputStream</code> and
74 * <code>com.sun.star.io.MarkableOutputStream</code>.
75 * Plugs the created pipe as output stream for the created
76 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
77 * for the created <code>MarkableInputStream</code>. Writes some data to the
78 * <code>MarkableOutputStream</code>.
79 * Object relations created :
81 * <li> <code>'StreamWriter'</code> for
82 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
83 * <li> <code>'ByteData'</code> for
84 * {@link ifc.io._XInputStream}(the data that should be written into
86 * <li> <code>'Connectable'</code> for
87 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
88 * <li> <code>'InputStream'</code> for
89 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
91 * @see com.sun.star.io.Pipe
92 * @see com.sun.star.io.MarkableInputStream
93 * @see com.sun.star.io.MarkableOutputStream
95 public TestEnvironment
createTestEnvironment(
96 TestParameters Param
, PrintWriter log
) throws StatusException
{
98 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();;
101 Object mostream
= null;
102 Object mistream
= null;
103 Object xConnect
= null;
105 aPipe
= xMSF
.createInstance("com.sun.star.io.Pipe");
106 mistream
= xMSF
.createInstance("com.sun.star.io.MarkableInputStream");
107 mostream
= xMSF
.createInstance("com.sun.star.io.MarkableOutputStream");
108 xConnect
= xMSF
.createInstance("com.sun.star.io.DataInputStream");
109 } catch(com
.sun
.star
.uno
.Exception e
) {
110 e
.printStackTrace(log
);
111 throw new StatusException("Couldn't create instance", e
) ;
114 // Creating construction :
115 // MarkableOutputStream -> Pipe -> MarkableInputStream
116 XActiveDataSource xdSmo
= (XActiveDataSource
)
117 UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
119 XOutputStream PipeOut
= (XOutputStream
)
120 UnoRuntime
.queryInterface(XOutputStream
.class, aPipe
);
121 XInputStream PipeIn
= (XInputStream
)
122 UnoRuntime
.queryInterface(XInputStream
.class, aPipe
);
124 xdSmo
.setOutputStream(PipeOut
);
126 XActiveDataSink xmSi
= (XActiveDataSink
)
127 UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
129 xmSi
.setInputStream(PipeIn
) ;
131 XInterface oObj
= (XInterface
) mistream
;
133 byte[] byteData
= new byte[] {1,2,3,4,5,6};
135 log
.println( "creating a new environment for object" );
136 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 tEnv
.addObjRelation("StreamWriter", mostream
);
141 tEnv
.addObjRelation("Connectable", xConnect
);
142 // add an inputStream
143 tEnv
.addObjRelation("InputStream", mistream
);
144 tEnv
.addObjRelation("ByteData", byteData
);
147 } // finish method getTestEnvironment