コード例 #1
0
ファイル: test_jni.py プロジェクト: yileye/rubicon-java
    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)
コード例 #2
0
ファイル: test_jni.py プロジェクト: stjordanis/rubicon-java
    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)