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