Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XActivationBroadcaster.java
blob5d2d15dc662821a7742751a73baed6b6504303a2
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
18 package ifc.sheet;
20 import com.sun.star.sheet.XActivationBroadcaster;
21 import com.sun.star.sheet.XActivationEventListener;
22 import com.sun.star.sheet.XSpreadsheet;
23 import com.sun.star.sheet.XSpreadsheetView;
24 import com.sun.star.uno.UnoRuntime;
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
31 public class _XActivationBroadcaster extends MultiMethodTest {
32 public XActivationBroadcaster oObj;
33 protected boolean listenerCalled = false;
34 protected XSpreadsheetView xSpreadsheetView = null;
35 protected XActivationEventListener listener = null;
36 protected XSpreadsheet two = null;
38 public void _addActivationEventListener() {
40 log.println("trying to add an invalid listener");
41 oObj.addActivationEventListener(listener);
42 log.println(".... OK");
44 log.println("adding a valid listener");
45 listener = new MyListener();
46 oObj.addActivationEventListener(listener);
48 XSpreadsheet org = xSpreadsheetView.getActiveSheet();
49 xSpreadsheetView.setActiveSheet(two);
51 if (!listenerCalled) {
52 log.println("Listener wasn't called");
55 xSpreadsheetView.setActiveSheet(org);
56 tRes.tested("addActivationEventListener()", listenerCalled);
59 public void _removeActivationEventListener() {
60 requiredMethod("addActivationEventListener()");
61 listenerCalled = false;
62 oObj.removeActivationEventListener(listener);
64 XSpreadsheet org = xSpreadsheetView.getActiveSheet();
65 xSpreadsheetView.setActiveSheet(two);
67 if (listenerCalled) {
68 log.println("Listener was called even though it is removed");
71 xSpreadsheetView.setActiveSheet(org);
72 tRes.tested("removeActivationEventListener()", !listenerCalled);
75 @Override
76 public void before() {
77 xSpreadsheetView = UnoRuntime.queryInterface(
78 XSpreadsheetView.class,
79 tEnv.getTestObject());
81 two = (XSpreadsheet) tEnv.getObjRelation("Sheet");
83 if ((xSpreadsheetView == null) || (two == null)) {
84 throw new StatusException(Status.failed(
85 "precondition for test is missing"));
89 protected class MyListener implements XActivationEventListener {
90 public void activeSpreadsheetChanged(com.sun.star.sheet.ActivationEvent activationEvent) {
91 listenerCalled = true;
94 public void disposing(com.sun.star.lang.EventObject eventObject) {