merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / util / _XSortable.java
blobcef34768d8e5c1db12b443437dc10d2a3643b587
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSortable.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc.util;
32 import java.io.PrintWriter;
34 import lib.MultiMethodTest;
35 import lib.Status;
36 import lib.StatusException;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.table.TableSortField;
40 import com.sun.star.util.XSortable;
43 /**
44 * Testing <code>com.sun.star.util.XSortable</code>
45 * interface methods :
46 * <ul>
47 * <li><code> createSortDescriptor()</code></li>
48 * <li><code> sort()</code></li>
49 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
52 * <li> <code>'SORTCHECKER'</code> : <code>
53 * _XSortable.XSortChecker</code> interface implementation
54 * </li>
55 * <ul><p>
56 * Test is <b> NOT </b> multithread compilant. <p>
57 * @see com.sun.star.util.XSortable
59 public class _XSortable extends MultiMethodTest {
60 // oObj filled by MultiMethodTest
61 public XSortable oObj = null;
62 XSortChecker checker = null;
63 PropertyValue[] oPV = null;
65 protected void before() {
66 checker = (XSortChecker) tEnv.getObjRelation("SORTCHECKER");
68 if (checker == null) {
69 throw new StatusException(Status.failed(
70 "Couldn't get relation 'SORTCHECKER'"));
73 checker.setPrintWriter(log);
76 /**
77 * Test calls the method. <p>
78 * Has <b> OK </b> status if the length of the returned array
79 * is greater than zero. <p>
81 public void _createSortDescriptor() {
82 boolean bResult = false;
84 log.println("test for createSortDescriptor() ");
85 oPV = oObj.createSortDescriptor();
87 if (oPV.length > 0) {
88 bResult = true;
90 for (int k = 0; k < oPV.length; k++) {
91 log.println("DescriptorProperty " + k + ": Name=" +
92 oPV[k].Name + "; Value=" + oPV[k].Value);
94 if (oPV[k].Name.equals("SortFields")) {
95 TableSortField[] tsf = (TableSortField[]) oPV[k].Value;
97 for (int l = 0; l < tsf.length; l++) {
98 log.println("\t isAscending: " +
99 tsf[l].IsAscending);
100 log.println("\t IsCaseSensitive: " +
101 tsf[l].IsCaseSensitive);
102 log.println("\t CollatorAlgorithm: " +
103 tsf[l].CollatorAlgorithm);
109 log.println("Found " + oPV.length + " PropertyValues");
110 tRes.tested("createSortDescriptor()", bResult);
114 * Test calls the method using descriptor created before as
115 * parameter. <p>
116 * Has <b> OK </b> status if the method successfully returns
117 * and no exceptions were thrown. <p>
118 * The following method tests are to be completed successfully before :
119 * <ul>
120 * <li> <code> createSortDescriptor() </code> : to have a descriptor
121 * for sort. </li>
122 * </ul>
124 public void _sort() {
126 checker.prepareToSort();
128 log.println(
129 "############## Sort algorithm: Alphanumeric Order: Ascending");
130 modifyDescriptor(false, true);
131 oObj.sort(oPV);
133 boolean res = checker.checkSort(false, true);
134 log.println(
135 "############################################################");
137 log.println(
138 "############# Sort algorithm: Alphanumeric Order: Descending");
139 modifyDescriptor(false, false);
140 oObj.sort(oPV);
141 res = checker.checkSort(false, false);
142 log.println(
143 "############################################################");
145 log.println(
146 "################# Sort algorithm: Numeric Order: Ascending");
147 modifyDescriptor(true, true);
148 oObj.sort(oPV);
149 res = checker.checkSort(true, true);
150 log.println(
151 "############################################################");
153 log.println(
154 "################## Sort algorithm: Numeric Order: Descending");
155 modifyDescriptor(true, false);
156 oObj.sort(oPV);
157 res = checker.checkSort(true, false);
158 log.println(
159 "############################################################");
161 tRes.tested("sort()", res);
164 protected void modifyDescriptor(boolean isSortNumeric,
165 boolean isSortAscending) {
166 for (int i = 0; i < oPV.length; i++) {
167 if (oPV[i].Name.equals("SortFields")) {
168 TableSortField[] TableFields = (TableSortField[]) oPV[i].Value;
170 if (TableFields.length == 0) {
171 TableFields = new TableSortField[1];
172 TableFields[0] = new TableSortField();
175 for (int k = 0; k < TableFields.length; k++) {
176 TableFields[k].IsAscending = isSortAscending;
178 if (isSortNumeric) {
179 TableFields[k].FieldType = com.sun.star.table.TableSortFieldType.NUMERIC;
180 TableFields[k].CollatorAlgorithm = "numeric";
181 } else {
182 TableFields[k].FieldType = com.sun.star.table.TableSortFieldType.ALPHANUMERIC;
183 TableFields[k].CollatorAlgorithm = "alphanumeric";
187 oPV[i].Value = TableFields;
190 if (oPV[i].Name.equals("isSortInTable")) {
191 oPV[i].Value = new Boolean(true);
194 if (oPV[i].Name.equals("IsSortColumns")) {
195 oPV[i].Value = new Boolean(false);
199 log.println("Modified sort descriptor: ");
201 if (oPV.length > 0) {
202 for (int k = 0; k < oPV.length; k++) {
203 log.println("DescriptorProperty " + k + ": Name=" +
204 oPV[k].Name + "; Value=" + oPV[k].Value);
206 if (oPV[k].Name.equals("SortFields")) {
207 TableSortField[] tsf = (TableSortField[]) oPV[k].Value;
209 for (int l = 0; l < tsf.length; l++) {
210 log.println("\t isAscending: " +
211 tsf[l].IsAscending);
212 log.println("\t IsCaseSensitive: " +
213 tsf[l].IsCaseSensitive);
214 log.println("\t CollatorAlgorithm: " +
215 tsf[l].CollatorAlgorithm);
223 * The interface for sort checking.
225 public static interface XSortChecker {
226 public void prepareToSort();
228 public boolean checkSort(boolean isSortNumbering,
229 boolean isSortAscending);
231 public void setPrintWriter(PrintWriter log);
235 * Forces environment recreation.
237 protected void after() {
238 disposeEnvironment();
241 } // finish class _XSortable