1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.io; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir import lib.Status; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.io.XInputStream; 30cdf0e10cSrcweir import com.sun.star.io.XOutputStream; 31cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 32cdf0e10cSrcweir import com.sun.star.uno.XInterface; 33cdf0e10cSrcweir 34cdf0e10cSrcweir /** 35cdf0e10cSrcweir * Testing <code>com.sun.star.io.XInputStream</code> 36cdf0e10cSrcweir * interface methods: 37cdf0e10cSrcweir * <ul> 38cdf0e10cSrcweir * <li><code>readBytes()</code></li> 39cdf0e10cSrcweir * <li><code>readSomeBytes()</code></li> 40cdf0e10cSrcweir * <li><code>skipBytes()</code></li> 41cdf0e10cSrcweir * <li><code>available()</code></li> 42cdf0e10cSrcweir * <li><code>closeInput()</code></li> 43cdf0e10cSrcweir * </ul> <p> 44cdf0e10cSrcweir * This test needs the following object relations : 45cdf0e10cSrcweir * <ul> 46cdf0e10cSrcweir * <li> <code>'StreamWriter'</code>: 47cdf0e10cSrcweir * object that supports interface <code>XOutputStream</code>; 48cdf0e10cSrcweir * a stream to write data to</li> 49cdf0e10cSrcweir * <li> <code>'ByteData'</code> (of type <code>byte []</code>): 50cdf0e10cSrcweir * data to write to the stream</li> 51cdf0e10cSrcweir * <ul> <p> 52cdf0e10cSrcweir 53cdf0e10cSrcweir * @see com.sun.star.io.XInputStream 54cdf0e10cSrcweir */ 55cdf0e10cSrcweir public class _XInputStream extends MultiMethodTest { 56cdf0e10cSrcweir 57cdf0e10cSrcweir public XInputStream oObj = null; 58cdf0e10cSrcweir public XOutputStream oStream = null; 59cdf0e10cSrcweir 60cdf0e10cSrcweir byte[] bytes = null; 61cdf0e10cSrcweir 62cdf0e10cSrcweir int bytesReady = 0 ; 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** 65cdf0e10cSrcweir * Before the test, the stream writer and the data are ecxtracted from 66cdf0e10cSrcweir * the object relations and the data is written to the stream. 67cdf0e10cSrcweir */ before()68cdf0e10cSrcweir public void before() { 69cdf0e10cSrcweir XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter"); 70cdf0e10cSrcweir oStream = (XOutputStream)UnoRuntime.queryInterface( 71cdf0e10cSrcweir XOutputStream.class, x) ; 72cdf0e10cSrcweir bytes = (byte[])tEnv.getObjRelation("ByteData"); 73cdf0e10cSrcweir try { 74cdf0e10cSrcweir oStream.writeBytes(bytes); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir catch(com.sun.star.io.NotConnectedException e) {} 77cdf0e10cSrcweir catch(com.sun.star.io.BufferSizeExceededException e) {} 78cdf0e10cSrcweir catch(com.sun.star.io.IOException e) {} 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir /** 82cdf0e10cSrcweir * After the test, the stream writer is closed and the 83cdf0e10cSrcweir * environment is disposed. 84cdf0e10cSrcweir */ after()85cdf0e10cSrcweir public void after() { 86cdf0e10cSrcweir try { 87cdf0e10cSrcweir oStream.flush(); 88cdf0e10cSrcweir oStream.closeOutput(); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir catch(com.sun.star.io.NotConnectedException e) {} 91cdf0e10cSrcweir catch(com.sun.star.io.BufferSizeExceededException e) {} 92cdf0e10cSrcweir catch(com.sun.star.io.IOException e) {} 93cdf0e10cSrcweir this.disposeEnvironment(); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir /** 96cdf0e10cSrcweir * Test calls the method and stores number of available bytes. <p> 97cdf0e10cSrcweir * Has <b> OK </b> status if the method successfully returns 98cdf0e10cSrcweir * and no exceptions were thrown. <p> 99cdf0e10cSrcweir */ _available()100cdf0e10cSrcweir public void _available() { 101cdf0e10cSrcweir boolean result = true ; 102cdf0e10cSrcweir try { 103cdf0e10cSrcweir bytesReady = oObj.available() ; 104cdf0e10cSrcweir log.println("Bytes available :" + bytesReady) ; 105cdf0e10cSrcweir } catch (com.sun.star.io.IOException e){ 106cdf0e10cSrcweir e.printStackTrace(log) ; 107cdf0e10cSrcweir result = false ; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir tRes.tested("available()", result) ; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir /** 114cdf0e10cSrcweir * Test reads one byte from stream. If no bytes available 115cdf0e10cSrcweir * then test of method is skipped. <p> 116cdf0e10cSrcweir * Has <b> OK </b> status if returned value equal to number of read bytes, 117cdf0e10cSrcweir * no exceptions were thrown and read data is not null. <p> 118cdf0e10cSrcweir * The following method tests are to be completed successfully before : 119cdf0e10cSrcweir * <ul> 120cdf0e10cSrcweir * <li> <code> available() </code> : to have available number 121cdf0e10cSrcweir * of bytes in stream </li> 122cdf0e10cSrcweir * </ul> 123cdf0e10cSrcweir */ _readBytes()124cdf0e10cSrcweir public void _readBytes() { 125cdf0e10cSrcweir requiredMethod("available()") ; 126cdf0e10cSrcweir boolean result ; 127cdf0e10cSrcweir 128cdf0e10cSrcweir if (bytesReady-- > 0) { 129cdf0e10cSrcweir try { 130cdf0e10cSrcweir byte[][] data = new byte[1][1] ; 131cdf0e10cSrcweir int read = oObj.readBytes(data, 1) ; 132cdf0e10cSrcweir 133cdf0e10cSrcweir result = read == 1 && 134cdf0e10cSrcweir data != null && 135cdf0e10cSrcweir data.length == 1 ; 136cdf0e10cSrcweir } catch (com.sun.star.io.IOException e){ 137cdf0e10cSrcweir e.printStackTrace(log) ; 138cdf0e10cSrcweir result = false ; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir tRes.tested("readBytes()", result) ; 142cdf0e10cSrcweir } else { 143cdf0e10cSrcweir log.println("No more bytes available in the stream"); 144cdf0e10cSrcweir tRes.tested("readBytes()", Status.skipped(false)); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir /** 149cdf0e10cSrcweir * Test reads one byte from stream. If no bytes available 150cdf0e10cSrcweir * then test of method is skipped. <p> 151cdf0e10cSrcweir * Has <b> OK </b> status if returned value equal to number of read bytes, 152cdf0e10cSrcweir * no exceptions were thrown and read data is not null. <p> 153cdf0e10cSrcweir * The following method tests are to be completed successfully before : 154cdf0e10cSrcweir * <ul> 155cdf0e10cSrcweir * <li> <code> available() </code> : to have available number 156cdf0e10cSrcweir * of bytes in stream </li> 157cdf0e10cSrcweir * </ul> 158cdf0e10cSrcweir */ _readSomeBytes()159cdf0e10cSrcweir public void _readSomeBytes() { 160cdf0e10cSrcweir requiredMethod("available()") ; 161cdf0e10cSrcweir boolean result ; 162cdf0e10cSrcweir 163cdf0e10cSrcweir if (bytesReady-- > 0) { 164cdf0e10cSrcweir try { 165cdf0e10cSrcweir byte[][] data = new byte [1][1] ; 166cdf0e10cSrcweir int read = oObj.readSomeBytes(data, 1) ; 167cdf0e10cSrcweir 168cdf0e10cSrcweir result = read == 1 && 169cdf0e10cSrcweir data != null && 170cdf0e10cSrcweir data.length == 1 ; 171cdf0e10cSrcweir } catch (com.sun.star.io.IOException e){ 172cdf0e10cSrcweir e.printStackTrace(log) ; 173cdf0e10cSrcweir result = false ; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir tRes.tested("readSomeBytes()", result) ; 176cdf0e10cSrcweir } else { 177cdf0e10cSrcweir log.println("No more bytes available in the stream") ; 178cdf0e10cSrcweir tRes.tested("readBytes()", Status.skipped(false)); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir /** 183cdf0e10cSrcweir * Test skips one byte from stream. If no bytes available 184cdf0e10cSrcweir * then test of method is skipped. <p> 185cdf0e10cSrcweir * Has <b> OK </b> status if the method successfully returns 186cdf0e10cSrcweir * and no exceptions were thrown. <p> 187cdf0e10cSrcweir * The following method tests are to be completed successfully before : 188cdf0e10cSrcweir * <ul> 189cdf0e10cSrcweir * <li> <code> available() </code> : to have available number 190cdf0e10cSrcweir * of bytes in stream </li> 191cdf0e10cSrcweir * </ul> 192cdf0e10cSrcweir */ _skipBytes()193cdf0e10cSrcweir public void _skipBytes() { 194cdf0e10cSrcweir requiredMethod("available()") ; 195cdf0e10cSrcweir boolean result ; 196cdf0e10cSrcweir 197cdf0e10cSrcweir if (bytesReady-- > 0) { 198cdf0e10cSrcweir try { 199cdf0e10cSrcweir oObj.skipBytes(1) ; 200cdf0e10cSrcweir 201cdf0e10cSrcweir result = true ; 202cdf0e10cSrcweir } catch (com.sun.star.io.IOException e){ 203cdf0e10cSrcweir e.printStackTrace(log) ; 204cdf0e10cSrcweir result = false ; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir tRes.tested("skipBytes()", result) ; 207cdf0e10cSrcweir } else { 208cdf0e10cSrcweir log.println("No more bytes available in the stream") ; 209cdf0e10cSrcweir tRes.tested("readBytes()", Status.skipped(false)); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir /** 214cdf0e10cSrcweir * Test calls the method and forces object environment recreation. <p> 215cdf0e10cSrcweir * Has <b> OK </b> status if the method successfully returns 216cdf0e10cSrcweir * and no exceptions were thrown. <p> 217cdf0e10cSrcweir * The following method tests are to be executed before : 218cdf0e10cSrcweir * <ul> 219cdf0e10cSrcweir * <li> <code> available() </code> </li> 220cdf0e10cSrcweir * <li> <code> readBytes() </code> </li> 221cdf0e10cSrcweir * <li> <code> readSomeBytes() </code> </li> 222cdf0e10cSrcweir * <li> <code> skipBytes() </code> </li> 223cdf0e10cSrcweir * </ul> 224cdf0e10cSrcweir */ _closeInput()225cdf0e10cSrcweir public void _closeInput() { 226cdf0e10cSrcweir executeMethod("available()") ; 227cdf0e10cSrcweir executeMethod("readBytes()") ; 228cdf0e10cSrcweir executeMethod("readSomeBytes()") ; 229cdf0e10cSrcweir executeMethod("skipBytes()") ; 230cdf0e10cSrcweir 231cdf0e10cSrcweir boolean result = true ; 232cdf0e10cSrcweir try { 233cdf0e10cSrcweir oObj.closeInput() ; 234cdf0e10cSrcweir } catch (com.sun.star.io.IOException e){ 235cdf0e10cSrcweir e.printStackTrace(log) ; 236cdf0e10cSrcweir result = false ; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir 239cdf0e10cSrcweir tRes.tested("closeInput()", result) ; 240cdf0e10cSrcweir this.disposeEnvironment() ; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244