Kaydet (Commit) d4c620ba authored tarafından Shubham Goyal's avatar Shubham Goyal Kaydeden (comit) Samuel Mehrbrodt

tdf#124011 Add __ne__ method to UNO types

Change-Id: I1dcb41b404d69e7437a2cc6f22d3391bb91f3acc
Reviewed-on: https://gerrit.libreoffice.org/69216
Tested-by: Jenkins
Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 27a092de
......@@ -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:
# 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)
......@@ -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;
}
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment