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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
28 import com
.sun
.star
.io
.XActiveDataSink
;
29 import com
.sun
.star
.io
.XActiveDataSource
;
30 import com
.sun
.star
.io
.XInputStream
;
31 import com
.sun
.star
.io
.XOutputStream
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.io.MarkableInputStream</code>. <p>
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::io::XInputStream</code></li>
42 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
43 * <li> <code>com::sun::star::io::XConnectable</code></li>
44 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
46 * @see com.sun.star.io.MarkableInputStream
47 * @see com.sun.star.io.XInputStream
48 * @see com.sun.star.io.XMarkableStream
49 * @see com.sun.star.io.XConnectable
50 * @see com.sun.star.io.XActiveDataSink
51 * @see ifc.io._XInputStream
52 * @see ifc.io._XMarkableStream
53 * @see ifc.io._XConnectable
54 * @see ifc.io._XActiveDataSink
56 public class MarkableInputStream
extends TestCase
{
59 * Creating a Testenvironment for the interfaces to be tested.
60 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
61 * <code>com.sun.star.io.MarkableInputStream</code> and
62 * <code>com.sun.star.io.MarkableOutputStream</code>.
63 * Plugs the created pipe as output stream for the created
64 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
65 * for the created <code>MarkableInputStream</code>. Writes some data to the
66 * <code>MarkableOutputStream</code>.
67 * Object relations created :
69 * <li> <code>'StreamWriter'</code> for
70 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
71 * <li> <code>'ByteData'</code> for
72 * {@link ifc.io._XInputStream}(the data that should be written into
74 * <li> <code>'Connectable'</code> for
75 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
76 * <li> <code>'InputStream'</code> for
77 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
79 * @see com.sun.star.io.Pipe
80 * @see com.sun.star.io.MarkableInputStream
81 * @see com.sun.star.io.MarkableOutputStream
84 public TestEnvironment
createTestEnvironment(
85 TestParameters Param
, PrintWriter log
) throws StatusException
{
87 XMultiServiceFactory xMSF
= Param
.getMSF();
90 Object mostream
= null;
91 Object mistream
= null;
92 Object xConnect
= null;
94 aPipe
= xMSF
.createInstance("com.sun.star.io.Pipe");
95 mistream
= xMSF
.createInstance("com.sun.star.io.MarkableInputStream");
96 mostream
= xMSF
.createInstance("com.sun.star.io.MarkableOutputStream");
97 xConnect
= xMSF
.createInstance("com.sun.star.io.DataInputStream");
98 } catch(com
.sun
.star
.uno
.Exception e
) {
99 e
.printStackTrace(log
);
100 throw new StatusException("Couldn't create instance", e
) ;
103 // Creating construction :
104 // MarkableOutputStream -> Pipe -> MarkableInputStream
105 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
107 XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class, aPipe
);
108 XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class, aPipe
);
110 xdSmo
.setOutputStream(PipeOut
);
112 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
114 xmSi
.setInputStream(PipeIn
) ;
116 XInterface oObj
= (XInterface
) mistream
;
118 byte[] byteData
= new byte[] {1,2,3,4,5,6};
120 log
.println( "creating a new environment for object" );
121 TestEnvironment tEnv
= new TestEnvironment( oObj
);
124 tEnv
.addObjRelation("StreamWriter", mostream
);
126 tEnv
.addObjRelation("Connectable", xConnect
);
127 // add an inputStream
128 tEnv
.addObjRelation("InputStream", mistream
);
129 tEnv
.addObjRelation("ByteData", byteData
);
132 } // finish method getTestEnvironment