Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XSortable.java
blobf0d78305420df07e9acbaabfa4b632b2481b9f24
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package ifc.util;
29 import java.io.PrintWriter;
31 import lib.MultiMethodTest;
32 import lib.Status;
33 import lib.StatusException;
35 import com.sun.star.beans.PropertyValue;
36 import com.sun.star.table.TableSortField;
37 import com.sun.star.util.XSortable;
40 /**
41 * Testing <code>com.sun.star.util.XSortable</code>
42 * interface methods :
43 * <ul>
44 * <li><code> createSortDescriptor()</code></li>
45 * <li><code> sort()</code></li>
46 * </ul> <p>
47 * This test needs the following object relations :
48 * <ul>
49 * <li> <code>'SORTCHECKER'</code> : <code>
50 * _XSortable.XSortChecker</code> interface implementation
51 * </li>
52 * <ul><p>
53 * Test is <b> NOT </b> multithread compilant. <p>
54 * @see com.sun.star.util.XSortable
56 public class _XSortable extends MultiMethodTest {
57 // oObj filled by MultiMethodTest
58 public XSortable oObj = null;
59 XSortChecker checker = null;
60 PropertyValue[] oPV = null;
62 protected void before() {
63 checker = (XSortChecker) tEnv.getObjRelation("SORTCHECKER");
65 if (checker == null) {
66 throw new StatusException(Status.failed(
67 "Couldn't get relation 'SORTCHECKER'"));
70 checker.setPrintWriter(log);
73 /**
74 * Test calls the method. <p>
75 * Has <b> OK </b> status if the length of the returned array
76 * is greater than zero. <p>
78 public void _createSortDescriptor() {
79 boolean bResult = false;
81 log.println("test for createSortDescriptor() ");
82 oPV = oObj.createSortDescriptor();
84 if (oPV.length > 0) {
85 bResult = true;
87 for (int k = 0; k < oPV.length; k++) {
88 log.println("DescriptorProperty " + k + ": Name=" +
89 oPV[k].Name + "; Value=" + oPV[k].Value);
91 if (oPV[k].Name.equals("SortFields")) {
92 TableSortField[] tsf = (TableSortField[]) oPV[k].Value;
94 for (int l = 0; l < tsf.length; l++) {
95 log.println("\t isAscending: " +
96 tsf[l].IsAscending);
97 log.println("\t IsCaseSensitive: " +
98 tsf[l].IsCaseSensitive);
99 log.println("\t CollatorAlgorithm: " +
100 tsf[l].CollatorAlgorithm);
106 log.println("Found " + oPV.length + " PropertyValues");
107 tRes.tested("createSortDescriptor()", bResult);
111 * Test calls the method using descriptor created before as
112 * parameter. <p>
113 * Has <b> OK </b> status if the method successfully returns
114 * and no exceptions were thrown. <p>
115 * The following method tests are to be completed successfully before :
116 * <ul>
117 * <li> <code> createSortDescriptor() </code> : to have a descriptor
118 * for sort. </li>
119 * </ul>
121 public void _sort() {
123 checker.prepareToSort();
125 log.println(
126 "############## Sort algorithm: Alphanumeric Order: Ascending");
127 modifyDescriptor(false, true);
128 oObj.sort(oPV);
130 boolean res = checker.checkSort(false, true);
131 log.println(
132 "############################################################");
134 log.println(
135 "############# Sort algorithm: Alphanumeric Order: Descending");
136 modifyDescriptor(false, false);
137 oObj.sort(oPV);
138 res = checker.checkSort(false, false);
139 log.println(
140 "############################################################");
142 log.println(
143 "################# Sort algorithm: Numeric Order: Ascending");
144 modifyDescriptor(true, true);
145 oObj.sort(oPV);
146 res = checker.checkSort(true, true);
147 log.println(
148 "############################################################");
150 log.println(
151 "################## Sort algorithm: Numeric Order: Descending");
152 modifyDescriptor(true, false);
153 oObj.sort(oPV);
154 res = checker.checkSort(true, false);
155 log.println(
156 "############################################################");
158 tRes.tested("sort()", res);
161 protected void modifyDescriptor(boolean isSortNumeric,
162 boolean isSortAscending) {
163 for (int i = 0; i < oPV.length; i++) {
164 if (oPV[i].Name.equals("SortFields")) {
165 TableSortField[] TableFields = (TableSortField[]) oPV[i].Value;
167 if (TableFields.length == 0) {
168 TableFields = new TableSortField[1];
169 TableFields[0] = new TableSortField();
172 for (int k = 0; k < TableFields.length; k++) {
173 TableFields[k].IsAscending = isSortAscending;
175 if (isSortNumeric) {
176 TableFields[k].FieldType = com.sun.star.table.TableSortFieldType.NUMERIC;
177 TableFields[k].CollatorAlgorithm = "numeric";
178 } else {
179 TableFields[k].FieldType = com.sun.star.table.TableSortFieldType.ALPHANUMERIC;
180 TableFields[k].CollatorAlgorithm = "alphanumeric";
184 oPV[i].Value = TableFields;
187 if (oPV[i].Name.equals("isSortInTable")) {
188 oPV[i].Value = new Boolean(true);
191 if (oPV[i].Name.equals("IsSortColumns")) {
192 oPV[i].Value = new Boolean(false);
196 log.println("Modified sort descriptor: ");
198 if (oPV.length > 0) {
199 for (int k = 0; k < oPV.length; k++) {
200 log.println("DescriptorProperty " + k + ": Name=" +
201 oPV[k].Name + "; Value=" + oPV[k].Value);
203 if (oPV[k].Name.equals("SortFields")) {
204 TableSortField[] tsf = (TableSortField[]) oPV[k].Value;
206 for (int l = 0; l < tsf.length; l++) {
207 log.println("\t isAscending: " +
208 tsf[l].IsAscending);
209 log.println("\t IsCaseSensitive: " +
210 tsf[l].IsCaseSensitive);
211 log.println("\t CollatorAlgorithm: " +
212 tsf[l].CollatorAlgorithm);
220 * The interface for sort checking.
222 public static interface XSortChecker {
223 public void prepareToSort();
225 public boolean checkSort(boolean isSortNumbering,
226 boolean isSortAscending);
228 public void setPrintWriter(PrintWriter log);
232 * Forces environment recreation.
234 protected void after() {
235 disposeEnvironment();
238 } // finish class _XSortable