[Libreoffice-commits] core.git: sw/JunitTest_sw_complex.mk sw/PythonTest_sw_python.mk sw/qa

kadertarlan kadertarlan1 at gmail.com
Wed Jan 27 06:33:59 PST 2016


 sw/JunitTest_sw_complex.mk                         |    2 
 sw/PythonTest_sw_python.mk                         |    1 
 sw/qa/complex/writer/CheckNamedPropertyValues.java |  110 ---------------------
 sw/qa/python/check_named_property_values.py        |   87 ++++++++++++++++
 4 files changed, 88 insertions(+), 112 deletions(-)

New commits:
commit 4a377f5d37a733e30de1c545c9e90eddd9dac9c3
Author: kadertarlan <kadertarlan1 at gmail.com>
Date:   Wed Jan 27 01:05:44 2016 +0200

    Convert Java unit test to Python (check_named_property_values.py)
    
    Change-Id: I70d05395b8b5ca89c6a2ebf63c1b4a7760a1559e
    Reviewed-on: https://gerrit.libreoffice.org/21829
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sw/JunitTest_sw_complex.mk b/sw/JunitTest_sw_complex.mk
index 688ef19..e0aaa97 100644
--- a/sw/JunitTest_sw_complex.mk
+++ b/sw/JunitTest_sw_complex.mk
@@ -30,7 +30,6 @@ $(eval $(call gb_JunitTest_add_sourcefiles,sw_complex,\
     sw/qa/complex/indeterminateState/CheckIndeterminateState \
     sw/qa/complex/writer/CheckBookmarks \
     sw/qa/complex/writer/CheckIndexedPropertyValues \
-    sw/qa/complex/writer/CheckNamedPropertyValues \
     sw/qa/complex/writer/CheckTable \
     sw/qa/complex/writer/LoadSaveTest \
     sw/qa/complex/writer/TestDocument \
@@ -51,7 +50,6 @@ $(eval $(call gb_JunitTest_add_classes,sw_complex,\
     complex.writer.CheckBookmarks \
     complex.writer.CheckTable \
     complex.writer.CheckIndexedPropertyValues \
-    complex.writer.CheckNamedPropertyValues \
     complex.writer.TextPortionEnumerationTest \
 ))
 
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 44d7ff4..e2efba0 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -18,6 +18,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
         check_flies \
  	check_fields \
         check_cross_references \
+        check_named_property_values \
 	check_styles \
 	check_table \
 	get_expression \
diff --git a/sw/qa/complex/writer/CheckNamedPropertyValues.java b/sw/qa/complex/writer/CheckNamedPropertyValues.java
deleted file mode 100644
index d09ebb6..0000000
--- a/sw/qa/complex/writer/CheckNamedPropertyValues.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-package complex.writer;
-
-import com.sun.star.beans.PropertyValue;
-import com.sun.star.container.XNameContainer;
-import com.sun.star.uno.UnoRuntime;
-import com.sun.star.uno.Type;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.openoffice.test.OfficeConnection;
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class CheckNamedPropertyValues {
-    @Test public void checkNamedPropertyValues()
-        throws com.sun.star.uno.Exception
-    {
-        Object instance = connection.getComponentContext().getServiceManager().
-                createInstanceWithContext( "com.sun.star.document.NamedPropertyValues", connection.getComponentContext());
-        XNameContainer xCont = UnoRuntime.queryInterface(XNameContainer.class, instance);
-
-        assertNotNull("XNameContainer was queried but returned null.", xCont);
-        PropertyValue[] prop1 = new PropertyValue[1];
-        prop1[0] = new PropertyValue();
-        prop1[0].Name  = "Jupp";
-        prop1[0].Value = "GoodGuy";
-
-        PropertyValue[] prop2 = new PropertyValue[1];
-        prop2[0] = new PropertyValue();
-        prop2[0].Name  = "Horst";
-        prop2[0].Value = "BadGuy";
-
-        Type t = xCont.getElementType();
-        assertFalse("Initial container is not empty.", xCont.hasElements());
-
-        xCont.insertByName("prop1", prop1);
-        PropertyValue[]ret = (PropertyValue[])xCont.getByName("prop1");
-        assertEquals(prop1[0].Name, ret[0].Name);
-        assertEquals(prop1[0].Value, ret[0].Value);
-        xCont.replaceByName("prop1", prop2);
-        ret = (PropertyValue[])xCont.getByName("prop1");
-        assertEquals(prop2[0].Name, ret[0].Name);
-        assertEquals(prop2[0].Value, ret[0].Value);
-        xCont.removeByName("prop1");
-        assertFalse("Could not remove PropertyValue.", xCont.hasElements());
-        xCont.insertByName("prop1", prop1);
-        xCont.insertByName("prop2", prop2);
-        assertTrue("Did not insert PropertyValue.", xCont.hasElements());
-        String[] names = xCont.getElementNames();
-        assertEquals("Not all element names were returned.", 2, names.length);
-        for (int i=0; i<names.length; i++) {
-            assertTrue(
-                "Got a wrong element name",
-                names[i].equals("prop1") || names[i].equals("prop2"));
-        }
-
-        try {
-            xCont.insertByName("prop2", prop1);
-            fail("ElementExistException was not thrown.");
-        }
-        catch(com.sun.star.container.ElementExistException e) {
-        }
-
-        try {
-            xCont.insertByName("prop3", "Example String");
-            fail("IllegalArgumentException was not thrown.");
-        }
-        catch(com.sun.star.lang.IllegalArgumentException e) {
-        }
-
-        try {
-            xCont.removeByName("prop3");
-            fail("NoSuchElementException was not thrown.");
-        }
-        catch(com.sun.star.container.NoSuchElementException e) {
-        }
-    }
-
-    @BeforeClass public static void setUpConnection() throws Exception {
-        connection.setUp();
-    }
-
-    @AfterClass public static void tearDownConnection()
-        throws InterruptedException, com.sun.star.uno.Exception
-    {
-        connection.tearDown();
-    }
-
-    private static final OfficeConnection connection = new OfficeConnection();
-}
diff --git a/sw/qa/python/check_named_property_values.py b/sw/qa/python/check_named_property_values.py
new file mode 100644
index 0000000..9d7825b
--- /dev/null
+++ b/sw/qa/python/check_named_property_values.py
@@ -0,0 +1,87 @@
+'''
+  This file is part of the LibreOffice project.
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+  This file incorporates work covered by the following license notice:
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements. See the NOTICE file distributed
+    with this work for additional information regarding copyright
+    ownership. The ASF licenses this file to you under the Apache
+    License, Version 2.0 (the "License"); you may not use this file
+    except in compliance with the License. You may obtain a copy of
+    the License at http://www.apache.org/licenses/LICENSE-2.0 .
+'''
+
+import unittest
+import unohelper
+import os
+import uno
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.beans import PropertyValue
+from com.sun.star.container import XNameContainer
+from org.libreoffice.unotest import OfficeConnection
+
+
+class CheckNamedPropertyValues(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+        cls.xContext = cls._uno.getContext()
+        cls.xDoc = cls._uno.openEmptyWriterDoc()
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown()
+
+
+    def test_checkNamedPropertyValues(self): 
+    
+        xServiceManager = self.xContext.ServiceManager
+        xCont = xServiceManager.createInstanceWithContext('com.sun.star.document.NamedPropertyValues', self.xContext)
+
+        p1 = PropertyValue(Name="Jupp", Value="GoodGuy")
+        prop1 = uno.Any("[]com.sun.star.beans.PropertyValue", (p1,))
+
+        p2 = PropertyValue(Name="Horst", Value="BadGuy")
+        prop2 = uno.Any("[]com.sun.star.beans.PropertyValue", (p2,))
+
+        t = xCont.getElementType()
+        self.assertFalse(xCont.hasElements()) #Initial container is not empty
+
+        uno.invoke(xCont, "insertByName", ("prop1", prop1))
+        ret = xCont["prop1"]
+        self.assertEqual(p1.Name, ret[0].Name)
+        self.assertEqual(p1.Value, ret[0].Value)
+
+        uno.invoke(xCont, "replaceByName", ("prop1", prop2))
+        ret = xCont["prop1"]
+        self.assertEqual(p2.Name, ret[0].Name)
+        self.assertEqual(p2.Value, ret[0].Value)
+
+        xCont.removeByName("prop1")
+        self.assertFalse(xCont.hasElements()) #Could not remove PropertyValue.
+        uno.invoke(xCont, "insertByName", ("prop1", prop1))
+        uno.invoke(xCont, "insertByName", ("prop2", prop2))
+        self.assertTrue(xCont.hasElements()) #Did not insert PropertyValue
+        names = xCont.getElementNames()
+        self.assertEqual(2, len(names)) #Not all element names were returned
+        for i in range(len(names)):
+            self.assertTrue( names[i]=="prop1" or names[i]=="prop2") #Got a wrong element name
+
+        with self.assertRaises(Exception):
+            uno.invoke(xCont, "insertByName", ("prop2", prop1))
+
+        with self.assertRaises(Exception):
+            uno.invoke(xCont, "insertByName",("prop3", "Example String"))
+
+        with self.assertRaises(Exception):
+            xCont.removeByName("prop3")
+
+
+


More information about the Libreoffice-commits mailing list