| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import jpype |
| 19 |
import common |
| 20 |
import subrun |
| 21 |
import unittest |
| 22 |
import os |
| 23 |
|
| 24 |
|
| 25 |
def proxy(s): |
| 26 |
if not isinstance(s, str): |
| 27 |
raise TypeError("Fail") |
| 28 |
return s |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
@subrun.TestCase |
| 33 |
class LegacyTestCase(unittest.TestCase): |
| 34 |
@classmethod |
| 35 |
def setUpClass(cls): |
| 36 |
|
| 37 |
jpype.startJVM(classpath=os.path.abspath( |
| 38 |
"test/classes"), convertStrings=True) |
| 39 |
|
| 40 |
def setUp(self): |
| 41 |
self._test = jpype.JClass("jpype.str.Test") |
| 42 |
self._intf = jpype.JClass("jpype.str.StringFunction") |
| 43 |
|
| 44 |
def testStaticField(self): |
| 45 |
s = self._test.staticField |
| 46 |
self.assertEqual(s, "staticField") |
| 47 |
self.assertIsInstance(s, str) |
| 48 |
|
| 49 |
def testMemberField(self): |
| 50 |
s = self._test().memberField |
| 51 |
self.assertEqual(s, "memberField") |
| 52 |
self.assertIsInstance(s, str) |
| 53 |
|
| 54 |
def testStaticMethod(self): |
| 55 |
s = self._test.staticCall() |
| 56 |
self.assertEqual(s, "staticCall") |
| 57 |
self.assertIsInstance(s, str) |
| 58 |
|
| 59 |
def testMemberMethod(self): |
| 60 |
s = self._test().memberCall() |
| 61 |
self.assertEqual(s, "memberCall") |
| 62 |
self.assertIsInstance(s, str) |
| 63 |
|
| 64 |
def testArrayItem(self): |
| 65 |
tc = ('apples', 'banana', 'cherries', 'dates', 'elderberry') |
| 66 |
for i in range(0, 5): |
| 67 |
s = self._test.array[i] |
| 68 |
self.assertEqual(s, tc[i]) |
| 69 |
self.assertIsInstance(s, str) |
| 70 |
|
| 71 |
def testArrayRange(self): |
| 72 |
tc = ('apples', 'banana', 'cherries', 'dates', 'elderberry') |
| 73 |
slc = self._test.array[1:-1] |
| 74 |
self.assertEqual(tuple(slc), tc[1:-1]) |
| 75 |
self.assertIsInstance(slc[1], str) |
| 76 |
|
| 77 |
def testProxy(self): |
| 78 |
p = jpype.JProxy([self._intf], dict={'call': proxy}) |
| 79 |
r = self._test().callProxy(p, "roundtrip") |
| 80 |
self.assertEqual(r, "roundtrip") |
| 81 |
self.assertIsInstance(r, str) |
| 82 |
|
| 83 |
def testNullBytes(self): |
| 84 |
s = self._test.callWithNullBytes() |
| 85 |
self.assertEqual(s, "call\u0000With\u0000Null\u0000Bytes") |
| 86 |
self.assertIsInstance(s, str) |
| 87 |
|
| 88 |
s = self._test.returnArgument("\u0394 16 byte encoded text\u0000with null\u0000 bytes \u1394") |
| 89 |
self.assertEqual(s, "\u0394 16 byte encoded text\u0000with null\u0000 bytes \u1394") |
| 90 |
self.assertIsInstance(s, str) |
| 91 |
|
| 92 |
s = self._test.returnArgument("\U0001F468\u200D\U0001F9B2 32 byte encoded text" |
| 93 |
"\u0000with null\u0000 bytes \U0001F468\u200D\U0001F9B2") |
| 94 |
self.assertEqual(s, "\U0001F468\u200D\U0001F9B2 32 byte encoded text" |
| 95 |
"\u0000with null\u0000 bytes \U0001F468\u200D\U0001F9B2") |
| 96 |
self.assertIsInstance(s, str) |