46 int main(
int argc,
char* argv[] )
52 bool parse_successful =
true;
59 CommandLineProcessor clp(
false,
false);
61 double rel_proc_speed = 1e-5;
62 clp.setOption(
"rel-proc-speed", &rel_proc_speed,
"Relative processor speed (try around 1.0 for timing)." );
65 clp.setOption(
"size", &size,
"Size of memory blocks created." );
67 size_t sizetOption = 10;
68 clp.setOption(
"sizeTOption", &sizetOption,
"An option of type size_t.");
70 long long longLongOption = 42;
71 clp.setOption(
"longLongOption", &longLongOption,
"An option of type long long." );
74 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
76 std::cout <<
"Test 1: CommandLineProcessor - No exceptions - All extra options ignored: ";
77 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
79 parse_successful =
false;
80 if (verbose) std::cout <<
"FAILED" << std::endl;
83 if (verbose) std::cout <<
"PASSED" << std::endl;
87 clp.setOption(
"num", &num,
"Number of memory blocks created (required option).",
true );
90 parse_return = clp.parse(argc,argv);
92 std::cout <<
"Test 2: CommandLineProcessor - No exceptions - All extra options ignored - 1 required: ";
93 if( parse_return != CommandLineProcessor::PARSE_ERROR )
95 parse_successful =
false;
96 if (verbose) std::cout <<
"FAILED" << std::endl;
99 if (verbose) std::cout <<
"PASSED" << std::endl;
104 std::cerr <<
"*** Caught UNEXPECTED unknown exception\n";
105 parse_successful =
false;
111 CommandLineProcessor clp2(
true,
false);
113 clp2.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
115 double rel_proc_speed = 1e-5;
116 clp2.setOption(
"rel-proc-speed", &rel_proc_speed,
"Relative processor speed (try around 1.0 for timing)." );
119 clp2.setOption(
"size", &size,
"Size of memory blocks created." );
123 clp2.setOption(
"num", &num,
"Number of memory blocks created (required option).",
true );
126 clp2.parse(argc,argv);
128 catch( CommandLineProcessor::ParseError &excpt ) {
130 std::cout <<
"*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
131 <<
"Test 3: CommandLineProcessor - Throw exceptions - All extra options ignored - 1 required: PASSED" << std::endl;
135 std::cout <<
"*** Caught UNEXPECTED unknown exception" << std::endl
136 <<
"Test 3: CommandLineProcessor - Throw exceptions - All extra options ignored - 1 required: FAILED" << std::endl;
137 parse_successful =
false;
142 CommandLineProcessor clp3(
false,
true);
145 CommandLineProcessor::EParseCommandLineReturn parse_return = clp3.parse(argc,argv);
147 std::cout <<
"Test 4 : CommandLineProcessor - No exceptions - Extra options not recognized: ";
148 if( parse_return != CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION )
150 parse_successful =
false;
151 if (verbose) std::cout <<
"FAILED" << std::endl;
154 if (verbose) std::cout <<
"PASSED" << std::endl;
157 clp3.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
160 clp3.setOption(
"num", &num,
"Number of memory blocks created (required option).",
true );
162 parse_return = clp3.parse(argc,argv);
164 std::cout <<
"Test 5 : CommandLineProcessor - No exceptions - Extra options not recognized - 1 required: ";
165 if( parse_return != CommandLineProcessor::PARSE_ERROR )
167 parse_successful =
false;
168 if (verbose) std::cout <<
"FAILED" << std::endl;
171 if (verbose) std::cout <<
"PASSED" << std::endl;
175 std::cerr <<
"*** Caught UNEXPECTED unknown exception" << std::endl;
176 parse_successful =
false;
182 std::cout <<
"Test 6 : CommandLineProcessor - Throw exceptions - Extra options not recognized: ";
184 CommandLineProcessor clp4(
true,
true);
187 clp4.parse(argc,argv);
189 catch( CommandLineProcessor::UnrecognizedOption &excpt ) {
191 std::cout <<
"*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
192 <<
"Test 6: CommandLineProcessor - Throw exceptions - Extra options not recognized: PASSED" << std::endl;
196 std::cout <<
"*** Caught UNEXPECTED unknown exception" << std::endl
197 <<
"Test 6: CommandLineProcessor - Throw exceptions - Extra options not recognized: FAILED" << std::endl;
198 parse_successful =
false;
204 std::cout <<
"Test 7 : CommandLineProcessor - Help position" << std::endl;
206 CommandLineProcessor clp7(
false,
false);
209 clp7.setOption(
"n", &n,
"A parameter");
211 char arg_c[] =
"command";
212 char arg_n[] =
"--n=20";
213 char arg_h[] =
"--help";
215 const int aux_argc = 3;
216 char *aux_argv[aux_argc];
218 std::stringbuf buffer1, buffer2;;
219 std::streambuf* oldbuffer = NULL;
222 aux_argv[0] = &arg_c[0];
223 aux_argv[1] = &arg_h[0];
224 aux_argv[2] = &arg_n[0];
226 oldbuffer = std::cerr.rdbuf(&buffer1);
227 clp7.parse(aux_argc, aux_argv);
228 std::cerr.rdbuf(oldbuffer);
231 aux_argv[0] = &arg_c[0];
232 aux_argv[1] = &arg_n[0];
233 aux_argv[2] = &arg_h[0];
235 oldbuffer = std::cerr.rdbuf(&buffer2);
236 clp7.parse(aux_argc, aux_argv);
237 std::cerr.rdbuf(oldbuffer);
240 std::cout <<
"Test 7 : CommandLineProcessor - Help position: ";
241 if (buffer1.str() != buffer2.str())
243 parse_successful =
false;
244 if (verbose) std::cout <<
"FAILED" << std::endl;
247 if (verbose) std::cout <<
"PASSED" << std::endl;
249 catch( CommandLineProcessor::UnrecognizedOption &excpt ) {
251 std::cout <<
"*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
252 <<
"Test 7: CommandLineProcessor - Help position: PASSED" << std::endl;
256 std::cout <<
"*** Caught UNEXPECTED unknown exception" << std::endl
257 <<
"Test 7: CommandLineProcessor - Help position: FAILED" << std::endl;
258 parse_successful =
false;
262 if (parse_successful) {
263 std::cout <<
"End Result: TEST PASSED" << std::endl;
267 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.