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 compliant. <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;
54 protected void before() {
55 checker
= (XSortChecker
) tEnv
.getObjRelation("SORTCHECKER");
57 if (checker
== null) {
58 throw new StatusException(Status
.failed(
59 "Couldn't get relation 'SORTCHECKER'"));
62 checker
.setPrintWriter(log
);
66 * Test calls the method. <p>
67 * Has <b> OK </b> status if the length of the returned array
68 * is greater than zero. <p>
70 public void _createSortDescriptor() {
71 boolean bResult
= false;
73 log
.println("test for createSortDescriptor() ");
74 oPV
= oObj
.createSortDescriptor();
79 for (int k
= 0; k
< oPV
.length
; k
++) {
80 log
.println("DescriptorProperty " + k
+ ": Name=" +
81 oPV
[k
].Name
+ "; Value=" + oPV
[k
].Value
);
83 if (oPV
[k
].Name
.equals("SortFields")) {
84 TableSortField
[] tsf
= (TableSortField
[]) oPV
[k
].Value
;
86 for (int l
= 0; l
< tsf
.length
; l
++) {
87 log
.println("\t isAscending: " +
89 log
.println("\t IsCaseSensitive: " +
90 tsf
[l
].IsCaseSensitive
);
91 log
.println("\t CollatorAlgorithm: " +
92 tsf
[l
].CollatorAlgorithm
);
98 log
.println("Found " + oPV
.length
+ " PropertyValues");
99 tRes
.tested("createSortDescriptor()", bResult
);
103 * Test calls the method using descriptor created before as
105 * Has <b> OK </b> status if the method successfully returns
106 * and no exceptions were thrown. <p>
107 * The following method tests are to be completed successfully before :
109 * <li> <code> createSortDescriptor() </code> : to have a descriptor
113 public void _sort() {
115 checker
.prepareToSort();
118 "############## Sort algorithm: Alphanumeric Order: Ascending");
119 modifyDescriptor(false, true);
122 boolean res
= checker
.checkSort(false, true);
124 "############################################################");
127 "############# Sort algorithm: Alphanumeric Order: Descending");
128 modifyDescriptor(false, false);
130 res
= checker
.checkSort(false, false);
132 "############################################################");
135 "################# Sort algorithm: Numeric Order: Ascending");
136 modifyDescriptor(true, true);
138 res
= checker
.checkSort(true, true);
140 "############################################################");
143 "################## Sort algorithm: Numeric Order: Descending");
144 modifyDescriptor(true, false);
146 res
= checker
.checkSort(true, false);
148 "############################################################");
150 tRes
.tested("sort()", res
);
153 protected void modifyDescriptor(boolean isSortNumeric
,
154 boolean isSortAscending
) {
155 for (int i
= 0; i
< oPV
.length
; i
++) {
156 if (oPV
[i
].Name
.equals("SortFields")) {
157 TableSortField
[] TableFields
= (TableSortField
[]) oPV
[i
].Value
;
159 if (TableFields
.length
== 0) {
160 TableFields
= new TableSortField
[1];
161 TableFields
[0] = new TableSortField();
164 for (int k
= 0; k
< TableFields
.length
; k
++) {
165 TableFields
[k
].IsAscending
= isSortAscending
;
168 TableFields
[k
].FieldType
= com
.sun
.star
.table
.TableSortFieldType
.NUMERIC
;
169 TableFields
[k
].CollatorAlgorithm
= "numeric";
171 TableFields
[k
].FieldType
= com
.sun
.star
.table
.TableSortFieldType
.ALPHANUMERIC
;
172 TableFields
[k
].CollatorAlgorithm
= "alphanumeric";
176 oPV
[i
].Value
= TableFields
;
179 if (oPV
[i
].Name
.equals("isSortInTable")) {
180 oPV
[i
].Value
= Boolean
.TRUE
;
183 if (oPV
[i
].Name
.equals("IsSortColumns")) {
184 oPV
[i
].Value
= Boolean
.FALSE
;
188 log
.println("Modified sort descriptor: ");
190 if (oPV
.length
> 0) {
191 for (int k
= 0; k
< oPV
.length
; k
++) {
192 log
.println("DescriptorProperty " + k
+ ": Name=" +
193 oPV
[k
].Name
+ "; Value=" + oPV
[k
].Value
);
195 if (oPV
[k
].Name
.equals("SortFields")) {
196 TableSortField
[] tsf
= (TableSortField
[]) oPV
[k
].Value
;
198 for (int l
= 0; l
< tsf
.length
; l
++) {
199 log
.println("\t isAscending: " +
201 log
.println("\t IsCaseSensitive: " +
202 tsf
[l
].IsCaseSensitive
);
203 log
.println("\t CollatorAlgorithm: " +
204 tsf
[l
].CollatorAlgorithm
);
212 * The interface for sort checking.
214 public interface XSortChecker
{
215 void prepareToSort();
217 boolean checkSort(boolean isSortNumbering
,
218 boolean isSortAscending
);
220 void setPrintWriter(PrintWriter log
);
224 * Forces environment recreation.
227 protected void after() {
228 disposeEnvironment();
231 } // finish class _XSortable