Debian Codegraph @

dbaccess/qa/uitest/query/tdf99619_create_join_undo_redo.py

raw symbols SCIP
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
2 #
3 # This file is part of the LibreOffice project.
4 #
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/.
8 #
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_url_for_data_file, get_state_as_dict, select_by_text
11 from uitest.test import DEFAULT_SLEEP
12
13 import sys
14 import time
15
16 #Bug 99619 - query design segfault on redoing an undone table join creation
17 class tdf99619(UITestCase):
18 def test_tdf99619(self):
19 # The sample file is an HSQLDB database with the two tables “person” and “object”. They both
20 # have a text field and a primary key. The object table additionally has an person_id field
21 # which is meant to reference an owner in the person table. There is also one query called
22 # “object_owners” which contains the two tables but no join.
23 with self.ui_test.load_file(get_url_for_data_file("tdf99619.odb")) as document:
24 xDbWindow = self.xUITest.getTopFocusWindow()
25
26 self.xUITest.executeCommand(".uno:DBViewQueries")
27 # The above command is run asynchronously via an event on the main thread so we need to
28 # wait until it is dispatched before executing the next command
29 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
30 xToolkit.waitUntilAllIdlesDispatched()
31
32 # We just want to select the single query in the list of queries but it seems difficult
33 # to get access to the treeview window for it because there are multiple treeviews in a
34 # hierarchy of windows with no name. However AppController handles SelectAll and that
35 # does the trick
36 self.xUITest.executeCommand(".uno:SelectAll")
37
38 xDbFrame = self.ui_test.get_desktop().getCurrentFrame()
39
40 with self.ui_test.open_subcomponent_through_command(".uno:DBQueryEdit") as xQueryFrame:
41 xQueryController = xQueryFrame.getController()
42
43 # Add a relation via the dialog
44 with self.ui_test.execute_blocking_action(
45 self.xUITest.executeCommandForProvider,
46 args=(".uno:DBAddRelation", xQueryController)) as xDialog:
47
48 # Choose the two tables
49 select_by_text(xDialog.getChild("table1"), "object")
50 select_by_text(xDialog.getChild("table2"), "person")
51
52 # Set the join type
53 select_by_text(xDialog.getChild("type"), "Inner join")
54
55 # Use a natural join because it’s too difficult to manipulate the grid to select
56 # fields
57 xDialog.getChild("natural").executeAction("CLICK", tuple())
58
59 # Undo the join
60 self.xUITest.executeCommandForProvider(".uno:Undo", xQueryFrame)
61 # Redo the join. This is where it crashes without any fixes to the bug
62 self.xUITest.executeCommandForProvider(".uno:Redo", xQueryFrame)
63
64 # Save the query. This only saves the query in memory
65 # and doesn’t change the database file on disk
66 self.xUITest.executeCommandForProvider(".uno:Save", xQueryFrame)
67
68 # Switch to SQL mode
69 self.xUITest.executeCommandForProvider(".uno:DBChangeDesignMode",
70 xQueryController)
71
72 # Get the SQL source for the query
73 xSql = self.xUITest.getTopFocusWindow().getChild("sql")
74 query = get_state_as_dict(xSql)["Text"]
75
76 # Make sure that the join is in the query
77 if "NATURAL INNER JOIN" not in query:
78 print(f"Join missing from query: {query}", file=sys.stderr)
79 self.assertTrue("NATURAL INNER JOIN" in query)
80
81 # vim: set shiftwidth=4 softtabstop=4 expandtab: