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 .
20 import java
.io
.PrintWriter
;
22 import lib
.MultiMethodTest
;
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
;
32 * Testing <code>com.sun.star.util.XSortable</code>
35 * <li><code> createSortDescriptor()</code></li>
36 * <li><code> sort()</code></li>
38 * This test needs the following object relations :
40 * <li> <code>'SORTCHECKER'</code> : <code>
41 * _XSortable.XSortChecker</code> interface implementation
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
);
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();
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: " +
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
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 :
108 * <li> <code> createSortDescriptor() </code> : to have a descriptor
112 public void _sort() {
114 checker
.prepareToSort();
117 "############## Sort algorithm: Alphanumeric Order: Ascending");
118 modifyDescriptor(false, true);
121 boolean res
= checker
.checkSort(false, true);
123 "############################################################");
126 "############# Sort algorithm: Alphanumeric Order: Descending");
127 modifyDescriptor(false, false);
129 res
= checker
.checkSort(false, false);
131 "############################################################");
134 "################# Sort algorithm: Numeric Order: Ascending");
135 modifyDescriptor(true, true);
137 res
= checker
.checkSort(true, true);
139 "############################################################");
142 "################## Sort algorithm: Numeric Order: Descending");
143 modifyDescriptor(true, false);
145 res
= checker
.checkSort(true, false);
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
;
167 TableFields
[k
].FieldType
= com
.sun
.star
.table
.TableSortFieldType
.NUMERIC
;
168 TableFields
[k
].CollatorAlgorithm
= "numeric";
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: " +
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