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.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
12 
13 
14 int main( int argc, char* argv[] )
15 {
17 
18  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
19 
20  bool verbose = true;
21  bool parse_successful = true;
22 
23  std::string test_arg[4];
24  std::string test_title[4];
25  test_arg[0] = "--method=Name_of_Method"; test_title[0] = "without Quotes";
26  test_arg[1] = "--method=\"Name_of_Method\""; test_title[1] = "with Quotes";
27  test_arg[2] = "--method=\"Name_of_Method"; test_title[2] = "with Leading Quote";
28  test_arg[3] = "--method=Name_of_Method\""; test_title[3] = "with Trailing Quote";
29 
30  for (int i=0; i<4; i++) {
31  try {
32  if (verbose)
33  std::cout << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << std::endl;
34 
35  argv[1] = &(test_arg[i][0]);
36  CommandLineProcessor CLP(true, true); // Recognize all options AND throw exceptions
37 
38  std::string method_name = "";
39 
40  CLP.setOption("method", &method_name, "Name of Method");
41  CLP.parse(argc, argv);
42 
43  if (verbose)
44  std::cout << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << ": ";
45  if (method_name != "Name_of_Method")
46  {
47  parse_successful = false;
48  if (verbose) std::cout << "FAILED" << std::endl;
49  }
50  else
51  if (verbose) std::cout << "PASSED" << std::endl;
52  }
53  catch( CommandLineProcessor::UnrecognizedOption &excpt ) {
54  if(verbose)
55  std::cout << "*** Caught EXPECTED standard exception : " << excpt.what() << std::endl
56  << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << ": PASSED" << std::endl;
57  }
58  catch( ... ) {
59  if(verbose)
60  std::cout << "*** Caught UNEXPECTED unknown exception" << std::endl
61  << "Test "<<i<<" : CLP - remove_quotes() " << test_title[i] << ": FAILED" << std::endl;
62  parse_successful = false; // No exceptions should be thrown for this command line processor.
63  }
64  }
65 
66  // Return whether the command line processor tests passed.
67  if (parse_successful) {
68  std::cout << "End Result: TEST PASSED" << std::endl;
69  return 0;
70  }
71  else {
72  std::cout << "End Result: TEST FAILED" << std::endl;
73  return 1;
74  }
75 }
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.