1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#! /usr/bin/env python
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import unittest
from org.libreoffice.unotest import UnoInProcess
from com.sun.star.lang import IllegalArgumentException
class XTextRangeCompare(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
@classmethod
def tearDownClass(cls):
cls._uno.tearDown()
def test_compareRegionStarts(self):
xDoc = self._uno.openEmptyWriterDoc()
cursor = xDoc.Text.createTextCursor()
xDoc.Text.insertString(cursor, "The first paragraph", 0)
self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor, cursor))
with self.assertRaises(IllegalArgumentException):
xDoc.Text.compareRegionStarts(cursor, None)
with self.assertRaises(IllegalArgumentException):
xDoc.Text.compareRegionStarts(None, cursor)
with self.assertRaises(IllegalArgumentException):
xDoc.Text.compareRegionStarts(None, None)
xDoc.close(True)
def test_compareRegionEnds(self):
xDoc = self._uno.openEmptyWriterDoc()
cursor = xDoc.Text.createTextCursor()
xDoc.Text.insertString(cursor, "The first paragraph", 0)
self.assertEqual(0, xDoc.Text.compareRegionEnds(cursor, cursor))
with self.assertRaises(IllegalArgumentException):
xDoc.Text.compareRegionEnds(cursor, None)
with self.assertRaises(IllegalArgumentException):
xDoc.Text.compareRegionEnds(None, cursor)
with self.assertRaises(IllegalArgumentException):
xDoc.Text.compareRegionEnds(None, None)
xDoc.close(True)
def test_compareRegionStarts_Different(self):
xDoc = self._uno.openEmptyWriterDoc()
cursor1 = xDoc.Text.createTextCursor()
cursor2 = xDoc.Text.createTextCursor()
xDoc.Text.insertString(cursor1, "The first paragraph", 0)
cursor1.gotoStart(False)
cursor2.gotoEnd(False)
self.assertTrue(cursor1.isCollapsed())
self.assertTrue(cursor1.isCollapsed())
self.assertEqual(1, xDoc.Text.compareRegionStarts(cursor1, cursor2))
self.assertEqual(-1, xDoc.Text.compareRegionStarts(cursor2, cursor1))
xDoc.close(True)
def test_compareRegionStarts_DiffSelection(self):
xDoc = self._uno.openEmptyWriterDoc()
cursor1 = xDoc.Text.createTextCursor()
cursor2 = xDoc.Text.createTextCursor()
xDoc.Text.insertString(cursor1, "The first paragraph", 0)
cursor1.gotoStart(False)
cursor1.gotoEnd(True)
cursor2.gotoEnd(False)
cursor2.gotoStart(True)
self.assertFalse(cursor1.isCollapsed())
self.assertFalse(cursor1.isCollapsed())
self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor1, cursor2))
self.assertEqual(0, xDoc.Text.compareRegionEnds(cursor1, cursor2))
xDoc.close(True)
def test_compareRegionStarts_DiffSelection(self):
xDoc = self._uno.openEmptyWriterDoc()
cursor1 = xDoc.Text.createTextCursor()
cursor2 = xDoc.Text.createTextCursor()
xDoc.Text.insertString(cursor1, "The first paragraph", 0)
cursor1.gotoStart(False)
cursor1.gotoEnd(True)
cursor1.goLeft(2, True)
cursor2.gotoEnd(False)
cursor2.gotoStart(True)
cursor2.goRight(2, True)
self.assertFalse(cursor1.isCollapsed())
self.assertFalse(cursor1.isCollapsed())
# whole text: 123456789
# cursor1: 1234567
# cursor2: 3456789
self.assertEqual(1, xDoc.Text.compareRegionStarts(cursor1, cursor2))
self.assertEqual(1, xDoc.Text.compareRegionEnds(cursor1, cursor2))
self.assertEqual(-1, xDoc.Text.compareRegionStarts(cursor2, cursor1))
self.assertEqual(-1, xDoc.Text.compareRegionEnds(cursor2, cursor1))
xDoc.close(True)
def test_compareRegionStarts_SameStart(self):
xDoc = self._uno.openEmptyWriterDoc()
cursor1 = xDoc.Text.createTextCursor()
cursor2 = xDoc.Text.createTextCursor()
xDoc.Text.insertString(cursor1, "The first paragraph", 0)
cursor1.gotoStart(False)
cursor1.goRight(2, False)
cursor1.goRight(5, True)
cursor2.gotoStart(False)
cursor2.goRight(2, False)
cursor2.goRight(7, True)
self.assertFalse(cursor1.isCollapsed())
self.assertFalse(cursor1.isCollapsed())
# whole text: 123456789
# cursor1: 34567
# cursor2: 3456789
self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor1, cursor2))
self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor2, cursor1))
self.assertEqual(1, xDoc.Text.compareRegionEnds(cursor1, cursor2))
self.assertEqual(-1, xDoc.Text.compareRegionEnds(cursor2, cursor1))
xDoc.close(True)
if __name__ == '__main__':
unittest.main()
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|