source: java2python/src/test/java/tudelft/utilities/j2p/PrintStreamExampleTest.java@ 381

Last change on this file since 381 was 378, checked in by wouter, 2 years ago

#114 cleaned up PrintStream translator. It now recognises much more calls and checks which of the overloaded functions is really called to map it to corresponding python code.

File size: 1.4 KB
Line 
1package tudelft.utilities.j2p;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.lang.reflect.InvocationTargetException;
7import java.lang.reflect.Method;
8import java.util.Arrays;
9import java.util.List;
10
11import org.junit.Test;
12
13import testcode.PrintStreamExample;
14
15public class PrintStreamExampleTest extends PyTest {
16
17 private static final Class<PrintStreamExample> mainprogram = PrintStreamExample.class;
18
19 private static final String TESTDIR = "src/test/java/";
20// private static final String FULLNAME = "testcode/PrintStreamExample.java";
21 private static final String SOURCECODE = mainprogram.getCanonicalName()
22 .replaceAll("\\.", "/") + ".java";
23
24 @Test
25 public void test() throws IOException, ClassNotFoundException {
26 System.out.println("TRANSLATION:");
27 System.out.println(translate(TESTDIR + SOURCECODE));
28 }
29
30 @Test
31 public void runInPython() throws Exception {
32
33 List<String> res = runPython(translate(TESTDIR + SOURCECODE),
34 SOURCECODE.replace(".java", ".py"));
35 System.out.println("expected was:");
36 runMain();
37 System.out.println("Actual: " + res);
38 assertEquals(Arrays.asList("He11.0True", "bye"), res);
39 }
40
41 public void runMain() throws NoSuchMethodException, SecurityException,
42 IllegalAccessException, IllegalArgumentException,
43 InvocationTargetException {
44 Method m = mainprogram.getMethod("main", String[].class);
45 String[] params = null;
46 m.invoke(null, (Object) params);
47 }
48}
Note: See TracBrowser for help on using the repository browser.