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.awt; 25cdf0e10cSrcweir 26cdf0e10cSrcweir 27cdf0e10cSrcweir import java.io.PrintWriter; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import lib.MultiMethodTest; 30cdf0e10cSrcweir 31cdf0e10cSrcweir import com.sun.star.awt.XImageConsumer; 32cdf0e10cSrcweir import com.sun.star.awt.XImageProducer; 33cdf0e10cSrcweir 34cdf0e10cSrcweir /** 35cdf0e10cSrcweir * Testing <code>com.sun.star.awt.XImageProducer</code> 36cdf0e10cSrcweir * interface methods : 37cdf0e10cSrcweir * <ul> 38cdf0e10cSrcweir * <li><code> addConsumer()</code></li> 39cdf0e10cSrcweir * <li><code> removeConsumer()</code></li> 40cdf0e10cSrcweir * <li><code> startProduction()</code></li> 41cdf0e10cSrcweir * </ul> <p> 42cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 43cdf0e10cSrcweir * @see com.sun.star.awt.XImageProducer 44cdf0e10cSrcweir */ 45cdf0e10cSrcweir public class _XImageProducer extends MultiMethodTest { 46cdf0e10cSrcweir 47cdf0e10cSrcweir public XImageProducer oObj = null; 48cdf0e10cSrcweir 49cdf0e10cSrcweir /** 50cdf0e10cSrcweir * Consumer implementation which sets flags on appropriate 51cdf0e10cSrcweir * method calls. 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir protected class TestImageConsumer implements XImageConsumer { 54cdf0e10cSrcweir PrintWriter log = null ; 55cdf0e10cSrcweir public boolean initCalled = false ; 56cdf0e10cSrcweir public boolean setColorModelCalled = false ; 57cdf0e10cSrcweir public boolean setPixelsByBytesCalled = false ; 58cdf0e10cSrcweir public boolean setPixelsByLongsCalled = false ; 59cdf0e10cSrcweir public boolean completeCalled = false ; 60cdf0e10cSrcweir TestImageConsumer(PrintWriter log)61cdf0e10cSrcweir TestImageConsumer(PrintWriter log) { 62cdf0e10cSrcweir log.println("### Consumer initialized" ) ; 63cdf0e10cSrcweir this.log = log ; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir init(int width, int height)66cdf0e10cSrcweir public void init(int width, int height) { 67cdf0e10cSrcweir log.println("### init() called") ; 68cdf0e10cSrcweir initCalled = true ; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir setColorModel(short bitCount, int[] RGBAPal, int redMask, int greenMask, int blueMask, int alphaMask)71cdf0e10cSrcweir public void setColorModel(short bitCount, int[] RGBAPal, 72cdf0e10cSrcweir int redMask, int greenMask, int blueMask, int alphaMask) { 73cdf0e10cSrcweir 74cdf0e10cSrcweir log.println("### setColorModel() called") ; 75cdf0e10cSrcweir setColorModelCalled = true ; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir setPixelsByBytes(int x, int y, int width, int height, byte[] data, int offset, int scanSize)78cdf0e10cSrcweir public void setPixelsByBytes(int x, int y, int width, int height, 79cdf0e10cSrcweir byte[] data, int offset, int scanSize) { 80cdf0e10cSrcweir 81cdf0e10cSrcweir log.println("### setPixelByBytes() called") ; 82cdf0e10cSrcweir setPixelsByBytesCalled = true ; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir setPixelsByLongs(int x, int y, int width, int height, int[] data, int offset, int scanSize)85cdf0e10cSrcweir public void setPixelsByLongs(int x, int y, int width, int height, 86cdf0e10cSrcweir int[] data, int offset, int scanSize) { 87cdf0e10cSrcweir 88cdf0e10cSrcweir log.println("### setPixelByLongs() called") ; 89cdf0e10cSrcweir setPixelsByLongsCalled = true ; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir complete(int status, XImageProducer prod)92cdf0e10cSrcweir public void complete(int status, XImageProducer prod) { 93cdf0e10cSrcweir log.println("### complete() called") ; 94cdf0e10cSrcweir completeCalled = true ; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir TestImageConsumer consumer = null ; 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** 101cdf0e10cSrcweir * Creates a new XImageConsumer implementation. 102cdf0e10cSrcweir */ before()103cdf0e10cSrcweir public void before() { 104cdf0e10cSrcweir consumer = new TestImageConsumer(log) ; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir /** 108cdf0e10cSrcweir * Adds a new consumer to producer. <p> 109cdf0e10cSrcweir * Has <b> OK </b> status if no runtime exceptions occured 110cdf0e10cSrcweir */ _addConsumer()111cdf0e10cSrcweir public void _addConsumer() { 112cdf0e10cSrcweir 113cdf0e10cSrcweir boolean result = true ; 114cdf0e10cSrcweir oObj.addConsumer(consumer) ; 115cdf0e10cSrcweir 116cdf0e10cSrcweir tRes.tested("addConsumer()", result) ; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir /** 120cdf0e10cSrcweir * Removes the consumer added before. <p> 121cdf0e10cSrcweir * Has <b> OK </b> status if no runtime exceptions occured 122cdf0e10cSrcweir * The following method tests are to be executed before : 123cdf0e10cSrcweir * <ul> 124cdf0e10cSrcweir * <li> <code> startProduction </code> </li> 125cdf0e10cSrcweir * </ul> 126cdf0e10cSrcweir */ _removeConsumer()127cdf0e10cSrcweir public void _removeConsumer() { 128cdf0e10cSrcweir executeMethod("startProduction()") ; 129cdf0e10cSrcweir 130cdf0e10cSrcweir boolean result = true ; 131cdf0e10cSrcweir oObj.removeConsumer(consumer) ; 132cdf0e10cSrcweir 133cdf0e10cSrcweir tRes.tested("removeConsumer()", result) ; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir /** 137cdf0e10cSrcweir * Starts the production and after short waiting checks what 138cdf0e10cSrcweir * consumer's methods were called. <p> 139cdf0e10cSrcweir * Has <b> OK </b> status if at least <code>init</code> consumer 140cdf0e10cSrcweir * methods was called. 141cdf0e10cSrcweir * The following method tests are to be completed successfully before : 142cdf0e10cSrcweir * <ul> 143cdf0e10cSrcweir * <li> <code> addConsumer </code> </li> 144cdf0e10cSrcweir * </ul> 145cdf0e10cSrcweir */ _startProduction()146cdf0e10cSrcweir public void _startProduction() { 147cdf0e10cSrcweir requiredMethod("addConsumer()") ; 148cdf0e10cSrcweir 149cdf0e10cSrcweir boolean result = true ; 150cdf0e10cSrcweir oObj.startProduction() ; 151cdf0e10cSrcweir 152cdf0e10cSrcweir try { 153cdf0e10cSrcweir Thread.sleep(500) ; 154cdf0e10cSrcweir } catch (InterruptedException e) {} 155cdf0e10cSrcweir 156cdf0e10cSrcweir tRes.tested("startProduction()", consumer.initCalled) ; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir 162