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 mod
._streams
.uno
;
21 import com
.sun
.star
.io
.XActiveDataSink
;
22 import com
.sun
.star
.io
.XActiveDataSource
;
23 import com
.sun
.star
.io
.XInputStream
;
24 import com
.sun
.star
.io
.XOutputStream
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XInterface
;
29 import java
.io
.PrintWriter
;
32 import lib
.TestEnvironment
;
33 import lib
.TestParameters
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.io.MarkableInputStream</code>. <p>
38 * Object implements the following interfaces :
40 * <li> <code>com::sun::star::io::XInputStream</code></li>
41 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
42 * <li> <code>com::sun::star::io::XConnectable</code></li>
43 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
45 * @see com.sun.star.io.MarkableInputStream
46 * @see com.sun.star.io.XInputStream
47 * @see com.sun.star.io.XMarkableStream
48 * @see com.sun.star.io.XConnectable
49 * @see com.sun.star.io.XActiveDataSink
50 * @see ifc.io._XInputStream
51 * @see ifc.io._XMarkableStream
52 * @see ifc.io._XConnectable
53 * @see ifc.io._XActiveDataSink
55 public class MarkableInputStream
extends TestCase
{
58 * Creating a TestEnvironment for the interfaces to be tested.
59 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
60 * <code>com.sun.star.io.MarkableInputStream</code> and
61 * <code>com.sun.star.io.MarkableOutputStream</code>.
62 * Plugs the created pipe as output stream for the created
63 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
64 * for the created <code>MarkableInputStream</code>. Writes some data to the
65 * <code>MarkableOutputStream</code>.
66 * Object relations created :
68 * <li> <code>'StreamWriter'</code> for
69 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
70 * <li> <code>'ByteData'</code> for
71 * {@link ifc.io._XInputStream}(the data that should be written into
73 * <li> <code>'Connectable'</code> for
74 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
75 * <li> <code>'InputStream'</code> for
76 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
78 * @see com.sun.star.io.Pipe
79 * @see com.sun.star.io.MarkableInputStream
80 * @see com.sun.star.io.MarkableOutputStream
83 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
85 XMultiServiceFactory xMSF
= Param
.getMSF();
88 Object mostream
= null;
89 Object mistream
= null;
90 Object xConnect
= null;
91 aPipe
= xMSF
.createInstance("com.sun.star.io.Pipe");
92 mistream
= xMSF
.createInstance("com.sun.star.io.MarkableInputStream");
93 mostream
= xMSF
.createInstance("com.sun.star.io.MarkableOutputStream");
94 xConnect
= xMSF
.createInstance("com.sun.star.io.DataInputStream");
96 // Creating construction :
97 // MarkableOutputStream -> Pipe -> MarkableInputStream
98 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
100 XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class, aPipe
);
101 XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class, aPipe
);
103 xdSmo
.setOutputStream(PipeOut
);
105 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
107 xmSi
.setInputStream(PipeIn
) ;
109 XInterface oObj
= (XInterface
) mistream
;
111 byte[] byteData
= new byte[] {1,2,3,4,5,6};
113 log
.println( "creating a new environment for object" );
114 TestEnvironment tEnv
= new TestEnvironment( oObj
);
117 tEnv
.addObjRelation("StreamWriter", mostream
);
119 tEnv
.addObjRelation("Connectable", xConnect
);
120 // add an inputStream
121 tEnv
.addObjRelation("InputStream", mistream
);
122 tEnv
.addObjRelation("ByteData", byteData
);
125 } // finish method getTestEnvironment