1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.awt;
25 
26 
27 import java.io.PrintWriter;
28 
29 import lib.MultiMethodTest;
30 
31 import com.sun.star.awt.XImageConsumer;
32 import com.sun.star.awt.XImageProducer;
33 
34 /**
35 * Testing <code>com.sun.star.awt.XImageProducer</code>
36 * interface methods :
37 * <ul>
38 *  <li><code> addConsumer()</code></li>
39 *  <li><code> removeConsumer()</code></li>
40 *  <li><code> startProduction()</code></li>
41 * </ul> <p>
42 * Test is <b> NOT </b> multithread compilant. <p>
43 * @see com.sun.star.awt.XImageProducer
44 */
45 public class _XImageProducer extends MultiMethodTest {
46 
47     public XImageProducer oObj = null;
48 
49     /**
50     * Consumer implementation which sets flags on appropriate
51     * method calls.
52     */
53     protected class TestImageConsumer implements XImageConsumer {
54         PrintWriter log = null ;
55         public boolean initCalled = false ;
56         public boolean setColorModelCalled = false ;
57         public boolean setPixelsByBytesCalled = false ;
58         public boolean setPixelsByLongsCalled = false ;
59         public boolean completeCalled = false ;
60 
TestImageConsumer(PrintWriter log)61         TestImageConsumer(PrintWriter log) {
62             log.println("### Consumer initialized" ) ;
63             this.log = log ;
64         }
65 
init(int width, int height)66         public void init(int width, int height) {
67             log.println("### init() called") ;
68             initCalled = true ;
69         }
70 
setColorModel(short bitCount, int[] RGBAPal, int redMask, int greenMask, int blueMask, int alphaMask)71         public void setColorModel(short bitCount, int[] RGBAPal,
72             int redMask, int greenMask, int blueMask, int alphaMask) {
73 
74             log.println("### setColorModel() called") ;
75             setColorModelCalled = true ;
76         }
77 
setPixelsByBytes(int x, int y, int width, int height, byte[] data, int offset, int scanSize)78         public void setPixelsByBytes(int x, int y, int width, int height,
79             byte[] data, int offset, int scanSize) {
80 
81             log.println("### setPixelByBytes() called") ;
82             setPixelsByBytesCalled = true ;
83         }
84 
setPixelsByLongs(int x, int y, int width, int height, int[] data, int offset, int scanSize)85         public void setPixelsByLongs(int x, int y, int width, int height,
86             int[] data, int offset, int scanSize) {
87 
88             log.println("### setPixelByLongs() called") ;
89             setPixelsByLongsCalled = true ;
90         }
91 
complete(int status, XImageProducer prod)92         public void complete(int status, XImageProducer prod) {
93             log.println("### complete() called") ;
94             completeCalled = true ;
95         }
96     }
97 
98     TestImageConsumer consumer = null ;
99 
100     /**
101     * Creates a new XImageConsumer implementation.
102     */
before()103     public void before() {
104         consumer = new TestImageConsumer(log) ;
105     }
106 
107     /**
108     * Adds a new consumer to producer. <p>
109     * Has <b> OK </b> status if no runtime exceptions occured
110     */
_addConsumer()111     public void _addConsumer() {
112 
113         boolean result = true ;
114         oObj.addConsumer(consumer) ;
115 
116         tRes.tested("addConsumer()", result) ;
117     }
118 
119     /**
120     * Removes the consumer added before. <p>
121     * Has <b> OK </b> status if no runtime exceptions occured
122     * The following method tests are to be executed before :
123     * <ul>
124     *  <li> <code> startProduction </code>  </li>
125     * </ul>
126     */
_removeConsumer()127     public void _removeConsumer() {
128         executeMethod("startProduction()") ;
129 
130         boolean result = true ;
131         oObj.removeConsumer(consumer) ;
132 
133         tRes.tested("removeConsumer()", result) ;
134     }
135 
136     /**
137     * Starts the production and after short waiting  checks what
138     * consumer's methods were called. <p>
139     * Has <b> OK </b> status if at least <code>init</code> consumer
140     * methods was called.
141     * The following method tests are to be completed successfully before :
142     * <ul>
143     *  <li> <code> addConsumer </code> </li>
144     * </ul>
145     */
_startProduction()146     public void _startProduction() {
147         requiredMethod("addConsumer()") ;
148 
149         boolean result = true ;
150         oObj.startProduction() ;
151 
152         try {
153             Thread.sleep(500) ;
154         } catch (InterruptedException e) {}
155 
156         tRes.tested("startProduction()", consumer.initCalled) ;
157     }
158 
159 }
160 
161 
162