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
;
28 import java
.io
.PrintWriter
;
29 import lib
.StatusException
;
31 import lib
.TestEnvironment
;
32 import lib
.TestParameters
;
35 * Test for object which is represented by service
36 * <code>com.sun.star.io.MarkableInputStream</code>. <p>
37 * Object implements the following interfaces :
39 * <li> <code>com::sun::star::io::XInputStream</code></li>
40 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
41 * <li> <code>com::sun::star::io::XConnectable</code></li>
42 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
44 * @see com.sun.star.io.MarkableInputStream
45 * @see com.sun.star.io.XInputStream
46 * @see com.sun.star.io.XMarkableStream
47 * @see com.sun.star.io.XConnectable
48 * @see com.sun.star.io.XActiveDataSink
49 * @see ifc.io._XInputStream
50 * @see ifc.io._XMarkableStream
51 * @see ifc.io._XConnectable
52 * @see ifc.io._XActiveDataSink
54 public class MarkableInputStream
extends TestCase
{
57 * Creating a Testenvironment for the interfaces to be tested.
58 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
59 * <code>com.sun.star.io.MarkableInputStream</code> and
60 * <code>com.sun.star.io.MarkableOutputStream</code>.
61 * Plugs the created pipe as output stream for the created
62 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
63 * for the created <code>MarkableInputStream</code>. Writes some data to the
64 * <code>MarkableOutputStream</code>.
65 * Object relations created :
67 * <li> <code>'StreamWriter'</code> for
68 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
69 * <li> <code>'ByteData'</code> for
70 * {@link ifc.io._XInputStream}(the data that should be written into
72 * <li> <code>'Connectable'</code> for
73 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
74 * <li> <code>'InputStream'</code> for
75 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
77 * @see com.sun.star.io.Pipe
78 * @see com.sun.star.io.MarkableInputStream
79 * @see com.sun.star.io.MarkableOutputStream
82 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
84 XMultiServiceFactory xMSF
= Param
.getMSF();
87 Object mostream
= null;
88 Object mistream
= null;
89 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");
95 } catch(com
.sun
.star
.uno
.Exception e
) {
96 e
.printStackTrace(log
);
97 throw new StatusException("Couldn't create instance", e
) ;
100 // Creating construction :
101 // MarkableOutputStream -> Pipe -> MarkableInputStream
102 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
104 XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class, aPipe
);
105 XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class, aPipe
);
107 xdSmo
.setOutputStream(PipeOut
);
109 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
111 xmSi
.setInputStream(PipeIn
) ;
113 XInterface oObj
= (XInterface
) mistream
;
115 byte[] byteData
= new byte[] {1,2,3,4,5,6};
117 log
.println( "creating a new environment for object" );
118 TestEnvironment tEnv
= new TestEnvironment( oObj
);
121 tEnv
.addObjRelation("StreamWriter", mostream
);
123 tEnv
.addObjRelation("Connectable", xConnect
);
124 // add an inputStream
125 tEnv
.addObjRelation("InputStream", mistream
);
126 tEnv
.addObjRelation("ByteData", byteData
);
129 } // finish method getTestEnvironment