14 int main(
int argc,
char* argv[] )
20 bool parse_successful =
true;
27 CommandLineProcessor clp(
false,
false);
29 double rel_proc_speed = 1e-5;
30 clp.setOption(
"rel-proc-speed", &rel_proc_speed,
"Relative processor speed (try around 1.0 for timing)." );
33 clp.setOption(
"size", &size,
"Size of memory blocks created." );
35 size_t sizetOption = 10;
36 clp.setOption(
"sizeTOption", &sizetOption,
"An option of type size_t.");
38 long long longLongOption = 42;
39 clp.setOption(
"longLongOption", &longLongOption,
"An option of type long long." );
42 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
44 std::cout <<
"Test 1: CommandLineProcessor - No exceptions - All extra options ignored: ";
45 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
47 parse_successful =
false;
48 if (verbose) std::cout <<
"FAILED" << std::endl;
51 if (verbose) std::cout <<
"PASSED" << std::endl;
55 clp.setOption(
"num", &num,
"Number of memory blocks created (required option).",
true );
58 parse_return = clp.parse(argc,argv);
60 std::cout <<
"Test 2: CommandLineProcessor - No exceptions - All extra options ignored - 1 required: ";
61 if( parse_return != CommandLineProcessor::PARSE_ERROR )
63 parse_successful =
false;
64 if (verbose) std::cout <<
"FAILED" << std::endl;
67 if (verbose) std::cout <<
"PASSED" << std::endl;
72 std::cerr <<
"*** Caught UNEXPECTED unknown exception\n";
73 parse_successful =
false;
79 CommandLineProcessor clp2(
true,
false);
81 clp2.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
83 double rel_proc_speed = 1e-5;
84 clp2.setOption(
"rel-proc-speed", &rel_proc_speed,
"Relative processor speed (try around 1.0 for timing)." );
87 clp2.setOption(
"size", &size,
"Size of memory blocks created." );
91 clp2.setOption(
"num", &num,
"Number of memory blocks created (required option).",
true );
94 clp2.parse(argc,argv);
96 catch( CommandLineProcessor::ParseError &excpt ) {
98 std::cout <<
"*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
99 <<
"Test 3: CommandLineProcessor - Throw exceptions - All extra options ignored - 1 required: PASSED" << std::endl;
103 std::cout <<
"*** Caught UNEXPECTED unknown exception" << std::endl
104 <<
"Test 3: CommandLineProcessor - Throw exceptions - All extra options ignored - 1 required: FAILED" << std::endl;
105 parse_successful =
false;
110 CommandLineProcessor clp3(
false,
true);
113 CommandLineProcessor::EParseCommandLineReturn parse_return = clp3.parse(argc,argv);
115 std::cout <<
"Test 4 : CommandLineProcessor - No exceptions - Extra options not recognized: ";
116 if( parse_return != CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION )
118 parse_successful =
false;
119 if (verbose) std::cout <<
"FAILED" << std::endl;
122 if (verbose) std::cout <<
"PASSED" << std::endl;
125 clp3.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
128 clp3.setOption(
"num", &num,
"Number of memory blocks created (required option).",
true );
130 parse_return = clp3.parse(argc,argv);
132 std::cout <<
"Test 5 : CommandLineProcessor - No exceptions - Extra options not recognized - 1 required: ";
133 if( parse_return != CommandLineProcessor::PARSE_ERROR )
135 parse_successful =
false;
136 if (verbose) std::cout <<
"FAILED" << std::endl;
139 if (verbose) std::cout <<
"PASSED" << std::endl;
143 std::cerr <<
"*** Caught UNEXPECTED unknown exception" << std::endl;
144 parse_successful =
false;
150 std::cout <<
"Test 6 : CommandLineProcessor - Throw exceptions - Extra options not recognized: ";
152 CommandLineProcessor clp4(
true,
true);
155 clp4.parse(argc,argv);
157 catch( CommandLineProcessor::UnrecognizedOption &excpt ) {
159 std::cout <<
"*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
160 <<
"Test 6: CommandLineProcessor - Throw exceptions - Extra options not recognized: PASSED" << std::endl;
164 std::cout <<
"*** Caught UNEXPECTED unknown exception" << std::endl
165 <<
"Test 6: CommandLineProcessor - Throw exceptions - Extra options not recognized: FAILED" << std::endl;
166 parse_successful =
false;
172 std::cout <<
"Test 7 : CommandLineProcessor - Help position" << std::endl;
174 CommandLineProcessor clp7(
false,
false);
177 clp7.setOption(
"n", &n,
"A parameter");
179 char arg_c[] =
"command";
180 char arg_n[] =
"--n=20";
181 char arg_h[] =
"--help";
183 const int aux_argc = 3;
184 char *aux_argv[aux_argc];
186 std::stringbuf buffer1, buffer2;;
187 std::streambuf* oldbuffer = NULL;
190 aux_argv[0] = &arg_c[0];
191 aux_argv[1] = &arg_h[0];
192 aux_argv[2] = &arg_n[0];
194 oldbuffer = std::cerr.rdbuf(&buffer1);
195 clp7.parse(aux_argc, aux_argv);
196 std::cerr.rdbuf(oldbuffer);
199 aux_argv[0] = &arg_c[0];
200 aux_argv[1] = &arg_n[0];
201 aux_argv[2] = &arg_h[0];
203 oldbuffer = std::cerr.rdbuf(&buffer2);
204 clp7.parse(aux_argc, aux_argv);
205 std::cerr.rdbuf(oldbuffer);
208 std::cout <<
"Test 7 : CommandLineProcessor - Help position: ";
209 if (buffer1.str() != buffer2.str())
211 parse_successful =
false;
212 if (verbose) std::cout <<
"FAILED" << std::endl;
215 if (verbose) std::cout <<
"PASSED" << std::endl;
217 catch( CommandLineProcessor::UnrecognizedOption &excpt ) {
219 std::cout <<
"*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
220 <<
"Test 7: CommandLineProcessor - Help position: PASSED" << std::endl;
224 std::cout <<
"*** Caught UNEXPECTED unknown exception" << std::endl
225 <<
"Test 7: CommandLineProcessor - Help position: FAILED" << std::endl;
226 parse_successful =
false;
230 if (parse_successful) {
231 std::cout <<
"End Result: TEST PASSED" << std::endl;
235 std::cout <<
"End Result: TEST FAILED" << std::endl;
Initialize, finalize, and query the global MPI session.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
int main(int argc, char *argv[])
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
Class that helps parse command line input arguments from (argc,argv[]) and set options.