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.frame;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.awt.XWindow;
27cdf0e10cSrcweir //import com.sun.star.awt.XWindow;
28cdf0e10cSrcweir import com.sun.star.frame.FrameAction;
29cdf0e10cSrcweir import com.sun.star.frame.FrameActionEvent;
30cdf0e10cSrcweir import com.sun.star.frame.XController;
31cdf0e10cSrcweir import com.sun.star.frame.XFrame;
32cdf0e10cSrcweir import com.sun.star.frame.XFrameActionListener;
33cdf0e10cSrcweir import com.sun.star.frame.XFramesSupplier;
34cdf0e10cSrcweir import com.sun.star.lang.EventObject;
35cdf0e10cSrcweir import java.io.PrintWriter;
36cdf0e10cSrcweir import lib.MultiMethodTest;
37cdf0e10cSrcweir import lib.TestEnvironment;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir /**
40cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XFrame</code>
41cdf0e10cSrcweir * interface methods:
42cdf0e10cSrcweir * <ul>
43cdf0e10cSrcweir *  <li><code> getName() </code></li>
44cdf0e10cSrcweir *  <li><code> setName() </code></li>
45cdf0e10cSrcweir *  <li><code> activate() </code></li>
46cdf0e10cSrcweir *  <li><code> deactivate() </code></li>
47cdf0e10cSrcweir *  <li><code> isActive() </code></li>
48cdf0e10cSrcweir *  <li><code> addFrameActionListener() </code></li>
49cdf0e10cSrcweir *  <li><code> removeFrameActionListener() </code></li>
50cdf0e10cSrcweir *  <li><code> getCreator() </code></li>
51cdf0e10cSrcweir *  <li><code> getComponentWindow() </code></li>
52cdf0e10cSrcweir *  <li><code> getContainerWindow() </code></li>
53cdf0e10cSrcweir *  <li><code> getController() </code></li>
54cdf0e10cSrcweir *  <li><code> isTop() </code></li>
55cdf0e10cSrcweir *  <li><code> findFrame() </code></li>
56cdf0e10cSrcweir *  <li><code> contextChanged() </code></li>
57cdf0e10cSrcweir *  <li><code> setCreator() </code></li>
58cdf0e10cSrcweir *  <li><code> setComponent() </code></li>
59cdf0e10cSrcweir *  <li><code> initialize() </code></li>
60cdf0e10cSrcweir * </ul><p>
61cdf0e10cSrcweir * This test needs the following object relations :
62cdf0e10cSrcweir * <ul>
63cdf0e10cSrcweir *  <li> <code>'XFrame'</code> (of type <code>XFrame</code>)
64cdf0e10cSrcweir *  <b>optional</b>: any frame named 'XFrame'.
65cdf0e10cSrcweir *  Could be used by <code>findFrame</code> method to try
66cdf0e10cSrcweir *  to find other frame than itself.</li>
67cdf0e10cSrcweir *
68cdf0e10cSrcweir *  <li> <code>'Desktop'</code> (of type <code>Object</code>):
69cdf0e10cSrcweir *  if exsists, then desktop component is tested</li>
70cdf0e10cSrcweir * </ul> <p>
71cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
72cdf0e10cSrcweir * @see com.sun.star.frame.XFrame
73cdf0e10cSrcweir */
74cdf0e10cSrcweir public class _XFrame extends MultiMethodTest {
75cdf0e10cSrcweir     final FrameAction[] actionEvent = new FrameAction[1] ;
76cdf0e10cSrcweir     final boolean[] listenerCalled = new boolean[] {false} ;
77cdf0e10cSrcweir     final boolean[] activatedCalled = new boolean[] {false} ;
78cdf0e10cSrcweir     final boolean[] deactivatedCalled = new boolean[] {false} ;
79cdf0e10cSrcweir     final TestFrameActionListener listener =
80cdf0e10cSrcweir         new TestFrameActionListener() ;
81cdf0e10cSrcweir     public static XFrame oObj = null;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /**
84cdf0e10cSrcweir     * Class used to test listeners.
85cdf0e10cSrcweir     */
86cdf0e10cSrcweir     private class TestFrameActionListener
87cdf0e10cSrcweir         implements XFrameActionListener {
88cdf0e10cSrcweir 
frameAction(FrameActionEvent e)89cdf0e10cSrcweir         public void frameAction(FrameActionEvent e) {
90cdf0e10cSrcweir             listenerCalled[0] = true ;
91cdf0e10cSrcweir             activatedCalled[0] |= e.Action == FrameAction.FRAME_ACTIVATED;
92cdf0e10cSrcweir             deactivatedCalled[0] |= e.Action == FrameAction.FRAME_DEACTIVATING;
93cdf0e10cSrcweir             actionEvent[0] = e.Action;
94cdf0e10cSrcweir         }
95cdf0e10cSrcweir 
disposing(EventObject e)96cdf0e10cSrcweir         public void disposing(EventObject e) {}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     /**
101cdf0e10cSrcweir     * Test calls the method. <p>
102cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null.
103cdf0e10cSrcweir     */
_getName()104cdf0e10cSrcweir     public void _getName() {
105cdf0e10cSrcweir         String name = oObj.getName() ;
106cdf0e10cSrcweir         if (name == null)
107cdf0e10cSrcweir             log.println("getName() returned null: FAILED") ;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         tRes.tested("getName()", name!=null) ;
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     /**
113cdf0e10cSrcweir     * Test calls the method. <p>
114cdf0e10cSrcweir     * Has <b> OK </b> status if set and gotten names are equal.
115cdf0e10cSrcweir     */
_setName()116cdf0e10cSrcweir     public void _setName() {
117cdf0e10cSrcweir         String sName = "XFrame" ;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         oObj.setName(sName);
120cdf0e10cSrcweir         String gName = oObj.getName();
121cdf0e10cSrcweir         boolean res = sName.equals(gName);
122cdf0e10cSrcweir         if (! res)
123cdf0e10cSrcweir             log.println("setName('" + sName +
124cdf0e10cSrcweir                 "'), but getName() return '" + gName + "'") ;
125cdf0e10cSrcweir         tRes.tested("setName()", res);
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     /**
129cdf0e10cSrcweir     * Test calls the method. <p>
130cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
131cdf0e10cSrcweir     * and no exceptions were thrown.
132cdf0e10cSrcweir     */
_activate()133cdf0e10cSrcweir     public void _activate() {
134cdf0e10cSrcweir         oObj.activate() ;
135cdf0e10cSrcweir         tRes.tested("activate()", true) ;
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     /**
139cdf0e10cSrcweir     * Test calls the method. <p>
140cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
141cdf0e10cSrcweir     * and no exceptions were thrown.
142cdf0e10cSrcweir     */
_deactivate()143cdf0e10cSrcweir     public void _deactivate() {
144cdf0e10cSrcweir         oObj.deactivate() ;
145cdf0e10cSrcweir         oObj.activate() ;
146cdf0e10cSrcweir         tRes.tested("deactivate()", true) ;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     /**
150cdf0e10cSrcweir     * Test calls the method. Then frame is deactivated and method called
151cdf0e10cSrcweir     * again. <p>
152cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() returns true or if the method
153cdf0e10cSrcweir     * always display real status of a frame during activation/deactivation.
154cdf0e10cSrcweir     */
_isActive()155cdf0e10cSrcweir     public void _isActive() {
156cdf0e10cSrcweir         boolean result = true;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
159cdf0e10cSrcweir             log.println("Desktop is always active");
160cdf0e10cSrcweir             tRes.tested("isActive()", oObj.isActive()) ;
161cdf0e10cSrcweir             return;
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         oObj.deactivate();
165cdf0e10cSrcweir         result &= !oObj.isActive();
166cdf0e10cSrcweir         if (oObj.isActive())
167cdf0e10cSrcweir             log.println("after deactivate() method call, isActive() returned true");
168cdf0e10cSrcweir         oObj.activate();
169cdf0e10cSrcweir         result &= oObj.isActive();
170cdf0e10cSrcweir         if (!oObj.isActive())
171cdf0e10cSrcweir             log.println("after activate() method call, isActive() returned false") ;
172cdf0e10cSrcweir         boolean res = isDesktop(log,tEnv,"isActive()");
173cdf0e10cSrcweir         if (res) result=res;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         tRes.tested("isActive()", result) ;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /**
179cdf0e10cSrcweir     * Test calls the method. Then frame status (activated/deactivated) is
180cdf0e10cSrcweir     * changed, and the listener is checked.<p>
181cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() method returnes true, or if the
182cdf0e10cSrcweir     * listener was called and frame was activated.
183cdf0e10cSrcweir     */
_addFrameActionListener()184cdf0e10cSrcweir     public void _addFrameActionListener() {
185cdf0e10cSrcweir         boolean result = true ;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         oObj.addFrameActionListener(listener) ;
188cdf0e10cSrcweir         oObj.activate() ;
189cdf0e10cSrcweir         oObj.deactivate() ;
190cdf0e10cSrcweir         oObj.activate() ;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
193cdf0e10cSrcweir             log.println("No actions supported by Desktop");
194cdf0e10cSrcweir             tRes.tested("addFrameActionListener()", true) ;
195cdf0e10cSrcweir             return;
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         try {
199cdf0e10cSrcweir             Thread.sleep(500);
200cdf0e10cSrcweir         }catch (InterruptedException ex) {}
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         if (!listenerCalled[0]) {
204cdf0e10cSrcweir             log.println("listener was not called.") ;
205cdf0e10cSrcweir             result = false ;
206cdf0e10cSrcweir         } else {
207cdf0e10cSrcweir             if (!activatedCalled[0]) {
208cdf0e10cSrcweir                 log.println("Listener was called, FRAME_ACTIVATED was not") ;
209cdf0e10cSrcweir                 result = false ;
210cdf0e10cSrcweir             }
211cdf0e10cSrcweir             if (!deactivatedCalled[0]) {
212cdf0e10cSrcweir                 log.println("Listener was called, FRAME_DEACTIVATING was not") ;
213cdf0e10cSrcweir                 result = false ;
214cdf0e10cSrcweir             }
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         boolean res = isDesktop(log, tEnv, "addFrameActionListener()");
218cdf0e10cSrcweir         if (res) result=res;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         tRes.tested("addFrameActionListener()", result) ;
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     /**
224cdf0e10cSrcweir     * Test calls the method.  Then frame status (activated/deactivated) is
225cdf0e10cSrcweir     * changed, and the listener is checked.<p>
226cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() method returns true, or if the
227cdf0e10cSrcweir     * method actually removes listener so it does not react on
228cdf0e10cSrcweir     * activate/deactivate events. <p>
229cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
230cdf0e10cSrcweir     * <ul>
231cdf0e10cSrcweir     *  <li> <code> addFrameActionListener() </code>: adds action listener
232cdf0e10cSrcweir     * to a frame </li>
233cdf0e10cSrcweir     * </ul>
234cdf0e10cSrcweir     */
_removeFrameActionListener()235cdf0e10cSrcweir     public void _removeFrameActionListener() {
236cdf0e10cSrcweir         boolean result = true;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         requiredMethod("addFrameActionListener()");
239cdf0e10cSrcweir         listenerCalled[0] = false;
240cdf0e10cSrcweir         oObj.removeFrameActionListener(listener);
241cdf0e10cSrcweir         oObj.activate();
242cdf0e10cSrcweir         oObj.deactivate();
243cdf0e10cSrcweir         oObj.activate();
244cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
245cdf0e10cSrcweir             log.println("No actions supported by Desktop");
246cdf0e10cSrcweir             tRes.tested("removeFrameActionListener()", true) ;
247cdf0e10cSrcweir             return;
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         if (listenerCalled[0])
251cdf0e10cSrcweir             log.println("Listener wasn't removed, and was called");
252cdf0e10cSrcweir         boolean res = isDesktop(log, tEnv, "removeFrameActionListener()");
253cdf0e10cSrcweir         if (res) result=res; else result = (!listenerCalled[0]);
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         tRes.tested("removeFrameActionListener()", result);
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     /**
259cdf0e10cSrcweir     * Test calls the method. <p>
260cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() method returns true or if the method
261cdf0e10cSrcweir     * does not return null.
262cdf0e10cSrcweir     */
_getCreator()263cdf0e10cSrcweir     public void _getCreator() {
264cdf0e10cSrcweir         boolean result = true;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
267cdf0e10cSrcweir             log.println("Desktop has no creator");
268cdf0e10cSrcweir             tRes.tested("getCreator()", true) ;
269cdf0e10cSrcweir             return;
270cdf0e10cSrcweir         }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         XFramesSupplier creator = oObj.getCreator() ;
273cdf0e10cSrcweir         if (creator == null)
274cdf0e10cSrcweir             log.println("getCreator() returns null") ;
275cdf0e10cSrcweir         boolean res = isDesktop(log,tEnv,"getCreator()");
276cdf0e10cSrcweir         if (res) result=res; else result = (creator != null);
277cdf0e10cSrcweir         tRes.tested("getCreator()", result) ;
278cdf0e10cSrcweir     }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     /**
281cdf0e10cSrcweir     * Test calls the method. <p>
282cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() method returns true or if the method
283cdf0e10cSrcweir     * does not return null.
284cdf0e10cSrcweir     */
_getComponentWindow()285cdf0e10cSrcweir     public void _getComponentWindow() {
286cdf0e10cSrcweir         boolean result = true;
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         XWindow win = oObj.getComponentWindow() ;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
291cdf0e10cSrcweir             log.println("Desktop has no component window");
292cdf0e10cSrcweir             tRes.tested("getComponentWindow()", true) ;
293cdf0e10cSrcweir             return;
294cdf0e10cSrcweir         }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         if (win == null)
297cdf0e10cSrcweir             log.println("getComponentWindow() returns null") ;
298cdf0e10cSrcweir         boolean res = isDesktop(log,tEnv,"getComponentWindow()");
299cdf0e10cSrcweir         if (res) result=res; else result = (win != null);
300cdf0e10cSrcweir         tRes.tested("getComponentWindow()", result) ;
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     /**
304cdf0e10cSrcweir     * Test calls the method. <p>
305cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() method returns true or if the method
306cdf0e10cSrcweir     * does not return null.
307cdf0e10cSrcweir     */
_getContainerWindow()308cdf0e10cSrcweir     public void _getContainerWindow() {
309cdf0e10cSrcweir         boolean result = true;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
312cdf0e10cSrcweir             log.println("Desktop has no container window");
313cdf0e10cSrcweir             tRes.tested("getContainerWindow()", true) ;
314cdf0e10cSrcweir             return;
315cdf0e10cSrcweir         }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir         XWindow win = oObj.getContainerWindow() ;
318cdf0e10cSrcweir         if (win == null)
319cdf0e10cSrcweir             log.println("getContainerWindow() returns null") ;
320cdf0e10cSrcweir         boolean res = isDesktop(log,tEnv,"getContainerWindow()");
321cdf0e10cSrcweir         if (res) result=res; else result = (win != null);
322cdf0e10cSrcweir         tRes.tested("getContainerWindow()", result) ;
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     /**
326cdf0e10cSrcweir     * Test calls the method. Then returned controller is checked. <p>
327cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() method returns true or
328cdf0e10cSrcweir     * if the method returns non-null controller, having frame that's equal to
329cdf0e10cSrcweir     * a (XFrame) oObj.
330cdf0e10cSrcweir     */
_getController()331cdf0e10cSrcweir     public void _getController() {
332cdf0e10cSrcweir         boolean result = true;
333cdf0e10cSrcweir         XController ctrl = oObj.getController();
334cdf0e10cSrcweir 
335cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
336cdf0e10cSrcweir             log.println("Desktop has no controller");
337cdf0e10cSrcweir             tRes.tested("getController()", true) ;
338cdf0e10cSrcweir             return;
339cdf0e10cSrcweir         }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         if (ctrl == null) {
342cdf0e10cSrcweir             log.println("getController() returns null");
343cdf0e10cSrcweir             result = false;
344cdf0e10cSrcweir         } else {
345cdf0e10cSrcweir             XFrame frm = ctrl.getFrame();
346cdf0e10cSrcweir             if (!oObj.equals(frm)) {
347cdf0e10cSrcweir                 log.println("Frame returned by controller not " +
348cdf0e10cSrcweir                     "equals to frame testing");
349cdf0e10cSrcweir                 result = false;
350cdf0e10cSrcweir             }
351cdf0e10cSrcweir         }
352cdf0e10cSrcweir         boolean res = isDesktop(log, tEnv, "getController()");
353cdf0e10cSrcweir         if (res) result=res;
354cdf0e10cSrcweir         tRes.tested("getController()", result) ;
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     /**
358cdf0e10cSrcweir     * Test calls the method. <p>
359cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
360cdf0e10cSrcweir     * and no exceptions were thrown.
361cdf0e10cSrcweir     */
_isTop()362cdf0e10cSrcweir     public void _isTop() {
363cdf0e10cSrcweir         log.println("isTop() = " + oObj.isTop());
364cdf0e10cSrcweir         tRes.tested("isTop()", true) ;
365cdf0e10cSrcweir     }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     /**
368cdf0e10cSrcweir     * After obtaining an object relation 'XFrame', test tries to find a frame
369cdf0e10cSrcweir     * named 'XFrame'. <p>
370cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns non-null object that's equal
371cdf0e10cSrcweir     * to previously obtained object relation.
372cdf0e10cSrcweir     */
_findFrame()373cdf0e10cSrcweir     public void _findFrame() {
374cdf0e10cSrcweir         boolean result = true ;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         XFrame aFrame = (XFrame) tEnv.getObjRelation("XFrame");
377cdf0e10cSrcweir 
378cdf0e10cSrcweir         if (aFrame != null) {
379cdf0e10cSrcweir             log.println("Trying to find a frame with name 'XFrame' ...");
380cdf0e10cSrcweir             XFrame frame = oObj.findFrame("XFrame",
381cdf0e10cSrcweir                 com.sun.star.frame.FrameSearchFlag.GLOBAL) ;
382cdf0e10cSrcweir             if (frame == null) {
383cdf0e10cSrcweir                 log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ;
384cdf0e10cSrcweir                 result = false ;
385cdf0e10cSrcweir             } else if ( !aFrame.equals(frame) ) {
386cdf0e10cSrcweir                 log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") "
387cdf0e10cSrcweir                     + " returns frame which is not equal to passed in relation") ;
388cdf0e10cSrcweir                 result = false ;
389cdf0e10cSrcweir             }
390cdf0e10cSrcweir         }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         log.println("Trying to find a frame with name '_self' ...");
393cdf0e10cSrcweir         XFrame frame = oObj.findFrame("_self",
394cdf0e10cSrcweir             com.sun.star.frame.FrameSearchFlag.AUTO) ;
395cdf0e10cSrcweir         if (frame == null) {
396cdf0e10cSrcweir             log.println("findFrame(\"_self\") returns null") ;
397cdf0e10cSrcweir             result = false ;
398cdf0e10cSrcweir         } else if ( !oObj.equals(frame) ) {
399cdf0e10cSrcweir             log.println("findFrame(\"_self\") "
400cdf0e10cSrcweir                 + " returns frame which is not equal to tested") ;
401cdf0e10cSrcweir             result = false ;
402cdf0e10cSrcweir         }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir         tRes.tested("findFrame()", result) ;
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     /**
408cdf0e10cSrcweir     * At first new listener is added, then test calls the method and result
409cdf0e10cSrcweir     * is checked. <p>
410cdf0e10cSrcweir     * Has <b> OK </b> status if isDesktop() method returnes true or if the
411cdf0e10cSrcweir     * listener was called and proper event past to listener.
412cdf0e10cSrcweir     */
_contextChanged()413cdf0e10cSrcweir     public void _contextChanged() {
414cdf0e10cSrcweir         boolean result = true;
415cdf0e10cSrcweir         TestFrameActionListener listener = new TestFrameActionListener();
416cdf0e10cSrcweir 
417cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
418cdf0e10cSrcweir             log.println("Desktop cann't change context");
419cdf0e10cSrcweir             tRes.tested("contextChanged()", true) ;
420cdf0e10cSrcweir             return;
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir         listenerCalled[0] = false;
424cdf0e10cSrcweir         oObj.addFrameActionListener(listener);
425cdf0e10cSrcweir         try {
426cdf0e10cSrcweir             oObj.contextChanged();
427cdf0e10cSrcweir             if ( !listenerCalled[0] ) {
428cdf0e10cSrcweir                 log.println("listener was not called on contextChanged() call.") ;
429cdf0e10cSrcweir                 result = false;
430cdf0e10cSrcweir             } else if (actionEvent[0] != FrameAction.CONTEXT_CHANGED) {
431cdf0e10cSrcweir                 log.println("listener was called, but Action != CONTEXT_CHANGED") ;
432cdf0e10cSrcweir                 result = false;
433cdf0e10cSrcweir             }
434cdf0e10cSrcweir         } finally {
435cdf0e10cSrcweir             oObj.removeFrameActionListener(listener);
436cdf0e10cSrcweir         }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir         boolean res = isDesktop(log, tEnv, "contextChanged()");
439cdf0e10cSrcweir         if (res) result = res;
440cdf0e10cSrcweir         tRes.tested("contextChanged()", result);
441cdf0e10cSrcweir     }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 
444cdf0e10cSrcweir     /**
445cdf0e10cSrcweir     * Test calls the method. Remembered old creater is restored at the end. <p>
446cdf0e10cSrcweir     * Has <b> OK </b> status if the method sucessfully set new value to (XFrame)
447cdf0e10cSrcweir     * oObj object.
448cdf0e10cSrcweir     */
_setCreator()449cdf0e10cSrcweir     public void _setCreator() {
450cdf0e10cSrcweir         if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
451cdf0e10cSrcweir             log.println("Desktop has no creator");
452cdf0e10cSrcweir             tRes.tested("setCreator()", true) ;
453cdf0e10cSrcweir             return;
454cdf0e10cSrcweir         }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir         XFramesSupplier oldCreator = oObj.getCreator() ;
457cdf0e10cSrcweir         oObj.setCreator(null) ;
458cdf0e10cSrcweir         tRes.tested("setCreator()", oObj.getCreator() == null) ;
459cdf0e10cSrcweir         oObj.setCreator(oldCreator) ;
460cdf0e10cSrcweir     }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     /**
463cdf0e10cSrcweir     * Test calls the method, then result is checked.<p>
464cdf0e10cSrcweir     * Has <b> OK </b> status if method returns true, and values, set by the
465cdf0e10cSrcweir     * method are nulls, or if method returns false, and values are not changed.
466cdf0e10cSrcweir     * This method destroy the object. Therfore all other methods have to be
467cdf0e10cSrcweir     * executed before :
468cdf0e10cSrcweir     * <ul>
469cdf0e10cSrcweir     *  <li> <code> getName() </code>
470cdf0e10cSrcweir     *  <li> <code> setName() </code>
471cdf0e10cSrcweir     *  <li> <code> activate() </code>
472cdf0e10cSrcweir     *  <li> <code> deactivate() </code>
473cdf0e10cSrcweir     *  <li> <code> isActive() </code>
474cdf0e10cSrcweir     *  <li> <code> addFrameActionListener() </code>
475cdf0e10cSrcweir     *  <li> <code> getComponentWindow() </code>
476cdf0e10cSrcweir     *  <li> <code> getContainerWindow() </code>
477cdf0e10cSrcweir     *  <li> <code> getController() </code>
478cdf0e10cSrcweir     *  <li> <code> isTop() </code>
479cdf0e10cSrcweir     *  <li> <code> findFrame() </code>
480cdf0e10cSrcweir     *  <li> <code> contextChanged() </code>
481cdf0e10cSrcweir     *  <li> <code> setCreator() </code>
482cdf0e10cSrcweir     *  object</li>
483cdf0e10cSrcweir     * </ul>
484cdf0e10cSrcweir     */
_setComponent()485cdf0e10cSrcweir     public void _setComponent() {
486cdf0e10cSrcweir         // setComponent() destr
487cdf0e10cSrcweir         requiredMethod("getName()") ;
488cdf0e10cSrcweir         requiredMethod("setName()") ;
489cdf0e10cSrcweir         requiredMethod("activate()") ;
490cdf0e10cSrcweir         requiredMethod("deactivate()") ;
491cdf0e10cSrcweir         requiredMethod("isActive()") ;
492cdf0e10cSrcweir         requiredMethod("addFrameActionListener()") ;
493cdf0e10cSrcweir         requiredMethod("getComponentWindow()") ;
494cdf0e10cSrcweir         requiredMethod("getContainerWindow()") ;
495cdf0e10cSrcweir         requiredMethod("getController()") ;
496cdf0e10cSrcweir         requiredMethod("isTop()") ;
497cdf0e10cSrcweir         requiredMethod("findFrame()") ;
498cdf0e10cSrcweir         requiredMethod("contextChanged()") ;
499cdf0e10cSrcweir         requiredMethod("setCreator()") ;
500cdf0e10cSrcweir 
501cdf0e10cSrcweir         boolean result = true;
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         XWindow oldWindow = oObj.getComponentWindow();
504cdf0e10cSrcweir         XController oldController = oObj.getController();
505cdf0e10cSrcweir         boolean rs = oObj.setComponent(null, null);
506cdf0e10cSrcweir         if (rs) {  // component must be changed
507cdf0e10cSrcweir             result &= oObj.getComponentWindow() == null;
508cdf0e10cSrcweir             result &= oObj.getController() == null;
509cdf0e10cSrcweir             if (!result)
510cdf0e10cSrcweir                 log.println("setComponent() returns true, but component is " +
511cdf0e10cSrcweir                  "not changed.");
512cdf0e10cSrcweir         } else {   // frame is not allowed to change component
513cdf0e10cSrcweir             result &= oObj.getComponentWindow() == oldWindow ;
514cdf0e10cSrcweir             result &= oObj.getController() == oldController ;
515cdf0e10cSrcweir             if (!result)
516cdf0e10cSrcweir                 log.println("setComponent() returns false, but component is" +
517cdf0e10cSrcweir                  "changed.");
518cdf0e10cSrcweir         }
519cdf0e10cSrcweir         tRes.tested("setComponent()", result);
520cdf0e10cSrcweir 
521cdf0e10cSrcweir     }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     /**
524cdf0e10cSrcweir      * Test calls the method. <p>
525cdf0e10cSrcweir      * Has <b> OK </b> status if the method successfully returns.
526cdf0e10cSrcweir      * In case a frame should initialised twice, a
527cdf0e10cSrcweir      * <CODE>com.sun.star.uno.RuntimeException</CODE> was thron. This is ok. But since
528cdf0e10cSrcweir      * a com.sun.star.uno.RuntimeException could thrown in any state the message of
529cdf0e10cSrcweir      * the exception must contain a defined string. In this case the test get an
530cdf0e10cSrcweir      * <CODE>OK</CODE> status.
531cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
532cdf0e10cSrcweir      * <ul>
533cdf0e10cSrcweir      *  <li> <code> setComponent() </code> : sets window and controller to the
534cdf0e10cSrcweir      *  object</li>
535cdf0e10cSrcweir      * </ul>
536cdf0e10cSrcweir      */
_initialize()537cdf0e10cSrcweir     public void _initialize() {
538cdf0e10cSrcweir         requiredMethod("setComponent()") ;
539cdf0e10cSrcweir         XWindow win = oObj.getContainerWindow() ;
540cdf0e10cSrcweir         boolean bOK = true;
541cdf0e10cSrcweir         try {
542cdf0e10cSrcweir             oObj.initialize(win) ;
543cdf0e10cSrcweir         } catch (com.sun.star.uno.RuntimeException e){
544cdf0e10cSrcweir             String message="Frame::initialized() is called more then once, which isnt usefull nor allowed.";
545cdf0e10cSrcweir             if (e.toString().indexOf(message) != -1){
546cdf0e10cSrcweir                 log.println(e.toString());
547cdf0e10cSrcweir                 log.println("methods throws exception, but it's OK");
548cdf0e10cSrcweir             }else{
549cdf0e10cSrcweir                 log.println(e.toString());
550cdf0e10cSrcweir                 bOK=false;
551cdf0e10cSrcweir             }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir         }
554cdf0e10cSrcweir         tRes.tested("initialize()", bOK) ;
555cdf0e10cSrcweir     }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     /**
558cdf0e10cSrcweir     * Checks does relation 'Desktop' exist. Returns true if exist.
559cdf0e10cSrcweir     */
isDesktop(PrintWriter log, TestEnvironment env, String method)560cdf0e10cSrcweir     public static boolean isDesktop(PrintWriter log,
561cdf0e10cSrcweir             TestEnvironment env, String method) {
562cdf0e10cSrcweir         Object isD = env.getObjRelation("Desktop");
563cdf0e10cSrcweir         if (isD != null) {
564cdf0e10cSrcweir             log.println("The Desktop doesn't support the method " + method);
565cdf0e10cSrcweir             log.println("It will always return true");
566cdf0e10cSrcweir             return true;
567cdf0e10cSrcweir         }
568cdf0e10cSrcweir         else {
569cdf0e10cSrcweir             return false;
570cdf0e10cSrcweir         }
571cdf0e10cSrcweir     }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     /**
574cdf0e10cSrcweir     * Forces environment recreation.
575cdf0e10cSrcweir     */
after()576cdf0e10cSrcweir     public void after() {
577cdf0e10cSrcweir         disposeEnvironment();
578cdf0e10cSrcweir     }
579cdf0e10cSrcweir }
580