CustusX  2023.01.05-dev+develop.0da12
An IGT application
cisstTestParameters.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5  $Id: cisstTestParameters.cpp,v 1.9 2007/04/26 20:12:05 anton Exp $
6 
7  Author(s): Anton Deguet, Ofri Sadowsky
8  Created on: 2003-11-10
9 
10  (C) Copyright 2003-2007 Johns Hopkins University (JHU), All Rights
11  Reserved.
12 
13 --- begin cisst license - do not edit ---
14 
15 This software is provided "as is" under an open source license, with
16 no warranty. The complete license can be found in license.txt and
17 http://www.cisst.org/cisst/license.txt.
18 
19 --- end cisst license ---
20 */
21 
22 
23 #include "cisstTestParameters.h"
24 #include <string.h>
25 #include <stdlib.h>
26 
27 
28 void cisstTestParameters::ParseCmdLine(int argc, char * argv[])
29 {
30  ProgramName = argv[0];
31  const size_t size = ProgramName.size();
32  size_t index;
33  for(index = 0; index < size; index++) {
34  if (ProgramName[index] == '\\') {
35  ProgramName[index]= '/';
36  }
37  }
38 
39  while (argc != 1) {
40  if (argc < 1) {
41  TestRunMode = PRINT_HELP;
42  return;
43  }
44 
45  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) {
46  TestRunMode = PRINT_HELP;
47  return;
48  }
49 
50  if (strcmp(argv[1], "--run") == 0 || strcmp(argv[1], "-r") == 0) {
51  TestRunMode = RUN_TESTS;
52  ++argv;
53  --argc;
54  continue;
55  }
56 
57  if (strcmp(argv[1], "--list") == 0 || strcmp(argv[1], "-l") == 0) {
58  TestRunMode = LIST_TESTS;
59  ++argv;
60  --argc;
61  continue;
62  }
63 
64  if (strcmp(argv[1], "--dart") == 0 || strcmp(argv[1], "-d") == 0) {
65  TestRunMode = GENERATE_CTEST_FILE;
66  ++argv;
67  --argc;
68  continue;
69  }
70 
71  if (strcmp(argv[1], "--numinstances") == 0 || strcmp(argv[1], "-o") == 0) {
72  NumTestInstances = atoi(argv[2]);
73  argv += 2;
74  argc -= 2;
75  continue;
76  }
77 
78  if (strcmp(argv[1], "--numiterations") == 0 || strcmp(argv[1], "-i") == 0) {
79  NumTestIterations = atoi(argv[2]);
80  argv += 2;
81  argc -= 2;
82  continue;
83  }
84 
85  if (strcmp(argv[1], "--testname") == 0 || strcmp(argv[1], "-t") == 0) {
86  TestNames.push_back( argv[2] );
87  argv += 2;
88  argc -= 2;
89  continue;
90  }
91 
92  TestRunMode = PRINT_HELP;
93  return;
94  }
95 }
96 
97 
99 int cisstTestParameters::PrintHelp(const char* programName) {
100  std::cerr
101  << programName << ": Usage" << std::endl
102  << "-h, --help print this message" << std::endl
103  << "-l, --list print the available test instances" << std::endl
104  << "-d, --dart print CMake/ctest commands in DartTestfile.txt format" << std::endl
105  << "-r, --run run the available test instances" << std::endl
106  << "-t, --testname [name] add the specified test case or suite to the list" << std::endl
107  << "-o, --numinstances [n] specify the number of instances to create of each test" << std::endl
108  << "-i, --numiterations [n] specify the number of iterations for each test instance" << std::endl;
109 
110  std::cerr << std::endl << std::endl;
111  std::cerr
112  << "If no names are specified, all tests are instantiated." << std::endl
113  << "Otherwise, the instantiated tests are those whose names or suite" << std::endl
114  << "were listed and which appear in the test registry." << std::endl
115  << "The number of instances and number of iterations is 1 by default" << std::endl;
116 
117 
118  return 0;
119 }
120 
121 
122 // ****************************************************************************
123 // Change History
124 // ****************************************************************************
125 //
126 // $Log: cisstTestParameters.cpp,v $
127 // Revision 1.9 2007/04/26 20:12:05 anton
128 // All files in tests: Applied new license text, separate copyright and
129 // updated dates, added standard header where missing.
130 //
131 // Revision 1.8 2006/11/20 20:33:53 anton
132 // Licensing: Applied new license to tests.
133 //
134 // Revision 1.7 2005/12/08 17:12:50 anton
135 // Test main library: Added license.
136 //
137 // Revision 1.6 2005/09/26 15:41:48 anton
138 // cisst: Added modelines for emacs and vi.
139 //
140 // Revision 1.5 2005/07/14 03:58:55 anton
141 // cisstTestParameters.cpp: Replace \ by / in path for CTest
142 //
143 // Revision 1.4 2005/06/03 01:22:03 anton
144 // Tests: Preliminary support for Dart2.
145 //
146 // Revision 1.3 2004/11/18 21:54:46 anton
147 // cisstTests: Added the possibility to run all the tests for a given suite.
148 //
149 // Revision 1.2 2004/05/11 16:35:08 kapoor
150 // Checked in **PREMATURE** dynamic object creation code. NO flames PLEASE
151 //
152 // Revision 1.1 2003/11/11 22:32:24 anton
153 // Created separate source and header files for the class cisstTestParameters
154 //
155 // ****************************************************************************
static int PrintHelp(const char *programName)
void ParseCmdLine(int argc, char *argv[])