merge the formfield patch from ooo-build
[ooovba.git] / sw / qa / complex / writer / CheckFlies.java
bloba54b02a3b58b3b950dddaed92872102c8fbfe378
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: $
10 * $Revision: $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package complex.writer;
33 import com.sun.star.beans.PropertyValue;
34 import com.sun.star.container.XNamed;
35 import com.sun.star.container.XNameAccess;
36 import com.sun.star.container.XIndexAccess;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 import complexlib.ComplexTestCase;
41 import java.math.BigInteger;
42 import java.util.Collection;
43 import java.util.ArrayList;
45 public class CheckFlies extends ComplexTestCase {
46 private XMultiServiceFactory m_xMsf = null;
47 private XTextDocument m_xDoc = null;
49 public String[] getTestMethodNames() {
50 return new String[]{"checkFlies"};
53 public void checkFlies()
54 throws com.sun.star.uno.Exception,
55 com.sun.star.io.IOException
57 try {
58 m_xMsf = (XMultiServiceFactory)param.getMSF();
59 m_xDoc = util.WriterTools.loadTextDoc(m_xMsf, util.utils.getFullTestURL("CheckFlies.odt"));
60 com.sun.star.text.XTextFramesSupplier xTFS = (com.sun.star.text.XTextFramesSupplier)UnoRuntime.queryInterface(
61 com.sun.star.text.XTextFramesSupplier.class,
62 m_xDoc);
63 checkTextFrames(xTFS);
64 com.sun.star.text.XTextGraphicObjectsSupplier xTGOS = (com.sun.star.text.XTextGraphicObjectsSupplier)UnoRuntime.queryInterface(
65 com.sun.star.text.XTextGraphicObjectsSupplier.class,
66 m_xDoc);
67 checkGraphicFrames(xTGOS);
68 com.sun.star.text.XTextEmbeddedObjectsSupplier xTEOS = (com.sun.star.text.XTextEmbeddedObjectsSupplier)UnoRuntime.queryInterface(
69 com.sun.star.text.XTextEmbeddedObjectsSupplier.class,
70 m_xDoc);
71 checkEmbeddedFrames(xTEOS);
72 } finally {
73 // closing test document
74 if(m_xDoc != null)
75 util.DesktopTools.closeDoc(m_xDoc);
79 private void checkEmbeddedFrames(com.sun.star.text.XTextEmbeddedObjectsSupplier xTGOS)
80 throws com.sun.star.lang.WrappedTargetException
82 Collection<String> vExpectedEmbeddedFrames = new ArrayList<String>();
83 vExpectedEmbeddedFrames.add("Object1");
84 int nEmbeddedFrames = vExpectedEmbeddedFrames.size();
85 com.sun.star.container.XNameAccess xEmbeddedFrames = xTGOS.getEmbeddedObjects();
86 for(String sFrameName : xEmbeddedFrames.getElementNames())
88 if(!vExpectedEmbeddedFrames.remove(sFrameName))
89 failed("Unexpected frame name");
90 try
92 xEmbeddedFrames.getByName(sFrameName);
94 catch(com.sun.star.container.NoSuchElementException e)
96 failed("Could not get embedded frame by name.");
98 if(!xEmbeddedFrames.hasByName(sFrameName))
99 failed("Could not find embedded frame by name.");
101 if(!vExpectedEmbeddedFrames.isEmpty())
102 failed("Missing expected embedded frames.");
105 xEmbeddedFrames.getByName("Nonexisting embedded frame");
106 failed("Got nonexisting embedded frame");
108 catch(com.sun.star.container.NoSuchElementException e)
110 if(xEmbeddedFrames.hasByName("Nonexisting embedded frame"))
111 failed("Has nonexisting embedded frame");
113 com.sun.star.container.XIndexAccess xEmbeddedFramesIdx = (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
114 com.sun.star.container.XIndexAccess.class,
115 xEmbeddedFrames);
116 if(xEmbeddedFramesIdx.getCount() != nEmbeddedFrames)
117 failed("Unexpected number of embedded frames reported.");
118 for(int nCurrentFrameIdx = 0; nCurrentFrameIdx < xEmbeddedFramesIdx.getCount(); nCurrentFrameIdx++)
122 xEmbeddedFramesIdx.getByIndex(nCurrentFrameIdx);
124 catch(com.sun.star.lang.IndexOutOfBoundsException e)
126 failed("Could not get embedded frame by index.");
131 private void checkGraphicFrames(com.sun.star.text.XTextGraphicObjectsSupplier xTGOS)
132 throws com.sun.star.lang.WrappedTargetException
134 Collection<String> vExpectedGraphicFrames = new ArrayList<String>();
135 vExpectedGraphicFrames.add("graphics1");
136 int nGraphicFrames = vExpectedGraphicFrames.size();
137 com.sun.star.container.XNameAccess xGraphicFrames = xTGOS.getGraphicObjects();
138 for(String sFrameName : xGraphicFrames.getElementNames())
140 if(!vExpectedGraphicFrames.remove(sFrameName))
141 failed("Unexpected frame name");
144 xGraphicFrames.getByName(sFrameName);
146 catch(com.sun.star.container.NoSuchElementException e)
148 failed("Could not get graphics frame by name.");
150 if(!xGraphicFrames.hasByName(sFrameName))
151 failed("Could not find graphics frame by name.");
153 if(!vExpectedGraphicFrames.isEmpty())
154 failed("Missing expected graphics frames.");
157 xGraphicFrames.getByName("Nonexisting graphics frame");
158 failed("Got nonexisting graphics frame");
160 catch(com.sun.star.container.NoSuchElementException e)
162 if(xGraphicFrames.hasByName("Nonexisting graphics frame"))
163 failed("Has nonexisting graphics frame");
165 com.sun.star.container.XIndexAccess xGraphicFramesIdx = (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
166 com.sun.star.container.XIndexAccess.class,
167 xGraphicFrames);
168 if(xGraphicFramesIdx.getCount() != nGraphicFrames)
169 failed("Unexpected number of graphics frames reported.");
170 for(int nCurrentFrameIdx = 0; nCurrentFrameIdx < xGraphicFramesIdx.getCount(); nCurrentFrameIdx++)
174 xGraphicFramesIdx.getByIndex(nCurrentFrameIdx);
176 catch(com.sun.star.lang.IndexOutOfBoundsException e)
178 failed("Could not get graphics frame by index.");
183 private void checkTextFrames(com.sun.star.text.XTextFramesSupplier xTFS)
184 throws com.sun.star.lang.WrappedTargetException
186 Collection<String> vExpectedTextFrames = new ArrayList<String>();
187 vExpectedTextFrames.add("Frame1");
188 vExpectedTextFrames.add("Frame2");
190 int nTextFrames = vExpectedTextFrames.size();
191 com.sun.star.container.XNameAccess xTextFrames = xTFS.getTextFrames();
192 for(String sFrameName : xTextFrames.getElementNames())
194 if(!vExpectedTextFrames.remove(sFrameName))
195 failed("Unexpected frame name");
198 xTextFrames.getByName(sFrameName);
200 catch(com.sun.star.container.NoSuchElementException e)
202 failed("Could not get text frame by name.");
204 if(!xTextFrames.hasByName(sFrameName))
205 failed("Could not find text frame by name.");
207 if(!vExpectedTextFrames.isEmpty())
208 failed("Missing expected text frames.");
211 xTextFrames.getByName("Nonexisting Textframe");
212 failed("Got nonexisting text frame.");
214 catch(com.sun.star.container.NoSuchElementException e)
216 if(xTextFrames.hasByName("Nonexisting text frame"))
217 failed("Has nonexisting text frame.");
219 com.sun.star.container.XIndexAccess xTextFramesIdx = (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
220 com.sun.star.container.XIndexAccess.class,
221 xTextFrames);
222 if(xTextFramesIdx.getCount() != nTextFrames)
223 failed("Unexpected number of text frames reported.");
224 for(int nCurrentFrameIdx = 0; nCurrentFrameIdx < xTextFramesIdx.getCount(); nCurrentFrameIdx++)
228 xTextFramesIdx.getByIndex(nCurrentFrameIdx);
230 catch(com.sun.star.lang.IndexOutOfBoundsException e)
232 failed("Could not get text frame by index.");