Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testWithCount(self):
o = Py_MetaDataTest_AllArgs.new()
v, c = OC_MetaDataTest.makeIntArray_count_on_((1,2,3,4), 3, o)
self.assertEquals(c, 3)
self.assertEquals(len(v), 3)
self.assertEquals(list(v), [1,2,3])
# XXX: This one would be nice to have, but not entirely trivial
#v, c = OC_MetaDataTest.makeIntArray_count_on_((1,2,3,4), None, o)
#self.assertEquals(c, 3)
#self.assertEquals(len(v), 3)
#self.assertEquals(list(v), [1,2,3,4])
self.assertRaises(ValueError, OC_MetaDataTest.makeIntArray_count_on_, [1,2,3], 4, o)
self.assertRaises(ValueError, OC_MetaDataTest.makeIntArray_count_on_, objc.NULL, 0, o)
self.assertRaises(ValueError, OC_MetaDataTest.makeIntArray_count_on_, objc.NULL, 1, o)
def testNULLterminated(self):
o = Py_MetaDataTest_AllArgs.new()
v = OC_MetaDataTest.makeStringArrayOn_(o)
self.assertEquals(len(v), 3)
self.assertEquals(list(v), [ b"jaap", b"pieter", b"hans" ])
v = OC_MetaDataTest.nullStringArrayOn_(o)
self.assertEquals(v, objc.NULL)
def testSizeInArgument(self):
o = Py_MetaDataTest_AllArgs.new()
v = OC_MetaDataTest.makeIntArrayOf_on_(3, o)
self.assertEquals(len(v), 3)
self.assertEquals(list(v), [20, 21, 22])
v = OC_MetaDataTest.makeIntArrayOf_on_(10, o)
self.assertEquals(len(v), 10)
self.assertEquals(list(v), list(range(20, 30)))
v = OC_MetaDataTest.nullIntArrayOf_on_(100, o)
self.assertEquals(v, objc.NULL)
def testFixedSize(self):
o = Py_MetaDataTest_AllArgs.new()
v = OC_MetaDataTest.fill4Tuple_on_(None, o)
self.assertEquals(list(v), list(range(9, 13)))
v = OC_MetaDataTest.fill4Tuple_on_(None, o)
self.assertEquals(list(v), list(range(9, 13)))
self.assertRaises(ValueError, OC_MetaDataTest.fill4Tuple_on_, objc.NULL, o)
n, v = OC_MetaDataTest.nullfill4Tuple_on_(None, o)
self.assertEquals(n, 1)
self.assertEquals(list(v), list(range(1, 5)))
n, v = OC_MetaDataTest.nullfill4Tuple_on_(None, o)
self.assertEquals(n, 1)
self.assertEquals(list(v), list(range(1, 5)))
def testInputOutput(self):
o = Py_MetaDataTest_AllArgs.new()
x, y = OC_MetaDataTest.swapX_andY_on_(42, 284, o)
self.assertEquals(x, 284*2)
self.assertEquals(y, 42*2)
self.assertRaises(ValueError, OC_MetaDataTest.swapX_andY_on_, 42, objc.NULL, o)
def testWithCountInResult(self):
o = Py_MetaDataTest_AllArgs.new()
c, v = OC_MetaDataTest.reverseArray_uptoCount_on_(range(10), 10, o)
self.assertEquals(c, 5)
self.assertEquals(len(v), 5)
self.assertEquals(list(v), [0, 10, 20, 30, 40])
c, v = OC_MetaDataTest.maybeReverseArray_on_([1,2,3,4], o)
self.assertEquals(c, 2)
self.assertEquals(len(v), 2)
self.assertEquals(list(v), [45, 51])
def testFixedSize(self):
o = Py_MetaDataTest_AllArgs.new()
v, = OC_MetaDataTest.make4Tuple_on_((1.0, 4.0, 8.0, 12.5), o)
self.assertEquals(len(v), 4)
self.assertEquals(list(v), [1.0, 4.0, 8.0, 12.5])
v, = OC_MetaDataTest.make4Tuple_on_((1, 2, 3, 4), o)
self.assertEquals(len(v), 4)
self.assertEquals(list(v), [1.0, 2.0, 3.0, 4.0])
self.assertRaises(ValueError, OC_MetaDataTest.make4Tuple_on_, (1, 2, 3), o)
self.assertRaises(ValueError, OC_MetaDataTest.make4Tuple_on_, (1, 2, 3, 4, 5), o)
self.assertRaises(ValueError, OC_MetaDataTest.make4Tuple_on_, objc.NULL, o)
v, = OC_MetaDataTest.null4Tuple_on_(objc.NULL, o)
self.assertIs(v, objc.NULL)
def testInput(self):
o = Py_MetaDataTest_AllArgs.new()
r = OC_MetaDataTest.sumX_andY_on_(1, 2, o)
self.assertEquals(r, 1**2+2**2)
r = OC_MetaDataTest.sumX_andY_on_(2535, 5325, o)
self.assertEquals(r, 2535**2 + 5325**2)
self.assertRaises(ValueError, OC_MetaDataTest.sumX_andY_on_, 42, objc.NULL, o)
def testNullTerminated(self):
o = Py_MetaDataTest_AllArgs.new()
v, = OC_MetaDataTest.makeStringArray_on_((b"hello", b"world", b"there"), o)
self.assertEquals(len(v), 3)
self.assertEquals(list(v), ["hello", "world", "there"])
NSObject = objc.lookUpClass('NSObject')
p, q = NSObject.new(), NSObject.new()
v, = o.makeObjectArray_((p, q))
self.assertEquals(len(v), 2)
self.assertIs(v[0], p)
self.assertIs(v[1], q)
v, = OC_MetaDataTest.makeStringArray_on_((), o)
self.assertEquals(len(v), 0)
self.assertRaises(ValueError, OC_MetaDataTest.makeStringArray_on_, [1,2], o)
def testNullTerminated(self):
o = Py_MetaDataTest_AllArgs.new()
a = (b'aap', b'boot', b'cello')
v = OC_MetaDataTest.reverseStrings_on_(a, o)
self.assertEquals(a, (b'aap', b'boot', b'cello'))
self.assertEquals(v, (b'paa', b'toob', b'ollec'))
self.assertRaises(ValueError, OC_MetaDataTest.reverseStrings_on_, (1,2), o)
self.assertRaises(ValueError, OC_MetaDataTest.reverseStrings_on_, objc.NULL, o)
a = (b'aap', b'boot', b'cello')
n, v = OC_MetaDataTest.nullreverseStrings_on_(a, o)
self.assertEquals(n, 10)
self.assertEquals(a, (b'aap', b'boot', b'cello'))
self.assertEquals(v, (b'paa', b'toob', b'ollec'))
n, v = OC_MetaDataTest.nullreverseStrings_on_(objc.NULL, o)