summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYevgen Muntyan <muntyan@tamu.edu>2006-11-18 13:24:42 +0000
committerJohan Dahlin <johan@src.gnome.org>2006-11-18 13:24:42 +0000
commit432a1851feaa99e8c3e6feb54a2c6d97810be0ec (patch)
treedde3798d219c006b619a1045754251348ae934ec /tests
parentf27cb5674c9526d1f1fc4537bd4612c42d9dce4d (diff)
downloadpygobject-432a1851feaa99e8c3e6feb54a2c6d97810be0ec.tar.gz
pygobject-432a1851feaa99e8c3e6feb54a2c6d97810be0ec.tar.xz
pygobject-432a1851feaa99e8c3e6feb54a2c6d97810be0ec.zip
reviewed by: Johan Dahlin <johan@gnome.org>
2006-11-18 Yevgen Muntyan <muntyan@tamu.edu> reviewed by: Johan Dahlin <johan@gnome.org> * gobject/gobjectmodule.c: (create_property): * gobject/pygparamspec.c: (pyg_param_spec_getattr): * tests/test_properties.py: Avoid truncating in pyg_param_spec_getattr, add test for all non-float numeric types. Fixes #353943
Diffstat (limited to 'tests')
-rw-r--r--tests/test_properties.py74
1 files changed, 73 insertions, 1 deletions
diff --git a/tests/test_properties.py b/tests/test_properties.py
index d75a810..5a819fa 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -1,9 +1,12 @@
+import struct
import unittest
from common import testhelper
from gobject import GObject, GType, new, PARAM_READWRITE, \
- PARAM_CONSTRUCT, PARAM_READABLE, PARAM_CONSTRUCT_ONLY, TYPE_UINT64
+ PARAM_CONSTRUCT, PARAM_READABLE, PARAM_WRITABLE, PARAM_CONSTRUCT_ONLY, \
+ TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, \
+ TYPE_INT64, TYPE_UINT64
class PropertyObject(GObject):
__gproperties__ = {
@@ -120,3 +123,72 @@ class TestProperties(unittest.TestCase):
}
except OverflowError, ex:
self.fail(str(ex))
+
+ def testRange(self):
+ # kiwi code
+ def max(c):
+ return 2 ** ((8 * struct.calcsize(c)) - 1) - 1
+ def umax(c):
+ return 2 ** (8 * struct.calcsize(c)) - 1
+
+ maxint = max('i')
+ minint = -maxint - 1
+ maxuint = umax('I')
+ maxlong = max('l')
+ minlong = -maxlong - 1
+ maxulong = umax('L')
+ maxint64 = max('q')
+ minint64 = -maxint64 - 1
+ maxuint64 = umax('Q')
+
+ types = dict(int=(TYPE_INT, minint, maxint),
+ uint=(TYPE_UINT, 0, maxuint),
+ long=(TYPE_LONG, minlong, maxlong),
+ ulong=(TYPE_ULONG, 0, maxulong),
+ int64=(TYPE_INT64, minint64, maxint64),
+ uint64=(TYPE_UINT64, 0, maxuint64))
+
+ def build_gproperties(types):
+ d = {}
+ for key, (gtype, min, max) in types.items():
+ d[key] = (gtype, 'blurb', 'desc', min, max, 0,
+ PARAM_READABLE | PARAM_WRITABLE)
+ return d
+
+ class RangeCheck(GObject):
+ __gproperties__ = build_gproperties(types)
+
+ def __init__(self):
+ self.values = {}
+ GObject.__init__(self)
+
+ def do_set_property(self, pspec, value):
+ self.values[pspec.name] = value
+
+ def do_get_property(self, pspec):
+ return self.values.get(pspec.name, pspec.default_value)
+
+ self.assertEqual(RangeCheck.props.int.minimum, minint)
+ self.assertEqual(RangeCheck.props.int.maximum, maxint)
+ self.assertEqual(RangeCheck.props.uint.minimum, 0)
+ self.assertEqual(RangeCheck.props.uint.maximum, maxuint)
+ self.assertEqual(RangeCheck.props.long.minimum, minlong)
+ self.assertEqual(RangeCheck.props.long.maximum, maxlong)
+ self.assertEqual(RangeCheck.props.ulong.minimum, 0)
+ self.assertEqual(RangeCheck.props.ulong.maximum, maxulong)
+ self.assertEqual(RangeCheck.props.int64.minimum, minint64)
+ self.assertEqual(RangeCheck.props.int64.maximum, maxint64)
+ self.assertEqual(RangeCheck.props.uint64.minimum, 0)
+ self.assertEqual(RangeCheck.props.uint64.maximum, maxuint64)
+
+ obj = RangeCheck()
+ for key, (gtype, min, max) in types.items():
+ self.assertEqual(obj.get_property(key),
+ getattr(RangeCheck.props, key).default_value)
+
+ obj.set_property(key, min)
+ self.assertEqual(obj.get_property(key), min)
+
+ obj.set_property(key, max)
+ self.assertEqual(obj.get_property(key), max)
+