bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XTextRangeCompare.java
blob2f9bf9a5ae149add146857c66ef7717eb5316168
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 .
19 package ifc.text;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.text.XText;
26 import com.sun.star.text.XTextCursor;
27 import com.sun.star.text.XTextDocument;
28 import com.sun.star.text.XTextRange;
29 import com.sun.star.text.XTextRangeCompare;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
33 /**
34 * Testing <code>com.sun.star.text.XTextRangeCompare</code>
35 * interface methods :
36 * <ul>
37 * <li><code> compareRegionStarts()</code></li>
38 * <li><code> compareRegionEnds()</code></li>
39 * </ul> <p>
40 * This test needs the following object relations :
41 * <ul>
42 * <li> <code>'TEXTDOC'</code> <b>optional</b>
43 * (must implement <code>XTextDocument</code>):
44 * can be used to obtain <code>Text</code> of the document from
45 * which cursors can be created.
46 * If the relation does not exist, the relation <code>TEXT</code>
47 * must be specified. </li>
48 * <li> <code>'TEXT'</code> <b>optional</b>
49 * (of type <code>XText</code>):
50 * used to create text cursor.
51 * If the relation does not exist, the relation <code>TEXTDOC</code>
52 * must be specified. </li>
53 * <ul> <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.text.XTextRangeCompare
57 public class _XTextRangeCompare extends MultiMethodTest {
59 /**
60 * the test object
62 public XTextRangeCompare oObj = null;
65 String nameStr = null;
67 XTextRange oRange = null;
68 XTextCursor cursor1 = null;
69 XTextCursor cursor2 = null;
70 String startStr = null;
71 String endStr = null;
72 XText oText = null;
74 /**
75 * Retrieves <code>XText</code> interface from relation 'TEXTDOC'
76 * or from 'TEXT'.
77 * @throws StatusException If neither 'TEXTDOC' nore 'TEXT'
78 * relation exists.
80 public void before() {
81 nameStr = this.getClass().getName();
83 XInterface oIfc = (XInterface)tEnv.getObjRelation("TEXTDOC");
84 if (oIfc!=null) {
85 XTextDocument oTDoc = UnoRuntime.queryInterface(
86 XTextDocument.class, oIfc);
87 oText = oTDoc.getText();
89 XText aText = (XText) tEnv.getObjRelation("TEXT");
90 if (aText != null) {
91 oText = aText;
94 if (oText == null) {
95 throw new StatusException(Status.failed
96 ("Neither 'TEXTDOC' nore 'TEXT' relation not found")) ;
101 * One cursor is created and to its position a paragraph
102 * inserted, then the fist five characters was selected.
103 * A second cursor was created and the last 7 characteres
104 * was selected.<p>
106 * Has <b>OK</b> status if the compare returns 1, i.e.
107 * the second cursor end is before the first.
109 public void _compareRegionEnds() {
110 boolean bResult = false;
111 short n = 0;
112 log.println( "testing compareRegionEnds()" );
114 try{
115 cursor1 = oText.createTextCursor();
116 oText.insertString(cursor1, nameStr, false);
118 cursor1.gotoStart(false);
119 cursor1.goRight((short)5, true);
120 cursor2 = oText.createTextCursor();
121 cursor2.gotoEnd(false);
122 cursor2.goLeft((short)7, true);
124 log.println("hole text: '" + oText.getString() + "'");
125 log.println("cursor1: '"+cursor1.getString() + "'");
126 log.println("cursor2: '"+cursor2.getString() + "'");
127 log.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
129 n = oObj.compareRegionEnds(cursor1, cursor2);
131 log.println( "Result (short) : " + n );
132 }catch(com.sun.star.lang.IllegalArgumentException e){
133 log.println( "Exception: " + e);
134 e.printStackTrace(log);
137 if (n == 1){bResult = true;}
138 tRes.tested( "compareRegionEnds()", bResult );
142 * One cursor is created and to its position a paragraph
143 * inserted, then the fist five characters was selected.
144 * A second cursor was created and the last 7 characters
145 * was selected.<p>
147 * Has <b>OK</b> status if the compare returns 1, i.e.
148 * the second cursor start is before the first.
150 public void _compareRegionStarts() {
151 boolean bResult = false;
152 short n = 0;
154 try{
155 cursor1 = oText.createTextCursor();
156 oText.insertString(cursor1, nameStr, false);
158 cursor1.gotoStart(false);
159 cursor1.goRight((short)5, true);
160 cursor2 = oText.createTextCursor();
161 cursor2.gotoEnd(false);
162 cursor2.goLeft((short)7, true);
164 log.println("hole text: '" + oText.getString() + "'");
165 log.println("cursor1: '"+cursor1.getString() + "'");
166 log.println("cursor2: '"+cursor2.getString() + "'");
167 log.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
168 n = oObj.compareRegionStarts(cursor1, cursor2);
170 log.println( "Result (short) : " + n );
171 }catch(com.sun.star.lang.IllegalArgumentException e){
172 log.println( "Exception: " + e);
173 e.printStackTrace(log);
175 if (n == 1){bResult = true;}
176 tRes.tested( "compareRegionStarts()", bResult );