00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "TestCommand.h"
00019
00020 namespace dtn {
00021
00022 TestCommand::TestCommand()
00023 : TclCommand("test"), id_(0)
00024 {
00025 add_to_help("segfault", "Generate a segfault.");
00026 add_to_help("panic", "Trigger a panic.");
00027 add_to_help("assert", "Trigger a false assert.");
00028 }
00029
00030 void
00031 TestCommand::bind_vars()
00032 {
00033 bind_var(new oasys::IntOpt("id", &id_, "id",
00034 "The test id. (Default is 0.)"));
00035 bind_var(new oasys::StringOpt("initscript", &initscript_, "script",
00036 "The script to start."));
00037 bind_var(new oasys::StringOpt("argv", &argv_, "args",
00038 "A string to pass as the argument to the script."));
00039 }
00040
00041 int
00042 TestCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
00043 {
00044 (void)interp;
00045
00046 if (argc < 2) {
00047 resultf("need a test subcommand");
00048 return TCL_ERROR;
00049 }
00050
00051 const char* cmd = argv[1];
00052 if (!strcmp(cmd, "segfault"))
00053 {
00054 int* x = NULL;
00055 (void)*x;
00056 NOTREACHED;
00057 }
00058 else if (!strcmp(cmd, "panic"))
00059 {
00060 PANIC("panic");
00061 }
00062 else if (!strcmp(cmd, "assert"))
00063 {
00064 ASSERT(0);
00065 }
00066
00067 return TCL_ERROR;
00068 }
00069
00070 }