예제 #1
0
 def test_string(self):
     "A Java string can be created, and the content returned"
     # This string contains unicode characters
     s = "H\xe9llo world"
     java_string = java.NewStringUTF(s.encode('utf-8'))
     self.assertEqual(
         java.GetStringUTFChars(java_string, None).decode('utf-8'), s)
예제 #2
0
    def test_string_method(self):
        "A Java string can be created, and the content returned"
        # This string contains unicode characters
        s = "Woop"
        java_string = java.NewStringUTF(s.encode('utf-8'))

        Example = java.FindClass("org/pybee/rubicon/test/Example")
        self.assertIsNotNone(Example.value)

        # Find the default constructor
        Example__init = java.GetMethodID(Example, "<init>", "()V")
        self.assertIsNotNone(Example__init.value)

        # Find the Example.duplicate_string() method on Example
        Example__duplicate_string = java.GetMethodID(
            Example, "duplicate_string",
            "(Ljava/lang/String;)Ljava/lang/String;")
        self.assertIsNotNone(Example__duplicate_string.value)

        # Create an instance of org.pybee.test.Example using the default constructor
        obj1 = java.NewObject(Example, Example__init)
        self.assertIsNotNone(obj1.value)

        # Invoke the string duplication method
        result = java.CallObjectMethod(obj1, Example__duplicate_string,
                                       java_string)
        self.assertEqual(
            java.GetStringUTFChars(cast(result, jstring),
                                   None).decode('utf-8'), "WoopWoop")