} catch (IllegalThreadStateException e) {
//that's ok
}
try {
IXmlRpcClient client = new ScriptXmlRpcClient(process, err, out);
client.setPort(port);
printArr(client.execute("addExec", new Object[] { "abc = 10" }));
printArr(client.execute("addExec", new Object[] { "abc" }));
printArr(client.execute("addExec", new Object[] { "import sys" }));
printArr(client.execute("addExec", new Object[] { "class Foo:" }));
printArr(client.execute("addExec", new Object[] { " print 20" }));
printArr(client.execute("addExec", new Object[] { " print >> sys.stderr, 30" }));
printArr(client.execute("addExec", new Object[] { "" }));
printArr(client.execute("addExec", new Object[] { "foo=Foo()" }));
printArr(client.execute("addExec", new Object[] { "foo.__doc__=None" }));
printArr("start get completions");
Object[] completions = (Object[]) client.execute("getCompletions", new Object[] { "fo" });
//the completions may come in any order, we must sort it for the test and remove things we don't expect.
Arrays.sort(completions, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
String s1 = (String) ((Object[]) o1)[0];
String s2 = (String) ((Object[]) o2)[0];
return s1.compareTo(s2);
}
});
ArrayList<Object> arrayList = new ArrayList<Object>();
for (Object o : completions) {
Object[] found = (Object[]) o;
if (found[0].equals("foo") || found[0].equals("Foo")) {
arrayList.add(found);
}
}
printArr(arrayList.toArray());
printArr("end get completions");
printArr("start raw_input");
printArr(client.execute("addExec", new Object[] { "raw_input()" }));
printArr("finish raw_input");
printArr(client.execute("addExec", new Object[] { "'foo'" }));
// System.out.println("Ask exit");
printArr(client.execute("addExec", new Object[] { "sys.exit(0)" }));
// System.out.println("End Ask exit");
} finally {
if (process != null) {
process.destroy();
}