|
25 | 25 | import java.io.File; |
26 | 26 | import java.io.FileNotFoundException; |
27 | 27 | import java.io.IOException; |
| 28 | +import java.lang.reflect.Array; |
28 | 29 | import java.math.BigDecimal; |
29 | 30 | import java.math.BigInteger; |
30 | 31 | import java.nio.file.Files; |
@@ -247,6 +248,35 @@ public void testCallPython() { |
247 | 248 | } |
248 | 249 | } |
249 | 250 |
|
| 251 | + @Test |
| 252 | + public void testInvokeMethodWithPrimitiveArrays() { |
| 253 | + PythonInterpreterConfig config = |
| 254 | + PythonInterpreterConfig.newBuilder().addPythonPaths(testDir).build(); |
| 255 | + try (PythonInterpreter interpreter = new PythonInterpreter(config)) { |
| 256 | + interpreter.exec("import test_call"); |
| 257 | + Object[][] cases = { |
| 258 | + {new boolean[] {true, false}, new Object[] {true, false}}, |
| 259 | + {new short[] {1, 2}, new Object[] {1L, 2L}}, |
| 260 | + {new int[] {1, 2}, new Object[] {1L, 2L}}, |
| 261 | + {new long[] {1, 2}, new Object[] {1L, 2L}}, |
| 262 | + {new float[] {1.5f, 2.5f}, new Object[] {1.5d, 2.5d}}, |
| 263 | + {new double[] {1.5, 2.5}, new Object[] {1.5d, 2.5d}} |
| 264 | + }; |
| 265 | + for (Object[] testCase : cases) { |
| 266 | + Object array = testCase[0]; |
| 267 | + assertArrayEquals( |
| 268 | + (Object[]) testCase[1], |
| 269 | + (Object[]) |
| 270 | + interpreter.invokeMethod("test_call", "test_call_one_arg", array)); |
| 271 | + Object empty = Array.newInstance(array.getClass().getComponentType(), 0); |
| 272 | + assertArrayEquals( |
| 273 | + new Object[0], |
| 274 | + (Object[]) |
| 275 | + interpreter.invokeMethod("test_call", "test_call_one_arg", empty)); |
| 276 | + } |
| 277 | + } |
| 278 | + } |
| 279 | + |
250 | 280 | @Test |
251 | 281 | public void testCallPythonWithAllTypes() throws Exception { |
252 | 282 | PythonInterpreterConfig config = |
|
0 commit comments