2 This is file is part of the LibreOffice project.
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 This file incorporates work covered by the following license notice:
10 Licensed to the Apache Software Foundation (ASF) under one or more
11 contributor license agreements. See the NOTICE file distributed
12 with this work for additional information regarding copyright
13 ownership. The ASF licenses this file to you under the Apache
14 License, Version 2.0 (the "License"); you may not use this file
15 except in compliance with the License. You may obtain a copy of
16 the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 from org
.libreoffice
.unotest
import UnoInProcess
23 class CheckFlies(unittest
.TestCase
):
27 cls
._uno
= UnoInProcess()
29 cls
.document
= cls
._uno
.openDocFromTDOC("CheckFlies.odt")
32 def tearDownClass(cls
):
35 def test_checkFlies(self
):
36 xTFS
= self
.__class
__.document
37 self
.checkTextFrames(xTFS
)
38 xTGOS
= self
.__class
__.document
39 self
.checkGraphicFrames(xTGOS
)
40 xTEOS
= self
.__class
__.document
41 self
.checkEmbeddedFrames(xTEOS
)
43 def checkEmbeddedFrames(self
, xTGOS
):
44 vExpectedEmbeddedFrames
= ["Object1"]
45 nEmbeddedFrames
= len(vExpectedEmbeddedFrames
)
46 xEmbeddedFrames
= xTGOS
.getEmbeddedObjects()
49 print (xEmbeddedFrames
)
50 for sFrameName
in xEmbeddedFrames
.getElementNames():
51 vExpectedEmbeddedFrames
.remove(sFrameName
)
52 # raises ValueError if not found
54 xEmbeddedFrames
[sFrameName
]
55 self
.assertTrue(xEmbeddedFrames
.hasByName(sFrameName
),
56 "Could not find embedded frame by name.")
58 self
.assertTrue(not(vExpectedEmbeddedFrames
),
59 "Missing expected embedded frames.")
61 xEmbeddedFramesIdx
= xEmbeddedFrames
63 self
.assertEqual(nEmbeddedFrames
, len(xEmbeddedFramesIdx
),
64 "Unexpected number of embedded frames reported")
66 for nCurrentFrameIdx
in range(len(xEmbeddedFramesIdx
)):
67 xEmbeddedFramesIdx
[nCurrentFrameIdx
]
69 def checkGraphicFrames(self
, xTGOS
):
70 vExpectedGraphicFrames
= ["graphics1"]
71 nGraphicFrames
= len(vExpectedGraphicFrames
)
72 xGraphicFrames
= xTGOS
.getGraphicObjects()
74 for sFrameName
in xGraphicFrames
.getElementNames():
75 vExpectedGraphicFrames
.remove(sFrameName
)
76 # raises ValueError if not found
77 xGraphicFrames
[sFrameName
]
79 sFrameName
in xGraphicFrames
,
80 "Could not find graphics frame by name.")
82 not(vExpectedGraphicFrames
),
83 "Missing expected graphics frames.")
85 xGraphicFramesIdx
= xGraphicFrames
86 self
.assertEqual(nGraphicFrames
, len(xGraphicFramesIdx
),
87 "Unexpected number of graphics frames reported")
89 for nCurrentFrameIdx
in range(len(xGraphicFramesIdx
)):
90 xGraphicFramesIdx
[nCurrentFrameIdx
]
92 def checkTextFrames(self
, xTFS
):
93 vExpectedTextFrames
= ["Frame1", "Frame2"]
94 nTextFrames
= len(vExpectedTextFrames
)
95 xTextFrames
= xTFS
.getTextFrames()
98 for sFrameName
in xTextFrames
.getElementNames():
99 vExpectedTextFrames
.remove(sFrameName
)
100 # raises ValueError if not found
101 xTextFrames
[sFrameName
]
103 sFrameName
in xTextFrames
,
104 "Could not find text frame by name.")
107 not(vExpectedTextFrames
), "Missing expected text frames.")
109 xTextFramesIdx
= xTextFrames
111 self
.assertEqual(nTextFrames
, len(xTextFrames
),
112 "Unexpected number of text frames reported")
114 for nCurrentFrameIdx
in range(len(xTextFramesIdx
)):
115 xTextFramesIdx
[nCurrentFrameIdx
]
118 if __name__
== "__main__":