1""" 2XXX: Should verify if test_methods2.py implements all tests in this file. 3 4Test lowlevel message passing details (Python -> ObjC) 5 6 7NOTE: 'long long' return-value test for calls from Objective-C are disabled, 8 they crash the interpreter. 9 10Done: 11- Return simple values, but need to add limit-cases (exactly INT_MAX et.al.) 12- Return structs, but need to add more complex cases 13- Pass in basic types 14- Pass in struct types, but need to add more complex cases 15- Pass by reference of basic types (in, out, inout) 16 [Need to add python side of case 'id'] 17 18Todo: 19- Pass by reference of struct types (in, out, inout) 20- more than 1 argument 21- More argument conversions 22 23Also Todo: Passing from Objective-C to python 24- Using NSInvocation '[obj forwardInvocation:inv]' 25- Using normal calls 26- Done: Return simple values, return structs, pass in basic types (c part) 27 28NOTES: 29- Always use makeCFloat when testing the value of a C float against a 30 precomputed (literal) value. Just comparing against a Python float won't work 31 as that is a C double which has a different representation from C floats 32 resulting in spurious test failures. 33- See also testbndl.m, the implementation there must be synchronized 34 with this file. 35""" 36from PyObjCTools.TestSupport import * 37import objc 38import sys 39import struct 40 41# Can't set the right signatures in plain Objective-C. 42for method, argmeta in [ 43 ( "passInOutChar:", { 2: dict(type_modifier='N')}), 44 ( "passOutChar:", { 2: dict(type_modifier='o')}), 45 ( "passInChar:", { 2: dict(type_modifier='n')}), 46 ( "passInOutUChar:", { 2: dict(type_modifier='N', type='^C')}), 47 ( "passOutUChar:", { 2: dict(type_modifier='o', type='^C')}), 48 ( "passInUChar:", { 2: dict(type_modifier='n', type='^C')}), 49 ( "passInOutShort:", { 2: dict(type_modifier='N')}), 50 ( "passOutShort:", { 2: dict(type_modifier='o')}), 51 ( "passInShort:", { 2: dict(type_modifier='n')}), 52 ( "passInOutUShort:", { 2: dict(type_modifier='N')}), 53 ( "passOutUShort:", { 2: dict(type_modifier='o')}), 54 ( "passInUShort:", { 2: dict(type_modifier='n')}), 55 ( "passInOutInt:", { 2: dict(type_modifier='N')}), 56 ( "passOutInt:", { 2: dict(type_modifier='o')}), 57 ( "passInInt:", { 2: dict(type_modifier='n')}), 58 ( "passInOutUInt:", { 2: dict(type_modifier='N')}), 59 ( "passOutUInt:", { 2: dict(type_modifier='o')}), 60 ( "passInUInt:", { 2: dict(type_modifier='n')}), 61 ( "passInOutLong:", { 2: dict(type_modifier='N')}), 62 ( "passOutLong:", { 2: dict(type_modifier='o')}), 63 ( "passInLong:", { 2: dict(type_modifier='n')}), 64 ( "passInOutULong:", { 2: dict(type_modifier='N')}), 65 ( "passOutULong:", { 2: dict(type_modifier='o')}), 66 ( "passInULong:", { 2: dict(type_modifier='n')}), 67 ( "passInOutLongLong:", { 2: dict(type_modifier='N')}), 68 ( "passOutLongLong:", { 2: dict(type_modifier='o')}), 69 ( "passInLongLong:", { 2: dict(type_modifier='n')}), 70 ( "passInOutULongLong:", { 2: dict(type_modifier='N')}), 71 ( "passOutULongLong:", { 2: dict(type_modifier='o')}), 72 ( "passInULongLong:", { 2: dict(type_modifier='n')}), 73 ( "passInOutFloat:", { 2: dict(type_modifier='N')}), 74 ( "passOutFloat:", { 2: dict(type_modifier='o')}), 75 ( "passInFloat:", { 2: dict(type_modifier='n')}), 76 ( "passInOutDouble:", { 2: dict(type_modifier='N')}), 77 ( "passOutDouble:", { 2: dict(type_modifier='o')}), 78 ( "passInDouble:", { 2: dict(type_modifier='n')}), 79 ( "passInOutCharp:", { 2: dict(type_modifier='N')}), 80 ( "passOutCharp:", { 2: dict(type_modifier='o')}), 81 ( "passInCharp:", { 2: dict(type_modifier='n')}), 82 ( "passInOutID:", { 2: dict(type_modifier='N')}), 83 ( "passOutID:", { 2: dict(type_modifier='o')}), 84 ( "passInID:", { 2: dict(type_modifier='n')}), 85 ]: 86 87 objc.registerMetaDataForSelector("OC_TestClass1", method, 88 dict(arguments=argmeta)) 89 90 91from PyObjCTest.testbndl import * 92 93def makeCFloat(value): 94 """ 95 C floats and doubles have a different representation, this function returns 96 the result of converting a python float (== C double) to a C float and back. 97 """ 98 return struct.unpack('f',struct.pack('f', value))[0] 99 100 101class PyOCTestSimpleReturns(TestCase): 102 # 103 # Test returns of simple types from instance and classs methods 104 # 105 def testClsLongLong(self): 106 OC_TestClass1.clsReset() 107 self.assertEquals(OC_TestClass1.longlongClsFunc(), -(1L << 60)) 108 self.assertEquals(OC_TestClass1.longlongClsFunc(), -42) 109 self.assertEquals(OC_TestClass1.longlongClsFunc(), 0) 110 self.assertEquals(OC_TestClass1.longlongClsFunc(), 42) 111 self.assertEquals(OC_TestClass1.longlongClsFunc(), (1L << 60)) 112 113 def testClsULongLong(self): 114 OC_TestClass1.clsReset() 115 self.assertEquals(OC_TestClass1.ulonglongClsFunc(), 0) 116 self.assertEquals(OC_TestClass1.ulonglongClsFunc(), 42) 117 self.assertEquals(OC_TestClass1.ulonglongClsFunc(), (1L << 63)) 118 119 def testClsLong(self): 120 OC_TestClass1.clsReset() 121 self.assertEquals(OC_TestClass1.longClsFunc(), -(1 << 30)) 122 self.assertEquals(OC_TestClass1.longClsFunc(), -42) 123 self.assertEquals(OC_TestClass1.longClsFunc(), 0) 124 self.assertEquals(OC_TestClass1.longClsFunc(), 42) 125 self.assertEquals(OC_TestClass1.longClsFunc(), (1 << 30)) 126 127 def testClsULong(self): 128 OC_TestClass1.clsReset() 129 self.assertEquals(OC_TestClass1.ulongClsFunc(), 0) 130 self.assertEquals(OC_TestClass1.ulongClsFunc(), 42) 131 self.assertEquals(OC_TestClass1.ulongClsFunc(), (1 << 30)) 132 133 def testClsInt(self): 134 OC_TestClass1.clsReset() 135 self.assertEquals(OC_TestClass1.intClsFunc(), -(1 << 30)) 136 self.assertEquals(OC_TestClass1.intClsFunc(), -42) 137 self.assertEquals(OC_TestClass1.intClsFunc(), 0) 138 self.assertEquals(OC_TestClass1.intClsFunc(), 42) 139 self.assertEquals(OC_TestClass1.intClsFunc(), (1 << 30)) 140 141 def testClsUInt(self): 142 OC_TestClass1.clsReset() 143 self.assertEquals(OC_TestClass1.uintClsFunc(), 0) 144 self.assertEquals(OC_TestClass1.uintClsFunc(), 42) 145 self.assertEquals(OC_TestClass1.uintClsFunc(), (1 << 30)) 146 147 def testClsShort(self): 148 OC_TestClass1.clsReset() 149 self.assertEquals(OC_TestClass1.shortClsFunc(), -(1 << 14)) 150 self.assertEquals(OC_TestClass1.shortClsFunc(), -42) 151 self.assertEquals(OC_TestClass1.shortClsFunc(), 0) 152 self.assertEquals(OC_TestClass1.shortClsFunc(), 42) 153 self.assertEquals(OC_TestClass1.shortClsFunc(), (1 << 14)) 154 155 def testClsUShort(self): 156 OC_TestClass1.clsReset() 157 self.assertEquals(OC_TestClass1.ushortClsFunc(), 0) 158 self.assertEquals(OC_TestClass1.ushortClsFunc(), 42) 159 self.assertEquals(OC_TestClass1.ushortClsFunc(), (1 << 14)) 160 161 def testClsChar(self): 162 # Fails with libffi due to the way we treat 'char' at the moment 163 OC_TestClass1.clsReset() 164 self.assertEquals(OC_TestClass1.charClsFunc(), -128) 165 self.assertEquals(OC_TestClass1.charClsFunc(), 0) 166 self.assertEquals(OC_TestClass1.charClsFunc(), 127) 167 168 def testClsUChar(self): 169 OC_TestClass1.clsReset() 170 self.assertEquals(OC_TestClass1.ucharClsFunc(), 0) 171 self.assertEquals(OC_TestClass1.ucharClsFunc(), 128) 172 self.assertEquals(OC_TestClass1.ucharClsFunc(), 255) 173 174 def testClsFloat(self): 175 # Fails, possibly rounding error 176 OC_TestClass1.clsReset() 177 self.assertEquals(OC_TestClass1.floatClsFunc(), makeCFloat(0.128)) 178 self.assertEquals(OC_TestClass1.floatClsFunc(), makeCFloat(1.0)) 179 self.assertEquals(OC_TestClass1.floatClsFunc(), makeCFloat(42.0)) 180 self.assertEquals(OC_TestClass1.floatClsFunc(), makeCFloat(1e10)) 181 182 def testClsDouble(self): 183 OC_TestClass1.clsReset() 184 self.assertEquals(OC_TestClass1.doubleClsFunc(), 0.128) 185 self.assertEquals(OC_TestClass1.doubleClsFunc(), 1.0) 186 self.assertEquals(OC_TestClass1.doubleClsFunc(), 42.0) 187 self.assertEquals(OC_TestClass1.doubleClsFunc(), 1e10) 188 189 def testClsCharp(self): 190 OC_TestClass1.clsReset() 191 self.assertEquals(OC_TestClass1.charpClsFunc(), 'hello') 192 self.assertEquals(OC_TestClass1.charpClsFunc(), 'world') 193 self.assertEquals(OC_TestClass1.charpClsFunc(), 'foobar') 194 195 def testClsID(self): 196 OC_TestClass1.clsReset() 197 self.assertEquals(len(OC_TestClass1.idClsFunc()), 0) 198 self.assertEquals(type(OC_TestClass1.idClsFunc()).__name__, 'NSHost') 199 self.assert_(str(OC_TestClass1.idClsFunc()) in ('{}', '{\n}')) 200 self.assertEquals(OC_TestClass1.idClsFunc(), None) 201 202 # testCls* ends here 203 204 def testLongLong(self): 205 obj = OC_TestClass1.new() 206 obj.reset() 207 self.assertEquals(obj.longlongFunc(), -(1L << 60)) 208 self.assertEquals(obj.longlongFunc(), -42) 209 self.assertEquals(obj.longlongFunc(), 0) 210 self.assertEquals(obj.longlongFunc(), 42) 211 self.assertEquals(obj.longlongFunc(), (1L << 60)) 212 213 def testULongLong(self): 214 obj = OC_TestClass1.new() 215 obj.reset() 216 self.assertEquals(obj.ulonglongFunc(), 0) 217 self.assertEquals(obj.ulonglongFunc(), 42) 218 self.assertEquals(obj.ulonglongFunc(), (1L << 63)) 219 220 def testLong(self): 221 obj = OC_TestClass1.new() 222 obj.reset() 223 self.assertEquals(obj.longFunc(), -(1 << 30)) 224 self.assertEquals(obj.longFunc(), -42) 225 self.assertEquals(obj.longFunc(), 0) 226 self.assertEquals(obj.longFunc(), 42) 227 self.assertEquals(obj.longFunc(), (1 << 30)) 228 229 def testULong(self): 230 obj = OC_TestClass1.new() 231 obj.reset() 232 self.assertEquals(obj.ulongFunc(), 0) 233 self.assertEquals(obj.ulongFunc(), 42) 234 self.assertEquals(obj.ulongFunc(), (1 << 30)) 235 236 def testInt(self): 237 obj = OC_TestClass1.new() 238 obj.reset() 239 self.assertEquals(obj.intFunc(), -(1 << 30)) 240 self.assertEquals(obj.intFunc(), -42) 241 self.assertEquals(obj.intFunc(), 0) 242 self.assertEquals(obj.intFunc(), 42) 243 self.assertEquals(obj.intFunc(), (1 << 30)) 244 245 def testUInt(self): 246 obj = OC_TestClass1.new() 247 obj.reset() 248 self.assertEquals(obj.uintFunc(), 0) 249 self.assertEquals(obj.uintFunc(), 42) 250 self.assertEquals(obj.uintFunc(), (1 << 30)) 251 252 def testShort(self): 253 obj = OC_TestClass1.new() 254 obj.reset() 255 self.assertEquals(obj.shortFunc(), -(1 << 14)) 256 self.assertEquals(obj.shortFunc(), -42) 257 self.assertEquals(obj.shortFunc(), 0) 258 self.assertEquals(obj.shortFunc(), 42) 259 self.assertEquals(obj.shortFunc(), (1 << 14)) 260 261 def testUShort(self): 262 obj = OC_TestClass1.new() 263 obj.reset() 264 self.assertEquals(obj.ushortFunc(), 0) 265 self.assertEquals(obj.ushortFunc(), 42) 266 self.assertEquals(obj.ushortFunc(), (1 << 14)) 267 268 def testChar(self): 269 obj = OC_TestClass1.new() 270 # Fails with libffi due to the way we treat 'char' at the moment 271 obj.reset() 272 self.assertEquals(obj.charFunc(), -128) 273 self.assertEquals(obj.charFunc(), 0) 274 self.assertEquals(obj.charFunc(), 127) 275 276 def testUChar(self): 277 obj = OC_TestClass1.new() 278 obj.reset() 279 self.assertEquals(obj.ucharFunc(), 0) 280 self.assertEquals(obj.ucharFunc(), 128) 281 self.assertEquals(obj.ucharFunc(), 255) 282 283 def testFloat(self): 284 # Fails, possibly rounding error 285 obj = OC_TestClass1.new() 286 obj.reset() 287 self.assertEquals(obj.floatFunc(), makeCFloat(0.128)) 288 self.assertEquals(obj.floatFunc(), makeCFloat(1.0)) 289 self.assertEquals(obj.floatFunc(), makeCFloat(42.0)) 290 self.assertEquals(obj.floatFunc(), makeCFloat(1e10)) 291 292 def testDouble(self): 293 obj = OC_TestClass1.new() 294 obj.reset() 295 self.assertEquals(obj.doubleFunc(), 0.128) 296 self.assertEquals(obj.doubleFunc(), 1.0) 297 self.assertEquals(obj.doubleFunc(), 42.0) 298 self.assertEquals(obj.doubleFunc(), 1e10) 299 300 def testCharp(self): 301 obj = OC_TestClass1.new() 302 obj.reset() 303 self.assertEquals(obj.charpFunc(), 'hello') 304 self.assertEquals(obj.charpFunc(), 'world') 305 self.assertEquals(obj.charpFunc(), 'foobar') 306 307 def testID(self): 308 obj = OC_TestClass1.new() 309 obj.reset() 310 self.assertEquals(len(obj.idFunc()), 0) 311 self.assertEquals(type(obj.idFunc()).__name__, 'NSHost') 312 self.assert_(str(obj.idFunc()) in ('{}', '{\n}')) 313 self.assertEquals(obj.idFunc(), None) 314 315 def testStruct1(self): 316 obj = OC_TestClass1.new() 317 318 self.assertEquals(obj.dummyFunc(), (-1, 1)) 319 320 def testStruct2(self): 321 obj = OC_TestClass1.new() 322 323 self.assertEquals(obj.dummy2Func(), ((1,2,3,4),)) 324 325 326class PyOCTestSimpleArguments(TestCase): 327 # 328 # Test argument passing of single basic values. 329 # 330 def setUp(self): 331 self.obj = OC_TestClass1.new() 332 333 def testLongLong(self): 334 self.assertEquals(self.obj.longlongArg_(0), 0) 335 self.assertEquals(self.obj.longlongArg_(10), 5) 336 self.assertEquals(self.obj.longlongArg_(10L), 5) 337 self.assertEquals(self.obj.longlongArg_(1L << 60), (1L << 59)) 338 self.assertEquals(self.obj.longlongArg_(-10), -5) 339 self.assertEquals(self.obj.longlongArg_(-10L), -5) 340 self.assertEquals(self.obj.longlongArg_(-1L << 60), -(1L << 59)) 341 342 # TODO: Out of range values 343 344 def testULongLong(self): 345 self.assertEquals(self.obj.ulonglongArg_(0), 0) 346 self.assertEquals(self.obj.ulonglongArg_(10), 5) 347 self.assertEquals(self.obj.ulonglongArg_(10L), 5) 348 self.assertEquals(self.obj.ulonglongArg_(1L << 60), (1L << 59)) 349 350 # TODO: Out of range values 351 352 def testLong(self): 353 self.assertEquals(self.obj.longArg_(0), 0) 354 self.assertEquals(self.obj.longArg_(10), 5) 355 self.assertEquals(self.obj.longArg_(10L), 5) 356 self.assertEquals(self.obj.longArg_(1 << 30), (1 << 29)) 357 self.assertEquals(self.obj.longArg_(-10), -5) 358 self.assertEquals(self.obj.longArg_(-10L), -5) 359 self.assertEquals(self.obj.longArg_(-1 << 30), -(1 << 29)) 360 361 # TODO: Out of range values 362 363 def testULong(self): 364 self.assertEquals(self.obj.ulongArg_(0), 0) 365 self.assertEquals(self.obj.ulongArg_(10), 5) 366 self.assertEquals(self.obj.ulongArg_(10L), 5) 367 self.assertEquals(self.obj.ulongArg_(1 << 30), (1 << 29)) 368 369 # TODO: Out of range values 370 371 def testInt(self): 372 self.assertEquals(self.obj.intArg_(0), 0) 373 self.assertEquals(self.obj.intArg_(10), 5) 374 self.assertEquals(self.obj.intArg_(10L), 5) 375 self.assertEquals(self.obj.intArg_(1 << 30), (1 << 29)) 376 self.assertEquals(self.obj.intArg_(-10), -5) 377 self.assertEquals(self.obj.intArg_(-10L), -5) 378 self.assertEquals(self.obj.intArg_(-1 << 30), -(1 << 29)) 379 380 self.assertEquals(self.obj.intArg_(10.0), 5) 381 382 self.assertRaises(ValueError, self.obj.intArg_, long(sys.maxint)+1) 383 self.assertRaises(ValueError, self.obj.intArg_, -long(sys.maxint)-2) 384 self.assertRaises(ValueError, self.obj.intArg_, -float(sys.maxint)-2) 385 386 def testUInt(self): 387 self.assertEquals(self.obj.uintArg_(0), 0) 388 self.assertEquals(self.obj.uintArg_(10), 5) 389 self.assertEquals(self.obj.uintArg_(10L), 5) 390 self.assertEquals(self.obj.uintArg_(1 << 30), (1 << 29)) 391 392 self.assertEquals(self.obj.uintArg_(10.0), 5) 393 394 self.assertRaises(ValueError, self.obj.uintArg_, -5) 395 self.assertRaises(ValueError, self.obj.uintArg_, -5L) 396 self.assertRaises(ValueError, self.obj.uintArg_, 1+2*(long(sys.maxint)+1)) 397 398 399 def testShort(self): 400 self.assertEquals(self.obj.shortArg_(0), 0) 401 self.assertEquals(self.obj.shortArg_(10), 5) 402 self.assertEquals(self.obj.shortArg_(10L), 5) 403 self.assertEquals(self.obj.shortArg_(1 << 14), (1 << 13)) 404 self.assertEquals(self.obj.shortArg_(-10), -5) 405 self.assertEquals(self.obj.shortArg_(-10L), -5) 406 self.assertEquals(self.obj.shortArg_(-(1 << 14)), -(1 << 13)) 407 408 self.assertEquals(self.obj.shortArg_(10.0), 5) 409 410 # Out of range arguments, assumes a short is 16 bits 411 self.assertRaises(ValueError, self.obj.shortArg_, -(1<<16)-1) 412 self.assertRaises(ValueError, self.obj.shortArg_, 1<<16) 413 self.assertRaises(ValueError, self.obj.shortArg_, -(1L<<16)-1) 414 self.assertRaises(ValueError, self.obj.shortArg_, 1L<<16) 415 416 def testUShort(self): 417 self.assertEquals(self.obj.ushortArg_(0), 0) 418 self.assertEquals(self.obj.ushortArg_(10), 5) 419 self.assertEquals(self.obj.ushortArg_(10L), 5) 420 self.assertEquals(self.obj.ushortArg_(1 << 14), (1 << 13)) 421 422 self.assertEquals(self.obj.ushortArg_(10.0), 5) 423 424 # Out of range arguments, assumes a short is 16 bits 425 self.assertRaises(ValueError, self.obj.ushortArg_, -5) 426 self.assertRaises(ValueError, self.obj.ushortArg_, -(1<<16)-1) 427 self.assertRaises(ValueError, self.obj.ushortArg_, 1<<16) 428 self.assertRaises(ValueError, self.obj.ushortArg_, -5L) 429 self.assertRaises(ValueError, self.obj.ushortArg_, -(1L<<16)-1) 430 self.assertRaises(ValueError, self.obj.ushortArg_, 1L<<16) 431 432 433 def testChar(self): 434 self.assertEquals(self.obj.charArg_(0), (0)) 435 self.assertEquals(self.obj.charArg_(10), (5)) 436 self.assertEquals(self.obj.charArg_(10L), (5)) 437 self.assertEquals(self.obj.charArg_(1 << 6), (1 << 5)) 438 self.assertEquals(self.obj.charArg_('\x00'), 0x00) 439 self.assertEquals(self.obj.charArg_('\x10'), ord('\x10')/2) 440 441 # TODO: Out of range arguments 442 443 def testUChar(self): 444 self.assertEquals(self.obj.ucharArg_(0), 0) 445 self.assertEquals(self.obj.ucharArg_(10), 5) 446 self.assertEquals(self.obj.ucharArg_(10L), 5) 447 self.assertEquals(self.obj.ucharArg_(1 << 7), (1 << 6)) 448 self.assertEquals(self.obj.ucharArg_('\x00'), 0) 449 self.assertEquals(self.obj.ucharArg_('\x10'), ord('\x10')/2) 450 451 self.assertEquals(self.obj.ucharArg_(10.0), 5) 452 453 # Out of range arguments 454 self.assertRaises(ValueError, self.obj.ucharArg_, -5) 455 self.assertRaises(ValueError, self.obj.ucharArg_, -256) 456 self.assertRaises(ValueError, self.obj.ucharArg_, 256) 457 self.assertRaises(ValueError, self.obj.ucharArg_, -5L) 458 self.assertRaises(ValueError, self.obj.ucharArg_, -256L) 459 self.assertRaises(ValueError, self.obj.ucharArg_, 256L) 460 461 def testCharp(self): 462 self.assertEquals(self.obj.charpArg_("hello world"), 'dlrow olleh') 463 464 self.assertRaises(ValueError, self.obj.charpArg_, 256L) 465 self.assertRaises(ValueError, self.obj.charpArg_, u"hello world") 466 467 def testIDPython(self): 468 # Test a Python object as the argument 469 s = self.obj.idArg_(u"hello") 470 self.assertEquals(len(s), 1) 471 self.assertEquals(s[0], u"hello") 472 473 def testIDOC(self): 474 # Test an Objective-C object as the argument 475 476 # NSHost gives problems on GNUstep, better check those problems 477 # seperately in the Foundation test suite. 478 #c = objc.lookUpClass("NSHost") 479 #o = c.hostWithAddress_('127.0.0.1') 480 481 c = objc.lookUpClass("NSScanner") 482 o = c.scannerWithString_(u"hello world") 483 s = self.obj.idArg_(o) 484 self.assertEquals(len(s), 1) 485 self.assert_(s[0] is o) 486 487 def testStruct1(self): 488 self.assertEquals(self.obj.dummyArg_((-1, 1)), (-2, 2)) 489 490 self.assertRaises(TypeError, self.obj.dummyArg_, 256L) 491 self.assertRaises(ValueError, self.obj.dummyArg_, (-1,)) 492 self.assertRaises(ValueError, self.obj.dummyArg_, (-1,1,2)) 493 494 def testStruct2(self): 495 self.assertEquals(self.obj.dummy2Arg_(((1,2,3,4),)), ((8,6,4,2),)) 496 497 self.assertRaises(ValueError, self.obj.dummy2Arg_, ((8,6,4,2),1)) 498 self.assertRaises(ValueError, self.obj.dummy2Arg_, ((8,6,4,),)) 499 self.assertRaises(ValueError, self.obj.dummy2Arg_, ((8,6,4,2,1),)) 500 501 502class PyOCTestByReferenceArguments(TestCase): 503 # 504 # Test argument passing of single basic values by reference. 505 # 506 def setUp(self): 507 self.obj = OC_TestClass1.new() 508 509 def testCharIn(self): 510 self.assertEquals(self.obj.passInChar_('\x10'), 0x19) 511 512 def testCharOut(self): 513 self.obj.reset() 514 self.assertEquals(self.obj.passOutChar_(None), -128) 515 self.assertEquals(self.obj.passOutChar_(None), 0) 516 self.assertEquals(self.obj.passOutChar_(None), 127) 517 518 def testCharInOut(self): 519 self.assertEquals(self.obj.passInOutChar_('\x10'), 0x3a) 520 521 def testUCharIn(self): 522 self.assertEquals(self.obj.passInUChar_(10), 19) 523 524 def testUCharOut(self): 525 self.obj.reset() 526 self.assertEquals(self.obj.passOutUChar_(None), 0) 527 self.assertEquals(self.obj.passOutUChar_(None), 128) 528 self.assertEquals(self.obj.passOutUChar_(None), 255) 529 530 def testUCharInOut(self): 531 self.assertEquals(self.obj.passInOutUChar_(10), 52) 532 533 def testShortIn(self): 534 self.assertEquals(self.obj.passInShort_(10), 19) 535 self.assertEquals(self.obj.passInShort_(-100), -91) 536 self.assertEquals(self.obj.passInShort_(-100.0), -91) 537 538 def testShortOut(self): 539 self.obj.reset() 540 self.assertEquals(self.obj.passOutShort_(None), -(1 << 14)) 541 self.assertEquals(self.obj.passOutShort_(None), -42) 542 self.assertEquals(self.obj.passOutShort_(None), 0) 543 self.assertEquals(self.obj.passOutShort_(None), 42) 544 self.assertEquals(self.obj.passOutShort_(None), 1 << 14) 545 546 def testShortInOut(self): 547 self.assertEquals(self.obj.passInOutShort_(10), 52) 548 self.assertEquals(self.obj.passInOutShort_(-100), -58) 549 self.assertEquals(self.obj.passInOutShort_(-100.0), -58) 550 551 def testUShortIn(self): 552 self.assertEquals(self.obj.passInUShort_(10), 19) 553 554 def testUShortOut(self): 555 self.obj.reset() 556 self.assertEquals(self.obj.passOutUShort_(None), 0) 557 self.assertEquals(self.obj.passOutUShort_(None), 42) 558 self.assertEquals(self.obj.passOutUShort_(None), (1 << 14)) 559 560 def testUShortInOut(self): 561 self.assertEquals(self.obj.passInOutUShort_(10), 52) 562 563 def testIntIn(self): 564 self.assertEquals(self.obj.passInInt_(10), 19) 565 self.assertEquals(self.obj.passInInt_(-100), -91) 566 567 def testIntOut(self): 568 self.obj.reset() 569 self.assertEquals(self.obj.passOutInt_(None), -(1 << 30)) 570 self.assertEquals(self.obj.passOutInt_(None), -42) 571 self.assertEquals(self.obj.passOutInt_(None), 0) 572 self.assertEquals(self.obj.passOutInt_(None), 42) 573 self.assertEquals(self.obj.passOutInt_(None), (1 << 30)) 574 575 def testIntInOut(self): 576 self.assertEquals(self.obj.passInOutInt_(10), 52) 577 self.assertEquals(self.obj.passInOutInt_(-100), -58) 578 self.assertEquals(self.obj.passInOutInt_(-100.0), -58) 579 580 def testUIntIn(self): 581 self.assertEquals(self.obj.passInUInt_(10), 19) 582 583 def testUIntOut(self): 584 self.obj.reset() 585 self.assertEquals(self.obj.passOutUInt_(None), 0) 586 self.assertEquals(self.obj.passOutUInt_(None), 42) 587 self.assertEquals(self.obj.passOutUInt_(None), (1 << 30)) 588 589 def testUIntInOut(self): 590 self.assertEquals(self.obj.passInOutUInt_(10), 52) 591 self.assertEquals(self.obj.passInOutUInt_(10.0), 52) 592 593 def testLongIn(self): 594 self.assertEquals(self.obj.passInLong_(10), 19) 595 self.assertEquals(self.obj.passInLong_(-100), -91) 596 597 def testLongOut(self): 598 self.obj.reset() 599 self.assertEquals(self.obj.passOutLong_(None), -(1 << 30)) 600 self.assertEquals(self.obj.passOutLong_(None), -42) 601 self.assertEquals(self.obj.passOutLong_(None), 0) 602 self.assertEquals(self.obj.passOutLong_(None), 42) 603 self.assertEquals(self.obj.passOutLong_(None), (1 << 30)) 604 605 def testLongInOut(self): 606 self.assertEquals(self.obj.passInOutLong_(10), 52) 607 self.assertEquals(self.obj.passInOutLong_(-100), -58) 608 self.assertEquals(self.obj.passInOutLong_(-100.0), -58) 609 610 def testULongIn(self): 611 self.assertEquals(self.obj.passInULong_(10), 19) 612 613 def testULongOut(self): 614 self.obj.reset() 615 self.assertEquals(self.obj.passOutULong_(None), 0) 616 self.assertEquals(self.obj.passOutULong_(None), 42) 617 self.assertEquals(self.obj.passOutULong_(None), (1 << 30)) 618 619 def testULongInOut(self): 620 self.assertEquals(self.obj.passInOutULong_(10), 52) 621 self.assertEquals(self.obj.passInOutULong_(10.0), 52) 622 623 def testLongLongIn(self): 624 self.assertEquals(self.obj.passInLongLong_(10), 19) 625 self.assertEquals(self.obj.passInLongLong_(-100), -91) 626 627 def testLongLongOut(self): 628 self.obj.reset() 629 self.assertEquals(self.obj.passOutLongLong_(None), -(1L << 60)) 630 self.assertEquals(self.obj.passOutLongLong_(None), -42) 631 self.assertEquals(self.obj.passOutLongLong_(None), 0) 632 self.assertEquals(self.obj.passOutLongLong_(None), 42) 633 self.assertEquals(self.obj.passOutLongLong_(None), (1L << 60)) 634 635 def testLongLongInOut(self): 636 self.assertEquals(self.obj.passInOutLongLong_(10), 52) 637 self.assertEquals(self.obj.passInOutLongLong_(-100), -58) 638 self.assertEquals(self.obj.passInOutLongLong_(-100.0), -58) 639 640 def testULongLongIn(self): 641 self.assertEquals(self.obj.passInULongLong_(10), 19) 642 643 def testULongLongOut(self): 644 self.obj.reset() 645 self.assertEquals(self.obj.passOutULongLong_(None), 0) 646 self.assertEquals(self.obj.passOutULongLong_(None), 42) 647 self.assertEquals(self.obj.passOutULongLong_(None), (1L << 63)) 648 649 def testULongLongInOut(self): 650 self.assertEquals(self.obj.passInOutULongLong_(10), 52) 651 self.assertEquals(self.obj.passInOutULongLong_(10.0), 52) 652 653 def testFloatIn(self): 654 self.assertEquals(self.obj.passInFloat_(10), makeCFloat(90.0)) 655 self.assertEquals(self.obj.passInFloat_(0.11), makeCFloat(0.99)) 656 657 def testFloatOut(self): 658 self.obj.reset() 659 self.assertEquals(self.obj.passOutFloat_(None), makeCFloat(0.128)) 660 self.assertEquals(self.obj.passOutFloat_(None), makeCFloat(1.0)) 661 self.assertEquals(self.obj.passOutFloat_(None), makeCFloat(42.0)) 662 self.assertEquals(self.obj.passOutFloat_(None), makeCFloat(1e10)) 663 664 def testFloatInOut(self): 665 self.assertEquals(self.obj.passInOutFloat_(10), makeCFloat(420)) 666 self.assertEquals(self.obj.passInOutFloat_(10.0), makeCFloat(420)) 667 self.assertEquals(self.obj.passInOutFloat_(0.01), makeCFloat(0.42)) 668 669 def testDoubleIn(self): 670 self.assertEquals(self.obj.passInDouble_(10), 90.0) 671 self.assertEquals(self.obj.passInDouble_(0.11), 0.99) 672 673 def testDoubleOut(self): 674 self.obj.reset() 675 self.assertEquals(self.obj.passOutDouble_(None), 0.128) 676 self.assertEquals(self.obj.passOutDouble_(None), 1.0) 677 self.assertEquals(self.obj.passOutDouble_(None), 42.0) 678 self.assertEquals(self.obj.passOutDouble_(None), 1e10) 679 680 def testDoubleInOut(self): 681 self.assertEquals(self.obj.passInOutDouble_(10), 420) 682 self.assertEquals(self.obj.passInOutDouble_(10.0), 420) 683 self.assertEquals(self.obj.passInOutDouble_(0.01), 0.42) 684 685 def testCharpIn(self): 686 self.assertEquals(self.obj.passInCharp_("hello"), "hheelllloo") 687 self.assertEquals(self.obj.passInCharp_("abcde"), "aabbccddee") 688 689 def testCharpOut(self): 690 self.obj.reset() 691 self.assertEquals(self.obj.passOutCharp_(None), "hello") 692 self.assertEquals(self.obj.passOutCharp_(None), "world") 693 self.assertEquals(self.obj.passOutCharp_(None), "foobar") 694 695 def testCharpInOut(self): 696 self.assertEquals(self.obj.passInOutCharp_("hello"), "hheelllloo") 697 self.assertEquals(self.obj.passInOutCharp_("abcdef"), "aabbccddeeff") 698 699 # TODO: structs (including Objective-C part) 700 701 702 703# 704# Below this point only TestCases that test calling Python from Objective-C 705# 706# Notes: 707# - There is both a pure python and an Python-ObjC hybrid class 708# (MyPyClass and MyOCClass). The former is not used in the first few tests, 709# we need to decide what functionality we'll support for these (e.g. do 710# we support selector objects, or only normal methods?) 711# - Every test below should exists in two variants: 712# * 'invoke' - Calls back from ObjC to Python using an NSInvocation 713# and the forwardInvocation method 714# * 'call' - Calls back from ObjC to Python using a normal ObjC method call 715 716# Values for 717# - 8-bit char 718# - 16-bit short 719# - 32-bit int/long 720# - 64-bit long long 721# Values are: max-negative, -42, 0, 42, max-positive, out-of-range, bad-type, None 722# 723CHAR_NUMBERS=[ -128, -42, 0, 42, 127, 'a', 128, "hello", None ] 724UCHAR_NUMBERS=[ 0, 42, 255, 'a', 256, "hello", None ] 725SHORT_NUMBERS=[ -32768, -42, 0, 32767, 32768, "hello", None ] 726USHORT_NUMBERS=[ 0, 42, 65535, 65536, "hello", None ] 727INT_NUMBERS=[ -2147483648, -42, 0, 2147483647, 2147483648, "hello", None ] 728UINT_NUMBERS=[ 0, 42, 4294967295, 4294967296, "hello", None ] 729LONG_NUMBERS=[ -2147483648, -42, 0, 2147483647, sys.maxint+1, "hello", None ] 730ULONG_NUMBERS=[ 0, 42, 4294967295L, 2*(sys.maxint+1), "hello", None ] 731LONGLONG_NUMBERS=[ -9223372036854775808L, -42, 0, 42, 9223372036854775807L, 9223372036854775808L, "hello", None ] 732ULONGLONG_NUMBERS=[0, 42, 18446744073709551615L, 18446744073709551616L, "hello", None ] 733 734FLOAT_NUMBERS = [ makeCFloat(0.1), makeCFloat(100.0) ] 735DOUBLE_NUMBERS = [ 1.5, 3.5, 1e10, 1.99e10 ] 736OBJECTS = [ u"hello", 1.0, range(4), lambda x: 10 ] 737DUMMY_OBJECTS = [ (1, 1), (-10, -10), (-4, -5), (0, 0), (10, 20) ] 738DUMMY2_OBJECTS = [ ((1, 2, 3, 4),), ((-9, -8, -7, -6),)] 739POINTS=[ (1.0, 2.0), (1e10, 2e10), (-0.5, 0.5) ] 740 741class MyPyClass: 742 def __init__(self): 743 self.idx = 0 744 745 def reset(self): 746 self.idx = 0 747 748 def idFunc(self): 749 i = self.idx 750 self.idx += 1 751 return OBJECTS[i] 752 753class MyOCClass (objc.lookUpClass('NSObject')): 754 def __init__(self): 755 self.idx = 0 756 757 def reset(self): 758 self.idx = 0 759 760 def charFunc(self): 761 i = self.idx 762 self.idx += 1 763 return CHAR_NUMBERS[i] 764 charFunc = objc.selector(charFunc, signature=OC_TestClass1.charFunc.signature) 765 766 def ucharFunc(self): 767 i = self.idx 768 self.idx += 1 769 return UCHAR_NUMBERS[i] 770 ucharFunc = objc.selector(ucharFunc, signature=OC_TestClass1.ucharFunc.signature) 771 772 def shortFunc(self): 773 i = self.idx 774 self.idx += 1 775 return SHORT_NUMBERS[i] 776 shortFunc = objc.selector(shortFunc, signature=OC_TestClass1.shortFunc.signature) 777 778 def ushortFunc(self): 779 i = self.idx 780 self.idx += 1 781 return USHORT_NUMBERS[i] 782 ushortFunc = objc.selector(ushortFunc, signature=OC_TestClass1.ushortFunc.signature) 783 784 def intFunc(self): 785 i = self.idx 786 self.idx += 1 787 return INT_NUMBERS[i] 788 intFunc = objc.selector(intFunc, signature=OC_TestClass1.intFunc.signature) 789 790 def uintFunc(self): 791 i = self.idx 792 self.idx += 1 793 return UINT_NUMBERS[i] 794 uintFunc = objc.selector(uintFunc, signature=OC_TestClass1.uintFunc.signature) 795 796 def longFunc(self): 797 i = self.idx 798 self.idx += 1 799 return LONG_NUMBERS[i] 800 longFunc = objc.selector(longFunc, signature=OC_TestClass1.longFunc.signature) 801 802 def ulongFunc(self): 803 i = self.idx 804 self.idx += 1 805 return ULONG_NUMBERS[i] 806 ulongFunc = objc.selector(ulongFunc, signature=OC_TestClass1.ulongFunc.signature) 807 808 def longlongFunc(self): 809 i = self.idx 810 self.idx += 1 811 return LONGLONG_NUMBERS[i] 812 longlongFunc = objc.selector(longlongFunc, signature=OC_TestClass1.longlongFunc.signature) 813 814 def ulonglongFunc(self): 815 i = self.idx 816 self.idx += 1 817 return ULONGLONG_NUMBERS[i] 818 ulonglongFunc = objc.selector(ulonglongFunc, signature=OC_TestClass1.ulonglongFunc.signature) 819 820 def floatFunc(self): 821 i = self.idx 822 self.idx += 1 823 return FLOAT_NUMBERS[i] 824 floatFunc = objc.selector(floatFunc, signature=OC_TestClass1.floatFunc.signature) 825 826 def doubleFunc(self): 827 i = self.idx 828 self.idx += 1 829 return DOUBLE_NUMBERS[i] 830 doubleFunc = objc.selector(doubleFunc, signature=OC_TestClass1.doubleFunc.signature) 831 832 def idFunc(self): 833 i = self.idx 834 self.idx += 1 835 return OBJECTS[i] 836 837 def dummyFunc(self): 838 i = self.idx 839 self.idx += 1 840 return DUMMY_OBJECTS[i] 841 dummyFunc = objc.selector(dummyFunc, signature=OC_TestClass1.dummyFunc.signature) 842 843 def dummy2Func(self): 844 i = self.idx 845 self.idx += 1 846 return DUMMY2_OBJECTS[i] 847 dummy2Func = objc.selector(dummy2Func, signature=OC_TestClass1.dummy2Func.signature) 848 849 def nspointFunc(self): 850 i = self.idx 851 self.idx += 1 852 return POINTS[i] 853 nspointFunc = objc.selector(nspointFunc, signature=OC_TestClass1.nspointFunc.signature) 854 855 def charArg_(self, arg): 856 return arg * 2 857 charArg_ = objc.selector(charArg_, signature=OC_TestClass1.charArg_.signature) 858 def ucharArg_(self, arg): 859 return arg * 2 860 ucharArg_ = objc.selector(ucharArg_, signature=OC_TestClass1.ucharArg_.signature) 861 862 def shortArg_(self, arg): 863 return arg * 2 864 shortArg_ = objc.selector(shortArg_, signature=OC_TestClass1.shortArg_.signature) 865 866 def ushortArg_(self, arg): 867 return arg * 2 868 ushortArg_ = objc.selector(ushortArg_, signature=OC_TestClass1.ushortArg_.signature) 869 870 def intArg_(self, arg): 871 return arg * 2 872 intArg_ = objc.selector(intArg_, signature=OC_TestClass1.intArg_.signature) 873 874 def uintArg_(self, arg): 875 return arg * 2 876 uintArg_ = objc.selector(uintArg_, signature=OC_TestClass1.uintArg_.signature) 877 878 def longArg_(self, arg): 879 return arg * 2 880 longArg_ = objc.selector(longArg_, signature=OC_TestClass1.longArg_.signature) 881 882 def ulongArg_(self, arg): 883 return arg * 2 884 ulongArg_ = objc.selector(ulongArg_, signature=OC_TestClass1.ulongArg_.signature) 885 886 def longlongArg_(self, arg): 887 return arg * 2 888 longlongArg_ = objc.selector(longlongArg_, signature=OC_TestClass1.longlongArg_.signature) 889 890 def ulonglongArg_(self, arg): 891 return arg * 2 892 ulonglongArg_ = objc.selector(ulonglongArg_, signature=OC_TestClass1.ulonglongArg_.signature) 893 894 def floatArg_(self, arg): 895 return arg * 2 896 floatArg_ = objc.selector(floatArg_, signature=OC_TestClass1.floatArg_.signature) 897 898 def doubleArg_(self, arg): 899 return arg * 2 900 doubleArg_ = objc.selector(doubleArg_, signature=OC_TestClass1.doubleArg_.signature) 901 902 903class OCPyTestSimpleCalls(TestCase): 904 # 905 # Test argument passing of single basic values by reference. 906 # 907 def setUp(self): 908 self.pyobj = MyPyClass() 909 self.ocobj = MyOCClass.new() 910 self.obj = OC_TestClass2.new() 911 912 def testCChar(self): 913 self.pyobj.reset() 914 self.ocobj.reset() 915 916 for o in CHAR_NUMBERS[:-3]: 917 if isinstance(o, str): 918 o = ord(o) 919 self.assertEquals(self.obj.callInstanceCharFuncOf_(self.ocobj), o) 920 921 self.assertRaises(ValueError, self.obj.callInstanceCharFuncOf_, self.ocobj) 922 self.assertRaises(ValueError, self.obj.callInstanceCharFuncOf_, self.ocobj) 923 self.assertRaises(ValueError, self.obj.callInstanceCharFuncOf_, self.ocobj) 924 925 def testIChar(self): 926 self.pyobj.reset() 927 self.ocobj.reset() 928 929 for o in CHAR_NUMBERS[:-3]: 930 if isinstance(o, str): 931 o = ord(o) 932 self.assertEquals(self.obj.invokeInstanceCharFuncOf_(self.ocobj), o) 933 934 self.assertRaises(ValueError, self.obj.invokeInstanceCharFuncOf_, self.ocobj) 935 self.assertRaises(ValueError, self.obj.invokeInstanceCharFuncOf_, self.ocobj) 936 self.assertRaises(ValueError, self.obj.invokeInstanceCharFuncOf_, self.ocobj) 937 938 def testCUChar(self): 939 self.pyobj.reset() 940 self.ocobj.reset() 941 942 for o in UCHAR_NUMBERS[:-3]: 943 if isinstance(o, str): 944 o = ord(o) 945 self.assertEquals(self.obj.callInstanceUnsignedCharFuncOf_(self.ocobj), o) 946 947 self.assertRaises(ValueError, self.obj.callInstanceUnsignedCharFuncOf_, self.ocobj) 948 self.assertRaises(ValueError, self.obj.callInstanceUnsignedCharFuncOf_, self.ocobj) 949 self.assertRaises(ValueError, self.obj.callInstanceUnsignedCharFuncOf_, self.ocobj) 950 951 def testIUChar(self): 952 self.pyobj.reset() 953 self.ocobj.reset() 954 955 for o in UCHAR_NUMBERS[:-3]: 956 if isinstance(o, str): 957 o = ord(o) 958 self.assertEquals(self.obj.invokeInstanceUnsignedCharFuncOf_(self.ocobj), o) 959 960 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedCharFuncOf_, self.ocobj) 961 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedCharFuncOf_, self.ocobj) 962 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedCharFuncOf_, self.ocobj) 963 964 def testCShort(self): 965 self.pyobj.reset() 966 self.ocobj.reset() 967 968 for o in SHORT_NUMBERS[:-3]: 969 self.assertEquals(self.obj.callInstanceShortFuncOf_(self.ocobj), o) 970 971 self.assertRaises(ValueError, self.obj.callInstanceShortFuncOf_, self.ocobj) 972 self.assertRaises(ValueError, self.obj.callInstanceShortFuncOf_, self.ocobj) 973 self.assertRaises(ValueError, self.obj.callInstanceShortFuncOf_, self.ocobj) 974 975 def testIShort(self): 976 self.pyobj.reset() 977 self.ocobj.reset() 978 979 for o in SHORT_NUMBERS[:-3]: 980 self.assertEquals(self.obj.invokeInstanceShortFuncOf_(self.ocobj), o) 981 982 self.assertRaises(ValueError, self.obj.invokeInstanceShortFuncOf_, self.ocobj) 983 self.assertRaises(ValueError, self.obj.invokeInstanceShortFuncOf_, self.ocobj) 984 self.assertRaises(ValueError, self.obj.invokeInstanceShortFuncOf_, self.ocobj) 985 986 def testCUShort(self): 987 self.pyobj.reset() 988 self.ocobj.reset() 989 990 for o in USHORT_NUMBERS[:-3]: 991 self.assertEquals(self.obj.callInstanceUnsignedShortFuncOf_(self.ocobj), o) 992 993 self.assertRaises(ValueError, self.obj.callInstanceUnsignedShortFuncOf_, self.ocobj) 994 self.assertRaises(ValueError, self.obj.callInstanceUnsignedShortFuncOf_, self.ocobj) 995 self.assertRaises(ValueError, self.obj.callInstanceUnsignedShortFuncOf_, self.ocobj) 996 997 def testIUShort(self): 998 self.pyobj.reset() 999 self.ocobj.reset() 1000 1001 for o in USHORT_NUMBERS[:-3]: 1002 self.assertEquals(self.obj.invokeInstanceUnsignedShortFuncOf_(self.ocobj), o) 1003 1004 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedShortFuncOf_, self.ocobj) 1005 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedShortFuncOf_, self.ocobj) 1006 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedShortFuncOf_, self.ocobj) 1007 1008 def testCInt(self): 1009 self.pyobj.reset() 1010 self.ocobj.reset() 1011 1012 for o in INT_NUMBERS[:-3]: 1013 self.assertEquals(self.obj.callInstanceIntFuncOf_(self.ocobj), o) 1014 1015 self.assertRaises(ValueError, self.obj.callInstanceIntFuncOf_, self.ocobj) 1016 self.assertRaises(ValueError, self.obj.callInstanceIntFuncOf_, self.ocobj) 1017 self.assertRaises(ValueError, self.obj.callInstanceIntFuncOf_, self.ocobj) 1018 1019 def testIInt(self): 1020 self.pyobj.reset() 1021 self.ocobj.reset() 1022 1023 for o in INT_NUMBERS[:-3]: 1024 self.assertEquals(self.obj.invokeInstanceIntFuncOf_(self.ocobj), o) 1025 1026 self.assertRaises(ValueError, self.obj.invokeInstanceIntFuncOf_, self.ocobj) 1027 self.assertRaises(ValueError, self.obj.invokeInstanceIntFuncOf_, self.ocobj) 1028 self.assertRaises(ValueError, self.obj.invokeInstanceIntFuncOf_, self.ocobj) 1029 1030 def testCUInt(self): 1031 self.pyobj.reset() 1032 self.ocobj.reset() 1033 1034 for o in UINT_NUMBERS[:-3]: 1035 self.assertEquals(self.obj.callInstanceUnsignedIntFuncOf_(self.ocobj), o) 1036 1037 self.assertRaises(ValueError, self.obj.callInstanceUnsignedIntFuncOf_, self.ocobj) 1038 self.assertRaises(ValueError, self.obj.callInstanceUnsignedIntFuncOf_, self.ocobj) 1039 self.assertRaises(ValueError, self.obj.callInstanceUnsignedIntFuncOf_, self.ocobj) 1040 1041 def testIUInt(self): 1042 self.pyobj.reset() 1043 self.ocobj.reset() 1044 1045 for o in UINT_NUMBERS[:-3]: 1046 self.assertEquals(self.obj.invokeInstanceUnsignedIntFuncOf_(self.ocobj), o) 1047 1048 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedIntFuncOf_, self.ocobj) 1049 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedIntFuncOf_, self.ocobj) 1050 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedIntFuncOf_, self.ocobj) 1051 1052 def testCLong(self): 1053 self.pyobj.reset() 1054 self.ocobj.reset() 1055 1056 for o in LONG_NUMBERS[:-3]: 1057 self.assertEquals(self.obj.callInstanceLongFuncOf_(self.ocobj), o) 1058 1059 self.assertRaises(ValueError, self.obj.callInstanceLongFuncOf_, self.ocobj) 1060 self.assertRaises(ValueError, self.obj.callInstanceLongFuncOf_, self.ocobj) 1061 self.assertRaises(ValueError, self.obj.callInstanceLongFuncOf_, self.ocobj) 1062 1063 def testILong(self): 1064 self.pyobj.reset() 1065 self.ocobj.reset() 1066 1067 for o in LONG_NUMBERS[:-3]: 1068 self.assertEquals(self.obj.invokeInstanceLongFuncOf_(self.ocobj), o) 1069 1070 self.assertRaises(ValueError, self.obj.invokeInstanceLongFuncOf_, self.ocobj) 1071 self.assertRaises(ValueError, self.obj.invokeInstanceLongFuncOf_, self.ocobj) 1072 self.assertRaises(ValueError, self.obj.invokeInstanceLongFuncOf_, self.ocobj) 1073 1074 def testCULong(self): 1075 self.pyobj.reset() 1076 self.ocobj.reset() 1077 1078 for o in ULONG_NUMBERS[:-3]: 1079 self.assertEquals(self.obj.callInstanceUnsignedLongFuncOf_(self.ocobj), o) 1080 1081 self.assertRaises(ValueError, self.obj.callInstanceUnsignedLongFuncOf_, self.ocobj) 1082 self.assertRaises(ValueError, self.obj.callInstanceUnsignedLongFuncOf_, self.ocobj) 1083 self.assertRaises(ValueError, self.obj.callInstanceUnsignedLongFuncOf_, self.ocobj) 1084 1085 def testIULong(self): 1086 self.pyobj.reset() 1087 self.ocobj.reset() 1088 1089 for o in ULONG_NUMBERS[:-3]: 1090 self.assertEquals(self.obj.invokeInstanceUnsignedLongFuncOf_(self.ocobj), o) 1091 1092 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedLongFuncOf_, self.ocobj) 1093 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedLongFuncOf_, self.ocobj) 1094 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedLongFuncOf_, self.ocobj) 1095 1096 def testCLongLong(self): 1097 self.pyobj.reset() 1098 self.ocobj.reset() 1099 1100 for o in LONGLONG_NUMBERS[:-3]: 1101 self.assertEquals(self.obj.callInstanceLongLongFuncOf_(self.ocobj), o) 1102 1103 self.assertRaises(ValueError, self.obj.callInstanceLongLongFuncOf_, self.ocobj) 1104 self.assertRaises(ValueError, self.obj.callInstanceLongLongFuncOf_, self.ocobj) 1105 self.assertRaises(ValueError, self.obj.callInstanceLongLongFuncOf_, self.ocobj) 1106 1107 def testILongLong(self): 1108 self.pyobj.reset() 1109 self.ocobj.reset() 1110 1111 for o in LONGLONG_NUMBERS[:-3]: 1112 self.assertEquals(self.obj.invokeInstanceLongLongFuncOf_(self.ocobj), o) 1113 1114 self.assertRaises(ValueError, self.obj.invokeInstanceLongLongFuncOf_, self.ocobj) 1115 self.assertRaises(ValueError, self.obj.invokeInstanceLongLongFuncOf_, self.ocobj) 1116 self.assertRaises(ValueError, self.obj.invokeInstanceLongLongFuncOf_, self.ocobj) 1117 1118 def testCULongLong(self): 1119 self.pyobj.reset() 1120 self.ocobj.reset() 1121 1122 for o in ULONGLONG_NUMBERS[:-3]: 1123 self.assertEquals(self.obj.callInstanceUnsignedLongLongFuncOf_(self.ocobj), o) 1124 1125 self.assertRaises(ValueError, self.obj.callInstanceUnsignedLongLongFuncOf_, self.ocobj) 1126 self.assertRaises(ValueError, self.obj.callInstanceUnsignedLongLongFuncOf_, self.ocobj) 1127 self.assertRaises(ValueError, self.obj.callInstanceUnsignedLongLongFuncOf_, self.ocobj) 1128 1129 def testIULongLong(self): 1130 self.pyobj.reset() 1131 self.ocobj.reset() 1132 1133 for o in ULONGLONG_NUMBERS[:-3]: 1134 self.assertEquals(self.obj.invokeInstanceUnsignedLongLongFuncOf_(self.ocobj), o) 1135 1136 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedLongLongFuncOf_, self.ocobj) 1137 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedLongLongFuncOf_, self.ocobj) 1138 self.assertRaises(ValueError, self.obj.invokeInstanceUnsignedLongLongFuncOf_, self.ocobj) 1139 1140 def testCFloat(self): 1141 self.pyobj.reset() 1142 self.ocobj.reset() 1143 1144 for o in FLOAT_NUMBERS: 1145 self.assertEquals(self.obj.callInstanceFloatFuncOf_(self.ocobj), o) 1146 1147 def testIFloat(self): 1148 self.pyobj.reset() 1149 self.ocobj.reset() 1150 1151 for o in FLOAT_NUMBERS: 1152 self.assertEquals(self.obj.invokeInstanceFloatFuncOf_(self.ocobj), o) 1153 1154 def testCDouble(self): 1155 self.pyobj.reset() 1156 self.ocobj.reset() 1157 1158 for o in DOUBLE_NUMBERS: 1159 self.assertEquals(self.obj.callInstanceDoubleFuncOf_(self.ocobj), o) 1160 1161 def testIDouble(self): 1162 self.pyobj.reset() 1163 self.ocobj.reset() 1164 1165 for o in DOUBLE_NUMBERS: 1166 self.assertEquals(self.obj.invokeInstanceDoubleFuncOf_(self.ocobj), o) 1167 1168 def testCId(self): 1169 self.pyobj.reset() 1170 self.ocobj.reset() 1171 1172 for o in OBJECTS: 1173 self.assertEquals(self.obj.callInstanceIdFuncOf_(self.ocobj), o) 1174 1175 def testIId(self): 1176 self.pyobj.reset() 1177 self.ocobj.reset() 1178 1179 for o in OBJECTS: 1180 self.assertEquals(self.obj.invokeInstanceIdFuncOf_(self.ocobj), o) 1181 1182 def testCId2(self): 1183 self.pyobj.reset() 1184 self.ocobj.reset() 1185 1186 for o in OBJECTS: 1187 self.assertEquals(self.obj.callInstanceIdFuncOf_(self.pyobj), o) 1188 1189 def testIId2(self): 1190 self.pyobj.reset() 1191 self.ocobj.reset() 1192 1193 for o in OBJECTS: 1194 self.assertEquals(self.obj.invokeInstanceIdFuncOf_(self.pyobj), o) 1195 1196 def testCStruct1(self): 1197 self.pyobj.reset() 1198 self.ocobj.reset() 1199 1200 for o in DUMMY_OBJECTS: 1201 self.assertEquals(self.obj.callInstanceDummyFuncOf_(self.ocobj), o) 1202 1203 def testIStruct1(self): 1204 self.pyobj.reset() 1205 self.ocobj.reset() 1206 1207 for o in DUMMY_OBJECTS: 1208 self.assertEquals(self.obj.invokeInstanceDummyFuncOf_(self.ocobj), o) 1209 1210 def testCStruct2(self): 1211 self.pyobj.reset() 1212 self.ocobj.reset() 1213 1214 for o in DUMMY2_OBJECTS: 1215 self.assertEquals(self.obj.callInstanceDummy2FuncOf_(self.ocobj), o) 1216 1217 def testIStruct2(self): 1218 self.pyobj.reset() 1219 self.ocobj.reset() 1220 1221 for o in DUMMY2_OBJECTS: 1222 self.assertEquals(self.obj.invokeInstanceDummy2FuncOf_(self.ocobj), o) 1223 1224 def testCNSPoint(self): 1225 self.pyobj.reset() 1226 self.ocobj.reset() 1227 1228 for o in POINTS: 1229 self.assertEquals(self.obj.callInstanceNSPointFuncOf_(self.ocobj), o) 1230 1231 def testINSPoint(self): 1232 self.pyobj.reset() 1233 self.ocobj.reset() 1234 1235 for o in POINTS: 1236 self.assertEquals(self.obj.invokeInstanceNSPointFuncOf_(self.ocobj), o) 1237 1238class OCPyTestSimpleArguments(TestCase): 1239 # 1240 # Test argument passing of single basic values. 1241 # 1242 # TODO: Copy and adapt rest of OCPyTestSimpleArguments 1243 # 1244 1245 def setUp(self): 1246 self.ocobj = MyOCClass.new() 1247 self.obj = OC_TestClass2.new() 1248 1249 def testCLongLong(self): 1250 self.assertEquals(self.obj.callInstanceLongLongArg_on_(0, self.ocobj), 0) 1251 self.assertEquals(self.obj.callInstanceLongLongArg_on_(10, self.ocobj), 20) 1252 self.assertEquals(self.obj.callInstanceLongLongArg_on_(1L << 60, self.ocobj), 1L << 61) 1253 self.assertEquals(self.obj.callInstanceLongLongArg_on_(-10, self.ocobj), -20) 1254 self.assertEquals(self.obj.callInstanceLongLongArg_on_(-(1L << 60), self.ocobj), -(1L << 61)) 1255 1256 def testILongLong(self): 1257 self.assertEquals(self.obj.invokeInstanceLongLongArg_on_(0, self.ocobj), 0) 1258 self.assertEquals(self.obj.invokeInstanceLongLongArg_on_(10, self.ocobj), 20) 1259 self.assertEquals(self.obj.invokeInstanceLongLongArg_on_(1L << 60, self.ocobj), 1L << 61) 1260 self.assertEquals(self.obj.invokeInstanceLongLongArg_on_(-10, self.ocobj), -20) 1261 self.assertEquals(self.obj.invokeInstanceLongLongArg_on_(-(1L << 60), self.ocobj), -(1L << 61)) 1262 1263if __name__ == '__main__': 1264 main() 1265