updated example script with new testOK() methods + better explanations

This commit is contained in:
fros4943 2008-11-05 18:17:45 +00:00
parent 18bb997761
commit 8cd7d7c981

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ScriptRunner.java,v 1.6 2008/10/02 21:20:26 fros4943 Exp $ * $Id: ScriptRunner.java,v 1.7 2008/11/05 18:17:45 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -63,7 +63,7 @@ import org.jdom.output.XMLOutputter;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.dialogs.MessageList; import se.sics.cooja.dialogs.MessageList;
@ClassDescription("(GUI) Test Script Editor") @ClassDescription("Test Script Editor")
@PluginType(PluginType.COOJA_PLUGIN) @PluginType(PluginType.COOJA_PLUGIN)
public class ScriptRunner extends VisPlugin { public class ScriptRunner extends VisPlugin {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -78,8 +78,8 @@ public class ScriptRunner extends VisPlugin {
private String oldInfo = null; private String oldInfo = null;
private static String exampleScript = private static String exampleScript =
"/* Script is called once for every node log output. */\n" + "/* Script is run for each mote log output, for example printf()'s */\n" +
"/* Input variables: Mote mote, int id, String msg. */\n" + "/* Input variables: Mote mote, int id, String msg, Hashtable global */\n" +
"\n" + "\n" +
"log.log('MOTE=' + mote + '\\n');\n" + "log.log('MOTE=' + mote + '\\n');\n" +
"log.log('ID=' + id + '\\n');\n" + "log.log('ID=' + id + '\\n');\n" +
@ -87,21 +87,20 @@ public class ScriptRunner extends VisPlugin {
"log.log('MSG=' + msg + '\\n');\n" + "log.log('MSG=' + msg + '\\n');\n" +
"\n" + "\n" +
"/* Hashtable global may be used to store state across script invokes */\n" + "/* Hashtable global may be used to store state across script invokes */\n" +
"log.log('STORED VAR=' + global.get('storedVar') + '\\n');\n" + "log.log('LAST MSG=' + global.get('lastMsg') + '\\n');\n" +
"global.put('storedVar', msg);\n" + "global.put('lastMsg', msg);\n" +
"\n" + "\n" +
"/* Contiki test script example */\n" + "/* Contiki test script example */\n" +
"if (msg.startsWith('Hello, world')) {\n" + "if (msg.startsWith('Hello, world')) {\n" +
" log.log('TEST OK\\n'); /* Report test success */\n" + " log.testOK(); /* Report test success and quit */\n" +
" \n" + "} else {\n" +
" /* To increase test run speed, close the simulator when done */\n" + " log.testFailed(); /* Report test failed and quit */\n" +
" //mote.getSimulation().getGUI().doQuit(false); /* Quit simulator (to end test run)*/\n" +
"}\n" + "}\n" +
"\n" + "\n" +
"//mote.getSimulation().getGUI().reloadCurrentSimulation(true); /* Reload simulation */\n"; "//mote.getSimulation().getGUI().reloadCurrentSimulation(true); /* Reload simulation */\n";
public ScriptRunner(GUI gui) { public ScriptRunner(GUI gui) {
super("(GUI) Test Script Editor", gui); super("Test Script Editor", gui);
this.gui = gui; this.gui = gui;
scriptTextArea = new JTextArea(8,50); scriptTextArea = new JTextArea(8,50);
@ -165,6 +164,8 @@ public class ScriptRunner extends VisPlugin {
new JScrollPane(scriptTextArea), new JScrollPane(scriptTextArea),
new JScrollPane(logTextArea) new JScrollPane(logTextArea)
); );
centerPanel.setOneTouchExpandable(true);
centerPanel.setResizeWeight(0.5);
JPanel buttonPanel = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(BorderLayout.WEST, importButton); buttonPanel.add(BorderLayout.WEST, importButton);
@ -263,7 +264,7 @@ public class ScriptRunner extends VisPlugin {
Simulation simulation = ScriptRunner.this.gui.getSimulation(); Simulation simulation = ScriptRunner.this.gui.getSimulation();
if (simulation == null) { if (simulation == null) {
JOptionPane.showMessageDialog(GUI.getTopParentContainer(), JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
"No simulation loaded. Aborting.", "Error", JOptionPane.ERROR_MESSAGE); "Create a simulation setup to test.", "No simulation to export", JOptionPane.ERROR_MESSAGE);
return; return;
} }
@ -273,8 +274,8 @@ public class ScriptRunner extends VisPlugin {
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = { s1, s2 }; Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(), int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(),
"Export current simulation config (.csc) and test script (.js)\n" + "The current simulation config (.csc) and test script (.js)\n" +
"to directory '" + testDir.getPath() + "'?", "will be stored in directory '" + testDir.getPath() + "'",
"Export Contiki test", JOptionPane.YES_NO_OPTION, "Export Contiki test", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, s1); JOptionPane.QUESTION_MESSAGE, null, options, s1);
if (n != JOptionPane.YES_OPTION) { if (n != JOptionPane.YES_OPTION) {
@ -290,8 +291,9 @@ public class ScriptRunner extends VisPlugin {
oldTestName = "mytest"; oldTestName = "mytest";
} }
String testName = (String) JOptionPane.showInputDialog(GUI.getTopParentContainer(), String testName = (String) JOptionPane.showInputDialog(GUI.getTopParentContainer(),
"Enter test name. No spaces or strange chars allowed.", "The test name correponds to the exported test files:\n" +
"Test name", JOptionPane.PLAIN_MESSAGE, null, null, "[testname].csc, [testname].js, [testname].info\n",
"Enter test name", JOptionPane.PLAIN_MESSAGE, null, null,
oldTestName); oldTestName);
if (testName == null) { if (testName == null) {
return; return;
@ -400,8 +402,10 @@ public class ScriptRunner extends VisPlugin {
oldInfo = ""; oldInfo = "";
} }
String info = (String) JOptionPane.showInputDialog(GUI.getTopParentContainer(), String info = (String) JOptionPane.showInputDialog(GUI.getTopParentContainer(),
"Optional test info", "This text describes the Contiki test and may contain\n" +
"(OPTIONAL) Enter test description", JOptionPane.PLAIN_MESSAGE, null, null, "information about the simulation setup, radio medium,\n" +
"node types, Contiki processes etc.\n\n",
"Enter test description", JOptionPane.PLAIN_MESSAGE, null, null,
oldInfo); oldInfo);
if (info != null && !info.equals("")) { if (info != null && !info.equals("")) {
oldInfo = info; oldInfo = info;