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