bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XSortable.java
blob9658828c5bd6cb6136c94a21e60e25f846bb51f9
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.util;
20 import java.io.PrintWriter;
22 import lib.MultiMethodTest;
23 import lib.Status;
24 import lib.StatusException;
26 import com.sun.star.beans.PropertyValue;
27 import com.sun.star.table.TableSortField;
28 import com.sun.star.util.XSortable;
31 /**
32 * Testing <code>com.sun.star.util.XSortable</code>
33 * interface methods :
34 * <ul>
35 * <li><code> createSortDescriptor()</code></li>
36 * <li><code> sort()</code></li>
37 * </ul> <p>
38 * This test needs the following object relations :
39 * <ul>
40 * <li> <code>'SORTCHECKER'</code> : <code>
41 * _XSortable.XSortChecker</code> interface implementation
42 * </li>
43 * <ul><p>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.util.XSortable
47 public class _XSortable extends MultiMethodTest {
48 // oObj filled by MultiMethodTest
49 public XSortable oObj = null;
50 XSortChecker checker = null;
51 PropertyValue[] oPV = null;
53 protected void before() {
54 checker = (XSortChecker) tEnv.getObjRelation("SORTCHECKER");
56 if (checker == null) {
57 throw new StatusException(Status.failed(
58 "Couldn't get relation 'SORTCHECKER'"));
61 checker.setPrintWriter(log);
64 /**
65 * Test calls the method. <p>
66 * Has <b> OK </b> status if the length of the returned array
67 * is greater than zero. <p>
69 public void _createSortDescriptor() {
70 boolean bResult = false;
72 log.println("test for createSortDescriptor() ");
73 oPV = oObj.createSortDescriptor();
75 if (oPV.length > 0) {
76 bResult = true;
78 for (int k = 0; k < oPV.length; k++) {
79 log.println("DescriptorProperty " + k + ": Name=" +
80 oPV[k].Name + "; Value=" + oPV[k].Value);
82 if (oPV[k].Name.equals("SortFields")) {
83 TableSortField[] tsf = (TableSortField[]) oPV[k].Value;
85 for (int l = 0; l < tsf.length; l++) {
86 log.println("\t isAscending: " +
87 tsf[l].IsAscending);
88 log.println("\t IsCaseSensitive: " +
89 tsf[l].IsCaseSensitive);
90 log.println("\t CollatorAlgorithm: " +
91 tsf[l].CollatorAlgorithm);
97 log.println("Found " + oPV.length + " PropertyValues");
98 tRes.tested("createSortDescriptor()", bResult);
102 * Test calls the method using descriptor created before as
103 * parameter. <p>
104 * Has <b> OK </b> status if the method successfully returns
105 * and no exceptions were thrown. <p>
106 * The following method tests are to be completed successfully before :
107 * <ul>
108 * <li> <code> createSortDescriptor() </code> : to have a descriptor
109 * for sort. </li>
110 * </ul>
112 public void _sort() {
114 checker.prepareToSort();
116 log.println(
117 "############## Sort algorithm: Alphanumeric Order: Ascending");
118 modifyDescriptor(false, true);
119 oObj.sort(oPV);
121 boolean res = checker.checkSort(false, true);
122 log.println(
123 "############################################################");
125 log.println(
126 "############# Sort algorithm: Alphanumeric Order: Descending");
127 modifyDescriptor(false, false);
128 oObj.sort(oPV);
129 res = checker.checkSort(false, false);
130 log.println(
131 "############################################################");
133 log.println(
134 "################# Sort algorithm: Numeric Order: Ascending");
135 modifyDescriptor(true, true);
136 oObj.sort(oPV);
137 res = checker.checkSort(true, true);
138 log.println(
139 "############################################################");
141 log.println(
142 "################## Sort algorithm: Numeric Order: Descending");
143 modifyDescriptor(true, false);
144 oObj.sort(oPV);
145 res = checker.checkSort(true, false);
146 log.println(
147 "############################################################");
149 tRes.tested("sort()", res);
152 protected void modifyDescriptor(boolean isSortNumeric,
153 boolean isSortAscending) {
154 for (int i = 0; i < oPV.length; i++) {
155 if (oPV[i].Name.equals("SortFields")) {
156 TableSortField[] TableFields = (TableSortField[]) oPV[i].Value;
158 if (TableFields.length == 0) {
159 TableFields = new TableSortField[1];
160 TableFields[0] = new TableSortField();
163 for (int k = 0; k < TableFields.length; k++) {
164 TableFields[k].IsAscending = isSortAscending;
166 if (isSortNumeric) {
167 TableFields[k].FieldType = com.sun.star.table.TableSortFieldType.NUMERIC;
168 TableFields[k].CollatorAlgorithm = "numeric";
169 } else {
170 TableFields[k].FieldType = com.sun.star.table.TableSortFieldType.ALPHANUMERIC;
171 TableFields[k].CollatorAlgorithm = "alphanumeric";
175 oPV[i].Value = TableFields;
178 if (oPV[i].Name.equals("isSortInTable")) {
179 oPV[i].Value = new Boolean(true);
182 if (oPV[i].Name.equals("IsSortColumns")) {
183 oPV[i].Value = new Boolean(false);
187 log.println("Modified sort descriptor: ");
189 if (oPV.length > 0) {
190 for (int k = 0; k < oPV.length; k++) {
191 log.println("DescriptorProperty " + k + ": Name=" +
192 oPV[k].Name + "; Value=" + oPV[k].Value);
194 if (oPV[k].Name.equals("SortFields")) {
195 TableSortField[] tsf = (TableSortField[]) oPV[k].Value;
197 for (int l = 0; l < tsf.length; l++) {
198 log.println("\t isAscending: " +
199 tsf[l].IsAscending);
200 log.println("\t IsCaseSensitive: " +
201 tsf[l].IsCaseSensitive);
202 log.println("\t CollatorAlgorithm: " +
203 tsf[l].CollatorAlgorithm);
211 * The interface for sort checking.
213 public static interface XSortChecker {
214 public void prepareToSort();
216 public boolean checkSort(boolean isSortNumbering,
217 boolean isSortAscending);
219 public void setPrintWriter(PrintWriter log);
223 * Forces environment recreation.
225 protected void after() {
226 disposeEnvironment();
229 } // finish class _XSortable