tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / writerperfect / qa / uitest / epubexport / epubexport.py
blob76d8c5e43229e3c72b789788cd8207b23f9af95f
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 com.sun.star.beans import PropertyValue
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from uitest.framework import UITestCase
13 from uitest.uihelper.common import get_state_as_dict
14 import uno
17 # Test for EPUBExportDialog and EPUBExportUIComponent.
18 class EPUBExportTest(UITestCase):
20 def testUIComponent(self):
21 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
23 # Make sure we get what we asked for.
24 self.assertEqual("com.sun.star.comp.Writer.EPUBExportUIComponent", uiComponent.getImplementationName())
25 self.assertEqual(True, uiComponent.supportsService("com.sun.star.ui.dialogs.FilterOptionsDialog"))
26 # Just make sure this doesn't fail.
27 uiComponent.setTitle(str())
29 with self.ui_test.execute_blocking_action(action=uiComponent.execute) as dialog:
30 # Select the second entry to request EPUB2, not EPUB3.
31 dialog.getChild("versionlb").executeAction("SELECT", mkPropertyValues({"POS": "1"}))
32 propertyValues = uiComponent.getPropertyValues()
33 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
34 epubVersion = [i.Value for i in filterData if i.Name == "EPUBVersion"][0]
35 # This was 30, EPUBExportDialog::VersionSelectHdl() did not set the version.
36 self.assertEqual(20, epubVersion)
38 def testCustomProperties(self):
39 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
41 # Make sure that by default the version is not altered.
42 propertyValues = uiComponent.getPropertyValues()
43 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
44 self.assertEqual(0, len([i.Value for i in filterData if i.Name == "EPUBVersion"]))
46 # But if we set it explicitly, then it's retained, even without interacting with the UI.
47 filterData = (PropertyValue(Name="EPUBVersion", Value=30),)
48 propertyValues = (PropertyValue(Name="FilterData", Value=uno.Any("[]com.sun.star.beans.PropertyValue", filterData)),)
49 uiComponent.setPropertyValues(propertyValues)
50 propertyValues = uiComponent.getPropertyValues()
51 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
52 epubVersion = [i.Value for i in filterData if i.Name == "EPUBVersion"][0]
53 self.assertEqual(30, epubVersion)
55 def testDialogVersionInput(self):
56 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
57 positions = []
58 for version in (20, 30):
59 filterData = (PropertyValue(Name="EPUBVersion", Value=version),)
60 propertyValues = (PropertyValue(Name="FilterData", Value=uno.Any("[]com.sun.star.beans.PropertyValue", filterData)),)
61 uiComponent.setPropertyValues(propertyValues)
62 with self.ui_test.execute_blocking_action(action=uiComponent.execute) as dialog:
63 versionlb = get_state_as_dict(dialog.getChild("versionlb"))
64 # Log the state of the versionlb widget and exit.
65 positions.append(versionlb["SelectEntryPos"])
66 # Make sure that initializing with 2 different versions results in 2 different widget states.
67 self.assertEqual(2, len(set(positions)))
69 def testCoverImage(self):
70 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
72 with self.ui_test.execute_blocking_action(action=uiComponent.execute) as dialog:
73 dialog.getChild("coverpath").executeAction("TYPE", mkPropertyValues({"TEXT": "cover.png"}))
74 propertyValues = uiComponent.getPropertyValues()
75 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
76 # The RVNGCoverImage key was missing, EPUBExportDialog::OKClickHdl() did not set it.
77 coverImage = [i.Value for i in filterData if i.Name == "RVNGCoverImage"][0]
78 self.assertEqual("cover.png", coverImage)
80 def testMediaDir(self):
81 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
83 with self.ui_test.execute_blocking_action(action=uiComponent.execute) as dialog:
84 dialog.getChild("mediadir").executeAction("TYPE", mkPropertyValues({"TEXT": "file:///foo/bar"}))
85 propertyValues = uiComponent.getPropertyValues()
86 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
87 # The RVNGMediaDir key was missing, EPUBExportDialog::OKClickHdl() did not set it.
88 mediaDir = [i.Value for i in filterData if i.Name == "RVNGMediaDir"][0]
89 self.assertEqual("file:///foo/bar", mediaDir)
91 def testFixedLayout(self):
92 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
94 with self.ui_test.execute_blocking_action(action=uiComponent.execute) as dialog:
95 # Select the second entry to request fixed, not reflowable layout.
96 dialog.getChild("layoutlb").executeAction("SELECT", mkPropertyValues({"POS": "1"}))
97 propertyValues = uiComponent.getPropertyValues()
98 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
99 # The EPUBLayoutMethod key was missing, EPUBExportDialog::OKClickHdl() did not set it.
100 layout = [i.Value for i in filterData if i.Name == "EPUBLayoutMethod"][0]
101 # 1 stands for libepubgen::EPUB_LAYOUT_METHOD_FIXED.
102 self.assertEqual(1, layout)
104 def testMeta(self):
105 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
107 with self.ui_test.execute_blocking_action(action=uiComponent.execute) as dialog:
108 dialog.getChild("identifier").executeAction("TYPE", mkPropertyValues({"TEXT": "baddcafe-e394-4cd6-9b83-7172794612e5"}))
109 dialog.getChild("title").executeAction("TYPE", mkPropertyValues({"TEXT": "unknown title from ui"}))
110 dialog.getChild("author").executeAction("TYPE", mkPropertyValues({"TEXT": "unknown author from ui"}))
111 dialog.getChild("language").executeAction("TYPE", mkPropertyValues({"TEXT": "sk"}))
112 dialog.getChild("date").executeAction("TYPE", mkPropertyValues({"TEXT": "2013-11-20T17:16:07Z"}))
114 propertyValues = uiComponent.getPropertyValues()
115 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
116 # These keys were missing, EPUBExportDialog::OKClickHdl() did not set them.
117 identifier = [i.Value for i in filterData if i.Name == "RVNGIdentifier"][0]
118 self.assertEqual("baddcafe-e394-4cd6-9b83-7172794612e5", identifier)
119 title = [i.Value for i in filterData if i.Name == "RVNGTitle"][0]
120 self.assertEqual("unknown title from ui", title)
121 initialCreator = [i.Value for i in filterData if i.Name == "RVNGInitialCreator"][0]
122 self.assertEqual("unknown author from ui", initialCreator)
123 language = [i.Value for i in filterData if i.Name == "RVNGLanguage"][0]
124 self.assertEqual("sk", language)
125 date = [i.Value for i in filterData if i.Name == "RVNGDate"][0]
126 self.assertEqual("2013-11-20T17:16:07Z", date)
128 # vim: set shiftwidth=4 softtabstop=4 expandtab: