Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / xtextcursor.py
blob2c374bee587061b3ce18ad971307048eb63caf7f
1 #! /usr/bin/env python
2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import unittest
11 from org.libreoffice.unotest import UnoInProcess
14 class TestXTextCursor(unittest.TestCase):
16 @classmethod
17 def setUpClass(cls):
18 cls._uno = UnoInProcess()
19 cls._uno.setUp()
20 cls._uno.openDocFromTDOC("xtextcursor.odt")
22 @classmethod
23 def tearDownClass(cls):
24 cls._uno.tearDown()
26 def createTextCursorInFrame(self, frameName):
27 xTextFrames = self._uno.getDoc().getTextFrames()
28 self.assertIsNotNone(xTextFrames)
29 xTextFrame = xTextFrames[frameName]
30 self.assertIsNotNone(xTextFrame)
31 xCursor = xTextFrame.getText().createTextCursor()
32 self.assertIsNotNone(xCursor)
33 return xCursor
35 def test_cursorMoveInText(self):
36 # Create cursor in frame with simple text (to avoid moving beyond)
37 xCursor = self.createTextCursorInFrame("FrameSimple")
39 xCursor.collapseToStart()
40 self.assertTrue(xCursor.isCollapsed())
41 self.assertTrue(xCursor.goRight(1, True))
42 self.assertFalse(xCursor.isCollapsed())
43 # Try to move right 10 characters, but we really can just 3, so partial move
44 self.assertFalse(xCursor.goRight(10, True))
45 self.assertFalse(xCursor.isCollapsed())
46 # Ensure that all line text is selected
47 self.assertEqual(xCursor.getString(), "1234")
49 self.assertFalse(xCursor.goRight(-10, True))
50 self.assertEqual(xCursor.getString(), "1234")
52 xCursor.collapseToEnd()
53 self.assertTrue(xCursor.isCollapsed())
54 self.assertTrue(xCursor.goLeft(2, True))
55 self.assertFalse(xCursor.isCollapsed())
56 self.assertEqual(xCursor.getString(), "34")
58 # Move to start without selection
59 self.assertTrue(xCursor.goLeft(2, False))
60 self.assertEqual(xCursor.getString(), "")
62 self.assertTrue(xCursor.isCollapsed())
64 # Select all text
65 xCursor.gotoStart(False)
66 self.assertTrue(xCursor.isCollapsed())
67 xCursor.gotoEnd(True)
68 self.assertFalse(xCursor.isCollapsed())
69 self.assertEqual(xCursor.getString(), "1234")
71 # Select all text from behind
72 xCursor.gotoEnd(False)
73 self.assertTrue(xCursor.isCollapsed())
74 xCursor.gotoStart(True)
75 self.assertFalse(xCursor.isCollapsed())
76 self.assertEqual(xCursor.getString(), "1234")
78 # Select all text, alternative way via gotoRange
79 xCursor2 = self.createTextCursorInFrame("FrameSimple")
80 xCursor2.gotoEnd(False)
81 xCursor2.gotoStart(True)
82 xCursor.gotoEnd(False)
83 self.assertTrue(xCursor.isCollapsed())
84 xCursor.gotoRange(xCursor2, True)
85 self.assertFalse(xCursor.isCollapsed())
86 self.assertEqual(xCursor.getString(), "1234")
88 def test_cursorMoveInTable(self):
89 # Create cursor in frame with table
90 xCursor = self.createTextCursorInFrame("FrameTable")
92 # Nothing is selected
93 xCursor.collapseToEnd()
94 self.assertTrue(xCursor.isCollapsed())
95 self.assertEqual(xCursor.getString(), "")
96 self.assertFalse(xCursor.goLeft(1, False))
97 self.assertFalse(xCursor.goLeft(1, True))
98 self.assertEqual(xCursor.getString(), "")
101 if __name__ == '__main__':
102 unittest.main()
104 # vim: set shiftwidth=4 softtabstop=4 expandtab: