Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / uitest / librelogo / run.py
bloba7f2d0aa25299b2f00ee6a6dc3f560c1d23d93bd
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 from uitest.framework import UITestCase
11 from uitest.uihelper.common import type_text
12 from com.sun.star.awt.FontSlant import NONE as __Slant_NONE__
13 from com.sun.star.awt.FontSlant import ITALIC as __Slant_ITALIC__
14 from com.sun.star.awt.FontUnderline import NONE as __Underline_NONE__
15 from com.sun.star.awt.FontUnderline import SINGLE as __Underline_SINGLE__
16 from com.sun.star.awt.FontStrikeout import NONE as __Strikeout_NONE__
17 from com.sun.star.awt.FontStrikeout import SINGLE as __Strikeout_SINGLE__
19 class LibreLogoTest(UITestCase):
20 LIBRELOGO_PATH = "vnd.sun.star.script:LibreLogo|LibreLogo.py$%s?language=Python&location=share"
22 def createMasterScriptProviderFactory(self):
23 xServiceManager = self.xContext.ServiceManager
24 return xServiceManager.createInstanceWithContext(
25 "com.sun.star.script.provider.MasterScriptProviderFactory",
26 self.xContext)
28 def getScript(self, command):
29 xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
30 document = self.ui_test.get_component()
31 xScriptProvider = xMasterScriptProviderFactory.createScriptProvider(document)
32 xScript = xScriptProvider.getScript(self.LIBRELOGO_PATH %command)
33 self.assertIsNotNone(xScript, "xScript was not loaded")
34 return xScript
36 def logo(self, command):
37 self.xUITest.executeCommand(self.LIBRELOGO_PATH %command)
39 def test_librelogo(self):
40 with self.ui_test.create_doc_in_start_center("writer") as document:
41 xWriterDoc = self.xUITest.getTopFocusWindow()
42 xWriterEdit = xWriterDoc.getChild("writer_edit")
43 # to check the state of LibreLogo program execution
44 xIsAlive = self.getScript("__is_alive__")
46 # run a program with basic drawing commands FORWARD and RIGHT
47 # using their abbreviated names FD and RT
48 type_text(xWriterEdit, "fd 100 rt 45 fd 100")
49 self.logo("run")
50 # wait for LibreLogo program termination
51 while xIsAlive.invoke((), (), ())[0]:
52 pass
53 # check shape count for
54 # a) program running:
55 # - turtle shape: result of program start
56 # - line shape: result of turtle drawing
57 # b) continuous line drawing (the regression
58 # related to the fix of tdf#106792 resulted shorter line
59 # segments than the turtle path and non-continuous line
60 # drawing, ie. in this example, three line shapes
61 # instead of a single one. See its fix in
62 # commit 502e8785085f9e8b54ee383080442c2dcaf95b15)
63 self.assertEqual(document.DrawPage.getCount(), 2)
65 # check formatting by "magic wand"
66 self.logo("__translate__")
67 # a) check expansion of abbreviated commands : fd -> FORWARD, rt -> RIGHT,
68 # b) check line breaking (fix for tdf#100941: new line instead of the text "\" and "n")
69 self.assertEqual(document.Text.String.replace('\r\n', '\n'), "\nFORWARD 100 RIGHT 45 FORWARD 100")
70 # c) check usage of real paragraphs instead of line break (tdf#120422)
71 # first paragraph is empty (for working page break)
72 self.assertEqual(document.Text.createEnumeration().nextElement().String, "")
74 # function definitions and calls can be in arbitrary order
75 document.Text.String = """
76 ; dragon curve
77 TO x n
78 IF n = 0 [ STOP ]
79 x n-1
80 RIGHT 90
81 y n-1 ; it worked only as "y(n-1)"
82 FORWARD 10
83 END
85 TO y n
86 IF n = 0 [ STOP ]
87 FORWARD 10
88 x n-1
89 LEFT 90
90 y n-1
91 END
93 PICTURE ; start new line draw
94 x 3 ; draw only a few levels
95 """
96 self.logo("run")
97 # wait for LibreLogo program termination
98 while xIsAlive.invoke((), (), ())[0]:
99 pass
100 # new shape + previous two ones = 3
101 self.assertEqual(document.DrawPage.getCount(), 3)
103 def check_label(self, hasCustomLock):
104 sLock = "CLEARSCREEN "
105 if hasCustomLock:
106 sLock = sLock + "SLEEP -1 "
107 with self.ui_test.create_doc_in_start_center("writer") as document:
108 xWriterDoc = self.xUITest.getTopFocusWindow()
109 xWriterEdit = xWriterDoc.getChild("writer_edit")
110 # to check the state of LibreLogo program execution
111 xIsAlive = self.getScript("__is_alive__")
113 #1 run a program with basic LABEL command
115 type_text(xWriterEdit, sLock + "LABEL 'Hello, World!'")
116 self.logo("run")
117 # wait for LibreLogo program termination
118 while xIsAlive.invoke((), (), ())[0]:
119 pass
121 # turtle and text shape
122 self.assertEqual(document.DrawPage.getCount(), 2)
123 textShape = document.DrawPage.getByIndex(1)
124 # text in the text shape
125 self.assertEqual(textShape.getString(), "Hello, World!")
127 #2 check italic, bold, underline + red and blue formatting
129 document.Text.String = sLock + "LABEL '<i><red>Hello</red>, <bold><blue>W<u>orld</blue></bold>!</i></u>'"
130 self.logo("run")
131 # wait for LibreLogo program termination
132 while xIsAlive.invoke((), (), ())[0]:
133 pass
135 # turtle and text shape
136 self.assertEqual(document.DrawPage.getCount(), 2)
137 textShape = document.DrawPage.getByIndex(1)
138 # text in the text shape
139 self.assertEqual(textShape.getString(), "Hello, World!")
140 # check portion formatting
141 c = textShape.createTextCursor()
142 c.gotoStart(False)
143 # before character "H"
144 self.assertEqual(c.CharPosture, __Slant_ITALIC__) # cursive
145 self.assertEqual(c.CharUnderline, __Underline_NONE__) # no underline
146 self.assertEqual(c.CharWeight, 100) # normal weight
147 self.assertEqual(c.CharColor, 0xFF0000) # red color
148 # after character " "
149 c.goRight(6, False)
150 self.assertEqual(c.CharPosture, __Slant_ITALIC__) # cursive
151 self.assertEqual(c.CharUnderline, __Underline_NONE__) # no underline
152 self.assertEqual(c.CharWeight, 100) # normal weight
153 self.assertEqual(c.CharColor, 0x000000) # black color
154 # after character "W"
155 c.goRight(2, False)
156 self.assertEqual(c.CharPosture, __Slant_ITALIC__) # cursive
157 self.assertEqual(c.CharUnderline, __Underline_NONE__) # no underline
158 self.assertEqual(c.CharWeight, 150) # bold
159 self.assertEqual(c.CharColor, 0x0000FF) # blue color
160 # 9th: after character "o"
161 c.goRight(1, False)
162 self.assertEqual(c.CharPosture, __Slant_ITALIC__) # cursive
163 self.assertEqual(c.CharUnderline, __Underline_SINGLE__) # underline
164 self.assertEqual(c.CharWeight, 150) # bold
165 self.assertEqual(c.CharColor, 0x0000FF) # blue color
166 # last: after character "!"
167 c.gotoEnd(False)
168 self.assertEqual(c.CharPosture, __Slant_ITALIC__) # cursive
169 self.assertEqual(c.CharUnderline, __Underline_SINGLE__) # underline
170 self.assertEqual(c.CharWeight, 100) # normal weight
171 self.assertEqual(c.CharColor, 0x000000) # black color
173 #2 check strike out, sub, sup, font name and font size formatting
175 document.Text.String = (
176 sLock + "FONTFAMILY 'Linux Biolinum G' FONTSIZE 12 " +
177 "LABEL '<s>x</s>, <sub>x</sub>, <sup>x</sup>, " +
178 "<FONTFAMILY Liberation Sans>x</FONTFAMILY>, " +
179 "<FONTHEIGHT 20>x</FONTHEIGHT>...'" )
181 self.logo("run")
182 # wait for LibreLogo program termination
183 while xIsAlive.invoke((), (), ())[0]:
184 pass
186 # turtle and text shape
187 self.assertEqual(document.DrawPage.getCount(), 2)
188 textShape = document.DrawPage.getByIndex(1)
189 # text in the text shape
190 self.assertEqual(textShape.getString(), "x, x, x, x, x...")
191 # check portion formatting
192 c = textShape.createTextCursor()
193 c.gotoStart(False)
194 # check portion formatting
195 c = textShape.createTextCursor()
196 c.gotoStart(False)
198 # strike out
199 self.assertEqual(c.CharStrikeout, __Strikeout_SINGLE__) # strike out
200 c.goRight(4, False)
202 # subscript
203 self.assertEqual(c.CharStrikeout, __Strikeout_NONE__) # no strike out
204 self.assertEqual(c.CharEscapement, -14000) # magic number for default subscript, see DFLT_ESC_AUTO_SUB
205 self.assertEqual(c.CharEscapementHeight, 58) # size in percent
206 c.goRight(3, False)
208 # superscript
209 self.assertEqual(c.CharEscapement, 14000) # magic number for default superscript, see DFLT_ESC_AUTO_SUPER
210 self.assertEqual(c.CharEscapementHeight, 58) # size in percent
211 c.goRight(3, False)
213 # font family
214 self.assertEqual(c.CharEscapement, 0) # no superscript
215 self.assertEqual(c.CharEscapementHeight, 100) # no superscript
216 self.assertEqual(c.CharFontName, "Liberation Sans") # new font family
217 c.goRight(3, False)
219 # font size
220 self.assertEqual(c.CharFontName, "Linux Biolinum G") # default font family
221 self.assertEqual(c.CharHeight, 20) # new font size
222 c.goRight(3, False)
224 # default font size
225 self.assertEqual(c.CharHeight, 12)
227 #3 check colors
229 document.Text.String = ( sLock +
230 "LABEL '<red>x</red>, <BLUE>x</BLUE>, " + # check ignoring case
231 "<FONTCOLOR GREEN>x</FONTCOLOR>, " + # check with command
232 "<FONTCOLOR 0x0000FF>x, " + # check with hexa code
233 "<FILLCOLOR ORANGE>x</FILLCOLOR>, " + # blue text with orange highlighting
234 "<FILLCOLOR 0xFF00FF>x</FILLCOLOR>" + # blue text with purple highlighting
235 "...</FONTCOLOR>'" )
237 self.logo("run")
238 # wait for LibreLogo program termination
239 while xIsAlive.invoke((), (), ())[0]:
240 pass
242 # turtle and text shape
243 self.assertEqual(document.DrawPage.getCount(), 2)
244 textShape = document.DrawPage.getByIndex(1)
245 # text in the text shape
246 self.assertEqual(textShape.getString(), "x, x, x, x, x, x...")
247 # check portion formatting
248 c = textShape.createTextCursor()
249 c.gotoStart(False)
250 # check portion formatting
251 c = textShape.createTextCursor()
252 c.gotoStart(False)
254 self.assertEqual(c.CharColor, 0xFF0000) # red
255 self.assertEqual(c.CharBackColor, -1) # transparent highlight
256 c.goRight(4, False)
258 self.assertEqual(c.CharColor, 0x0000FF) # blue
259 self.assertEqual(c.CharBackColor, -1) # transparent highlight
260 c.goRight(3, False)
262 self.assertEqual(c.CharColor, 0x008000) # green
263 self.assertEqual(c.CharBackColor, -1) # transparent highlight
264 c.goRight(3, False)
266 self.assertEqual(c.CharColor, 0x0000FF) # blue
267 self.assertEqual(c.CharBackColor, -1) # transparent highlight
268 c.goRight(3, False)
270 self.assertEqual(c.CharColor, 0x0000FF) # blue
271 self.assertEqual(c.CharBackColor, 0xFFA500) # orange highlight
272 c.goRight(3, False)
274 self.assertEqual(c.CharColor, 0x0000FF) # blue
275 self.assertEqual(c.CharBackColor, 0xFF00FF) # purple highlight
276 c.goRight(3, False)
278 self.assertEqual(c.CharColor, 0x0000FF) # blue
279 self.assertEqual(c.CharBackColor, -1) # transparent highlight
281 #4 check font features
283 document.Text.String = (
284 sLock + "FONTFAMILY 'Linux Biolinum G' " +
285 "LABEL 'a <smcp>smcp <pnum>1<onum>1</pnum> 1</onum>1</smcp>...'" )
287 self.logo("run")
288 # wait for LibreLogo program termination
289 while xIsAlive.invoke((), (), ())[0]:
290 pass
292 # turtle and text shape
293 self.assertEqual(document.DrawPage.getCount(), 2)
294 textShape = document.DrawPage.getByIndex(1)
295 # text in the text shape
296 self.assertEqual(textShape.getString(), "a smcp 11 11...")
297 # check portion formatting
298 c = textShape.createTextCursor()
299 c.gotoStart(False)
300 # check portion formatting
301 c = textShape.createTextCursor()
302 c.gotoStart(False)
304 self.assertEqual(c.CharFontName, "Linux Biolinum G")
305 c.goRight(3, False)
306 self.assertEqual(c.CharFontName, "Linux Biolinum G:smcp")
307 c.goRight(5, False)
308 self.assertEqual(c.CharFontName, "Linux Biolinum G:smcp&pnum")
309 c.goRight(1, False)
310 self.assertEqual(c.CharFontName, "Linux Biolinum G:smcp&pnum&onum")
311 c.goRight(2, False)
312 self.assertEqual(c.CharFontName, "Linux Biolinum G:smcp&onum")
313 c.goRight(1, False)
314 self.assertEqual(c.CharFontName, "Linux Biolinum G:smcp")
316 def test_LABEL(self):
317 self.check_label(False)
319 def test_custom_lock(self):
320 self.check_label(True)
322 # vim: set shiftwidth=4 softtabstop=4 expandtab: