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