summaryrefslogtreecommitdiffstats
path: root/pyuno/qa
diff options
context:
space:
mode:
Diffstat (limited to 'pyuno/qa')
-rw-r--r--pyuno/qa/pytests/insertremovecells.py80
-rw-r--r--pyuno/qa/pytests/testcollections_XCellRange.py401
-rw-r--r--pyuno/qa/pytests/testcollections_XEnumeration.py122
-rw-r--r--pyuno/qa/pytests/testcollections_XEnumerationAccess.py146
-rw-r--r--pyuno/qa/pytests/testcollections_XIndexAccess.py326
-rw-r--r--pyuno/qa/pytests/testcollections_XIndexContainer.py204
-rw-r--r--pyuno/qa/pytests/testcollections_XIndexReplace.py241
-rw-r--r--pyuno/qa/pytests/testcollections_XNameAccess.py203
-rw-r--r--pyuno/qa/pytests/testcollections_XNameContainer.py132
-rw-r--r--pyuno/qa/pytests/testcollections_XNameReplace.py79
-rw-r--r--pyuno/qa/pytests/testcollections_base.py63
-rw-r--r--pyuno/qa/pytests/testcollections_misc.py83
-rw-r--r--pyuno/qa/pytests/testcollections_misc2.py62
-rw-r--r--pyuno/qa/pytests/testcollections_mixednameindex.py50
-rw-r--r--pyuno/qa/pytests/testdocuments/fdo74824.odsbin0 -> 4811 bytes
-rw-r--r--pyuno/qa/pytests/testssl.py10
16 files changed, 2202 insertions, 0 deletions
diff --git a/pyuno/qa/pytests/insertremovecells.py b/pyuno/qa/pytests/insertremovecells.py
new file mode 100644
index 000000000..f1c0fa176
--- /dev/null
+++ b/pyuno/qa/pytests/insertremovecells.py
@@ -0,0 +1,80 @@
+import pathlib
+import re
+import unittest
+
+from os import getenv, path
+
+from org.libreoffice.unotest import pyuno, mkPropertyValue, makeCopyFromTDOC
+
+
+class InsertRemoveCells(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.xContext = pyuno.getComponentContext()
+ pyuno.private_initTestEnvironment()
+
+ def test_fdo74824_load(self):
+ ctxt = self.xContext
+ assert(ctxt)
+
+ smgr = ctxt.ServiceManager
+ desktop = smgr.createInstanceWithContext('com.sun.star.frame.Desktop', ctxt)
+ load_props = tuple(mkPropertyValue(k, v) for (k, v) in (
+ ('Hidden', True),
+ ('ReadOnly', False)
+ ))
+ tdoc_path = makeCopyFromTDOC('fdo74824.ods')
+ url = pathlib.Path(tdoc_path).as_uri()
+ doc = desktop.loadComponentFromURL(url, "_blank", 0, load_props)
+
+ sheet = doc.Sheets.Sheet1
+ area = sheet.getCellRangeByName('A2:B4')
+ addr = area.getRangeAddress()
+
+ # 2 = intended to shift cells right, but I don't know where to find
+ # the ENUM to put in its place. Corrections welcome.
+ sheet.insertCells(addr, 2)
+
+ # basically, the insertCells call is the test: it should not crash
+ # LibreOffice. However, for completeness, we should test the cell
+ # contents as well.
+
+ empty_cells = (
+ (0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3),
+ (3, 1), (4, 0), (4, 2), (5, 0), (5, 2), (5, 3),
+ )
+ formula_cells = (
+ (2, 0, '=(1+GDR)^-D1', '1.000', 1.0),
+ (4, 1, '=(1+GDR)^-F2', '0.125', 0.125),
+ (4, 3, '=SUM(C1:C2)', '1.000', 1.0),
+ )
+ value_cells = (
+ (2, 2, '2010', 2010.0),
+ (2, 3, '7', 7.0),
+ (3, 0, '0', 0),
+ (3, 2, '2012', 2012.0),
+ (3, 3, '6', 6.0),
+ (5, 1, '1', 1.0),
+ )
+ for pos in empty_cells:
+ cell = sheet.getCellByPosition(*pos)
+ self.assertEqual('EMPTY', cell.Type.value)
+
+ for x, y, f, s, val in formula_cells:
+ cell = sheet.getCellByPosition(x, y)
+ self.assertEqual('FORMULA', cell.Type.value)
+ self.assertEqual(f, cell.getFormula())
+ self.assertEqual(s, cell.String)
+ self.assertEqual(val, cell.Value)
+
+ for x, y, s, val in value_cells:
+ cell = sheet.getCellByPosition(x, y)
+ self.assertEqual(s, cell.String)
+ self.assertEqual(val, cell.Value)
+
+ doc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/pyuno/qa/pytests/testcollections_XCellRange.py b/pyuno/qa/pytests/testcollections_XCellRange.py
new file mode 100644
index 000000000..641482433
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XCellRange.py
@@ -0,0 +1,401 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+from com.sun.star.table import CellAddress
+
+# TextTable instance factory
+def getTextTableInstance(doc):
+ return doc.createInstance('com.sun.star.text.TextTable')
+
+# Tests behaviour of objects implementing XCellRange using the new-style
+# collection accessors
+
+class TestXCellRange(CollectionsTestBase):
+
+ # TODO negative indices
+
+ # Tests syntax:
+ # cell = cellrange[0,0] # Access cell by indices
+ # For:
+ # Spreadsheet
+ # Cell at Row 0, Col 0
+ def test_XCellRange_Spreadsheet_Cell_00(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ cell = sht[0, 0]
+
+ # Then
+ self.assertEqual(0, cell.CellAddress.Sheet)
+ self.assertEqual(0, cell.CellAddress.Row)
+ self.assertEqual(0, cell.CellAddress.Column)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # cell = cellrange[0,0] # Access cell by indices
+ # For:
+ # Text table
+ # Cell at Row 0, Col 0
+ def test_XCellRange_Table_Cell_00(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ text_table = getTextTableInstance(doc)
+ text_table.initialize(10, 10)
+ cursor = doc.Text.createTextCursor()
+ doc.Text.insertTextContent(cursor, text_table, False)
+ tbl = doc.TextTables[0]
+
+ # When
+ cell = tbl[0, 0]
+
+ # Then
+ self.assertEqual('A1', cell.CellName)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # cell = cellrange[0,0] # Access cell by indices
+ # For:
+ # Spreadsheet
+ # Cell at Row 3, Col 7
+ def test_XCellRange_Spreadsheet_Cell_37(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht[3, 7]
+
+ # Then
+ self.assertEqual(0, rng.CellAddress.Sheet)
+ self.assertEqual(3, rng.CellAddress.Row)
+ self.assertEqual(7, rng.CellAddress.Column)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # cell = cellrange[0,0] # Access cell by indices
+ # For:
+ # Text table
+ # Cell at Row 3, Col 7
+ def test_XCellRange_Table_Cell_37(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ text_table = getTextTableInstance(doc)
+ text_table.initialize(10, 10)
+ cursor = doc.Text.createTextCursor()
+ doc.Text.insertTextContent(cursor, text_table, False)
+ tbl = doc.TextTables[0]
+
+ # When
+ cell = tbl[3, 7]
+
+ # Then
+ self.assertEqual('H4', cell.CellName)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[0,1:2] # Access cell range by index,slice
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_Index_Slice(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht[0, 1:3]
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(0, rng.RangeAddress.StartRow)
+ self.assertEqual(1, rng.RangeAddress.StartColumn)
+ self.assertEqual(0, rng.RangeAddress.EndRow)
+ self.assertEqual(2, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[0,1:2] # Access cell range by index,slice
+ # For:
+ # Text table
+ def test_XCellRange_Table_Range_Index_Slice(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ text_table = getTextTableInstance(doc)
+ text_table.initialize(10, 10)
+ cursor = doc.Text.createTextCursor()
+ doc.Text.insertTextContent(cursor, text_table, False)
+ tbl = doc.TextTables[0]
+ doc.lockControllers()
+ tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
+ doc.unlockControllers()
+
+ # When
+ rng = tbl[0, 1:3]
+
+ # Then
+ self.assertEqual((('101', '102'),), rng.DataArray)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[1:2,0] # Access cell range by slice,index
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_Slice_Index(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht[1:3, 0]
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(1, rng.RangeAddress.StartRow)
+ self.assertEqual(0, rng.RangeAddress.StartColumn)
+ self.assertEqual(2, rng.RangeAddress.EndRow)
+ self.assertEqual(0, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[1:2,0] # Access cell range by index,slice
+ # For:
+ # Text table
+ def test_XCellRange_Table_Range_Slice_Index(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ text_table = getTextTableInstance(doc)
+ text_table.initialize(10, 10)
+ cursor = doc.Text.createTextCursor()
+ doc.Text.insertTextContent(cursor, text_table, False)
+ tbl = doc.TextTables[0]
+ doc.lockControllers()
+ tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
+ doc.unlockControllers()
+
+ # When
+ rng = tbl[1:3, 0]
+
+ # Then
+ self.assertEqual((('110',), ('120',)), rng.DataArray)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[0:1,2:3] # Access cell range by slices
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_Slices(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht[1:3, 3:5]
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(1, rng.RangeAddress.StartRow)
+ self.assertEqual(3, rng.RangeAddress.StartColumn)
+ self.assertEqual(2, rng.RangeAddress.EndRow)
+ self.assertEqual(4, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[0:1,2:3] # Access cell range by slices
+ # For:
+ # Spreadsheet
+ # Zero rows/columns
+ def test_XCellRange_Spreadsheet_Range_Slices_Invalid(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When / Then
+ with self.assertRaises(KeyError):
+ rng = sht[1:1, 3:5]
+ with self.assertRaises(KeyError):
+ rng = sht[1:3, 3:3]
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[0:1,2:3] # Access cell range by slices
+ # For:
+ # Text table
+ def test_XCellRange_Table_Range_Slices(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ text_table = getTextTableInstance(doc)
+ text_table.initialize(10, 10)
+ cursor = doc.Text.createTextCursor()
+ doc.Text.insertTextContent(cursor, text_table, False)
+ tbl = doc.TextTables[0]
+ doc.lockControllers()
+ tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
+ doc.unlockControllers()
+
+ # When
+ rng = tbl[1:3, 3:5]
+
+ # Then
+ self.assertEqual((('113', '114'), ('123', '124')), rng.DataArray)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # rng = cellrange['A1:B2'] # Access cell range by descriptor
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_Descriptor(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht['A3:B4']
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(2, rng.RangeAddress.StartRow)
+ self.assertEqual(0, rng.RangeAddress.StartColumn)
+ self.assertEqual(3, rng.RangeAddress.EndRow)
+ self.assertEqual(1, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange['A1:B2'] # Access cell range by descriptor
+ # For:
+ # Table
+ def test_XCellRange_Table_Range_Descriptor(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ text_table = getTextTableInstance(doc)
+ text_table.initialize(10, 10)
+ cursor = doc.Text.createTextCursor()
+ doc.Text.insertTextContent(cursor, text_table, False)
+ tbl = doc.TextTables[0]
+ doc.lockControllers()
+ tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
+ doc.unlockControllers()
+
+ # When
+ rng = tbl['A3:B4']
+
+ # Then
+ self.assertEqual((('120', '121'), ('130', '131')), rng.DataArray)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # rng = cellrange['Name'] # Access cell range by name
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_Name(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+ expr = '$' + sht.Name + '.$C2:F10'
+ addr = CellAddress(Sheet=0, Row=1, Column=2)
+ sht.NamedRanges.addNewByName('foo', expr, addr, 0)
+
+ # When
+ rng = sht['foo']
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(1, rng.RangeAddress.StartRow)
+ self.assertEqual(2, rng.RangeAddress.StartColumn)
+ self.assertEqual(9, rng.RangeAddress.EndRow)
+ self.assertEqual(5, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[0] # Access cell range by row index
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_RowIndex(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht[0]
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(0, rng.RangeAddress.StartRow)
+ self.assertEqual(0, rng.RangeAddress.StartColumn)
+ self.assertEqual(0, rng.RangeAddress.EndRow)
+ self.assertEqual(16383, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[0,:] # Access cell range by row index
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_RowIndex_FullSlice(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht[0, :]
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(0, rng.RangeAddress.StartRow)
+ self.assertEqual(0, rng.RangeAddress.StartColumn)
+ self.assertEqual(0, rng.RangeAddress.EndRow)
+ self.assertEqual(16383, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # rng = cellrange[:,0] # Access cell range by column index
+ # For:
+ # Spreadsheet
+ def test_XCellRange_Spreadsheet_Range_FullSlice_ColumnIndex(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ sht = spr.Sheets[0]
+
+ # When
+ rng = sht[:, 0]
+
+ # Then
+ self.assertEqual(0, rng.RangeAddress.Sheet)
+ self.assertEqual(0, rng.RangeAddress.StartRow)
+ self.assertEqual(0, rng.RangeAddress.StartColumn)
+ self.assertEqual(1048575, rng.RangeAddress.EndRow)
+ self.assertEqual(0, rng.RangeAddress.EndColumn)
+
+ spr.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XEnumeration.py b/pyuno/qa/pytests/testcollections_XEnumeration.py
new file mode 100644
index 000000000..8d1f8eece
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XEnumeration.py
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+
+# Tests behaviour of objects implementing XEnumeration using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXEnumeration(CollectionsTestBase):
+
+ # Tests syntax:
+ # for val in itr: ... # Iteration of named iterator
+ # For:
+ # 1 element
+ def test_XEnumeration_ForIn(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ paragraphs = []
+ itr = iter(doc.Text.createEnumeration())
+ for para in itr:
+ paragraphs.append(para)
+
+ # Then
+ self.assertEqual(1, len(paragraphs))
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in itr: ... # Test value presence
+ # For:
+ # Present value
+ def test_XEnumeration_IfIn_Present(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ paragraph = doc.Text.createEnumeration().nextElement()
+ itr = iter(doc.Text.createEnumeration())
+ result = paragraph in itr
+
+ # Then
+ self.assertTrue(result)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in itr: ... # Test value presence
+ # For:
+ # Absent value
+ def test_XEnumeration_IfIn_Absent(self):
+ # Given
+ doc1 = self.createBlankTextDocument()
+ doc2 = self.createBlankTextDocument()
+
+ # When
+ paragraph = doc2.Text.createEnumeration().nextElement()
+ itr = iter(doc1.Text.createEnumeration())
+ result = paragraph in itr
+
+ # Then
+ self.assertFalse(result)
+
+ doc1.close(True)
+ doc2.close(True)
+
+ # Tests syntax:
+ # if val in itr: ... # Test value presence
+ # For:
+ # None
+ def test_XEnumeration_IfIn_None(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ itr = iter(doc.Text.createEnumeration())
+ result = None in itr
+
+ # Then
+ self.assertFalse(result)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in itr: ... # Test value presence
+ # For:
+ # Invalid value (string)
+ # Note: Ideally this would raise TypeError in the same manner as for
+ # XEnumerationAccess, but an XEnumeration doesn't know the type of its
+ # values
+ def test_XEnumeration_IfIn_String(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ itr = iter(doc.Text.createEnumeration())
+ result = 'foo' in itr
+
+ # Then
+ self.assertFalse(result)
+
+ doc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XEnumerationAccess.py b/pyuno/qa/pytests/testcollections_XEnumerationAccess.py
new file mode 100644
index 000000000..a62b05ce9
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XEnumerationAccess.py
@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+
+# Tests behaviour of objects implementing XEnumerationAccess using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXEnumerationAccess(CollectionsTestBase):
+
+ # Tests syntax:
+ # for val in obj: ... # Implicit iterator
+ # For:
+ # 1 element
+ def test_XEnumerationAccess_ForIn(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ paragraphs = []
+ for para in doc.Text:
+ paragraphs.append(para)
+
+ # Then
+ self.assertEqual(1, len(paragraphs))
+
+ doc.close(True)
+
+ # Tests syntax:
+ # itr = iter(obj) # Named iterator
+ # For:
+ # 1 element
+ def test_XEnumerationAccess_Iter(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ itr = iter(doc.Text)
+
+ # Then
+ self.assertIsNotNone(next(itr))
+ with self.assertRaises(StopIteration):
+ next(itr)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # Present value
+ def test_XEnumerationAccess_IfIn_Present(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ paragraph = doc.Text.createEnumeration().nextElement()
+ result = paragraph in doc.Text
+
+ # Then
+ self.assertTrue(result)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # Absent value
+ def test_XEnumerationAccess_IfIn_Absent(self):
+ # Given
+ doc1 = self.createBlankTextDocument()
+ doc2 = self.createBlankTextDocument()
+
+ # When
+ paragraph = doc2.Text.createEnumeration().nextElement()
+ result = paragraph in doc1.Text
+
+ # Then
+ self.assertFalse(result)
+
+ doc1.close(True)
+ doc2.close(True)
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # None
+ def test_XEnumerationAccess_IfIn_None(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ result = None in doc.Text
+
+ # Then
+ self.assertFalse(result)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # Invalid value (string)
+ def test_XEnumerationAccess_IfIn_String(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ result = 'foo' in doc.Text
+
+ # Then
+ self.assertFalse(result)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # Invalid value (dict)
+ def test_XEnumerationAccess_IfIn_String(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ result = {} in doc.Text
+
+ doc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XIndexAccess.py b/pyuno/qa/pytests/testcollections_XIndexAccess.py
new file mode 100644
index 000000000..e3eeb45ce
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XIndexAccess.py
@@ -0,0 +1,326 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from inspect import isclass
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+# Footnote instance factory
+def getFootnoteInstance(doc):
+ return doc.createInstance("com.sun.star.text.Footnote")
+
+# Tests behaviour of objects implementing XIndexAccess using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXIndexAccess(CollectionsTestBase):
+
+ def insertTestFootnotes(self, doc, count):
+ cursor = doc.Text.createTextCursor()
+ for i in range(count):
+ footnote = getFootnoteInstance(doc)
+ footnote.Label = 'n'+str(i)
+ doc.Text.insertTextContent(cursor, footnote, 0)
+
+ def readValuesTestFixture(self, doc, count, key, expected):
+ # Given
+ doc.Text.setString('')
+ self.insertTestFootnotes(doc, count)
+
+ # When
+ captured = None
+ try:
+ actual = doc.Footnotes[key]
+ except Exception as e:
+ captured = e
+
+ # Then
+ if isclass(expected) and issubclass(expected, Exception):
+ # expected is exception
+ self.assertNotEqual(None, captured)
+ self.assertEqual(expected.__name__, type(captured).__name__)
+ elif type(expected) is tuple:
+ # expected is tuple
+ self.assertEqual(None, captured)
+ self.assertTrue(type(actual) is tuple)
+ self.assertEqual(len(expected), len(actual))
+ for i in range(len(expected)):
+ self.assertEqual('n'+str(expected[i]), actual[i].Label)
+ else:
+ # expected is value
+ self.assertEqual(None, captured)
+ self.assertTrue(type(actual) is not tuple)
+ self.assertEqual('n'+str(expected), actual.Label)
+
+ # Tests syntax:
+ # num = len(obj) # Number of elements
+ # For:
+ # length = 0
+ def test_XIndexAccess_Len_0(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ count = len(doc.Footnotes)
+
+ # Then
+ self.assertEqual(0, count)
+
+ doc.close(True);
+
+ # Tests syntax:
+ # num = len(obj) # Number of elements
+ # For:
+ # length = 1
+ def test_XIndexAccess_Len_1(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ cursor = doc.Text.createTextCursor()
+ footnote = getFootnoteInstance(doc)
+ doc.Text.insertTextContent(cursor, footnote, 0)
+
+ # When
+ count = len(doc.Footnotes)
+
+ # Then
+ self.assertEqual(1, count)
+
+ doc.close(True);
+
+ # Tests syntax:
+ # val = obj[0] # Access by index
+ # For:
+ # Single indices
+ def test_XIndexAccess_ReadIndex_Single(self):
+ doc = self.createBlankTextDocument()
+ self.readValuesTestFixture(doc, 0, -1, IndexError)
+ self.readValuesTestFixture(doc, 0, 0, IndexError)
+ self.readValuesTestFixture(doc, 0, 1, IndexError)
+ self.readValuesTestFixture(doc, 1, -3, IndexError)
+ self.readValuesTestFixture(doc, 1, -2, IndexError)
+ self.readValuesTestFixture(doc, 1, -1, 0)
+ self.readValuesTestFixture(doc, 1, 0, 0)
+ self.readValuesTestFixture(doc, 1, 1, IndexError)
+ self.readValuesTestFixture(doc, 1, 2, IndexError)
+ self.readValuesTestFixture(doc, 2, -4, IndexError)
+ self.readValuesTestFixture(doc, 2, -3, IndexError)
+ self.readValuesTestFixture(doc, 2, -2, 0)
+ self.readValuesTestFixture(doc, 2, -1, 1)
+ self.readValuesTestFixture(doc, 2, 0, 0)
+ self.readValuesTestFixture(doc, 2, 1, 1)
+ self.readValuesTestFixture(doc, 2, 2, IndexError)
+ self.readValuesTestFixture(doc, 2, 3, IndexError)
+ doc.close(True);
+
+ def test_XIndexAccess_ReadIndex_Single_Invalid(self):
+ doc = self.createBlankTextDocument()
+ self.readValuesTestFixture(doc, 0, None, TypeError)
+ self.readValuesTestFixture(doc, 0, 'foo', TypeError)
+ self.readValuesTestFixture(doc, 0, 12.34, TypeError)
+ self.readValuesTestFixture(doc, 0, (0, 1), TypeError)
+ self.readValuesTestFixture(doc, 0, [0, 1], TypeError)
+ self.readValuesTestFixture(doc, 0, {'a': 'b'}, TypeError)
+ doc.close(True);
+
+ # Tests syntax:
+ # val1,val2 = obj[2:4] # Access by slice
+ def test_XIndexAccess_ReadSlice(self):
+ doc = self.createBlankTextDocument()
+ test_max = 4
+ for i in range(test_max):
+ t = tuple(range(i))
+ for j in [x for x in range(-test_max-2, test_max+3)] + [None]:
+ for k in [x for x in range(-test_max-2, test_max+3)] + [None]:
+ key = slice(j, k)
+ expected = t[key]
+ self.readValuesTestFixture(doc, i, key, expected)
+ doc.close(True);
+
+ # Tests syntax:
+ # val1,val2 = obj[0:3:2] # Access by extended slice
+ def test_XIndexAccess_ReadExtendedSlice(self):
+ doc = self.createBlankTextDocument()
+ test_max = 4
+ for i in range(test_max):
+ t = tuple(range(i))
+ for j in [x for x in range(-test_max-2, test_max+3)] + [None]:
+ for k in [x for x in range(-test_max-2, test_max+3)] + [None]:
+ for l in [-2, -1, 2]:
+ key = slice(j, k, l)
+ expected = t[key]
+ self.readValuesTestFixture(doc, i, key, expected)
+ doc.close(True);
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # Present element
+ def test_XIndexAccess_In_Present(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ cursor = doc.Text.createTextCursor()
+ footnote = getFootnoteInstance(doc)
+ footnote.setLabel('foo')
+ doc.Text.insertTextContent(cursor, footnote, 0)
+ footnote = doc.Footnotes[0]
+
+ # When
+ present = footnote in doc.Footnotes
+
+ # Then
+ self.assertTrue(present)
+
+ doc.close(True);
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # None
+ def test_XIndexAccess_In_None(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ present = None in doc.Footnotes
+
+ # Then
+ self.assertFalse(present)
+
+ doc.close(True);
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # Absent element (string)
+ def test_XIndexAccess_In_String(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When / Then
+ present = "foo" in doc.Footnotes
+
+ # Then
+ self.assertFalse(present)
+
+ doc.close(True);
+
+ # Tests syntax:
+ # if val in obj: ... # Test value presence
+ # For:
+ # Absent element (dict)
+ def test_XIndexAccess_In_Dict(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ present = {} in doc.Footnotes
+
+ doc.close(True);
+
+ # Tests syntax:
+ # for val in obj: ... # Implicit iterator (values)
+ # For:
+ # 0 elements
+ def test_XIndexAccess_ForIn_0(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When
+ read_footnotes = []
+ for f in doc.Footnotes:
+ read_footnotes.append(f)
+
+ # Then
+ self.assertEqual(0, len(read_footnotes))
+
+ doc.close(True);
+
+ # Tests syntax:
+ # for val in obj: ... # Implicit iterator (values)
+ # For:
+ # 1 element
+ def test_XIndexAccess_ForIn_1(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ cursor = doc.Text.createTextCursor()
+ footnote = getFootnoteInstance(doc)
+ footnote.setLabel('foo')
+ doc.Text.insertTextContent(cursor, footnote, 0)
+
+ # When
+ read_footnotes = []
+ for f in doc.Footnotes:
+ read_footnotes.append(f)
+
+ # Then
+ self.assertEqual(1, len(read_footnotes))
+ self.assertEqual('foo', read_footnotes[0].Label)
+
+ doc.close(True);
+
+ # Tests syntax:
+ # for val in obj: ... # Implicit iterator (values)
+ # For:
+ # 2 elements
+ def test_XIndexAccess_ForIn_2(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ cursor = doc.Text.createTextCursor()
+ footnote1 = getFootnoteInstance(doc)
+ footnote2 = getFootnoteInstance(doc)
+ footnote1.setLabel('foo')
+ footnote2.setLabel('bar')
+ doc.Text.insertTextContent(cursor, footnote1, 0)
+ doc.Text.insertTextContent(cursor, footnote2, 0)
+
+ # When
+ read_footnotes = []
+ for f in doc.Footnotes:
+ read_footnotes.append(f)
+
+ # Then
+ self.assertEqual(2, len(read_footnotes))
+ self.assertEqual('foo', read_footnotes[0].Label)
+ self.assertEqual('bar', read_footnotes[1].Label)
+
+ doc.close(True);
+
+ # Tests syntax:
+ # itr = iter(obj) # Named iterator (values)
+ # For:
+ # 1 element
+ def test_XIndexAccess_Iter_0(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ cursor = doc.Text.createTextCursor()
+ footnote = getFootnoteInstance(doc)
+ footnote.setLabel('foo')
+ doc.Text.insertTextContent(cursor, footnote, 0)
+
+ # When
+ itr = iter(doc.Footnotes)
+
+ # Then
+ self.assertIsNotNone(next(itr))
+ with self.assertRaises(StopIteration):
+ next(itr)
+
+ doc.close(True);
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XIndexContainer.py b/pyuno/qa/pytests/testcollections_XIndexContainer.py
new file mode 100644
index 000000000..1df5f0774
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XIndexContainer.py
@@ -0,0 +1,204 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+# DataForm factory
+def getDataFormInstance(doc):
+ return doc.createInstance("com.sun.star.form.component.DataForm")
+
+
+# Tests behaviour of objects implementing XIndexContainer using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXIndexContainer(CollectionsTestBase):
+
+ def generateTestPropertyValues(self, count):
+ sm = self.context.ServiceManager
+ values = sm.createInstanceWithContext("com.sun.star.document.IndexedPropertyValues", self.context)
+ for i in range(count):
+ properties = (PropertyValue(Name='n'+str(i), Value='v'+str(i)),)
+ uno.invoke(values, "insertByIndex", (i, uno.Any("[]com.sun.star.beans.PropertyValue", properties)))
+ return values
+
+ def generateTestTuple(self, values):
+ properties = []
+ for i in values:
+ properties.append((PropertyValue(Name='n'+str(i), Value='v'+str(i)),))
+ return tuple(properties)
+
+ def assignValuesTestFixture(self, count, key, values, expected):
+ # Given
+ property_values = self.generateTestPropertyValues(count)
+ if type(values) is list:
+ to_assign = self.generateTestTuple(values)
+ else:
+ to_assign = values
+ if not (isinstance(expected, Exception)):
+ to_compare = self.generateTestTuple(expected)
+
+ # When
+ captured = None
+ try:
+ property_values[key] = to_assign
+ except Exception as e:
+ captured = e
+
+ # Then
+ if isinstance(expected, Exception):
+ # expected is exception
+ self.assertNotEqual(None, captured)
+ self.assertEqual(type(expected).__name__, type(captured).__name__)
+ else:
+ # expected is list
+ self.assertEqual(None, captured)
+ self.assertEqual(len(expected), property_values.getCount())
+ for i in range(property_values.getCount()):
+ self.assertEqual(to_compare[i][0].Name, property_values[i][0].Name)
+
+ def deleteValuesTestFixture(self, count, key, expected):
+ # Given
+ property_values = self.generateTestPropertyValues(count)
+ if not (isinstance(expected, Exception)):
+ to_compare = self.generateTestTuple(expected)
+
+ # When
+ captured = None
+ try:
+ del property_values[key]
+ except Exception as e:
+ captured = e
+
+ # Then
+ if isinstance(expected, Exception):
+ # expected is exception
+ self.assertNotEqual(None, captured)
+ self.assertEqual(type(expected).__name__, type(captured).__name__)
+ else:
+ # expected is list
+ self.assertEqual(None, captured)
+ self.assertEqual(len(expected), property_values.getCount())
+ for i in range(property_values.getCount()):
+ self.assertEqual(to_compare[i][0].Name, property_values[i][0].Name)
+
+ # Tests syntax:
+ # obj[2:4] = val1,val2 # Replace by slice
+ # obj[2:3] = val1,val2 # Insert/replace by slice
+ # obj[2:2] = (val,) # Insert by slice
+ # obj[2:4] = (val,) # Replace/delete by slice
+ # obj[2:3] = () # Delete by slice (implicit)
+ # For:
+ # Cases requiring sequence type coercion
+ def test_XIndexContainer_AssignSlice(self):
+ base_max = 5
+ assign_max = 5
+ for i in range(base_max):
+ for j in [x for x in range(-base_max-2, base_max+3)] + [None]:
+ for k in [x for x in range(-base_max-2, base_max+3)] + [None]:
+ key = slice(j, k)
+ for l in range(assign_max):
+ assign = [y+100 for y in range(l)]
+ expected = list(range(i))
+ expected[key] = assign
+ self.assignValuesTestFixture(i, key, assign, expected)
+
+ # Tests syntax:
+ # obj[2:4] = val1,val2 # Replace by slice
+ # obj[2:3] = val1,val2 # Insert/replace by slice
+ # obj[2:2] = (val,) # Insert by slice
+ # For:
+ # Cases not requiring sequence type coercion
+ # Invalid values
+ def test_XIndexContainer_AssignSlice_Invalid(self):
+ self.assignValuesTestFixture(2, slice(0, 2), None, TypeError())
+ self.assignValuesTestFixture(2, slice(0, 2), 'foo', TypeError())
+ self.assignValuesTestFixture(2, slice(0, 2), 12.34, TypeError())
+ self.assignValuesTestFixture(2, slice(0, 2), {'a': 'b'}, TypeError())
+ self.assignValuesTestFixture(2, slice(0, 2), ('foo',), TypeError())
+ self.assignValuesTestFixture(2, slice(0, 2), ('foo', 'foo'), TypeError())
+
+ # Tests syntax:
+ # obj[2:2] = (val,) # Insert by slice
+ # For:
+ # Cases not requiring sequence type coercion
+ def test_XIndexContainer_AssignSlice_NoCoercion(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ form = getDataFormInstance(doc)
+ form.Name = 'foo'
+
+ # When
+ doc.DrawPage.Forms[0:0] = (form,)
+
+ # Then
+ self.assertEqual('foo', doc.DrawPage.Forms[0].Name)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0:3:2] = val1,val2 # Replace by extended slice
+ # For:
+ # Cases requiring sequence type coercion
+ def test_XIndexContainer_AssignExtendedSlice(self):
+ base_max = 5
+ assign_max = 5
+ for i in range(base_max):
+ for j in [x for x in range(-base_max-2, base_max+3)] + [None]:
+ for k in [x for x in range(-base_max-2, base_max+3)] + [None]:
+ for l in [-2, -1, 1, 2]:
+ key = slice(j, k, l)
+ for m in range(assign_max):
+ assign = [y+100 for y in range(m)]
+ expected = list(range(i))
+ try:
+ expected[key] = assign
+ except Exception as e:
+ expected = e
+
+ self.assignValuesTestFixture(i, key, assign, expected)
+
+ # Tests syntax:
+ # del obj[0] # Delete by index
+ def test_XIndexContainer_DelIndex(self):
+ base_max = 5
+ for i in range(base_max):
+ for j in [x for x in range(-base_max-2, base_max+3)]:
+ expected = list(range(i))
+ try:
+ del expected[j]
+ except Exception as e:
+ expected = e
+ self.deleteValuesTestFixture(i, j, expected)
+
+ # Tests syntax:
+ # del obj[2:4] # Delete by slice
+ def test_XIndexContainer_DelSlice(self):
+ baseMax = 5
+ for i in range(baseMax):
+ for j in [x for x in range(-baseMax-2, baseMax+3)] + [None]:
+ for k in [x for x in range(-baseMax-2, baseMax+3)] + [None]:
+ key = slice(j, k)
+ expected = list(range(i))
+ try:
+ del expected[key]
+ except Exception as e:
+ expected = e
+ self.deleteValuesTestFixture(i, key, expected)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XIndexReplace.py b/pyuno/qa/pytests/testcollections_XIndexReplace.py
new file mode 100644
index 000000000..78361cbca
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XIndexReplace.py
@@ -0,0 +1,241 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+
+# ContentIndex instance factory
+def getContentIndexInstance(doc):
+ return doc.createInstance("com.sun.star.text.ContentIndex")
+
+# Tests behaviour of objects implementing XIndexReplace using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXIndexReplace(CollectionsTestBase):
+
+ def generateTestContentIndex(self, doc):
+ index = getContentIndexInstance(doc)
+ for i in range(10):
+ styles = ('n'+str(i),)
+ uno.invoke(index.LevelParagraphStyles, "replaceByIndex", (i, uno.Any("[]string", styles)))
+ return index
+
+ def generateTestTuple(self, values):
+ properties = []
+ for i in values:
+ properties.append(('n'+str(i),),)
+ return tuple(properties)
+
+ def assignValuesTestFixture(self, doc, key, values, expected):
+ # Given
+ index = self.generateTestContentIndex(doc)
+ to_assign = self.generateTestTuple(values)
+ if not (isinstance(expected, Exception)):
+ toCompare = self.generateTestTuple(expected)
+
+ # When
+ captured = None
+ try:
+ index.LevelParagraphStyles[key] = to_assign
+ except Exception as e:
+ captured = e
+
+ # Then
+ if isinstance(expected, Exception):
+ # expected is exception
+ self.assertNotEqual(None, captured)
+ self.assertEqual(type(expected).__name__, type(captured).__name__)
+ else:
+ # expected is list
+ self.assertEqual(None, captured)
+ for i in range(10):
+ self.assertEqual(toCompare[i][0],
+ index.LevelParagraphStyles[i][0])
+
+ # Tests syntax:
+ # obj[0] = val # Replace by index
+ # For:
+ # Cases requiring sequence type coercion
+ def test_XIndexReplace_ReplaceIndex(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When
+ index.LevelParagraphStyles[0] = ('Caption',)
+
+ # Then
+ self.assertEqual(('Caption',), index.LevelParagraphStyles[0])
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0] = val # Replace by index
+ # For:
+ # Invalid value (None)
+ def test_XIndexReplace_ReplaceIndex_Invalid_None(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ index.LevelParagraphStyles[0] = None
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0] = val # Replace by index
+ # For:
+ # Invalid value (String)
+ def test_XIndexReplace_ReplaceIndex_Invalid_String(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ index.LevelParagraphStyles[0] = 'foo'
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0] = val # Replace by index
+ # For:
+ # Invalid value (Float)
+ def test_XIndexReplace_ReplaceIndex_Invalid_Float(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ index.LevelParagraphStyles[0] = 12.34
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0] = val # Replace by index
+ # For:
+ # Invalid value (List)
+ def test_XIndexReplace_ReplaceIndex_Invalid_List(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ index.LevelParagraphStyles[0] = [0, 1]
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0] = val # Replace by index
+ # For:
+ # Invalid value (Dict)
+ def test_XIndexReplace_ReplaceIndex_Invalid_Dict(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ index.LevelParagraphStyles[0] = {'a': 'b'}
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0] = val # Replace by index
+ # For:
+ # Invalid value (inconsistently typed tuple)
+ def test_XIndexReplace_ReplaceIndex_Invalid_InconsistentTuple(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ index.LevelParagraphStyles[0] = ('Caption', ())
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[2:4] = val1,val2 # Replace by slice
+ # For:
+ # Cases requiring sequence type coercion
+ def test_XIndexReplace_ReplaceSlice(self):
+ assign_max = 12
+ doc = self.createBlankTextDocument()
+ t = tuple(range(10))
+ for j in [x for x in range(-12, 13)] + [None]:
+ for k in [x for x in range(-12, 13)] + [None]:
+ key = slice(j, k)
+ for l in range(assign_max):
+ assign = [y+100 for y in range(l)]
+ expected = list(range(10))
+ try:
+ expected[key] = assign
+ except Exception as e:
+ expected = e
+ if (len(expected) != 10):
+ expected = ValueError()
+ self.assignValuesTestFixture(doc, key, assign, expected)
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[2:4] = val1,val2 # Replace by slice
+ # For:
+ # Invalid values (inconsistently value types in tuple)
+ def test_XIndexReplace_ReplaceSlice_Invalid_InconsistentTuple(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ index = getContentIndexInstance(doc)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ index.LevelParagraphStyles[0:2] = (
+ ('Caption',),
+ 12.34
+ )
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[0:3:2] = val1,val2 # Replace by extended slice
+ # For:
+ # Cases requiring sequence type coercion
+ def test_XIndexReplace_ReplaceExtendedSlice(self):
+ assign_max = 12
+ doc = self.createBlankTextDocument()
+ t = tuple(range(10))
+ for j in [x for x in range(-12, 13)] + [None]:
+ for k in [x for x in range(-12, 13)] + [None]:
+ for l in [-2, -1, 2]:
+ key = slice(j, k, l)
+ for m in range(assign_max):
+ assign = [y+100 for y in range(m)]
+ expected = list(range(10))
+ try:
+ expected[key] = assign
+ except Exception as e:
+ expected = e
+ self.assignValuesTestFixture(doc, key, assign, expected)
+ doc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XNameAccess.py b/pyuno/qa/pytests/testcollections_XNameAccess.py
new file mode 100644
index 000000000..498e17e28
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XNameAccess.py
@@ -0,0 +1,203 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+
+# Tests behaviour of objects implementing XNameAccess using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXNameAccess(CollectionsTestBase):
+
+ # Tests syntax:
+ # num = len(obj) # Number of keys
+ # For:
+ # 2 elements
+ def test_XNameAccess_Len(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When
+ length = len(drw.Links)
+
+ # Then
+ self.assertEqual(2, length)
+
+ drw.close(True)
+
+ # Tests syntax:
+ # val = obj[key] # Access by key
+ # For:
+ # 1/2 elements
+ def test_XNameAccess_ReadKey(self):
+ # Given
+ drw = self.createBlankDrawing()
+ drw.DrawPages[0].Name = 'foo'
+
+ # When
+ link = drw.Links['foo']
+
+ # Then
+ self.assertEqual('foo', link.getName())
+
+ drw.close(True)
+
+ # Tests syntax:
+ # val = obj[key] # Access by key
+ # For:
+ # Missing key
+ def test_XNameAccess_ReadKey_Missing(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When / Then
+ with self.assertRaises(KeyError):
+ link = drw.Links['foo']
+
+ drw.close(True)
+
+ # Tests syntax:
+ # val = obj[key] # Access by key
+ # For:
+ # Invalid key type (None)
+ def test_XNameAccess_ReadKey_Invalid_None(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ link = drw.Links[None]
+
+ drw.close(True)
+
+ # Tests syntax:
+ # val = obj[key] # Access by key
+ # For:
+ # Invalid key type (float)
+ def test_XNameAccess_ReadKey_Invalid_Float(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ link = drw.Links[12.34]
+
+ drw.close(True)
+
+ # Tests syntax:
+ # val = obj[key] # Access by key
+ # For:
+ # Invalid key type (tuple)
+ def test_XNameAccess_ReadKey_Invalid_Tuple(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ link = drw.Links[(1, 2)]
+
+ drw.close(True)
+
+ # Tests syntax:
+ # val = obj[key] # Access by key
+ # For:
+ # Invalid key type (list)
+ def test_XNameAccess_ReadKey_Invalid_List(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ link = drw.Links[[1, 2]]
+
+ drw.close(True)
+
+ # Tests syntax:
+ # val = obj[key] # Access by key
+ # For:
+ # Invalid key type (dict)
+ def test_XNameAccess_ReadKey_Invalid_Dict(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ link = drw.Links[{'a': 'b'}]
+
+ drw.close(True)
+
+ # Tests syntax:
+ # if key in obj: ... # Test key presence
+ # For:
+ # 1/2 elements
+ def test_XNameAccess_In(self):
+ # Given
+ drw = self.createBlankDrawing()
+ drw.DrawPages[0].Name = 'foo'
+
+ # When
+ present = 'foo' in drw.Links
+
+ # Then
+ self.assertTrue(present)
+
+ drw.close(True)
+
+ # Tests syntax:
+ # for key in obj: ... # Implicit iterator (keys)
+ # For:
+ # 2 elements
+ def test_XNameAccess_ForIn(self):
+ # Given
+ drw = self.createBlankDrawing()
+ i = 0
+ for name in drw.Links.getElementNames():
+ drw.Links.getByName(name).Name = 'foo' + str(i)
+ i += 1
+
+ # When
+ read_links = []
+ for link in drw.Links:
+ read_links.append(link)
+
+ # Then
+ self.assertEqual(['foo0', 'foo1'], read_links)
+
+ drw.close(True)
+
+ # Tests syntax:
+ # itr = iter(obj) # Named iterator (keys)
+ # For:
+ # 2 elements
+ def test_XNameAccess_Iter(self):
+ # Given
+ drw = self.createBlankDrawing()
+
+ # When
+ itr = iter(drw.Links)
+
+ # Then
+ self.assertIsNotNone(next(itr))
+ self.assertIsNotNone(next(itr))
+ with self.assertRaises(StopIteration):
+ next(itr)
+
+ drw.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XNameContainer.py b/pyuno/qa/pytests/testcollections_XNameContainer.py
new file mode 100644
index 000000000..c544ca9dd
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XNameContainer.py
@@ -0,0 +1,132 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+# SheetCellRanges instance factory
+def getSheetCellRangesInstance(spr):
+ return spr.createInstance("com.sun.star.sheet.SheetCellRanges")
+
+
+# Tests behaviour of objects implementing XNameContainer using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXNameContainer(CollectionsTestBase):
+
+ # Tests syntax:
+ # obj[key] = val # Insert by key
+ # For:
+ # 0->1 element
+ def test_XNameContainer_InsertName(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ ranges = getSheetCellRangesInstance(spr)
+ new_range = spr.Sheets[0].getCellRangeByPosition(1, 2, 1, 2)
+
+ # When
+ ranges['foo'] = new_range
+
+ # Then
+ self.assertEqual(1, len(ranges.ElementNames))
+
+ spr.close(True)
+
+ # Tests syntax:
+ # obj[key] = val # Insert by key
+ # For:
+ # Invalid key
+ def test_XNameContainer_InsertName_Invalid(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ ranges = getSheetCellRangesInstance(spr)
+ new_range = spr.Sheets[0].getCellRangeByPosition(1, 2, 1, 2)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ ranges[12.34] = new_range
+
+ spr.close(True)
+
+ # Tests syntax:
+ # obj[key] = val # Replace by key
+ def test_XNameContainer_ReplaceName(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ ranges = getSheetCellRangesInstance(spr)
+ new_range1 = spr.Sheets[0].getCellRangeByPosition(1, 2, 1, 2)
+ new_range2 = spr.Sheets[0].getCellRangeByPosition(6, 6, 6, 6)
+
+ # When
+ ranges['foo'] = new_range1
+ ranges['foo'] = new_range2
+
+ # Then
+ self.assertEqual(1, len(ranges.ElementNames))
+ read_range = ranges['foo']
+ self.assertEqual(6, read_range.CellAddress.Column)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # del obj[key] # Delete by key
+ # For:
+ # 1/2 elements
+ def test_XNameContainer_DelKey(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+ spr.Sheets.insertNewByName('foo', 1)
+
+ # When
+ del spr.Sheets['foo']
+
+ # Then
+ self.assertEqual(1, len(spr.Sheets))
+ self.assertFalse('foo' in spr.Sheets)
+
+ spr.close(True)
+
+ # Tests syntax:
+ # del obj[key] # Delete by key
+ # For:
+ # Missing key
+ def test_XNameContainer_DelKey_Missing(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+
+ # When / Then
+ with self.assertRaises(KeyError):
+ del spr.Sheets['foo']
+
+ spr.close(True)
+
+ # Tests syntax:
+ # del obj[key] # Delete by key
+ # For:
+ # Invalid key (float)
+ def test_XNameContainer_DelKey_Invalid(self):
+ # Given
+ spr = self.createBlankSpreadsheet()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ del spr.Sheets[12.34]
+
+ spr.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_XNameReplace.py b/pyuno/qa/pytests/testcollections_XNameReplace.py
new file mode 100644
index 000000000..18476fd2b
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_XNameReplace.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+
+def getScriptName():
+ return 'macro://Standard.Module1.MySave()'
+
+# Tests behaviour of objects implementing XNameReplace using the new-style
+# collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestXNameReplace(CollectionsTestBase):
+
+ # Tests syntax:
+ # obj[key] = val # Replace by key
+ # For:
+ # 1 element
+ def test_XNameReplace_ReplaceName(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
+
+ # When
+ doc.Events['OnSave'] = event_properties
+
+ # Then
+ on_save = [p.Value for p in doc.Events['OnSave'] if p.Name == 'Script'][0]
+ self.assertEqual(getScriptName(), on_save)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[key] = val # Replace by key
+ # For:
+ # Invalid key
+ def test_XNameReplace_ReplaceName_Invalid(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
+
+ # When / Then
+ with self.assertRaises(KeyError):
+ doc.Events['qqqqq'] = event_properties
+
+ doc.close(True)
+
+ # Tests syntax:
+ # obj[key] = val # Replace by key
+ # For:
+ # Invalid key type
+ def test_XNameReplace_ReplaceName_Invalid(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ doc.Events[12.34] = event_properties
+
+ doc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_base.py b/pyuno/qa/pytests/testcollections_base.py
new file mode 100644
index 000000000..d3e806882
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_base.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from org.libreoffice.unotest import pyuno
+from com.sun.star.beans import PropertyValue
+
+testEnvironmentInitialized = False
+
+class CollectionsTestBase(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.context = pyuno.getComponentContext()
+ global testEnvironmentInitialized
+ if not testEnvironmentInitialized:
+ pyuno.private_initTestEnvironment()
+ testEnvironmentInitialized = True
+
+ def setUp(self):
+ self._components = []
+
+ def tearDown(self):
+ for component in self._components:
+ try:
+ component.close(True)
+ except Exception:
+ pass
+
+ def createHiddenWindow(self, url):
+ service_manager = self.context.ServiceManager
+ desktop = service_manager.createInstanceWithContext('com.sun.star.frame.Desktop', self.context)
+ load_props = (
+ PropertyValue(Name='Hidden', Value=True),
+ PropertyValue(Name='ReadOnly', Value=False)
+ )
+ component = desktop.loadComponentFromURL(url, '_blank', 0, load_props)
+ return component
+
+ def createBlankTextDocument(self):
+ component = self.createHiddenWindow('private:factory/swriter')
+ self._components.append(component)
+ return component
+
+ def createBlankSpreadsheet(self):
+ component = self.createHiddenWindow('private:factory/scalc')
+ self._components.append(component)
+ return component
+
+ def createBlankDrawing(self):
+ component = self.createHiddenWindow('private:factory/sdraw')
+ self._components.append(component)
+ return component
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_misc.py b/pyuno/qa/pytests/testcollections_misc.py
new file mode 100644
index 000000000..1dba098ee
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_misc.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+
+# Miscellaneous tests of the behaviour of UNO objects using the new-style
+# collection accessors
+
+class TestMisc(CollectionsTestBase):
+
+ # Tests syntax:
+ # for val in obj: ... # Implicit iterator
+ # For:
+ # Invalid type
+ def test_misc_IterateInvalidType(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ for val in doc.UIConfigurationManager:
+ pass
+
+ doc.close(True)
+
+ # Tests syntax:
+ # if val in itr: ... # Test value presence
+ # For:
+ # Invalid type
+ def test_misc_InInvalidType(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ foo = "bar" in doc.UIConfigurationManager
+
+ doc.close(True)
+
+ # Tests syntax:
+ # num = len(obj) # Number of elements
+ # For:
+ # Invalid type
+ def test_misc_LenInvalidType(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ len(doc.UIConfigurationManager)
+
+ doc.close(True)
+
+ # Tests syntax:
+ # val = obj[0] # Access by index
+ # For:
+ # Invalid type
+ def test_misc_SubscriptInvalidType(self):
+ # Given
+ doc = self.createBlankTextDocument()
+
+ # When / Then
+ with self.assertRaises(TypeError):
+ doc.UIConfigurationManager[0]
+
+ doc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testcollections_misc2.py b/pyuno/qa/pytests/testcollections_misc2.py
new file mode 100644
index 000000000..b696e050a
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_misc2.py
@@ -0,0 +1,62 @@
+
+# execute run procedure as Python macro for testing
+
+import uno
+import sys
+import unittest
+
+from com.sun.star.awt.FontSlant import ITALIC
+from com.sun.star.awt.FontSlant import NONE
+from com.sun.star.uno.TypeClass import STRING
+from com.sun.star.uno.TypeClass import LONG
+from com.sun.star.awt import Point
+
+class Test124953(unittest.TestCase):
+
+ def test_Enum(self):
+ italic = uno.Enum("com.sun.star.awt.FontSlant", "ITALIC")
+ none_ = uno.Enum("com.sun.star.awt.FontSlant", "NONE")
+ self.assertEqual(ITALIC, ITALIC)
+ self.assertEqual(ITALIC, italic)
+ self.assertFalse((ITALIC != italic))
+ self.assertNotEqual(ITALIC, NONE)
+ self.assertEqual(NONE, none_)
+
+ def test_Type(self):
+
+ STRING_TYPE = uno.getTypeByName("string")
+ LONG_TYPE = uno.getTypeByName("long")
+ string_type = uno.Type("string", STRING)
+ long_type = uno.Type("long", LONG)
+ self.assertEqual(STRING_TYPE, STRING_TYPE)
+ self.assertEqual(STRING_TYPE, string_type)
+ self.assertFalse((STRING_TYPE != string_type))
+ self.assertNotEqual(STRING_TYPE, LONG)
+ self.assertEqual(LONG_TYPE, long_type)
+
+ def test_Char(self):
+ char_a = uno.Char("a")
+ char_a2 = uno.Char("a")
+ char_b = uno.Char("b")
+ self.assertEqual(char_a, char_a)
+ self.assertEqual(char_a, char_a2)
+ self.assertFalse((char_a != char_a2))
+ self.assertNotEqual(char_a, char_b)
+
+ def test_ByteSequence(self):
+ b1 = uno.ByteSequence(bytes("abcdefg", encoding="utf8"))
+ b2 = uno.ByteSequence(bytes("abcdefg", encoding="utf8"))
+ b3 = uno.ByteSequence(bytes("1234567", encoding="utf8"))
+ self.assertEqual(b1, b1)
+ self.assertEqual(b1, b2)
+ self.assertFalse(b1 != b2)
+ self.assertNotEqual(b1, b3)
+
+ def test_Struct(self):
+ point1 = Point(100, 200)
+ point2 = Point(100, 200)
+ point3 = Point(0, 10)
+ self.assertEqual(point1, point1)
+ self.assertEqual(point1, point2)
+ self.assertFalse((point1 != point2))
+ self.assertNotEqual(point1, point3)
diff --git a/pyuno/qa/pytests/testcollections_mixednameindex.py b/pyuno/qa/pytests/testcollections_mixednameindex.py
new file mode 100644
index 000000000..b4c7958c6
--- /dev/null
+++ b/pyuno/qa/pytests/testcollections_mixednameindex.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+#
+# 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
+import uno
+
+from testcollections_base import CollectionsTestBase
+from com.sun.star.beans import PropertyValue
+
+
+# Tests behaviour of objects implementing both XIndexAccess and XNameAccess
+# using the new-style collection accessors
+# The objects chosen have no special meaning, they just happen to implement the
+# tested interfaces
+
+class TestMixedNameIndex(CollectionsTestBase):
+
+ # Tests:
+ # Ability to access a dual XName*/XIndex* object by both name and index
+ def testWriterTextTableNameAndIndex(self):
+ # Given
+ doc = self.createBlankTextDocument()
+ text_table = doc.createInstance("com.sun.star.text.TextTable")
+ text_table.initialize(2, 2)
+ text_table.Name = 'foo'
+ cursor = doc.Text.createTextCursor()
+ doc.Text.insertTextContent(cursor, text_table, False)
+
+ # When
+ table_by_name = doc.TextTables['foo']
+ table_by_index = doc.TextTables[0]
+
+ # Then
+ self.assertEqual('foo', table_by_name.Name)
+ self.assertEqual('foo', table_by_index.Name)
+ self.assertEqual(table_by_name, table_by_index)
+
+ doc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/pyuno/qa/pytests/testdocuments/fdo74824.ods b/pyuno/qa/pytests/testdocuments/fdo74824.ods
new file mode 100644
index 000000000..122bae22d
--- /dev/null
+++ b/pyuno/qa/pytests/testdocuments/fdo74824.ods
Binary files differ
diff --git a/pyuno/qa/pytests/testssl.py b/pyuno/qa/pytests/testssl.py
new file mode 100644
index 000000000..6ec9875fb
--- /dev/null
+++ b/pyuno/qa/pytests/testssl.py
@@ -0,0 +1,10 @@
+import unittest
+
+
+# I want to ensure that import ssl works on all platforms
+class SSLTest(unittest.TestCase):
+ def test_ssl_import(self):
+ import ssl
+
+if __name__ == '__main__':
+ unittest.main()