TestCommand.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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 } // namespace dtn

Generated on Sat Sep 8 08:43:35 2007 for DTN Reference Implementation by  doxygen 1.5.3