servlib/cmd/TestCommand.cc
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2004-2006 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifdef HAVE_CONFIG_H
       
    18 #  include <dtn-config.h>
       
    19 #endif
       
    20 
       
    21 #include "TestCommand.h"
       
    22 
       
    23 namespace dtn {
       
    24 
       
    25 TestCommand::TestCommand()
       
    26     : TclCommand("test"), id_(0)
       
    27 {
       
    28     add_to_help("segfault", "Generate a segfault.");
       
    29     add_to_help("panic", "Trigger a panic.");
       
    30     add_to_help("assert", "Trigger a false assert.");
       
    31 }
       
    32 
       
    33 void
       
    34 TestCommand::bind_vars()
       
    35 {
       
    36     bind_var(new oasys::IntOpt("id", &id_, "id",
       
    37                                "The test id. (Default is 0.)"));
       
    38     bind_var(new oasys::StringOpt("initscript", &initscript_, "script",
       
    39                                   "The script to start."));
       
    40     bind_var(new oasys::StringOpt("argv", &argv_, "args",
       
    41                                   "A string to pass as the argument to the script."));
       
    42 }
       
    43 
       
    44 int
       
    45 TestCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
       
    46 {
       
    47     (void)interp;
       
    48     
       
    49     if (argc < 2) {
       
    50         resultf("need a test subcommand");
       
    51         return TCL_ERROR;
       
    52     }
       
    53 
       
    54     const char* cmd = argv[1];
       
    55     if (!strcmp(cmd, "segfault"))
       
    56     {
       
    57         int* x = NULL;
       
    58         (void)*x;
       
    59         NOTREACHED;
       
    60     }
       
    61     else if (!strcmp(cmd, "panic"))
       
    62     {
       
    63         PANIC("panic");
       
    64     }
       
    65     else if (!strcmp(cmd, "assert"))
       
    66     {
       
    67         ASSERT(0);
       
    68     }
       
    69 
       
    70     return TCL_ERROR;
       
    71 }
       
    72 
       
    73 } // namespace dtn