summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/java/ifc/frame/_XFrame.java
blob: 41333721f8dfcfc4138c468b19e3132abe212b8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

package ifc.frame;

import com.sun.star.awt.XWindow;
//import com.sun.star.awt.XWindow;
import com.sun.star.frame.FrameAction;
import com.sun.star.frame.FrameActionEvent;
import com.sun.star.frame.XController;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XFrameActionListener;
import com.sun.star.frame.XFramesSupplier;
import com.sun.star.lang.EventObject;
import java.io.PrintWriter;
import lib.MultiMethodTest;
import lib.TestEnvironment;

/**
* Testing <code>com.sun.star.frame.XFrame</code>
* interface methods:
* <ul>
*  <li><code> getName() </code></li>
*  <li><code> setName() </code></li>
*  <li><code> activate() </code></li>
*  <li><code> deactivate() </code></li>
*  <li><code> isActive() </code></li>
*  <li><code> addFrameActionListener() </code></li>
*  <li><code> removeFrameActionListener() </code></li>
*  <li><code> getCreator() </code></li>
*  <li><code> getComponentWindow() </code></li>
*  <li><code> getContainerWindow() </code></li>
*  <li><code> getController() </code></li>
*  <li><code> isTop() </code></li>
*  <li><code> findFrame() </code></li>
*  <li><code> contextChanged() </code></li>
*  <li><code> setCreator() </code></li>
*  <li><code> setComponent() </code></li>
*  <li><code> initialize() </code></li>
* </ul><p>
* This test needs the following object relations :
* <ul>
*  <li> <code>'XFrame'</code> (of type <code>XFrame</code>)
*  <b>optional</b>: any frame named 'XFrame'.
*  Could be used by <code>findFrame</code> method to try
*  to find other frame than itself.</li>
*
*  <li> <code>'Desktop'</code> (of type <code>Object</code>):
*  if exsists, then desktop component is tested</li>
* </ul> <p>
* Test is <b> NOT </b> multithread compliant. <p>
* @see com.sun.star.frame.XFrame
*/
public class _XFrame extends MultiMethodTest {
    final FrameAction[] actionEvent = new FrameAction[1] ;
    final boolean[] listenerCalled = new boolean[] {false} ;
    final boolean[] activatedCalled = new boolean[] {false} ;
    final boolean[] deactivatedCalled = new boolean[] {false} ;
    final TestFrameActionListener listener =
        new TestFrameActionListener() ;
    public static XFrame oObj = null;

    /**
    * Class used to test listeners.
    */
    private class TestFrameActionListener
        implements XFrameActionListener {

        public void frameAction(FrameActionEvent e) {
            listenerCalled[0] = true ;
            activatedCalled[0] |= e.Action == FrameAction.FRAME_ACTIVATED;
            deactivatedCalled[0] |= e.Action == FrameAction.FRAME_DEACTIVATING;
            actionEvent[0] = e.Action;
        }

        public void disposing(EventObject e) {}

    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if the method does not return null.
    */
    public void _getName() {
        String name = oObj.getName() ;
        if (name == null)
            log.println("getName() returned null: FAILED") ;

        tRes.tested("getName()", name!=null) ;
    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if set and gotten names are equal.
    */
    public void _setName() {
        String sName = "XFrame" ;

        oObj.setName(sName);
        String gName = oObj.getName();
        boolean res = sName.equals(gName);
        if (! res)
            log.println("setName('" + sName +
                "'), but getName() return '" + gName + "'") ;
        tRes.tested("setName()", res);
    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if the method successfully returns
    * and no exceptions were thrown.
    */
    public void _activate() {
        oObj.activate() ;
        tRes.tested("activate()", true) ;
    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if the method successfully returns
    * and no exceptions were thrown.
    */
    public void _deactivate() {
        oObj.deactivate() ;
        oObj.activate() ;
        tRes.tested("deactivate()", true) ;
    }

    /**
    * Test calls the method. Then frame is deactivated and method called
    * again. <p>
    * Has <b> OK </b> status if isDesktop() returns true or if the method
    * always display real status of a frame during activation/deactivation.
    */
    public void _isActive() {
        boolean result = true;

        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("Desktop is always active");
            tRes.tested("isActive()", oObj.isActive()) ;
            return;
        }

        oObj.deactivate();
        result &= !oObj.isActive();
        if (oObj.isActive())
            log.println("after deactivate() method call, isActive() returned true");
        oObj.activate();
        result &= oObj.isActive();
        if (!oObj.isActive())
            log.println("after activate() method call, isActive() returned false") ;
        boolean res = isDesktop(log,tEnv,"isActive()");
        if (res) result=res;

        tRes.tested("isActive()", result) ;
    }

    /**
    * Test calls the method. Then frame status (activated/deactivated) is
    * changed, and the listener is checked.<p>
    * Has <b> OK </b> status if isDesktop() method returnes true, or if the
    * listener was called and frame was activated.
    */
    public void _addFrameActionListener() {
        boolean result = true ;

        oObj.addFrameActionListener(listener) ;
        oObj.activate() ;
        oObj.deactivate() ;
        oObj.activate() ;

        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("No actions supported by Desktop");
            tRes.tested("addFrameActionListener()", true) ;
            return;
        }

        try {
            Thread.sleep(500);
        }catch (InterruptedException ex) {}


        if (!listenerCalled[0]) {
            log.println("listener was not called.") ;
            result = false ;
        } else {
            if (!activatedCalled[0]) {
                log.println("Listener was called, FRAME_ACTIVATED was not") ;
                result = false ;
            }
            if (!deactivatedCalled[0]) {
                log.println("Listener was called, FRAME_DEACTIVATING was not") ;
                result = false ;
            }
        }

        boolean res = isDesktop(log, tEnv, "addFrameActionListener()");
        if (res) result=res;

        tRes.tested("addFrameActionListener()", result) ;
    }

    /**
    * Test calls the method.  Then frame status (activated/deactivated) is
    * changed, and the listener is checked.<p>
    * Has <b> OK </b> status if isDesktop() method returns true, or if the
    * method actually removes listener so it does not react on
    * activate/deactivate events. <p>
    * The following method tests are to be completed successfully before :
    * <ul>
    *  <li> <code> addFrameActionListener() </code>: adds action listener
    * to a frame </li>
    * </ul>
    */
    public void _removeFrameActionListener() {
        boolean result = true;

        requiredMethod("addFrameActionListener()");
        listenerCalled[0] = false;
        oObj.removeFrameActionListener(listener);
        oObj.activate();
        oObj.deactivate();
        oObj.activate();
        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("No actions supported by Desktop");
            tRes.tested("removeFrameActionListener()", true) ;
            return;
        }

        if (listenerCalled[0])
            log.println("Listener wasn't removed, and was called");
        boolean res = isDesktop(log, tEnv, "removeFrameActionListener()");
        if (res) result=res; else result = (!listenerCalled[0]);

        tRes.tested("removeFrameActionListener()", result);
    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if isDesktop() method returns true or if the method
    * does not return null.
    */
    public void _getCreator() {
        boolean result = true;

        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("Desktop has no creator");
            tRes.tested("getCreator()", true) ;
            return;
        }

        XFramesSupplier creator = oObj.getCreator() ;
        if (creator == null)
            log.println("getCreator() returns null") ;
        boolean res = isDesktop(log,tEnv,"getCreator()");
        if (res) result=res; else result = (creator != null);
        tRes.tested("getCreator()", result) ;
    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if isDesktop() method returns true or if the method
    * does not return null.
    */
    public void _getComponentWindow() {
        boolean result = true;

        XWindow win = oObj.getComponentWindow() ;

        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("Desktop has no component window");
            tRes.tested("getComponentWindow()", true) ;
            return;
        }

        if (win == null)
            log.println("getComponentWindow() returns null") ;
        boolean res = isDesktop(log,tEnv,"getComponentWindow()");
        if (res) result=res; else result = (win != null);
        tRes.tested("getComponentWindow()", result) ;
    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if isDesktop() method returns true or if the method
    * does not return null.
    */
    public void _getContainerWindow() {
        boolean result = true;

        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("Desktop has no container window");
            tRes.tested("getContainerWindow()", true) ;
            return;
        }

        XWindow win = oObj.getContainerWindow() ;
        if (win == null)
            log.println("getContainerWindow() returns null") ;
        boolean res = isDesktop(log,tEnv,"getContainerWindow()");
        if (res) result=res; else result = (win != null);
        tRes.tested("getContainerWindow()", result) ;
    }

    /**
    * Test calls the method. Then returned controller is checked. <p>
    * Has <b> OK </b> status if isDesktop() method returns true or
    * if the method returns non-null controller, having frame that's equal to
    * a (XFrame) oObj.
    */
    public void _getController() {
        boolean result = true;
        XController ctrl = oObj.getController();

        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("Desktop has no controller");
            tRes.tested("getController()", true) ;
            return;
        }

        if (ctrl == null) {
            log.println("getController() returns null");
            result = false;
        } else {
            XFrame frm = ctrl.getFrame();
            if (!oObj.equals(frm)) {
                log.println("Frame returned by controller not " +
                    "equals to frame testing");
                result = false;
            }
        }
        boolean res = isDesktop(log, tEnv, "getController()");
        if (res) result=res;
        tRes.tested("getController()", result) ;
    }

    /**
    * Test calls the method. <p>
    * Has <b> OK </b> status if the method successfully returns
    * and no exceptions were thrown.
    */
    public void _isTop() {
        log.println("isTop() = " + oObj.isTop());
        tRes.tested("isTop()", true) ;
    }

    /**
    * After obtaining an object relation 'XFrame', test tries to find a frame
    * named 'XFrame'. <p>
    * Has <b> OK </b> status if the method returns non-null object that's equal
    * to previously obtained object relation.
    */
    public void _findFrame() {
        boolean result = true ;

        XFrame aFrame = (XFrame) tEnv.getObjRelation("XFrame");

        if (aFrame != null) {
            log.println("Trying to find a frame with name 'XFrame' ...");
            XFrame frame = oObj.findFrame("XFrame",
                com.sun.star.frame.FrameSearchFlag.GLOBAL) ;
            if (frame == null) {
                log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ;
                result = false ;
            } else if ( !aFrame.equals(frame) ) {
                log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") "
                    + " returns frame which is not equal to passed in relation") ;
                result = false ;
            }
        }

        log.println("Trying to find a frame with name '_self' ...");
        XFrame frame = oObj.findFrame("_self",
            com.sun.star.frame.FrameSearchFlag.AUTO) ;
        if (frame == null) {
            log.println("findFrame(\"_self\") returns null") ;
            result = false ;
        } else if ( !oObj.equals(frame) ) {
            log.println("findFrame(\"_self\") "
                + " returns frame which is not equal to tested") ;
            result = false ;
        }

        tRes.tested("findFrame()", result) ;
    }

    /**
    * At first new listener is added, then test calls the method and result
    * is checked. <p>
    * Has <b> OK </b> status if isDesktop() method returnes true or if the
    * listener was called and proper event past to listener.
    */
    public void _contextChanged() {
        boolean result = true;
        TestFrameActionListener listener = new TestFrameActionListener();

        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("Desktop cann't change context");
            tRes.tested("contextChanged()", true) ;
            return;
        }

        listenerCalled[0] = false;
        oObj.addFrameActionListener(listener);
        try {
            oObj.contextChanged();
            if ( !listenerCalled[0] ) {
                log.println("listener was not called on contextChanged() call.") ;
                result = false;
            } else if (actionEvent[0] != FrameAction.CONTEXT_CHANGED) {
                log.println("listener was called, but Action != CONTEXT_CHANGED") ;
                result = false;
            }
        } finally {
            oObj.removeFrameActionListener(listener);
        }

        boolean res = isDesktop(log, tEnv, "contextChanged()");
        if (res) result = res;
        tRes.tested("contextChanged()", result);
    }


    /**
    * Test calls the method. Remembered old creater is restored at the end. <p>
    * Has <b> OK </b> status if the method successfully set new value to (XFrame)
    * oObj object.
    */
    public void _setCreator() {
        if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
            log.println("Desktop has no creator");
            tRes.tested("setCreator()", true) ;
            return;
        }

        XFramesSupplier oldCreator = oObj.getCreator() ;
        oObj.setCreator(null) ;
        tRes.tested("setCreator()", oObj.getCreator() == null) ;
        oObj.setCreator(oldCreator) ;
    }

    /**
    * Test calls the method, then result is checked.<p>
    * Has <b> OK </b> status if method returns true, and values, set by the
    * method are nulls, or if method returns false, and values are not changed.
    * This method destroy the object. Therfore all other methods have to be
    * executed before :
    * <ul>
    *  <li> <code> getName() </code>
    *  <li> <code> setName() </code>
    *  <li> <code> activate() </code>
    *  <li> <code> deactivate() </code>
    *  <li> <code> isActive() </code>
    *  <li> <code> addFrameActionListener() </code>
    *  <li> <code> getComponentWindow() </code>
    *  <li> <code> getContainerWindow() </code>
    *  <li> <code> getController() </code>
    *  <li> <code> isTop() </code>
    *  <li> <code> findFrame() </code>
    *  <li> <code> contextChanged() </code>
    *  <li> <code> setCreator() </code>
    *  object</li>
    * </ul>
    */
    public void _setComponent() {
        // setComponent() destr
        requiredMethod("getName()") ;
        requiredMethod("setName()") ;
        requiredMethod("activate()") ;
        requiredMethod("deactivate()") ;
        requiredMethod("isActive()") ;
        requiredMethod("addFrameActionListener()") ;
        requiredMethod("getComponentWindow()") ;
        requiredMethod("getContainerWindow()") ;
        requiredMethod("getController()") ;
        requiredMethod("isTop()") ;
        requiredMethod("findFrame()") ;
        requiredMethod("contextChanged()") ;
        requiredMethod("setCreator()") ;

        boolean result = true;

        XWindow oldWindow = oObj.getComponentWindow();
        XController oldController = oObj.getController();
        boolean rs = oObj.setComponent(null, null);
        if (rs) {  // component must be changed
            result &= oObj.getComponentWindow() == null;
            result &= oObj.getController() == null;
            if (!result)
                log.println("setComponent() returns true, but component is " +
                 "not changed.");
        } else {   // frame is not allowed to change component
            result &= oObj.getComponentWindow() == oldWindow ;
            result &= oObj.getController() == oldController ;
            if (!result)
                log.println("setComponent() returns false, but component is" +
                 "changed.");
        }
        tRes.tested("setComponent()", result);

    }

    /**
     * Test calls the method. <p>
     * Has <b> OK </b> status if the method successfully returns.
     * In case a frame should initialised twice, a
     * <CODE>com.sun.star.uno.RuntimeException</CODE> was thron. This is ok. But since
     * a com.sun.star.uno.RuntimeException could thrown in any state the message of
     * the exception must contain a defined string. In this case the test get an
     * <CODE>OK</CODE> status.
     * The following method tests are to be completed successfully before :
     * <ul>
     *  <li> <code> setComponent() </code> : sets window and controller to the
     *  object</li>
     * </ul>
     */
    public void _initialize() {
        requiredMethod("setComponent()") ;
        XWindow win = oObj.getContainerWindow() ;
        boolean bOK = true;
        try {
            oObj.initialize(win) ;
        } catch (com.sun.star.uno.RuntimeException e){
            String message="Frame::initialized() is called more than once, which isnt useful nor allowed.";
            if (e.toString().indexOf(message) != -1){
                log.println(e.toString());
                log.println("methods throws exception, but it's OK");
            }else{
                log.println(e.toString());
                bOK=false;
            }

        }
        tRes.tested("initialize()", bOK) ;
    }

    /**
    * Checks does relation 'Desktop' exist. Returns true if exist.
    */
    public static boolean isDesktop(PrintWriter log,
            TestEnvironment env, String method) {
        Object isD = env.getObjRelation("Desktop");
        if (isD != null) {
            log.println("The Desktop doesn't support the method " + method);
            log.println("It will always return true");
            return true;
        }
        else {
            return false;
        }
    }

    /**
    * Forces environment recreation.
    */
    public void after() {
        disposeEnvironment();
    }
}