[Libreoffice-commits] .: Branch 'libreoffice-3-5' - 3 commits - sw/JunitTest_sw_complex.mk sw/qa

Miklos Vajna vmiklos at kemper.freedesktop.org
Mon Mar 5 05:54:35 PST 2012


 sw/JunitTest_sw_complex.mk                      |    2 
 sw/qa/complex/writer/CheckFields.java           |  179 ++++++++++++++++++++++++
 sw/qa/complex/writer/testdocuments/fdo39694.ott |binary
 3 files changed, 181 insertions(+)

New commits:
commit 2ece920ad7d3876ee6c49bd819ee9aaf99c72e66
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Mar 5 12:32:39 2012 +0100

    sw: CheckFields: oops, forgot to close the document
    (cherry picked from commit 72a3c7a2778c493ef1d3f740a0b4b14f805c624a)
    
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/sw/qa/complex/writer/CheckFields.java b/sw/qa/complex/writer/CheckFields.java
index f966e52..00c6916 100644
--- a/sw/qa/complex/writer/CheckFields.java
+++ b/sw/qa/complex/writer/CheckFields.java
@@ -36,6 +36,7 @@ import com.sun.star.lang.XServiceInfo;
 import com.sun.star.beans.XPropertySet;
 import com.sun.star.beans.PropertyValue;
 import com.sun.star.container.XEnumeration;
+import com.sun.star.util.XCloseable;
 import com.sun.star.text.XText;
 import com.sun.star.text.XTextContent;
 import com.sun.star.text.XTextDocument;
@@ -138,6 +139,11 @@ public class CheckFields
             }
         }
         assertTrue(placeholders.isEmpty());
+        XCloseable xClos = (XCloseable) UnoRuntime.queryInterface(
+                    XCloseable.class, xComp);
+        if (xClos != null) {
+            xClos.close(true);
+        }
     }
 
     @Test
commit 24a5db94da34fc40c713d6534b5f741dfee50e44
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Mar 5 12:20:48 2012 +0100

    fdo#39694, fdo#42073: add junit test for these
    (cherry picked from commit 870e5a8e8251967b513b4255231ee9665b085431)
    
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/sw/JunitTest_sw_complex.mk b/sw/JunitTest_sw_complex.mk
index 4ed426d..b242c8d 100644
--- a/sw/JunitTest_sw_complex.mk
+++ b/sw/JunitTest_sw_complex.mk
@@ -40,6 +40,7 @@ $(eval $(call gb_JunitTest_add_sourcefiles,sw_complex,\
     sw/qa/complex/writer/CheckBookmarks \
     sw/qa/complex/writer/CheckCrossReferences \
     sw/qa/complex/writer/CheckFlies \
+    sw/qa/complex/writer/CheckFields \
     sw/qa/complex/writer/CheckIndexedPropertyValues \
     sw/qa/complex/writer/CheckNamedPropertyValues \
     sw/qa/complex/writer/LoadSaveTest \
@@ -60,6 +61,7 @@ $(eval $(call gb_JunitTest_add_classes,sw_complex,\
     complex.writer.CheckBookmarks \
     complex.checkColor.CheckChangeColor \
     complex.writer.CheckCrossReferences \
+    complex.writer.CheckFields\
     complex.writer.CheckFlies \
     complex.writer.CheckIndexedPropertyValues \
     complex.writer.CheckNamedPropertyValues \
diff --git a/sw/qa/complex/writer/CheckFields.java b/sw/qa/complex/writer/CheckFields.java
new file mode 100644
index 0000000..f966e52
--- /dev/null
+++ b/sw/qa/complex/writer/CheckFields.java
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * [ Copyright (C) 2012 Red Hat, Inc., Michael Stahl <mstahl at redhat.com> (initial developer) ]
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+package complex.writer;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextField;
+import com.sun.star.text.XTextFieldsSupplier;
+import com.sun.star.text.XTextRange;
+import com.sun.star.text.XTextCursor;
+
+import org.openoffice.test.OfficeConnection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import java.util.Set;
+import java.util.HashSet;
+
+
+public class CheckFields
+{
+    private static final OfficeConnection connection = new OfficeConnection();
+
+    @BeforeClass public static void setUpConnection() throws Exception {
+        connection.setUp();
+//Thread.sleep(5000);
+    }
+
+    @AfterClass public static void tearDownConnection()
+        throws InterruptedException, com.sun.star.uno.Exception
+    {
+        connection.tearDown();
+    }
+
+    private XMultiServiceFactory m_xMSF = null;
+    private XComponentContext m_xContext = null;
+    private XTextDocument m_xDoc = null;
+
+    @Before public void before() throws Exception
+    {
+        m_xMSF = UnoRuntime.queryInterface(
+            XMultiServiceFactory.class,
+            connection.getComponentContext().getServiceManager());
+        m_xContext = connection.getComponentContext();
+        assertNotNull("could not get component context.", m_xContext);
+        m_xDoc = util.WriterTools.createTextDoc(m_xMSF);
+    }
+
+    @After public void after()
+    {
+        util.DesktopTools.closeDoc(m_xDoc);
+    }
+
+    @Test
+    public void test_fdo39694_load() throws Exception
+    {
+        PropertyValue[] loadProps = new PropertyValue[2];
+        loadProps[0] = new PropertyValue();
+        loadProps[0].Name = "AsTemplate";
+        loadProps[0].Value = new Boolean(true);
+        loadProps[1] = new PropertyValue();
+        loadProps[1].Name = "Hidden";
+        loadProps[1].Value = new Boolean(true);
+
+        String file = TestDocument.getUrl("fdo39694.ott");
+        XComponent xComp = util.DesktopTools.loadDoc(m_xMSF, file, loadProps);
+        XTextDocument xTextDoc = (XTextDocument)
+            UnoRuntime.queryInterface(XTextDocument.class, xComp);
+
+        XTextFieldsSupplier xTFS = (XTextFieldsSupplier)
+            UnoRuntime.queryInterface(XTextFieldsSupplier.class, xComp);
+        XEnumeration xEnum = xTFS.getTextFields().createEnumeration();
+        Set<String> placeholders = new HashSet<String>();
+        placeholders.add("<Kadr1>");
+        placeholders.add("<Kadr2>");
+        placeholders.add("<Kadr3>");
+        placeholders.add("<Kadr4>");
+        placeholders.add("<Pnname>");
+        placeholders.add("<Pvname>");
+        placeholders.add("<Pgeboren>");
+
+        while (xEnum.hasMoreElements())
+        {
+            Object xField = xEnum.nextElement();
+            XServiceInfo xSI = (XServiceInfo)
+                UnoRuntime.queryInterface(XServiceInfo.class, xField);
+            if (xSI.supportsService("com.sun.star.text.TextField.JumpEdit"))
+            {
+                XTextContent xContent = (XTextContent)
+                    UnoRuntime.queryInterface(XTextContent.class, xField);
+                XTextRange xAnchor = xContent.getAnchor();
+                String readContent = xAnchor.getString();
+                if (!placeholders.remove(readContent))
+                {
+                    System.out.println("field not found: " + readContent);
+                    assertFalse(true);
+                }
+            }
+        }
+        assertTrue(placeholders.isEmpty());
+    }
+
+    @Test
+    public void test_fdo42073() throws Exception
+    {
+        XMultiServiceFactory xDocFactory = (XMultiServiceFactory)
+            UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xDoc);
+        Object xField =
+            xDocFactory.createInstance("com.sun.star.text.TextField.Input");
+
+        XText xBodyText = m_xDoc.getText();
+        XTextCursor xCursor = xBodyText.createTextCursor();
+        XTextField xTextField = (XTextField)
+            UnoRuntime.queryInterface(XTextField.class, xField);
+        xBodyText.insertTextContent(xCursor, xTextField, true);
+
+        XPropertySet xPropSet = (XPropertySet)
+            UnoRuntime.queryInterface(XPropertySet.class, xField);
+        {
+            Object readContent = xPropSet.getPropertyValue("Content");
+            assertEquals("", readContent);
+        }
+
+        String content = "this is not surprising";
+        xPropSet.setPropertyValue("Content", content);
+        Object readContent = xPropSet.getPropertyValue("Content");
+        assertEquals(content, readContent);
+        readContent = xTextField.getPresentation(false);
+        assertEquals(content, readContent);
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 60d9055545fb1d9b9a950b2b3979a0b7a0f23ae8
Author: Juergen Steinhilber <j.steinhilber at rta.de>
Date:   Mon Mar 5 12:08:41 2012 +0100

    fdo#39694: add test document
    (cherry picked from commit 0982257e5902a29c3faf90c0fa3dba809a2462e5)
    
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/sw/qa/complex/writer/testdocuments/fdo39694.ott b/sw/qa/complex/writer/testdocuments/fdo39694.ott
new file mode 100644
index 0000000..959d2a6
Binary files /dev/null and b/sw/qa/complex/writer/testdocuments/fdo39694.ott differ


More information about the Libreoffice-commits mailing list