1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSortable.java,v $
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 ************************************************************************/
32 import java
.io
.PrintWriter
;
34 import lib
.MultiMethodTest
;
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
;
44 * Testing <code>com.sun.star.util.XSortable</code>
47 * <li><code> createSortDescriptor()</code></li>
48 * <li><code> sort()</code></li>
50 * This test needs the following object relations :
52 * <li> <code>'SORTCHECKER'</code> : <code>
53 * _XSortable.XSortChecker</code> interface implementation
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
);
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();
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: " +
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
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 :
120 * <li> <code> createSortDescriptor() </code> : to have a descriptor
124 public void _sort() {
126 checker
.prepareToSort();
129 "############## Sort algorithm: Alphanumeric Order: Ascending");
130 modifyDescriptor(false, true);
133 boolean res
= checker
.checkSort(false, true);
135 "############################################################");
138 "############# Sort algorithm: Alphanumeric Order: Descending");
139 modifyDescriptor(false, false);
141 res
= checker
.checkSort(false, false);
143 "############################################################");
146 "################# Sort algorithm: Numeric Order: Ascending");
147 modifyDescriptor(true, true);
149 res
= checker
.checkSort(true, true);
151 "############################################################");
154 "################## Sort algorithm: Numeric Order: Descending");
155 modifyDescriptor(true, false);
157 res
= checker
.checkSort(true, false);
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
;
179 TableFields
[k
].FieldType
= com
.sun
.star
.table
.TableSortFieldType
.NUMERIC
;
180 TableFields
[k
].CollatorAlgorithm
= "numeric";
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: " +
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