1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.awt; 29 30 31 import java.io.PrintWriter; 32 33 import lib.MultiMethodTest; 34 35 import com.sun.star.awt.XImageConsumer; 36 import com.sun.star.awt.XImageProducer; 37 38 /** 39 * Testing <code>com.sun.star.awt.XImageProducer</code> 40 * interface methods : 41 * <ul> 42 * <li><code> addConsumer()</code></li> 43 * <li><code> removeConsumer()</code></li> 44 * <li><code> startProduction()</code></li> 45 * </ul> <p> 46 * Test is <b> NOT </b> multithread compilant. <p> 47 * @see com.sun.star.awt.XImageProducer 48 */ 49 public class _XImageProducer extends MultiMethodTest { 50 51 public XImageProducer oObj = null; 52 53 /** 54 * Consumer implementation which sets flags on appropriate 55 * method calls. 56 */ 57 protected class TestImageConsumer implements XImageConsumer { 58 PrintWriter log = null ; 59 public boolean initCalled = false ; 60 public boolean setColorModelCalled = false ; 61 public boolean setPixelsByBytesCalled = false ; 62 public boolean setPixelsByLongsCalled = false ; 63 public boolean completeCalled = false ; 64 65 TestImageConsumer(PrintWriter log) { 66 log.println("### Consumer initialized" ) ; 67 this.log = log ; 68 } 69 70 public void init(int width, int height) { 71 log.println("### init() called") ; 72 initCalled = true ; 73 } 74 75 public void setColorModel(short bitCount, int[] RGBAPal, 76 int redMask, int greenMask, int blueMask, int alphaMask) { 77 78 log.println("### setColorModel() called") ; 79 setColorModelCalled = true ; 80 } 81 82 public void setPixelsByBytes(int x, int y, int width, int height, 83 byte[] data, int offset, int scanSize) { 84 85 log.println("### setPixelByBytes() called") ; 86 setPixelsByBytesCalled = true ; 87 } 88 89 public void setPixelsByLongs(int x, int y, int width, int height, 90 int[] data, int offset, int scanSize) { 91 92 log.println("### setPixelByLongs() called") ; 93 setPixelsByLongsCalled = true ; 94 } 95 96 public void complete(int status, XImageProducer prod) { 97 log.println("### complete() called") ; 98 completeCalled = true ; 99 } 100 } 101 102 TestImageConsumer consumer = null ; 103 104 /** 105 * Creates a new XImageConsumer implementation. 106 */ 107 public void before() { 108 consumer = new TestImageConsumer(log) ; 109 } 110 111 /** 112 * Adds a new consumer to producer. <p> 113 * Has <b> OK </b> status if no runtime exceptions occured 114 */ 115 public void _addConsumer() { 116 117 boolean result = true ; 118 oObj.addConsumer(consumer) ; 119 120 tRes.tested("addConsumer()", result) ; 121 } 122 123 /** 124 * Removes the consumer added before. <p> 125 * Has <b> OK </b> status if no runtime exceptions occured 126 * The following method tests are to be executed before : 127 * <ul> 128 * <li> <code> startProduction </code> </li> 129 * </ul> 130 */ 131 public void _removeConsumer() { 132 executeMethod("startProduction()") ; 133 134 boolean result = true ; 135 oObj.removeConsumer(consumer) ; 136 137 tRes.tested("removeConsumer()", result) ; 138 } 139 140 /** 141 * Starts the production and after short waiting checks what 142 * consumer's methods were called. <p> 143 * Has <b> OK </b> status if at least <code>init</code> consumer 144 * methods was called. 145 * The following method tests are to be completed successfully before : 146 * <ul> 147 * <li> <code> addConsumer </code> </li> 148 * </ul> 149 */ 150 public void _startProduction() { 151 requiredMethod("addConsumer()") ; 152 153 boolean result = true ; 154 oObj.startProduction() ; 155 156 try { 157 Thread.sleep(500) ; 158 } catch (InterruptedException e) {} 159 160 tRes.tested("startProduction()", consumer.initCalled) ; 161 } 162 163 } 164 165 166