Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / chart / _XChartData.java
blobc0a4bc3c7be5d0fdf1230f9378431d0486a2f03c
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.chart;
20 import com.sun.star.chart.ChartDataChangeEvent;
21 import com.sun.star.chart.XChartData;
22 import com.sun.star.chart.XChartDataArray;
23 import com.sun.star.chart.XChartDataChangeEventListener;
24 import com.sun.star.lang.EventObject;
25 import com.sun.star.uno.UnoRuntime;
27 import lib.MultiMethodTest;
30 /**
31 * Testing <code>com.sun.star.chart.XChartData</code>
32 * interface methods :
33 * <ul>
34 * <li><code> addChartDataChangeEventListener()</code></li>
35 * <li><code> removeChartDataChangeEventListener()</code></li>
36 * <li><code> getNotANumber()</code></li>
37 * <li><code> isNotANumber()</code></li>
38 * </ul> <p>
39 * @see com.sun.star.chart.XChartData
41 public class _XChartData extends MultiMethodTest {
42 public XChartData oObj = null;
43 boolean result = true;
44 double nan = 0;
45 XChartDataArray dataArray = null;
46 boolean[] dataChanged = new boolean[2];
47 XChartDataChangeEventListener listener1 = new MyEventListener();
48 XChartDataChangeEventListener listener2 = new MyEventListener2();
50 /**
51 * Test calls the method adding two listeners and then changes data. <p>
52 * Has <b> OK </b> status if after data were changed
53 * listeners were called. <p>
55 public void _addChartDataChangeEventListener() {
56 dataChanged[0] = false;
57 dataChanged[1] = false;
59 oObj.addChartDataChangeEventListener(listener1);
60 oObj.addChartDataChangeEventListener(listener2);
62 dataArray = UnoRuntime.queryInterface(
63 XChartDataArray.class, oObj);
65 double[][] data = dataArray.getData();
66 data[0][0] += 0.1;
67 dataArray.setData(data);
69 if (!dataChanged[0]) {
70 log.println("ChartDataChangeEventListener1 " +
71 "isn't called after changing data");
74 if (!dataChanged[1]) {
75 log.println("ChartDataChangeEventListener2 " +
76 "isn't called after changing data");
79 tRes.tested("addChartDataChangeEventListener()",
80 dataChanged[0] && dataChanged[1]);
83 /**
84 * Test calls the method for one listener, changes data,
85 * calls the method for other listener and again changes data. <p>
86 * Has <b> OK </b> status if listener is not called after removing. <p>
87 * The following method tests are to be completed successfully before :
88 * <ul>
89 * <li> <code>addChartDataChangeEventListener</code> : to have listeners
90 * that must be removed by the method </li>
91 * </ul>
93 public void _removeChartDataChangeEventListener() {
94 requiredMethod("addChartDataChangeEventListener()");
96 dataChanged[0] = false;
97 dataChanged[1] = false;
99 oObj.removeChartDataChangeEventListener(listener1);
100 dataArray = UnoRuntime.queryInterface(
101 XChartDataArray.class, oObj);
103 double[][] data = dataArray.getData();
104 data[0][0] += 0.1;
105 dataArray.setData(data);
106 oObj.removeChartDataChangeEventListener(listener2);
108 if (dataChanged[0]) {
109 log.println("ChartDataChangeEventListener1 is " +
110 "called after removing listener");
113 tRes.tested("removeChartDataChangeEventListener()",
114 ((!dataChanged[0]) && (dataChanged[1])));
118 * Test calls the method and checks returned value. <p>
119 * Has <b> OK </b> status if the return value isn't equal to 1. <p>
121 public void _getNotANumber() {
122 result = true;
124 nan = oObj.getNotANumber();
125 log.println("Current NotANumber is " + nan);
126 result = nan != 1;
128 tRes.tested("getNotANumber()", result);
132 * Test calls the method with NAN value and with non NAN value. <p>
133 * Has <b> OK </b> status if the method returns true for NAN value and
134 * returns false for other value<p>
135 * The following method tests are to be completed successfully before :
136 * <ul>
137 * <li> <code>getNotANumber</code> : to have the current NAN value </li>
138 * </ul>
140 public void _isNotANumber() {
141 requiredMethod("getNotANumber()");
142 result = true;
144 result = (oObj.isNotANumber(nan) && !oObj.isNotANumber(nan + 1));
146 tRes.tested("isNotANumber()", result);
150 * Forces environment recreation.
152 @Override
153 protected void after() {
154 disposeEnvironment();
157 class MyEventListener implements XChartDataChangeEventListener {
158 public void disposing(EventObject oEvent) {
159 System.out.println("Listener1 disposed");
162 public void chartDataChanged(ChartDataChangeEvent ev) {
163 dataChanged[0] = true;
167 class MyEventListener2 implements XChartDataChangeEventListener {
168 public void disposing(EventObject oEvent) {
169 System.out.println("Listener2 disposed");
172 public void chartDataChanged(ChartDataChangeEvent ev) {
173 dataChanged[1] = true;