Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_CLP_Remove_Quotes.cpp
Go to the documentation of this file.
3 
4 
5 int main( int argc, char* argv[] )
6 {
8 
9  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
10 
11  bool verbose = true;
12  bool parse_successful = true;
13 
14  std::string test_arg[4];
15  std::string test_title[4];
16  test_arg[0] = "--method=Name_of_Method"; test_title[0] = "without Quotes";
17  test_arg[1] = "--method=\"Name_of_Method\""; test_title[1] = "with Quotes";
18  test_arg[2] = "--method=\"Name_of_Method"; test_title[2] = "with Leading Quote";
19  test_arg[3] = "--method=Name_of_Method\""; test_title[3] = "with Trailing Quote";
20 
21  for (int i=0; i<4; i++) {
22  try {
23  if (verbose)
24  std::cout << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << std::endl;
25 
26  argv[1] = &(test_arg[i][0]);
27  CommandLineProcessor CLP(true, true); // Recognize all options AND throw exceptions
28 
29  std::string method_name = "";
30 
31  CLP.setOption("method", &method_name, "Name of Method");
32  CLP.parse(argc, argv);
33 
34  if (verbose)
35  std::cout << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << ": ";
36  if (method_name != "Name_of_Method")
37  {
38  parse_successful = false;
39  if (verbose) std::cout << "FAILED" << std::endl;
40  }
41  else
42  if (verbose) std::cout << "PASSED" << std::endl;
43  }
44  catch( CommandLineProcessor::UnrecognizedOption &excpt ) {
45  if(verbose)
46  std::cout << "*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
47  << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << ": PASSED" << std::endl;
48  }
49  catch( ... ) {
50  if(verbose)
51  std::cout << "*** Caught UNEXPECTED unknown exception" << std::endl
52  << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << ": FAILED" << std::endl;
53  parse_successful = false; // No exceptions should be thrown for this command line processor.
54  }
55  }
56 
57  // Return whether the command line processor tests passed.
58  if (parse_successful) {
59  std::cout << "End Result: TEST PASSED" << std::endl;
60  return 0;
61  }
62  else {
63  std::cout << "End Result: TEST FAILED" << std::endl;
64  return 1;
65  }
66 }
Initialize, finalize, and query the global MPI session.
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.