def test_non_existent(self): "Non-existent classes/methods/fields return None from Find/Get APIs" # A class that doesn't exist UnknownClass = java.FindClass("java/XXX") self.assertIsNone(UnknownClass.value) # A class that does exist, that we can then search for non-existent methods Example = java.FindClass("org/pybee/rubicon/test/Example") self.assertIsNotNone(Example.value) # Fields and Methods (static and non-static) self.assertIsNone(java.GetMethodID(Example, "xxx", "()V").value) self.assertIsNone(java.GetStaticMethodID(Example, "xxx", "()V").value) self.assertIsNone(java.GetFieldID(Example, "xxx", "I").value) self.assertIsNone(java.GetStaticFieldID(Example, "xxx", "I").value) # Bad descriptors for existing fields/methods also fail. self.assertIsNone( java.GetMethodID(Example, "get_int_field", "()D").value) self.assertIsNone( java.GetStaticMethodID(Example, "get_static_int_field", "()D").value) self.assertIsNone(java.GetFieldID(Example, "int_field", "D").value) self.assertIsNone( java.GetStaticFieldID(Example, "static_int_field", "D").value)
def test_static(self): "Static methods and fields can be invoked" # Get a reference to the org.beeware.test.Example class Example = java.FindClass("org/beeware/rubicon/test/Example") self.assertIsNotNone(Example.value) # Find the BaseExample.set_static_base_int_field() method on Example Example__set_static_base_int_field = java.GetStaticMethodID(Example, "set_static_base_int_field", "(I)V") self.assertIsNotNone(Example__set_static_base_int_field.value) # Find the Example.get_static_base_int_field() method on Example Example__get_static_base_int_field = java.GetStaticMethodID(Example, "get_static_base_int_field", "()I") self.assertIsNotNone(Example__get_static_base_int_field.value) # Find the Example.set_static_int_field() method Example__set_static_int_field = java.GetStaticMethodID(Example, "set_static_int_field", "(I)V") self.assertIsNotNone(Example__set_static_int_field.value) # Find the Example.get_static_int_field() method Example__get_static_int_field = java.GetStaticMethodID(Example, "get_static_int_field", "()I") self.assertIsNotNone(Example__get_static_int_field.value) # Find Example.static_int_field Example__static_int_field = java.GetStaticFieldID(Example, "static_int_field", "I") self.assertIsNotNone(Example__static_int_field.value) # Find Example.static_base_int_field Example__static_base_int_field = java.GetStaticFieldID(Example, "static_base_int_field", "I") self.assertIsNotNone(Example__static_base_int_field.value) # Use the get_static_int_field and get_static_base_int_field methods self.assertEqual(java.CallStaticIntMethod(Example, Example__get_static_base_int_field), 1) self.assertEqual(java.CallStaticIntMethod(Example, Example__get_static_int_field), 11) self.assertEqual(java.GetStaticIntField(Example, Example__static_base_int_field), 1) self.assertEqual(java.GetStaticIntField(Example, Example__static_int_field), 11) # Use the set_static_int_field and set_static_base_int_field methods java.CallVoidMethod(Example, Example__set_static_base_int_field, 1137) java.CallVoidMethod(Example, Example__set_static_int_field, 1142) # Confirm that the values have changed self.assertEqual(java.CallStaticIntMethod(Example, Example__get_static_base_int_field), 1137) self.assertEqual(java.CallStaticIntMethod(Example, Example__get_static_int_field), 1142) self.assertEqual(java.GetStaticIntField(Example, Example__static_base_int_field), 1137) self.assertEqual(java.GetStaticIntField(Example, Example__static_int_field), 1142)
def test_jlong(self): """"A jlong can be created, and the content returned, even for large/small values that push the boundaries of signed 64-bit integers""" # Get the getter and setter Example = java.FindClass(b"org/beeware/rubicon/test/Example") getter = java.GetStaticMethodID(Example, b"get_static_long_field", b"()J") self.assertIsNotNone(getter.value) setter = java.GetStaticMethodID(Example, b"set_static_long_field", b"(J)V") self.assertIsNotNone(setter.value) for num in (0, -1, 1 << 31, 1 << 32, -1 * 1 << 32, (1 << 63 - 1), -1 * (1 << 63 - 1)): # Validate rubicon.types.jlong. self.assertEqual(jlong(num).value, num) # Validate round trips through Java. java.CallStaticVoidMethod(Example, setter, jlong(num)) self.assertEqual(java.CallStaticLongMethod(Example, getter), num)