xref: /AOO41X/test/testuno/source/fvt/uno/sw/frame/CheckFrames.java (revision eba4d44a33e5be0b2528d5a9a6f0dcbf65adaa0d)
1*eba4d44aSLiu Zhe /**************************************************************
2*eba4d44aSLiu Zhe  *
3*eba4d44aSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4*eba4d44aSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5*eba4d44aSLiu Zhe  * distributed with this work for additional information
6*eba4d44aSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7*eba4d44aSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8*eba4d44aSLiu Zhe  * "License"); you may not use this file except in compliance
9*eba4d44aSLiu Zhe  * with the License.  You may obtain a copy of the License at
10*eba4d44aSLiu Zhe  *
11*eba4d44aSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12*eba4d44aSLiu Zhe  *
13*eba4d44aSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14*eba4d44aSLiu Zhe  * software distributed under the License is distributed on an
15*eba4d44aSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*eba4d44aSLiu Zhe  * KIND, either express or implied.  See the License for the
17*eba4d44aSLiu Zhe  * specific language governing permissions and limitations
18*eba4d44aSLiu Zhe  * under the License.
19*eba4d44aSLiu Zhe  *
20*eba4d44aSLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe 
22*eba4d44aSLiu Zhe package fvt.uno.sw.frame;
23*eba4d44aSLiu Zhe 
24*eba4d44aSLiu Zhe import static org.junit.Assert.assertArrayEquals;
25*eba4d44aSLiu Zhe import static org.junit.Assert.assertEquals;
26*eba4d44aSLiu Zhe import static org.junit.Assert.assertFalse;
27*eba4d44aSLiu Zhe import static org.junit.Assert.assertTrue;
28*eba4d44aSLiu Zhe 
29*eba4d44aSLiu Zhe import org.junit.After;
30*eba4d44aSLiu Zhe import org.junit.AfterClass;
31*eba4d44aSLiu Zhe import org.junit.Before;
32*eba4d44aSLiu Zhe import org.junit.Test;
33*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
34*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
35*eba4d44aSLiu Zhe 
36*eba4d44aSLiu Zhe import com.sun.star.container.NoSuchElementException;
37*eba4d44aSLiu Zhe import com.sun.star.container.XIndexAccess;
38*eba4d44aSLiu Zhe import com.sun.star.container.XNameAccess;
39*eba4d44aSLiu Zhe import com.sun.star.text.XTextDocument;
40*eba4d44aSLiu Zhe import com.sun.star.text.XTextFrame;
41*eba4d44aSLiu Zhe import com.sun.star.text.XTextFramesSupplier;
42*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
43*eba4d44aSLiu Zhe 
44*eba4d44aSLiu Zhe public class CheckFrames {
45*eba4d44aSLiu Zhe 
46*eba4d44aSLiu Zhe 	private static final UnoApp app = new UnoApp();
47*eba4d44aSLiu Zhe 
48*eba4d44aSLiu Zhe 	private XTextDocument document = null;
49*eba4d44aSLiu Zhe 
50*eba4d44aSLiu Zhe 	@Test(expected = NoSuchElementException.class)
testLoadTextFrame()51*eba4d44aSLiu Zhe 	public void testLoadTextFrame() throws Exception {
52*eba4d44aSLiu Zhe 		document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.prepareData("uno/sw/CheckFlies.odt")));
53*eba4d44aSLiu Zhe 		XTextFramesSupplier xTFS = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, document);
54*eba4d44aSLiu Zhe 		String[] expectedNames = { "Frame1", "Frame2" };
55*eba4d44aSLiu Zhe 		String[] expectedContents = { "PageBoundFrame", "ParaBoundFrame" };
56*eba4d44aSLiu Zhe 		XNameAccess xTextFrames = xTFS.getTextFrames();
57*eba4d44aSLiu Zhe 		assertArrayEquals("Text frame names", expectedNames, xTextFrames.getElementNames());
58*eba4d44aSLiu Zhe 		assertTrue("Has text frame named Frame1", xTextFrames.hasByName(expectedNames[0]));
59*eba4d44aSLiu Zhe 		assertFalse("Has nonexisting text frame.", xTextFrames.hasByName("Nonexisting text frame"));
60*eba4d44aSLiu Zhe 
61*eba4d44aSLiu Zhe 		XIndexAccess xTextFramesIdx = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextFrames);
62*eba4d44aSLiu Zhe 		assertEquals("Text frame count", expectedNames.length, xTextFramesIdx.getCount());
63*eba4d44aSLiu Zhe 		String[] contents = new String[expectedNames.length];
64*eba4d44aSLiu Zhe 		for (int i = 0; i < xTextFramesIdx.getCount(); i++) {
65*eba4d44aSLiu Zhe 			Object obj = xTextFramesIdx.getByIndex(i);
66*eba4d44aSLiu Zhe 			XTextFrame frame = (XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, obj);
67*eba4d44aSLiu Zhe 			contents[i] = frame.getText().getString();
68*eba4d44aSLiu Zhe 		}
69*eba4d44aSLiu Zhe 		assertArrayEquals("Text frame contents", expectedContents, contents);
70*eba4d44aSLiu Zhe 		xTextFrames.getByName("Nonexisting Textframe");
71*eba4d44aSLiu Zhe 	}
72*eba4d44aSLiu Zhe 
73*eba4d44aSLiu Zhe 	@Before
setUp()74*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
75*eba4d44aSLiu Zhe 		app.start();
76*eba4d44aSLiu Zhe 	}
77*eba4d44aSLiu Zhe 
78*eba4d44aSLiu Zhe 	@After
tearDown()79*eba4d44aSLiu Zhe 	public void tearDown() {
80*eba4d44aSLiu Zhe 		app.closeDocument(document);
81*eba4d44aSLiu Zhe 	}
82*eba4d44aSLiu Zhe 
83*eba4d44aSLiu Zhe 	@AfterClass
tearDownConnection()84*eba4d44aSLiu Zhe 	public static void tearDownConnection() throws InterruptedException, Exception {
85*eba4d44aSLiu Zhe 		app.close();
86*eba4d44aSLiu Zhe 	}
87*eba4d44aSLiu Zhe 
88*eba4d44aSLiu Zhe }
89