def test_check_method_vs_field(self): """check that HashMap and ArrayList have a size method and not a size field. Both the HashMap and ArrayList implementations have a `size()` method that is a wrapper for an `int` field also named `size`. The `autoclass` function must pick one of these two. If it were to pick the field, this would cause an "'int' object is not callable" TypeError when attempting to call the size method. This unit test is here to ensure that future changes to `autoclass` continue to prefer methods over fields. """ def assert_is_method(obj, name): multiple = "JavaMultipleMethod" in str( type(obj.__class__.__dict__[name])) single = "JavaMethod" in str(type(obj.__class__.__dict__[name])) self.assertTrue(multiple or single) hm = autoclass("java.util.HashMap", include_protected=True, include_private=True)() assert_is_method(hm, 'size') al = autoclass("java.util.ArrayList", include_protected=True, include_private=True)() assert_is_method(al, 'size')
def test_class(self): lstClz = autoclass("java.util.List") self.assertTrue("_class" in dir(lstClz)) self.assertEqual("java.util.List", lstClz._class.getName()) alstClz = autoclass("java.util.ArrayList") self.assertTrue("_class" in dir(alstClz)) self.assertEqual("java.util.ArrayList", alstClz._class.getName()) self.assertEqual("java.util.ArrayList", alstClz().getClass().getName())
def test_unicode(self): System = autoclass('java.lang.System') System.out.printf(u'é') Stack = autoclass('java.util.Stack') stack = Stack() emoji = u'\U0001F602' stack.push(emoji) popped = stack.pop() popped = py2_decode(popped) # <AK> chanded to use of py2_decode self.assertEquals(emoji, popped)
def test_unicode(self): System = autoclass('java.lang.System') System.out.printf(u'é') Stack = autoclass('java.util.Stack') stack = Stack() emoji = u'\U0001F602' stack.push(emoji) popped = stack.pop() if sys.version_info < (3, 0): popped = popped.decode('utf-8') self.assertEquals(emoji, popped)
def test_instance_fields(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.fieldZ, True) self.assertEquals(test.fieldB, 127) self.assertEquals(test.fieldC, 'k') self.assertEquals(test.fieldS, 32767) self.assertEquals(test.fieldI, 2147483467) self.assertEquals(test.fieldJ, 9223372036854775807) self.assertAlmostEquals(test.fieldF, 1.23456789) self.assertEquals(test.fieldD, 1.23456789) self.assertEquals(test.fieldString, py2_encode(u'hello \U0001F30E!')) test2 = autoclass('org.jnius.BasicsTest')(10) self.assertEquals(test2.fieldB, 10) self.assertEquals(test.fieldB, 127) self.assertEquals(test2.fieldB, 10)
def test_instance_fields(self): test = autoclass("org.jnius.BasicsTest")() self.assertEquals(test.fieldZ, True) self.assertEquals(test.fieldB, 127) self.assertEquals(test.fieldC, "k") self.assertEquals(test.fieldS, 32767) self.assertEquals(test.fieldI, 2147483467) self.assertEquals(test.fieldJ, 2147483467) self.assertAlmostEquals(test.fieldF, 1.23456789) self.assertEquals(test.fieldD, 1.23456789) self.assertEquals(test.fieldString, "helloworld") test2 = autoclass("org.jnius.BasicsTest")(10) self.assertEquals(test2.fieldB, 10) self.assertEquals(test.fieldB, 127) self.assertEquals(test2.fieldB, 10)
def test_instance_fields(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.fieldZ, True) self.assertEquals(test.fieldB, 127) self.assertEquals(test.fieldC, 'k') self.assertEquals(test.fieldS, 32767) self.assertEquals(test.fieldI, 2147483467) self.assertEquals(test.fieldJ, 2147483467) self.assertAlmostEquals(test.fieldF, 1.23456789) self.assertEquals(test.fieldD, 1.23456789) self.assertEquals(test.fieldString, 'helloworld') test2 = autoclass('org.jnius.BasicsTest')(10) self.assertEquals(test2.fieldB, 10) self.assertEquals(test.fieldB, 127) self.assertEquals(test2.fieldB, 10)
def test_multiple_methods(self): String = autoclass('java.lang.String') s = String('hello') self.assertEquals(s.getBytes(), [104, 101, 108, 108, 111]) self.assertEquals(s.getBytes('utf8'), [104, 101, 108, 108, 111]) self.assertEquals(s.indexOf(ord('e')), 1) self.assertEquals(s.indexOf(ord('e'), 2), -1)
def test_pass_intfloat_as_string(self): CharsAndStrings = autoclass("org.jnius.CharsAndStrings") self.assertIsNone(CharsAndStrings.testStringDefNull) with self.assertRaises(JavaException): # we cannot provide an int to a String CharsAndStrings.setString("a", 2) with self.assertRaises(JavaException): # we cannot provide an float to a String CharsAndStrings.setString("a", 2.2) alist = autoclass("java.util.ArrayList")() with self.assertRaises(JavaException): # we cannot provide a list to a String CharsAndStrings.setString("a", alist) system = autoclass("java.lang.System") with self.assertRaises(JavaException): system.setErr("a string")
def test_child_fields_all(self): Test = autoclass('org.jnius.ChildVisibilityTest', include_protected=True, include_private=True) test = Test() self.assertTrue(hasattr(test, 'fieldPublic')) self.assertTrue(hasattr(test, 'fieldPackageProtected')) self.assertTrue(hasattr(test, 'fieldProtected')) self.assertTrue(hasattr(test, 'fieldPrivate')) self.assertEqual(test.fieldPublic, py2_encode("Public")) self.assertEqual(test.fieldPackageProtected, py2_encode("PackageProtected")) self.assertEqual(test.fieldProtected, py2_encode("Protected")) self.assertEqual(test.fieldPrivate, py2_encode("Private")) self.assertTrue(hasattr(test, 'fieldChildPublic')) self.assertTrue(hasattr(test, 'fieldChildPackageProtected')) self.assertTrue(hasattr(test, 'fieldChildProtected')) self.assertTrue(hasattr(test, 'fieldChildPrivate')) self.assertEqual(test.fieldChildPublic, py2_encode("ChildPublic")) self.assertEqual(test.fieldChildPackageProtected, py2_encode("ChildPackageProtected")) self.assertEqual(test.fieldChildProtected, py2_encode("ChildProtected")) self.assertEqual(test.fieldChildPrivate, py2_encode("ChildPrivate"))
def test_child_static_methods_all(self): Test = autoclass('org.jnius.ChildVisibilityTest', include_protected=True, include_private=True) self.assertTrue(hasattr(Test, 'methodStaticPublic')) self.assertTrue(hasattr(Test, 'methodStaticPackageProtected')) self.assertTrue(hasattr(Test, 'methodStaticProtected')) self.assertTrue(hasattr(Test, 'methodStaticPrivate')) self.assertEqual(Test.methodStaticPublic(), py2_encode("StaticPublic")) self.assertEqual(Test.methodStaticPackageProtected(), py2_encode("StaticPackageProtected")) self.assertEqual(Test.methodStaticProtected(), py2_encode("StaticProtected")) self.assertEqual(Test.methodStaticPrivate(), py2_encode("StaticPrivate")) self.assertTrue(hasattr(Test, 'methodChildStaticPublic')) self.assertTrue(hasattr(Test, 'methodChildStaticPackageProtected')) self.assertTrue(hasattr(Test, 'methodChildStaticProtected')) self.assertTrue(hasattr(Test, 'methodChildStaticPrivate')) self.assertEqual(Test.methodChildStaticPublic(), py2_encode("ChildStaticPublic")) self.assertEqual(Test.methodChildStaticPackageProtected(), py2_encode("ChildStaticPackageProtected")) self.assertEqual(Test.methodChildStaticProtected(), py2_encode("ChildStaticProtected")) self.assertEqual(Test.methodChildStaticPrivate(), py2_encode("ChildStaticPrivate"))
def test_signatures(self): # >>> from jnius import autoclass # >>> cls = autoclass('java.lang.String') # >>> cls.valueOf.signatures() # [(['boolean'], 'java/lang/String'), # (['char'], 'java/lang/String'), # (['char[]'], 'java/lang/String'), # (['char[]', 'int', 'int'], 'java/lang/String'), # (['double'], 'java/lang/String'), # (['float'], 'java/lang/String'), # (['int'], 'java/lang/String'), # (['java/lang/Object'], 'java/lang/String'), # (['long'], 'java/lang/String')] cls = autoclass("java.lang.String") result = cls.valueOf.signatures() assert isinstance(result, list) assert all(isinstance(f, tuple) for f in result) assert sorted(result) == sorted([ (['boolean'], 'java/lang/String'), (['char'], 'java/lang/String'), (['char[]'], 'java/lang/String'), (['char[]', 'int', 'int'], 'java/lang/String'), (['double'], 'java/lang/String'), (['float'], 'java/lang/String'), (['int'], 'java/lang/String'), (['java/lang/Object'], 'java/lang/String'), (['long'], 'java/lang/String') ])
def test_check_method_vs_property(self): """check that "bean" properties don't replace methods. The ExecutorService Interface has methods `shutdown()`, `isShutdown()`, `isTerminated()`. The `autoclass` function will create a Python `property` if a function name matches a JavaBean name pattern. Those properties are important but they should not take priority over a method. For this Interface it wants to create properties called `shutdown` and `terminated` because of `isShutdown` and `isTerminated`. A `shutdown` property would conflict with the `shutdown()` method so it should be skipped. The `terminated` property is OK though. """ executor = autoclass("java.util.concurrent.Executors") pool = executor.newFixedThreadPool(1) self.assertTrue( isinstance(pool.__class__.__dict__['shutdown'], JavaMethod)) self.assertTrue( isinstance(pool.__class__.__dict__['terminated'], property)) self.assertTrue( isinstance(pool.__class__.__dict__['isShutdown'], JavaMethod)) self.assertTrue( isinstance(pool.__class__.__dict__['isTerminated'], JavaMethod))
def test_multiple_constructors_varargs(self): VariableArgConstructors = autoclass( 'org.jnius.VariableArgConstructors') c1 = VariableArgConstructors(1, 'var2', 42, None, 4) self.assertEqual(c1.constructorUsed, 1) c2 = VariableArgConstructors(1, 'var2', None, 4) self.assertEqual(c2.constructorUsed, 2)
def test_multiple_dimensions(self): MultipleDims = autoclass('org.jnius.MultipleDimensions') matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] self.assertEquals(MultipleDims.methodParamsMatrixI(matrix), True) self.assertEquals(MultipleDims.methodReturnMatrixI(), matrix)
def test_list_interface(self): ArrayList = autoclass('java.util.ArrayList') words = ArrayList() words.add('hello') words.add('world') self.assertIsNotNone(words.stream()) self.assertIsNotNone(words.iterator())
def test_stack(self): Stack = autoclass('java.util.Stack') stack = Stack() self.assertIsInstance(stack, Stack) stack.push('hello') stack.push('world') self.assertEqual(stack.pop(), 'world') self.assertEqual(stack.pop(), 'hello')
def test_instances_methods_params(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodParamsZBCSIJFD( True, 127, 'k', 32767, 2147483467, 2147483467, 1.23456789, 1.23456789), True) self.assertEquals(test.methodParamsString('helloworld'), True) self.assertEquals(test.methodParamsArrayI([1, 2, 3]), True) self.assertEquals(test.methodParamsArrayString([ 'hello', 'world']), True)
def test_instances_methods_params(self): test = autoclass("org.jnius.BasicsTest")() self.assertEquals( test.methodParamsZBCSIJFD(True, 127, "k", 32767, 2147483467, 2147483467, 1.23456789, 1.23456789), True ) self.assertEquals(test.methodParamsString("helloworld"), True) self.assertEquals(test.methodParamsArrayI([1, 2, 3]), True) self.assertEquals(test.methodParamsArrayString(["hello", "world"]), True)
def test_mmap_toString(self): mapClass = autoclass('java.util.HashMap') hmap = mapClass() hmap.put("a", "1") hmap.toString() mmap = cast('java.util.Map', hmap) mmap.toString() mmap.getClass()
def test_super_interface(self): LinkedList = autoclass('java.util.LinkedList') words = LinkedList() words.add('hello') words.add('world') q = cast('java.util.Queue', words) self.assertEqual(2, q.size()) self.assertEqual(2, len(q)) self.assertIsNotNone(q.iterator())
def test_collection(self): HashSet = autoclass('java.util.HashSet') aset = HashSet() aset.add('hello') aset.add('world') #check that the __len__ dunder is applied to a Collection not a List self.assertEqual(2, len(aset)) #check that the __len__ dunder is applied to it cast as a Collection self.assertEqual(2, len(cast("java.util.Collection", aset)))
def test_should_wrap_java_iterable_as_python_iterable(self): SimpleIterable = autoclass('org.jnius.SimpleIterable') si = SimpleIterable() expected = ["hello", "world"] actual = list(si.getIterable()) self.assertEquals(expected, actual)
def test_instances_methods_params(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodParamsZBCSIJFD( True, 127, 'k', 32767, 2147483467, 9223372036854775807, 1.23456789, 1.23456789), True) self.assertEquals(test.methodParamsZBCSIJFD( True, long(127), 'k', long(32767), long(2147483467), 9223372036854775807, 1.23456789, 1.23456789), True) self.assertEquals(test.methodParamsString(py2_encode(u'hello \U0001F30E!')), True) self.assertEquals(test.methodParamsArrayI([1, 2, 3]), True) self.assertEquals(test.methodParamsArrayString([ py2_encode(u'hello'), py2_encode(u'\U0001F30E')]), True)
def test_static_multi_methods(self): Test = autoclass('org.jnius.ChildVisibilityTest', include_protected=True, include_private=False) self.assertTrue(hasattr(Test, 'methodStaticMultiArgs')) self.assertTrue(isinstance(Test.methodStaticMultiArgs, JavaMultipleMethod)) self.assertTrue(Test.methodStaticMultiArgs(True)) self.assertTrue(Test.methodStaticMultiArgs(True, False)) with self.assertRaises(JavaException): Test.methodStaticMultiArgs(True, False, True)
def test_java_string(self): JString = autoclass('java.lang.String') testString1 = JString('hello world') self.assertTrue(testString1.equals('hello world')) if sys.version_info.major >= 3: testString2 = JString('umlauts: äöü') self.assertTrue(testString2.equals('umlauts: äöü')) testString3 = JString('happy face: ☺') self.assertTrue(testString3.equals('happy face: ☺'))
def test_value_nested(self): ''' Test that we cover the circular implementation of java.lang.Enum that on value returns the parent i.e. the Enum class instead of e.g. some Exception or segfault which means we can do Enum.X.X.X... Currently does not check anything, ref pyjnius#32: https://github.com/kivy/pyjnius/issues/32. ''' _ = autoclass('org.jnius.SimpleEnum')
def test_instance_methods(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodZ(), True) self.assertEquals(test.methodB(), 127) self.assertEquals(test.methodC(), 'k') self.assertEquals(test.methodS(), 32767) self.assertEquals(test.methodI(), 2147483467) self.assertEquals(test.methodJ(), 2147483467) self.assertAlmostEquals(test.methodF(), 1.23456789) self.assertEquals(test.methodD(), 1.23456789) self.assertEquals(test.methodString(), 'helloworld')
def test_java_exception_handling(self): Stack = autoclass('java.util.Stack') stack = Stack() try: stack.pop() self.fail("Expected exception to be thrown") except JavaException as je: # print "Got JavaException: " + str(je) # print "Got Exception Class: " + je.classname # print "Got stacktrace: \n" + '\n'.join(je.stacktrace) self.assertEquals("java.util.EmptyStackException", je.classname)
def test_static_methods_public_only(self): Test = autoclass('org.jnius.VisibilityTest', include_protected=False, include_private=False) self.assertTrue(hasattr(Test, 'methodStaticPublic')) self.assertFalse(hasattr(Test, 'methodStaticPackageProtected')) self.assertFalse(hasattr(Test, 'methodStaticProtected')) self.assertFalse(hasattr(Test, 'methodStaticPrivate')) self.assertEqual(Test.methodStaticPublic(), py2_encode("StaticPublic"))
def test_static_methods(self): Test = autoclass("org.jnius.BasicsTest") self.assertEquals(Test.methodStaticZ(), True) self.assertEquals(Test.methodStaticB(), 127) self.assertEquals(Test.methodStaticC(), "k") self.assertEquals(Test.methodStaticS(), 32767) self.assertEquals(Test.methodStaticI(), 2147483467) self.assertEquals(Test.methodStaticJ(), 2147483467) self.assertAlmostEquals(Test.methodStaticF(), 1.23456789) self.assertEquals(Test.methodStaticD(), 1.23456789) self.assertEquals(Test.methodStaticString(), "helloworld")
def test_instance_methods(self): test = autoclass("org.jnius.BasicsTest")() self.assertEquals(test.methodZ(), True) self.assertEquals(test.methodB(), 127) self.assertEquals(test.methodC(), "k") self.assertEquals(test.methodS(), 32767) self.assertEquals(test.methodI(), 2147483467) self.assertEquals(test.methodJ(), 2147483467) self.assertAlmostEquals(test.methodF(), 1.23456789) self.assertEquals(test.methodD(), 1.23456789) self.assertEquals(test.methodString(), "helloworld")
def test_static_fields(self): Test = autoclass("org.jnius.BasicsTest") self.assertEquals(Test.fieldStaticZ, True) self.assertEquals(Test.fieldStaticB, 127) self.assertEquals(Test.fieldStaticC, "k") self.assertEquals(Test.fieldStaticS, 32767) self.assertEquals(Test.fieldStaticI, 2147483467) self.assertEquals(Test.fieldStaticJ, 2147483467) self.assertAlmostEquals(Test.fieldStaticF, 1.23456789) self.assertEquals(Test.fieldStaticD, 1.23456789) self.assertEquals(Test.fieldStaticString, "helloworld")
def test_multiple_methods_two_args(self): MultipleMethods = autoclass('org.jnius.MultipleMethods') self.assertEqual(MultipleMethods.resolve('one', 'two'), 'resolved two args') # <AK> added self.assertEqual(MultipleMethods.resolve_fixedargs('one', 'two'), 'resolved two String args') with self.assertRaises(JavaException): MultipleMethods.resolve_fixedargs('one') with self.assertRaises(JavaException): MultipleMethods.resolve_fixedargs(1, 1)
def test_instance_fields(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.fieldZ, True) self.assertEquals(test.fieldB, 127) self.assertEquals(test.fieldC, 'k') self.assertEquals(test.fieldS, 32767) self.assertEquals(test.fieldI, 2147483467) self.assertEquals(test.fieldJ, 2147483467) self.assertAlmostEquals(test.fieldF, 1.23456789) self.assertEquals(test.fieldD, 1.23456789) self.assertEquals(test.fieldString, 'helloworld')
def test_static_fields(self): Test = autoclass('org.jnius.BasicsTest') self.assertEquals(Test.fieldStaticZ, True) self.assertEquals(Test.fieldStaticB, 127) self.assertEquals(Test.fieldStaticC, 'k') self.assertEquals(Test.fieldStaticS, 32767) self.assertEquals(Test.fieldStaticI, 2147483467) self.assertEquals(Test.fieldStaticJ, 2147483467) self.assertAlmostEquals(Test.fieldStaticF, 1.23456789) self.assertEquals(Test.fieldStaticD, 1.23456789) self.assertEquals(Test.fieldStaticString, 'helloworld')
def test_static_methods(self): Test = autoclass('org.jnius.BasicsTest') self.assertEquals(Test.methodStaticZ(), True) self.assertEquals(Test.methodStaticB(), 127) self.assertEquals(Test.methodStaticC(), 'k') self.assertEquals(Test.methodStaticS(), 32767) self.assertEquals(Test.methodStaticI(), 2147483467) self.assertEquals(Test.methodStaticJ(), 2147483467) self.assertAlmostEquals(Test.methodStaticF(), 1.23456789) self.assertEquals(Test.methodStaticD(), 1.23456789) self.assertEquals(Test.methodStaticString(), 'helloworld')
def test_static_fields(self): Test = autoclass('org.jnius.BasicsTest') self.assertEquals(Test.fieldStaticZ, True) self.assertEquals(Test.fieldStaticB, 127) self.assertEquals(Test.fieldStaticC, 'k') self.assertEquals(Test.fieldStaticS, 32767) self.assertEquals(Test.fieldStaticI, 2147483467) self.assertEquals(Test.fieldStaticJ, 9223372036854775807) self.assertAlmostEquals(Test.fieldStaticF, 1.23456789) self.assertEquals(Test.fieldStaticD, 1.23456789) self.assertEquals(Test.fieldStaticString, py2_encode(u'hello \U0001F30E!'))
def test_instance_methods(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodZ(), True) self.assertEquals(test.methodB(), 127) self.assertEquals(test.methodC(), 'k') self.assertEquals(test.methodS(), 32767) self.assertEquals(test.methodI(), 2147483467) self.assertEquals(test.methodJ(), 9223372036854775807) self.assertAlmostEquals(test.methodF(), 1.23456789) self.assertEquals(test.methodD(), 1.23456789) self.assertEquals(test.methodString(), py2_encode(u'hello \U0001F30E!'))
def test_static_methods(self): Test = autoclass('org.jnius.BasicsTest') self.assertEquals(Test.methodStaticZ(), True) self.assertEquals(Test.methodStaticB(), 127) self.assertEquals(Test.methodStaticC(), 'k') self.assertEquals(Test.methodStaticS(), 32767) self.assertEquals(Test.methodStaticI(), 2147483467) self.assertEquals(Test.methodStaticJ(), 9223372036854775807) self.assertAlmostEquals(Test.methodStaticF(), 1.23456789) self.assertEquals(Test.methodStaticD(), 1.23456789) self.assertEquals(Test.methodStaticString(), py2_encode(u'hello \U0001F30E!'))
def test_java_exception_chaining(self): BasicsTest = autoclass('org.jnius.BasicsTest') basics = BasicsTest() try: basics.methodExceptionChained() self.fail("Expected exception to be thrown") except JavaException as je: # print "Got JavaException: " + str(je) # print "Got Exception Class: " + je.classname # print "Got Exception Message: " + je.innermessage # print "Got stacktrace: \n" + '\n'.join(je.stacktrace) self.assertEquals("java.lang.IllegalArgumentException", je.classname) self.assertEquals("helloworld2", je.innermessage) self.assertIn("Caused by:", je.stacktrace) self.assertEquals(11, len(je.stacktrace))
def test_instances_methods_array(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodArrayZ(), [True] * 3) self.assertEquals(test.methodArrayB(), [127] * 3) self.assertEquals(test.methodArrayC(), ['k'] * 3) self.assertEquals(test.methodArrayS(), [32767] * 3) self.assertEquals(test.methodArrayI(), [2147483467] * 3) self.assertEquals(test.methodArrayJ(), [2147483467] * 3) ret = test.methodArrayF() ref = [1.23456789] * 3 self.assertAlmostEquals(ret[0], ref[0]) self.assertAlmostEquals(ret[1], ref[1]) self.assertAlmostEquals(ret[2], ref[2]) self.assertEquals(test.methodArrayD(), [1.23456789] * 3) self.assertEquals(test.methodArrayString(), ['helloworld'] * 3)
def test_instances_methods_array(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodArrayZ(), [True] * 3) self.assertEquals(test.methodArrayB()[0], 127) if sys.version_info >= (3, 0): self.assertEquals(test.methodArrayB(), [127] * 3) self.assertEquals(test.methodArrayC(), ['k'] * 3) self.assertEquals(test.methodArrayS(), [32767] * 3) self.assertEquals(test.methodArrayI(), [2147483467] * 3) self.assertEquals(test.methodArrayJ(), [9223372036854775807] * 3) ret = test.methodArrayF() ref = [1.23456789] * 3 self.assertAlmostEquals(ret[0], ref[0]) self.assertAlmostEquals(ret[1], ref[1]) self.assertAlmostEquals(ret[2], ref[2]) self.assertEquals(test.methodArrayD(), [1.23456789] * 3) self.assertEquals(test.methodArrayString(), [py2_encode(u'hello \U0001F30E!')] * 3)
def test_instance_set_fields(self): test = autoclass('org.jnius.BasicsTest')() test.fieldSetZ = True test.fieldSetB = 127 test.fieldSetC = ord('k') test.fieldSetS = 32767 test.fieldSetI = 2147483467 test.fieldSetJ = 9223372036854775807 test.fieldSetF = 1.23456789 test.fieldSetD = 1.23456789 self.assertTrue(test.testFieldSetZ()) self.assertTrue(test.testFieldSetB()) self.assertTrue(test.testFieldSetC()) self.assertTrue(test.testFieldSetS()) self.assertTrue(test.testFieldSetI()) self.assertTrue(test.testFieldSetJ()) self.assertTrue(test.testFieldSetF()) self.assertTrue(test.testFieldSetD())
def test_instance_set_fields(self): test = autoclass("org.jnius.BasicsTest")() test.fieldSetZ = True test.fieldSetB = 127 test.fieldSetC = ord("k") test.fieldSetS = 32767 test.fieldSetI = 2147483467 test.fieldSetJ = 2147483467 test.fieldSetF = 1.23456789 test.fieldSetD = 1.23456789 self.assertTrue(test.testFieldSetZ()) self.assertTrue(test.testFieldSetB()) self.assertTrue(test.testFieldSetC()) self.assertTrue(test.testFieldSetS()) self.assertTrue(test.testFieldSetI()) self.assertTrue(test.testFieldSetJ()) self.assertTrue(test.testFieldSetF()) self.assertTrue(test.testFieldSetD())
def test_instance_getter_naming(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.disabled, True) self.assertEquals(test.enabled, False)
def test_return_array_as_object_of_integers(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodReturnIntegers(), [1, 2])
def test_return_array_as_object_array_of_strings(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodReturnStrings(), [py2_encode(u'Hello'), py2_encode(u'\U0001F30E')])
def test_instances_methods_params_array_byte(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodParamsArrayByte([127, 127, 127]), True) ret = test.methodArrayB() self.assertEquals(test.methodParamsArrayByte(ret), True)
def test_instances_methods_params_object_list_long(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodParamsObject([1, 2]), True)
def test_instances_methods_params_object_list_str(self): test = autoclass('org.jnius.BasicsTest')() self.assertEquals(test.methodParamsObject([ 'hello', 'world']), True)
def test_unicode(self): System = autoclass('java.lang.System') System.out.printf(u'é')