diff options
author | Shubham Goyal <22shubh22@gmail.com> | 2019-03-12 15:32:33 +0530 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-03-18 09:34:41 +0100 |
commit | d4c620ba7e9abccd8a82e2c64bd0d8cdf9538380 (patch) | |
tree | cee244cdf20c23ff3e9ab146050afa3ca5718993 /pyuno | |
parent | 27a092ded129c1773c62331fb8a206c0ccd97eb6 (diff) |
tdf#124011 Add __ne__ method to UNO types
Change-Id: I1dcb41b404d69e7437a2cc6f22d3391bb91f3acc
Reviewed-on: https://gerrit.libreoffice.org/69216
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'pyuno')
-rw-r--r-- | pyuno/PythonTest_pyuno_pytests_testcollections.mk | 1 | ||||
-rw-r--r-- | pyuno/qa/pytests/testcollections_misc2.py | 72 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_except.cxx | 3 | ||||
-rw-r--r-- | pyuno/source/module/uno.py | 11 |
4 files changed, 87 insertions, 0 deletions
diff --git a/pyuno/PythonTest_pyuno_pytests_testcollections.mk b/pyuno/PythonTest_pyuno_pytests_testcollections.mk index ba8fe2e8cb7f..abd26699c298 100644 --- a/pyuno/PythonTest_pyuno_pytests_testcollections.mk +++ b/pyuno/PythonTest_pyuno_pytests_testcollections.mk @@ -21,6 +21,7 @@ $(eval $(call gb_PythonTest_add_modules,pyuno_pytests_testcollections,$(SRCDIR)/ testcollections_XCellRange \ testcollections_mixednameindex \ testcollections_misc \ + testcollections_misc2 \ )) # vim: set noet sw=4 ts=4: diff --git a/pyuno/qa/pytests/testcollections_misc2.py b/pyuno/qa/pytests/testcollections_misc2.py new file mode 100644 index 000000000000..8566d2838e81 --- /dev/null +++ b/pyuno/qa/pytests/testcollections_misc2.py @@ -0,0 +1,72 @@ + +# execute run procedure as Python macro for testing + +import uno +import sys +import unittest + +from com.sun.star.awt.FontSlant import ITALIC +from com.sun.star.awt.FontSlant import NONE +from com.sun.star.uno.TypeClass import STRING +from com.sun.star.uno.TypeClass import LONG +from com.sun.star.awt import Point + +class Test124953(unittest.TestCase): + + def test_Enum(self): + italic = uno.Enum("com.sun.star.awt.FontSlant", "ITALIC") + none_ = uno.Enum("com.sun.star.awt.FontSlant", "NONE") + self.assertEqual(ITALIC, ITALIC) + self.assertEqual(ITALIC, italic) + self.assertFalse((ITALIC != italic)) + self.assertNotEqual(ITALIC, NONE) + self.assertEqual(NONE, none_) + + def test_Type(self): + + STRING_TYPE = uno.getTypeByName("string") + LONG_TYPE = uno.getTypeByName("long") + string_type = uno.Type("string", STRING) + long_type = uno.Type("long", LONG) + self.assertEqual(STRING_TYPE, STRING_TYPE) + self.assertEqual(STRING_TYPE, string_type) + self.assertFalse((STRING_TYPE != string_type)) + self.assertNotEqual(STRING_TYPE, LONG) + self.assertEqual(LONG_TYPE, long_type) + + def test_Char(self): + if sys.version_info[0] == 3: + char_a = uno.Char("a") + char_a2 = uno.Char("a") + char_b = uno.Char("b") + else: + char_a = uno.Char(u"a") + char_a2 = uno.Char(u"a") + char_b = uno.Char(u"b") + self.assertEqual(char_a, char_a) + self.assertEqual(char_a, char_a2) + self.assertFalse((char_a != char_a2)) + self.assertNotEqual(char_a, char_b) + + def test_ByteSequence(self): + if sys.version_info[0] == 3: + b1 = uno.ByteSequence(bytes("abcdefg", encoding="utf8")) + b2 = uno.ByteSequence(bytes("abcdefg", encoding="utf8")) + b3 = uno.ByteSequence(bytes("1234567", encoding="utf8")) + else: + b1 = uno.ByteSequence("abcdefg") + b2 = uno.ByteSequence("abcdefg") + b3 = uno.ByteSequence("1234567") + self.assertEqual(b1, b1) + self.assertEqual(b1, b2) + self.assertFalse(b1 != b2) + self.assertNotEqual(b1, b3) + + def test_Struct(self): + point1 = Point(100, 200) + point2 = Point(100, 200) + point3 = Point(0, 10) + self.assertEqual(point1, point1) + self.assertEqual(point1, point2) + self.assertFalse((point1 != point2)) + self.assertNotEqual(point1, point3) diff --git a/pyuno/source/module/pyuno_except.cxx b/pyuno/source/module/pyuno_except.cxx index 0d627dd2566e..ebe00ac6811b 100644 --- a/pyuno/source/module/pyuno_except.cxx +++ b/pyuno/source/module/pyuno_except.cxx @@ -162,6 +162,7 @@ static PyRef createClass( const OUString & name, const Runtime &runtime ) PyRef getter = getObjectFromUnoModule( runtime,"_uno_struct__getattr__" ); PyRef repr = getObjectFromUnoModule( runtime,"_uno_struct__repr__" ); PyRef eq = getObjectFromUnoModule( runtime,"_uno_struct__eq__" ); + PyRef ne = getObjectFromUnoModule( runtime,"_uno_struct__ne__" ); PyObject_SetAttrString( ret.get(), "__pyunostruct__", @@ -181,6 +182,8 @@ static PyRef createClass( const OUString & name, const Runtime &runtime ) ret.get(), "__str__", repr.get() ); PyObject_SetAttrString( ret.get(), "__eq__", eq.get() ); + PyObject_SetAttrString( + ret.get(), "__ne__", ne.get() ); } return ret; } diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index bccf22d0f8ac..6d671e620f21 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -170,6 +170,9 @@ class Enum: return (self.typeName == that.typeName) and (self.value == that.value) + def __ne__(self,other): + return not self.__eq__(other) + class Type: """Represents a UNO type. @@ -194,6 +197,9 @@ class Type: return self.typeClass == that.typeClass and self.typeName == that.typeName + def __ne__(self,other): + return not self.__eq__(other) + def __hash__(self): return self.typeName.__hash__() @@ -259,6 +265,9 @@ class Char: return False + def __ne__(self,other): + return not self.__eq__(other) + class ByteSequence: """Represents a UNO ByteSequence value. @@ -527,6 +536,8 @@ def _uno_struct__str__(self): return str(self.__dict__["value"]) +def _uno_struct__ne__(self, other): + return not self.__eq__(other) def _uno_struct__eq__(self, that): """Compares two UNO structs. |