|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include "Teuchos_ParameterList.hpp" 00043 #include "Teuchos_GlobalMPISession.hpp" 00044 #include "Teuchos_CommandLineProcessor.hpp" 00045 #include "Teuchos_getConst.hpp" 00046 #include "Teuchos_Version.hpp" 00047 #include "Teuchos_StandardCatchMacros.hpp" 00048 #include "Teuchos_FancyOStream.hpp" 00049 #include "Teuchos_ArrayRCP.hpp" 00050 #include "Teuchos_StandardParameterEntryValidators.hpp" 00051 00052 #ifdef HAVE_TEUCHOS_EXTENDED 00053 #include "Teuchos_XMLParameterListCoreHelpers.hpp" 00054 #endif 00055 00056 #ifdef HAVE_MPI 00057 #include "mpi.h" 00058 #endif 00059 00060 using Teuchos::CommandLineProcessor; 00061 using Teuchos::ParameterList; 00062 using Teuchos::getParameter; 00063 typedef ParameterList::PrintOptions PLPrintOptions; 00064 using Teuchos::ParameterEntry; 00065 using Teuchos::OSTab; 00066 using Teuchos::rcp; 00067 using Teuchos::inoutArg; 00068 00069 void print_break() { std::cout << "---------------------------------------------------" << std::endl; } 00070 double Plus ( double a, double b ) { return a+b; } 00071 00072 int main( int argc, char *argv[] ) 00073 { 00074 00075 using std::cout; 00076 using std::endl; 00077 00078 bool verbose = true; 00079 int FailedTests = 0; 00080 bool result; 00081 00082 Teuchos::GlobalMPISession mpiSession(&argc,&argv); 00083 const int procRank = Teuchos::GlobalMPISession::getRank(); 00084 00085 bool success = true; 00086 00087 try { 00088 00089 // Read options from the command line. 00090 CommandLineProcessor clp(false); // Don't throw exceptions 00091 clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." ); 00092 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv); 00093 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) { 00094 cout << "Processor "<< procRank <<", parse_return "<< parse_return << std::endl; 00095 cout << "End Result: TEST FAILED" << std::endl; 00096 return parse_return; 00097 } 00098 00099 // Only print on 0 processor 00100 if (procRank != 0 && verbose) 00101 verbose = false; 00102 00103 if (verbose) 00104 cout << Teuchos::Teuchos_Version() << std::endl << std::endl; 00105 00106 //----------------------------------------------------------- 00107 // Create Main Parameter List / Sublist Structure 00108 //----------------------------------------------------------- 00109 00110 ParameterList PL_Main("PL_Main"); 00111 const std::string Direction_Doc = "This sublist controls how direction is computed."; 00112 ParameterList& PL_Direction = PL_Main.sublist("Direction",false,Direction_Doc); 00113 ParameterList& PL_Newton = PL_Direction.sublist("Newton"); 00114 ParameterList& PL_LinSol = PL_Newton.sublist("Linear Solver"); 00115 ParameterList& PL_LineSearch = PL_Main.sublist("Line Search"); 00116 00117 //----------------------------------------------------------- 00118 // Check Parameter List Structure 00119 //----------------------------------------------------------- 00120 if (verbose) { 00121 print_break(); 00122 cout << "Empty Parameter List Structure" << std::endl; 00123 print_break(); 00124 cout<<PL_Main<< std::endl; 00125 } 00126 if (verbose) cout << "Is 'Direction' recognized as a sublist of 'Main' ... "; 00127 if ( PL_Main.isSublist( "Direction" ) ) { 00128 if (verbose) cout << "yes"<< std::endl; 00129 } else { 00130 if (verbose) cout << "no"<< std::endl; 00131 FailedTests++; 00132 } 00133 if (verbose) cout << "Is 'Newton' recognized as a sublist of 'Direction' ... "; 00134 if ( PL_Direction.isSublist( "Newton" ) ) { 00135 if (verbose) cout << "yes"<< std::endl; 00136 } else { 00137 if (verbose) cout << "no"<< std::endl; 00138 FailedTests++; 00139 } 00140 if (verbose) cout << "Is 'Linear Solver' recognized as a sublist of 'Newton' ... "; 00141 if ( PL_Newton.isSublist( "Linear Solver" ) ) { 00142 if (verbose) cout << "yes"<< std::endl; 00143 } else { 00144 if (verbose) cout << "no"<< std::endl; 00145 FailedTests++; 00146 } 00147 if (verbose) cout << "Is 'Line Search' recognized as a sublist of 'Main' ... "; 00148 if ( PL_Main.isSublist( "Line Search" ) ) { 00149 if (verbose) cout << "yes"<< std::endl; 00150 } else { 00151 if (verbose) cout << "no"<< std::endl; 00152 FailedTests++; 00153 } 00154 00155 if (verbose) cout << "Is subist documentation std::string maintained ...\n"; 00156 { 00157 Teuchos::OSTab tab(cout); 00158 const Teuchos::ParameterEntry 00159 *paramEntry = PL_Main.getEntryPtr("Direction"); 00160 TEUCHOS_TEST_FOR_EXCEPT(0==paramEntry); 00161 const std::string extracted_Direction_Doc = paramEntry->docString(); 00162 if (verbose) tab.o() << "Expected doc std::string = \"" << Direction_Doc << "\"\n"; 00163 if (verbose) tab.o() << "Extracted doc std::string = \"" << extracted_Direction_Doc << "\"\n"; 00164 if (extracted_Direction_Doc == Direction_Doc) { 00165 if (verbose) tab.o() << "passed! They match :-)\n"; 00166 } 00167 else { 00168 if (verbose) tab.o() << "failed! They do not match :-("<< std::endl; 00169 FailedTests++; 00170 } 00171 } 00172 00173 00174 //----------------------------------------------------------- 00175 // Fill in Direction Sublist 00176 //----------------------------------------------------------- 00177 00178 double tol = 0.0; 00179 bool RBNS = false; 00180 PL_Direction.get("Method", "Newton"); 00181 PL_LinSol.set("Tol",1e-5); 00182 tol = PL_LinSol.get("Tolerance",1e-10); 00183 (void)tol; // Not used, bad test! 00184 RBNS = PL_Newton.get("Rescue Bad Newton Solve", true ); 00185 (void)RBNS; // Not used, bad test! 00186 00187 //----------------------------------------------------------- 00188 // Print out Direction Sublist 00189 //----------------------------------------------------------- 00190 if (verbose) { 00191 print_break(); 00192 cout << "Direction Parameter List" << std::endl; 00193 print_break(); 00194 PL_Direction.print(cout); 00195 } 00196 if (verbose) cout << "Is 'Newton' recognized as a parameter of 'Direction' ... "; 00197 if ( PL_Direction.isParameter( "Newton" ) ) { 00198 if (verbose) cout << "yes"<< std::endl; 00199 } else { 00200 if (verbose) cout << "no"<< std::endl; 00201 FailedTests++; 00202 } 00203 if (verbose) cout << "Is 'Tolerance' recognized as a parameter of 'Newton' ... "; 00204 if ( PL_Newton.isParameter( "Tolerance" ) ) { 00205 if (verbose) cout << "yes (should be no)"<< std::endl; 00206 FailedTests++; 00207 } else { 00208 if (verbose) cout << "no (as expected)"<< std::endl; 00209 } 00210 if (verbose) cout << "Is 'Tolerance' recognized as a parameter of 'Linear Solver' ... "; 00211 if ( PL_LinSol.isParameter( "Tolerance" ) ) { 00212 if (verbose) cout << "yes"<< std::endl; 00213 } else { 00214 if (verbose) cout << "no"<< std::endl; 00215 FailedTests++; 00216 } 00217 if (verbose) cout << "Is 'Rescue Bad Newton Solve' recognized as a parameter of 'Newton' ... "; 00218 if ( PL_Newton.isParameter( "Rescue Bad Newton Solve" ) ) { 00219 if (verbose) cout << "yes"<< std::endl; 00220 } else { 00221 if (verbose) cout << "no"<< std::endl; 00222 FailedTests++; 00223 } 00224 00225 //----------------------------------------------------------- 00226 // Line Search Sublist 00227 // (if there are no failures, this will be constructed and added) 00228 //----------------------------------------------------------- 00229 if (!FailedTests) { 00230 int ARI = 0, default_step = 0, max_iter_inc = 0, rec_step = 0; 00231 double alpha_factor = 0.0, min_bnds_factor = 0.0, max_bnds_factor = 0.0; 00232 bool force_interp = true, use_cntrs = false; 00233 std::string ls_method = "Polynomial"; 00234 // This is to force a char* to be passed into the get method to see if the template 00235 // specialization for char* is working. 00236 char* ls_method_char = const_cast<char *>(ls_method.c_str()); 00237 ParameterList PL_My_LineSearch("PL_My_LineSearch"); 00238 ls_method = PL_My_LineSearch.get("Method", ls_method_char); 00239 ParameterList& PL_Polynomial = PL_My_LineSearch.sublist("Polynomial"); 00240 ARI = PL_Polynomial.get("Allowed Relative Increase", 100 ); 00241 (void)ARI; // Not used, bad test! 00242 alpha_factor = PL_Polynomial.get("Alpha Factor", 0.0001 ); 00243 (void)alpha_factor; // Not used, bad test! 00244 default_step = PL_Polynomial.get("Default Step", 1 ); 00245 (void)default_step; // Not used, bad test! 00246 force_interp = PL_Polynomial.get("Force Interpolation", false ); 00247 (void)force_interp; // Not used, bad test! 00248 std::string interp_type = PL_Polynomial.get("Interpolation Type", "Cubic" ); 00249 max_bnds_factor = PL_Polynomial.get("Max Bounds Factor", 0.5 ); 00250 (void)max_bnds_factor; // Not used, bad test! 00251 PL_Polynomial.set("Max Iters", 3 ); 00252 max_iter_inc = PL_Polynomial.get("Maximum Iteration for Increase", 0 ); 00253 (void)max_iter_inc; // Not used, bad test! 00254 min_bnds_factor = PL_Polynomial.get("Min Bounds Factor", 0.1 ); 00255 (void)min_bnds_factor; // Not used, bad test! 00256 rec_step = PL_Polynomial.get("Recovery Step", 1 ); 00257 (void)rec_step; // Not used, bad test! 00258 std::string rec_step_type = PL_Polynomial.get("Recovery Step Type", "Constant"); 00259 std::string suff_dec_cond = PL_Polynomial.get("Sufficient Decrease Condition", "Armijo-Goldstein" ); 00260 use_cntrs = PL_Polynomial.get("Use Counters", true ); 00261 (void)use_cntrs; // Not used, bad test! 00262 PL_Main.set("Nonlinear Solver", "Line Search Based"); 00263 00264 //----------------------------------------------------------- 00265 // Set the Line Search Parameter List equal to the one just constructed 00266 //----------------------------------------------------------- 00267 PL_LineSearch.setParameters(PL_My_LineSearch); 00268 ParameterList& PL_My_Polynomial = PL_LineSearch.sublist("Polynomial"); 00269 if (verbose) cout<< "Is 'operator=' functional ... "; 00270 if ( PL_My_Polynomial.isParameter("Recovery Step Type") ) { 00271 if (verbose) cout<< "yes" << std::endl; 00272 } else { 00273 if (verbose) cout<< "no" << std::endl; 00274 FailedTests++; 00275 } 00276 00277 //----------------------------------------------------------- 00278 // Set Copying of parameter sublists and names 00279 //----------------------------------------------------------- 00280 00281 if (verbose) { 00282 print_break(); 00283 if (verbose) cout << "Test copying of sublist\n"; 00284 print_break(); 00285 PL_Direction.print(cout); 00286 } 00287 { 00288 const ParameterList 00289 &linearSolverPL = PL_Main.sublist("Direction").sublist("Newton").sublist("Line Search"); 00290 const ParameterList 00291 linearSolverPL_copy(linearSolverPL); 00292 if (verbose) cout << "linearSolverPL.name() = " << linearSolverPL.name() << endl; 00293 if (verbose) cout << "linearSolverPL_copy.name() = " << linearSolverPL_copy.name() << endl; 00294 if (verbose) cout << "linearSolverPL_copy == linearSolverPL.name() : "; 00295 if (linearSolverPL_copy == linearSolverPL.name()) { 00296 if (verbose) cout << "passed" << endl; 00297 } 00298 else { 00299 if (verbose) cout << "failed" << endl; 00300 FailedTests++; 00301 } 00302 } 00303 00304 if (verbose) { 00305 print_break(); 00306 if (verbose) cout << "General tests\n"; 00307 print_break(); 00308 PL_Direction.print(cout); 00309 } 00310 00311 ParameterList Copied_PL_Main(PL_Main); 00312 00313 if (verbose) cout << "Copied_PL_Main.name() == PL_Main.name() : "; 00314 if (Copied_PL_Main.name() == PL_Main.name()) { 00315 if (verbose) cout << "passed" << endl; 00316 } 00317 else { 00318 if (verbose) cout << "failed" << endl; 00319 FailedTests++; 00320 if (verbose) cout << "Copyed_PL_Main.name() = " << Copied_PL_Main.name() << endl; 00321 } 00322 00323 if (verbose) cout<< "Is the copy constructor functional ... "; 00324 if ( Copied_PL_Main.isParameter("Nonlinear Solver") ) { 00325 if (verbose) cout<< "yes" << std::endl; 00326 } else { 00327 if (verbose) cout<< "no" << std::endl; 00328 FailedTests++; 00329 } 00330 00331 bool tempMeth = true; 00332 00333 //----------------------------------------------------------- 00334 // Check the templated 'get' method. 00335 //----------------------------------------------------------- 00336 // 00337 //----------------------------------------------------------- 00338 // Retrieve some information from the parameter list using templated "get" method. 00339 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00340 // non-templated code needs ".template" before the method name ) 00341 //----------------------------------------------------------- 00342 int max_iters = 0, max_iters_again = 0; 00343 std::string nonlin_solver; 00344 tempMeth = true; 00345 try { 00346 max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters"); 00347 max_iters_again = Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters"); 00348 nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>("Nonlinear Solver"); 00349 } 00350 catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; } 00351 if (verbose) { 00352 cout<< "Is the templated 'get' method functional ... "<<std::endl; 00353 cout<< " Can we retrieve information using the CORRECT variable type ... "; 00354 } 00355 if (tempMeth && max_iters==3) { if (verbose) cout << "yes" << std::endl; } 00356 else { if (verbose) cout << "no" << std::endl; FailedTests++; } 00357 if (verbose) { 00358 cout<< " Can we retrieve const information using the CORRECT variable type ... "; 00359 } 00360 if (tempMeth && max_iters_again==3) { if (verbose) cout << "yes" << std::endl; } 00361 else { if (verbose) cout << "no" << std::endl; FailedTests++; } 00362 00363 //----------------------------------------------------------- 00364 // Retrieve some information from the parameter list that we know is a bad "get". 00365 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00366 // non-templated code needs ".template" before the method name ) 00367 //----------------------------------------------------------- 00368 float mbf = 0.0; 00369 tempMeth = false; 00370 try { 00371 mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>( "Tol" ); 00372 (void)mbf; // Not used, bad test! 00373 FailedTests++; 00374 } 00375 catch( const Teuchos::Exceptions::InvalidParameter&) { 00376 tempMeth = true; 00377 } 00378 if (verbose) { 00379 cout<< " Can we retrieve information using the WRONG variable type ... "; 00380 } 00381 if (tempMeth) { if (verbose) cout << "no" << std::endl; } 00382 else { if (verbose) cout << "yes" << std::endl; } 00383 00384 //----------------------------------------------------------- 00385 // Retrieve some information from the parameter list using templated "get" method. 00386 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00387 // non-templated code needs ".template" before the method name ) 00388 //----------------------------------------------------------- 00389 tempMeth = true; 00390 try { 00391 max_iters = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER get<int>("Max Iters"); 00392 nonlin_solver = PL_Main.INVALID_TEMPLATE_QUALIFIER get<std::string>("Nonlinear Solver"); 00393 } 00394 catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; } 00395 if (verbose) { 00396 cout<< "Is the templated 'get' method functional ... "<<std::endl; 00397 cout<< " Can we retrieve information using the CORRECT variable type ... "; 00398 } 00399 if (tempMeth && max_iters==3) { if (verbose) cout << "yes" << std::endl; } 00400 else { if (verbose) cout << "no" << std::endl; FailedTests++; } 00401 00402 //----------------------------------------------------------- 00403 // Retrieve some information from the parameter list that we know is a bad "get". 00404 //----------------------------------------------------------- 00405 tempMeth = false; 00406 try { 00407 mbf = PL_LinSol.INVALID_TEMPLATE_QUALIFIER get<float>( "Tol" ); 00408 (void)mbf; // Not used, bad test! 00409 FailedTests++; 00410 } 00411 catch( const Teuchos::Exceptions::InvalidParameter&) { 00412 tempMeth = true; 00413 } 00414 if (verbose) { 00415 cout<< " Can we retrieve information using the WRONG variable type ... "; 00416 } 00417 if (tempMeth) { if (verbose) cout << "no" << std::endl; } 00418 else { if (verbose) cout << "yes" << std::endl; } 00419 00420 //----------------------------------------------------------- 00421 // Check the templated 'getPtr' method. 00422 //----------------------------------------------------------- 00423 00424 //----------------------------------------------------------- 00425 // Retrieve some information from the parameter list using templated "get" method. 00426 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00427 // non-templated code needs ".template" before the method name ) 00428 //----------------------------------------------------------- 00429 int *max_iters_ptr = 0; 00430 const int *max_iters_ptr_again = 0; 00431 std::string* nonlin_solver_ptr; 00432 00433 max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters"); 00434 max_iters_ptr_again = Teuchos::getConst(PL_My_Polynomial).INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters"); 00435 nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>("Nonlinear Solver"); 00436 00437 if (verbose) { 00438 cout<< "Is the templated 'getPtr' method functional ... "<<std::endl; 00439 cout<< " Can we retrieve information using the CORRECT variable type ... "; 00440 } 00441 if (max_iters_ptr) { 00442 if ((*max_iters_ptr)==3) { 00443 if (verbose) cout << "yes" << std::endl; 00444 } 00445 else { if (verbose) cout << "no" << std::endl; FailedTests++; } 00446 } 00447 if (verbose) { 00448 cout<< " Can we retrieve const information using the CORRECT variable type ... "; 00449 } 00450 if (max_iters_ptr_again) { 00451 if ((*max_iters_ptr_again)==3) { 00452 if (verbose) cout << "yes" << std::endl; 00453 } 00454 else { if (verbose) cout << "no" << std::endl; FailedTests++; } 00455 } 00456 00457 //----------------------------------------------------------- 00458 // Retrieve some information from the parameter list that we know is a bad "get". 00459 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00460 // non-templated code needs ".template" before the method name ) 00461 //----------------------------------------------------------- 00462 float* mbf_ptr = 0; 00463 00464 mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>( "Tol" ); 00465 00466 if (mbf_ptr) 00467 ++FailedTests; 00468 00469 if (verbose) { 00470 cout<< " Can we retrieve information using the WRONG variable type ... "; 00471 } 00472 if (!mbf_ptr) { if (verbose) cout << "no" << std::endl; } 00473 else { if (verbose) cout << "yes" << std::endl; } 00474 00475 //----------------------------------------------------------- 00476 // Retrieve some information from the parameter list using templated "get" method. 00477 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00478 // non-templated code needs ".template" before the method name ) 00479 //----------------------------------------------------------- 00480 00481 max_iters_ptr = PL_My_Polynomial.INVALID_TEMPLATE_QUALIFIER getPtr<int>("Max Iters"); 00482 nonlin_solver_ptr = PL_Main.INVALID_TEMPLATE_QUALIFIER getPtr<std::string>("Nonlinear Solver"); 00483 (void)nonlin_solver_ptr; // Not used, bad test! 00484 00485 if (verbose) { 00486 cout<< "Is the templated 'getPtr' method functional ... "<<std::endl; 00487 cout<< " Can we retrieve information using the CORRECT variable type ... "; 00488 } 00489 if (max_iters_ptr) { 00490 if ((*max_iters_ptr)==3) { 00491 if (verbose) cout << "yes" << std::endl; 00492 } 00493 else { if (verbose) cout << "no" << std::endl; FailedTests++; } 00494 } 00495 00496 //----------------------------------------------------------- 00497 // Retrieve some information from the parameter list that we know is a bad "get". 00498 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00499 // non-templated code needs ".template" before the method name ) 00500 //----------------------------------------------------------- 00501 00502 mbf_ptr = PL_LinSol.INVALID_TEMPLATE_QUALIFIER getPtr<float>( "Tol" ); 00503 00504 if (mbf_ptr) 00505 ++FailedTests; 00506 00507 if (verbose) { 00508 cout<< " Can we retrieve information using the WRONG variable type ... "; 00509 } 00510 if (!mbf_ptr) { if (verbose) cout << "no" << std::endl; } 00511 else { if (verbose) cout << "yes" << std::endl; } 00512 00513 //----------------------------------------------------------- 00514 // Check the 'getParameter' helper function. 00515 //----------------------------------------------------------- 00516 int def_step = 0; 00517 double alpha_fact = 0.0; 00518 tempMeth = true; 00519 try { 00520 def_step = Teuchos::getParameter<int>(PL_Polynomial, "Default Step"); 00521 alpha_fact = Teuchos::getParameter<double>(PL_Polynomial, "Alpha Factor"); 00522 (void)alpha_fact; // Not used, bad test! 00523 } 00524 catch( const Teuchos::Exceptions::InvalidParameter&) { tempMeth = false; } 00525 if (verbose && def_step==1) { 00526 cout<< "Is the helper function 'getParameter' functional ... "; 00527 } 00528 if (tempMeth) { if (verbose) cout << "yes" << std::endl; } 00529 else { if (verbose) cout << "no" << std::endl; FailedTests++; } 00530 00531 //----------------------------------------------------------- 00532 // Check templated isType functionality 00533 // (This will be tested using the INVALID_TEMPLATE_QUALIFIER which indicates whether a 00534 // non-templated code needs ".template" before the method name ) 00535 //----------------------------------------------------------- 00536 bool PT1, PT2, PT3; 00537 PT1 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<int>("Default Step"); 00538 PT2 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<long int>("Default Step"); 00539 PT3 = PL_Polynomial.INVALID_TEMPLATE_QUALIFIER isType<std::string>("Interpolation Type"); 00540 if (verbose) { 00541 cout<< "Is the templated 'isType' method functional ... "<<std::endl; 00542 cout<< " Is the 'Default Step' of type 'int' ... "; 00543 } 00544 if (PT1) { if (verbose) cout<< "yes" << std::endl; } 00545 else { if (verbose) cout<< "no" << std::endl; FailedTests++; } 00546 if (verbose) { 00547 cout<< " Is the 'Default Step' of type 'long int' ... "; 00548 } 00549 if (PT2) { if (verbose) cout<< "yes" << std::endl; FailedTests++; } 00550 else { if (verbose) cout<< "no (as expected)" << std::endl; } 00551 if (verbose) { 00552 cout<< " Is the 'Interpolation Type' of type 'std::string' ... "; 00553 } 00554 if (PT3) { if (verbose) cout<< "yes" << std::endl; } 00555 else { if (verbose) cout<< "no" << std::endl; FailedTests++; } 00556 00557 //----------------------------------------------------------- 00558 // Check the 'isParameterType' helper function. 00559 //----------------------------------------------------------- 00560 bool PT4, PT5; 00561 PT4 = Teuchos::isParameterType<double>(PL_Polynomial, "Max Bounds Factor"); 00562 PT5 = Teuchos::isParameterType<float>(PL_Polynomial, "Max Bounds Factor"); 00563 if (verbose) { 00564 cout<< "Is the helper function 'isParameterType' functional ... "<<std::endl; 00565 cout<< " Is the 'Max Bounds Factor' of type 'double' ... "; 00566 } 00567 if (PT4) { if (verbose) cout<< "yes" <<std::endl; } 00568 else { if (verbose) cout<< "no" << std::endl; FailedTests++; } 00569 if (verbose) { 00570 cout<< " Is the 'Max Bounds Factor' of type 'float' ... "; 00571 } 00572 if (PT5) { if (verbose) cout<< "yes" <<std::endl; FailedTests++; } 00573 else { if (verbose) cout<< "no (as expected)" << std::endl; } 00574 00575 //----------------------------------------------------------- 00576 // Can we pass a pointer to a std::vector to the parameter list. 00577 //----------------------------------------------------------- 00578 Teuchos::ArrayRCP<double> tempvec1_arcp = Teuchos::arcp<double>(10); 00579 { 00580 double * tempvec1 = tempvec1_arcp.get(); 00581 for (int i=0; i<10; i++) { tempvec1[i] = i; } 00582 PL_Main.set( "Address of Norm Vector", tempvec1 ); 00583 double* tempvec2 = Teuchos::getParameter<double*>( PL_Main, "Address of Norm Vector" ); 00584 tempvec1[4] = 2.0; tempvec1[6] = 1.0; 00585 if (verbose) { 00586 cout<< "Can we pass a pointer to a std::vector to a parameter list ... "; 00587 } 00588 if ((tempvec2[4]-tempvec1[4])!=0.0 || (tempvec2[6]-tempvec1[6])!=0.0) { 00589 if (verbose) { cout<<"no"<<std::endl; } 00590 FailedTests++; 00591 } else { 00592 if (verbose) { cout<<"yes"<<std::endl; } 00593 } 00594 } 00595 00596 //----------------------------------------------------------- 00597 // We can add Array<T> objects of various types T as std::string parameters! 00598 //----------------------------------------------------------- 00599 if(verbose) { 00600 print_break(); 00601 cout << "Setting int and double array objects as std::string parameters ...\n"; 00602 print_break(); 00603 } 00604 const Teuchos::Array<int> 00605 intArray = Teuchos::tuple<int>(0,1,2,3,4,5,6); 00606 const Teuchos::Array<double> 00607 doubleArray = Teuchos::tuple<double>(0,1.0,2.0,3.0,4.0,5.0,6.0); 00608 //const Teuchos::Array<bool> 00609 //boolArray = Teuchos::tuple<bool>(true,true,false,false); 00610 Teuchos::setStringParameterFromArray("Int Array",intArray,&PL_Main); 00611 Teuchos::setStringParameterFromArray("Double Array",doubleArray,&PL_Main); 00612 //Teuchos::setStringParameterFromArray("Bool Array",boolArray,&PL_Main); 00613 if(verbose) { 00614 print_break(); 00615 cout << "Testing retrieval of set array objects ...\n"; 00616 print_break(); 00617 } 00618 { 00619 00620 const Teuchos::Array<int> 00621 readIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,"Int Array"); 00622 result = readIntArray == intArray; 00623 if(!result) ++FailedTests; 00624 if(verbose) 00625 cout 00626 << "readIntArray = " << readIntArray << " == intArray = " << intArray << " ? " 00627 << (result ? "passed" : "failed") 00628 << "\n"; 00629 00630 const Teuchos::Array<int> 00631 readDoubleAsIntArray = Teuchos::getArrayFromStringParameter<int>(PL_Main,"Double Array"); 00632 result = readDoubleAsIntArray == intArray; 00633 if(!result) ++FailedTests; 00634 if(verbose) 00635 cout 00636 << "readDoubleAsIntArray = " << readDoubleAsIntArray << " == intArray = " << intArray << " ? " 00637 << (result ? "passed" : "failed") 00638 << "\n"; 00639 00640 /* 00641 const Teuchos::Array<bool> 00642 readBoolArray = Teuchos::getArrayFromStringParameter<bool>(PL_Main,"Bool Array"); 00643 result = readBoolArray == boolArray; 00644 if(!result) ++FailedTests; 00645 if(verbose) 00646 cout 00647 << "readBoolArray = " << readBoolArray << " == boolArray = " << boolArray << " ? " 00648 << (result ? "passed" : "failed") 00649 << "\n"; 00650 */ 00651 00652 if(verbose) { 00653 print_break(); 00654 } 00655 00656 } 00657 00658 //----------------------------------------------------------- 00659 // We can directly set the array strings! 00660 //----------------------------------------------------------- 00661 00662 if(verbose) { 00663 print_break(); 00664 cout << "Setting a array of doubles as a std::string parameter directly ...\n"; 00665 print_break(); 00666 } 00667 00668 PL_Main.set( 00669 "Double Array" 00670 ," {\n" 00671 " 0.00000\n" 00672 " ,1.0e0\n" 00673 " ,0.2e1\n" 00674 " ,30.0e-1\n" 00675 " ,4\n" 00676 " ,5.0000\n" 00677 " ,6\n" 00678 " }\n " 00679 ); 00680 00681 { 00682 00683 const Teuchos::Array<double> 00684 readDoubleArray = Teuchos::getArrayFromStringParameter<double>(PL_Main,"Double Array"); 00685 Teuchos::Array<int> 00686 doubleAsIntArray(readDoubleArray.size()); 00687 for(int i=0;i<static_cast<int>(readDoubleArray.size());++i) 00688 doubleAsIntArray[i] = static_cast<int>(readDoubleArray[i]); 00689 result = doubleAsIntArray == intArray; 00690 if(!result) ++FailedTests; 00691 if(verbose) 00692 cout 00693 << "doubleAsIntArray = " << doubleAsIntArray << " == intArray = " << intArray << " ? " 00694 << (result ? "passed" : "failed") 00695 << "\n"; 00696 00697 if(verbose) { 00698 print_break(); 00699 } 00700 00701 } 00702 00703 //----------------------------------------------------------- 00704 // Can we pass a pointer to a function to the parameter list. 00705 // Use a simple function, pass it in and get it back out ... 00706 // ( HKT 03/23/2004 This test is not supported on Janus ) 00707 //----------------------------------------------------------- 00708 #ifndef JANUS_STLPORT 00709 double (*pt2Function) (double, double); 00710 PL_Main.set( "Address to Simple Function", &Plus ); 00711 pt2Function = Teuchos::getParameter<double(*)(double,double)>( PL_Main, "Address to Simple Function" ); 00712 if (verbose) { 00713 cout<< "Can we pass a pointer to a function to a parameter list ... "; 00714 } 00715 if ( pt2Function( 1.0, 2.0 ) != 3.0 ) { 00716 if (verbose) cout<<"no"<<std::endl; 00717 FailedTests++; 00718 } else { 00719 if (verbose) cout<<"yes"<<std::endl; 00720 } 00721 #endif 00722 } 00723 00724 //----------------------------------------------------------- 00725 // We can store and retrieve void* pointers! 00726 //----------------------------------------------------------- 00727 00728 { 00729 ParameterList pl; 00730 int someInt = 1; 00731 void *someIntPtr = &someInt; 00732 pl.set("Some Pointer", someIntPtr); 00733 void *someIntPtrRtn = getParameter<void*>(pl, "Some Pointer"); 00734 TEUCHOS_TEST_FOR_EXCEPT(someIntPtrRtn != someIntPtr); 00735 if (verbose) 00736 cout << "someIntPtrRtn = " << someIntPtrRtn << " == " << someIntPtr << " : "; 00737 if (someIntPtrRtn == someIntPtr) { 00738 if (verbose) cout << "passed\n"; 00739 } 00740 else { 00741 if (verbose) cout << "failed\n"; 00742 FailedTests++; 00743 } 00744 } 00745 00746 //----------------------------------------------------------- 00747 // Print using the public iterators 00748 // KL - 7 August 2004 00749 //----------------------------------------------------------- 00750 ParameterList::ConstIterator iter; 00751 00752 if (verbose) 00753 { 00754 print_break(); 00755 cout << " printing using public iterators " 00756 << std::endl; 00757 print_break(); 00758 } 00759 for (iter = PL_Main.begin(); iter != PL_Main.end(); ++iter) 00760 { 00761 const ParameterEntry& val = PL_Main.entry(iter); 00762 const std::string& name = PL_Main.name(iter); 00763 if (val.isList()) 00764 { 00765 if (verbose) cout << name << std::endl; 00766 const ParameterList& sublist = Teuchos::getValue<ParameterList>(val); 00767 ParameterList::ConstIterator i; 00768 for (i=sublist.begin(); i != sublist.end(); ++i) 00769 { 00770 const std::string& nm = sublist.name(i); 00771 const ParameterEntry& v = sublist.entry(i); 00772 if (v.isList()) 00773 { 00774 if (verbose) cout << " " << nm << std::endl; 00775 if (verbose) Teuchos::getValue<ParameterList>(v).print(cout, 6); 00776 } 00777 else 00778 { 00779 if (verbose) cout << " " << nm << " " << v << std::endl; 00780 } 00781 } 00782 } 00783 else 00784 { 00785 if (verbose) cout << name << " " << val << std::endl; 00786 } 00787 } 00788 00789 00790 #if defined(HAVE_TEUCHOS_EXTENDED) 00791 00792 try { 00793 00794 if (verbose) { 00795 00796 print_break(); 00797 cout << "writing to XML std::ostream" << std::endl; 00798 print_break(); 00799 writeParameterListToXmlOStream(PL_Main,cout); 00800 00801 print_break(); 00802 cout << "writing to XML file" << std::endl; 00803 print_break(); 00804 writeParameterListToXmlFile(PL_Main,"PL_Main.xml"); 00805 00806 print_break(); 00807 cout << "reading from XML file" << std::endl; 00808 print_break(); 00809 ParameterList readBack; 00810 updateParametersFromXmlFile("PL_Main.xml", inoutArg(readBack)); 00811 if (verbose) readBack.print(cout); 00812 00813 print_break(); 00814 cout << "reading from XML std::string" << std::endl; 00815 print_break(); 00816 std::ifstream xmlInFile("PL_Main.xml"); 00817 std::string xmlStr; 00818 while(!xmlInFile.eof()) { 00819 std::string line; 00820 std::getline(xmlInFile,line); 00821 xmlStr += line + "\n"; 00822 } 00823 readBack = ParameterList(); 00824 updateParametersFromXmlString(xmlStr, inoutArg(readBack)); 00825 if (verbose) readBack.print(cout); 00826 00827 } 00828 00829 } 00830 catch(const std::exception& e) 00831 { 00832 if(verbose) { 00833 std::cerr << "caught std::exception:\n\n"; 00834 OSTab tab(std::cerr); 00835 std::cerr << e.what() << std::endl; 00836 } 00837 FailedTests++; 00838 } 00839 00840 #endif // defined(HAVE_TEUCHOS_EXTENDED) 00841 00842 //----------------------------------------------------------- 00843 // Print out main list 00844 //----------------------------------------------------------- 00845 00846 if (verbose) { 00847 print_break(); 00848 cout << "The Final Parameter List" << std::endl; 00849 print_break(); 00850 PL_Main.print(cout); 00851 print_break(); 00852 cout << "The unused parameters" << std::endl; 00853 PL_Main.unused(cout); 00854 } 00855 00856 //----------------------------------------------------------- 00857 // Show error outputs 00858 //----------------------------------------------------------- 00859 00860 if (verbose) { 00861 print_break(); 00862 cout << "Accessing a sublist using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n"; 00863 print_break(); 00864 } 00865 try { 00866 PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solvers",true); 00867 if (verbose) cout << "Did not throw std::exception, error!\n"; 00868 ++FailedTests; 00869 } 00870 catch(const Teuchos::Exceptions::InvalidParameterName &e) { 00871 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n"; 00872 OSTab tab(std::cerr); 00873 std::cerr << e.what() << std::endl; 00874 } 00875 if (verbose) { 00876 print_break(); 00877 cout << "Accessing a parameter using the wrong name (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n"; 00878 print_break(); 00879 } 00880 try { 00881 Teuchos::getParameter<int>(PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solver"),"Tolerances"); 00882 if (verbose) cout << "Did not throw std::exception, error!\n"; 00883 ++FailedTests; 00884 } 00885 catch(const Teuchos::Exceptions::InvalidParameterName &e) { 00886 if(verbose) { 00887 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n"; 00888 OSTab tab(std::cerr); 00889 std::cerr << e.what() << std::endl; 00890 } 00891 } 00892 catch(const std::exception &e) { 00893 if(verbose) { 00894 std::cerr << "caught unexpected std::exception:\n\n"; 00895 OSTab tab(std::cerr); 00896 std::cerr << e.what() << std::endl; 00897 } 00898 ++FailedTests; 00899 } 00900 00901 if (verbose) { 00902 print_break(); 00903 cout << "Accessing a parameter using the wrong parameter type (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n"; 00904 print_break(); 00905 } 00906 try { 00907 Teuchos::getParameter<int>(PL_Main.sublist("Direction").sublist("Newton").sublist("Linear Solver"),"Tolerance"); 00908 if (verbose) cout << "Did not throw std::exception, error!\n"; 00909 ++FailedTests; 00910 } 00911 catch(const Teuchos::Exceptions::InvalidParameterType &e) { 00912 if(verbose) { 00913 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n"; 00914 OSTab tab(std::cerr); 00915 std::cerr << e.what() << std::endl; 00916 } 00917 } 00918 catch(const std::exception &e) { 00919 if(verbose) { 00920 std::cerr << "caught unexpected std::exception:\n\n"; 00921 OSTab tab(std::cerr); 00922 std::cerr << e.what() << std::endl; 00923 } 00924 ++FailedTests; 00925 } 00926 00927 //----------------------------------------------------------- 00928 // Validate the parameter list 00929 //----------------------------------------------------------- 00930 00931 // Create a validator version of PL_Main that we will validate against! 00932 Teuchos::ParameterList PL_Main_valid("PL_Main_copy"); 00933 PL_Main_valid.setParameters(PL_Main); 00934 00935 // Create a validator for the "Nonlinear Solver" parameter 00936 Teuchos::setStringToIntegralParameter<int>( 00937 "Nonlinear Solver", "Line Search Based", 00938 "Selects the type of nonlinear solver to use", 00939 Teuchos::tuple<std::string>("Line Search Based","Trust Region Based"), 00940 &PL_Main 00941 ); 00942 00943 /* 00944 Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> > 00945 nonlinearSolverValidator = rcp( 00946 new Teuchos::StringToIntegralParameterEntryValidator<int>( 00947 Teuchos::tuple<std::string>("Line Search Based","Trust Region Based") 00948 ,"Nonlinear Solver" 00949 ) 00950 ); 00951 PL_Main_valid.set( 00952 "Nonlinear Solver", "Line Search Based" 00953 ,"Selects the type of nonlinear solver to use" 00954 ,nonlinearSolverValidator 00955 ); 00956 */ 00957 00958 // Create a validator for the parameter "Line Search"->"Polynomial"->"Max Iters" 00959 // that accepts an 'int', a 'double' or a 'std::string' value! 00960 typedef Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes AcceptedTypes; 00961 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator> 00962 linesearchMaxItersValiator = rcp( 00963 new Teuchos::AnyNumberParameterEntryValidator( 00964 Teuchos::AnyNumberParameterEntryValidator::PREFER_INT, // Not used here! 00965 AcceptedTypes(false).allowInt(true).allowDouble(true).allowString(true) 00966 ) 00967 ); 00968 PL_Main_valid.sublist("Line Search").sublist("Polynomial").set( 00969 "Max Iters",3 00970 ,"The maximum number of inner linear search iterations allowed." 00971 ,linesearchMaxItersValiator 00972 ); 00973 00974 // Create a validator for the parameter "Direction"->"Newton"->"Linear Solver"->"Tol" 00975 // that accepts a 'double' or a 'std::string' value! 00976 typedef Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes AcceptedTypes; 00977 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator> 00978 linSolveTolValidator = rcp( 00979 new Teuchos::AnyNumberParameterEntryValidator( 00980 Teuchos::AnyNumberParameterEntryValidator::PREFER_INT, // Not used here! 00981 AcceptedTypes(false).allowDouble(true).allowString(true) 00982 ) 00983 ); 00984 PL_Main_valid.sublist("Direction",true).sublist("Newton",true) 00985 .sublist("Linear Solver",true).set( 00986 "Tol", double(1e-5) 00987 ,"Select the linear solve tolerance" 00988 ,linSolveTolValidator 00989 ); 00990 00991 if (verbose) { 00992 print_break(); 00993 cout << "Validating the parameter list against itself (should not throw std::exception)...\n"; 00994 print_break(); 00995 } 00996 try { 00997 PL_Main.validateParameters(PL_Main_valid); 00998 if (verbose) cout << "Did not throw std::exception, success!\n\n"; 00999 } 01000 catch(const std::exception &e) { 01001 if(verbose) { 01002 std::cerr << "caught unexpected std::exception:\n\n"; 01003 OSTab tab(std::cerr); 01004 std::cerr << e.what() << std::endl; 01005 } 01006 ++FailedTests; 01007 } 01008 01009 if (verbose) { 01010 print_break(); 01011 cout << "Adding an invalid parameter type then validating (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n"; 01012 print_break(); 01013 } 01014 try { 01015 PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iters",(short int)(3)); // Should be an int! 01016 PL_Main.validateParameters(PL_Main_valid); 01017 if (verbose) cout << "Did not throw std::exception, error!\n"; 01018 ++FailedTests; 01019 } 01020 catch(const Teuchos::Exceptions::InvalidParameterType &e) { 01021 if(verbose) { 01022 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n"; 01023 OSTab tab(std::cerr); 01024 std::cerr << e.what() << std::endl; 01025 } 01026 } 01027 catch(const std::exception &e) { 01028 if(verbose) { 01029 std::cerr << "caught unexpected std::exception:\n\n"; 01030 OSTab tab(std::cerr); 01031 std::cerr << e.what() << std::endl; 01032 } 01033 ++FailedTests; 01034 } 01035 PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iters",3); // Put back the valid int! 01036 01037 if (verbose) { 01038 print_break(); 01039 cout << "Adding an invalid parameter name then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n"; 01040 print_break(); 01041 } 01042 try { 01043 PL_Main.sublist("Line Search").sublist("Polynomial").set("Max Iter",10); 01044 PL_Main.validateParameters(PL_Main_valid); 01045 if (verbose) cout << "Did not throw std::exception, error!\n"; 01046 ++FailedTests; 01047 } 01048 catch(const Teuchos::Exceptions::InvalidParameterName &e) { 01049 if(verbose) { 01050 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n"; 01051 OSTab tab(std::cerr); 01052 std::cerr << e.what() << std::endl; 01053 } 01054 } 01055 catch(const std::exception &e) { 01056 if(verbose) { 01057 std::cerr << "caught unexpected std::exception:\n\n"; 01058 OSTab tab(std::cerr); 01059 std::cerr << e.what() << std::endl; 01060 } 01061 ++FailedTests; 01062 } 01063 PL_Main.sublist("Line Search").sublist("Polynomial").remove("Max Iter"); 01064 01065 if (verbose) { 01066 print_break(); 01067 cout << "Adding an invalid parameter type then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterType std::exception)...\n"; 01068 print_break(); 01069 } 01070 try { 01071 PL_Main.set("Nonlinear Solver",int(0)); // Should be a std::string! 01072 PL_Main.validateParameters(PL_Main_valid); 01073 if (verbose) cout << "Did not throw std::exception, error!\n"; 01074 ++FailedTests; 01075 } 01076 catch(const Teuchos::Exceptions::InvalidParameterType &e) { 01077 if(verbose) { 01078 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterType:\n\n"; 01079 OSTab tab(std::cerr); 01080 std::cerr << e.what() << std::endl; 01081 } 01082 } 01083 catch(const std::exception &e) { 01084 if(verbose) { 01085 std::cerr << "caught unexpected std::exception:\n\n"; 01086 OSTab tab(std::cerr); 01087 std::cerr << e.what() << std::endl; 01088 } 01089 ++FailedTests; 01090 } 01091 PL_Main.set("Nonlinear Solver","Line Search Based"); // Put back the valid value! 01092 01093 if (verbose) { 01094 print_break(); 01095 cout << "Adding an invalid parameter value then validating using validator (should throw a Teuchos::Exceptions::InvalidParameterValue std::exception)...\n"; 01096 print_break(); 01097 } 01098 try { 01099 PL_Main.set("Nonlinear Solver","LineSearch Based"); // Should be "Line Search Based"! 01100 PL_Main.validateParameters(PL_Main_valid); 01101 if (verbose) cout << "Did not throw std::exception, error!\n"; 01102 ++FailedTests; 01103 } 01104 catch(const Teuchos::Exceptions::InvalidParameterValue &e) { 01105 if(verbose) { 01106 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterValue:\n\n"; 01107 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01108 } 01109 } 01110 catch(const std::exception &e) { 01111 if(verbose) { 01112 std::cerr << "caught unexpected std::exception:\n\n"; 01113 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01114 } 01115 ++FailedTests; 01116 } 01117 PL_Main.set("Nonlinear Solver","Line Search Based"); // Put back the valid value! 01118 01119 if (verbose) { 01120 print_break(); 01121 cout << "Use the validator to access integral value (should *not* throw std::exception)...\n"; 01122 print_break(); 01123 } 01124 try { 01125 const int 01126 nonlinearSolverValue = Teuchos::getIntegralValue<int>(PL_Main,"Nonlinear Solver"); 01127 const bool 01128 l_result = (nonlinearSolverValue == 0); 01129 cout 01130 << "Read value = " << nonlinearSolverValue << " == 0 : " 01131 << ( l_result ? "passed" : "failed") << "\n"; 01132 if(!l_result) ++FailedTests; 01133 } 01134 catch(const std::exception &e) { 01135 if(verbose) { 01136 std::cerr << "caught unexpected std::exception:\n\n"; 01137 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01138 } 01139 ++FailedTests; 01140 } 01141 01142 if (verbose) { 01143 print_break(); 01144 cout << "Use the validator to access std::string value (should *not* throw std::exception)...\n"; 01145 print_break(); 01146 } 01147 try { 01148 const std::string 01149 nonlinearSolverValue = Teuchos::getStringValue<int>(PL_Main,"Nonlinear Solver"); 01150 const bool 01151 l_result = (nonlinearSolverValue == "Line Search Based"); 01152 cout 01153 << "Read value = \"" << nonlinearSolverValue << " == \"Line Search Based\" : " 01154 << ( l_result ? "passed" : "failed") << "\n"; 01155 if(!l_result) ++FailedTests; 01156 } 01157 catch(const std::exception &e) { 01158 if(verbose) { 01159 std::cerr << "caught unexpected std::exception:\n\n"; 01160 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01161 } 01162 ++FailedTests; 01163 } 01164 01165 //----------------------------------------------------------- 01166 // Validate and set defaults 01167 //----------------------------------------------------------- 01168 01169 // Set the default parameters for an emplty list 01170 ParameterList validatedPL; 01171 01172 if (verbose) { 01173 print_break(); 01174 cout << "Validating and setting defaults for an empty parameter list (should not throw) ...\n"; 01175 print_break(); 01176 } 01177 try { 01178 validatedPL.validateParametersAndSetDefaults(PL_Main_valid); 01179 if (verbose) cout << "Did not throw std::exception, success!\n\n"; 01180 } 01181 catch(const std::exception &e) { 01182 if(verbose) { 01183 std::cerr << "caught unexpected std::exception:\n\n"; 01184 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01185 } 01186 ++FailedTests; 01187 } 01188 01189 if (verbose) { 01190 print_break(); 01191 cout << "Parameter list with defaults set:" << std::endl; 01192 print_break(); 01193 validatedPL.print(cout,PLPrintOptions().showTypes(true).showDoc(true)); 01194 print_break(); 01195 } 01196 01197 if (verbose) { 01198 print_break(); 01199 cout << "Checking that validatedPL and PL_Main_valid have the same values : "; 01200 } 01201 result = haveSameValues(validatedPL,PL_Main_valid); 01202 if(!result) 01203 ++FailedTests; 01204 if (verbose) { 01205 cout << ( result ? "passed" : "failed" ) << "\n"; 01206 print_break(); 01207 } 01208 01209 // 01210 // Testing access of numbers using validator where validator is not buried 01211 // in the parameter 01212 // 01213 01214 for( int type_i = 0; type_i < 3; ++type_i ) { 01215 01216 ParameterList &Polynomial_sublist 01217 = PL_Main.sublist("Line Search",true).sublist("Polynomial",true); 01218 01219 std::string typeName; 01220 01221 // Set the input type 01222 01223 switch(type_i) { 01224 case 0: 01225 typeName = "int"; 01226 Polynomial_sublist.set("Max Iters",(int)(3)); 01227 break; 01228 case 1: 01229 typeName = "double"; 01230 Polynomial_sublist.set("Max Iters",(double)(3.0)); 01231 break; 01232 case 2: 01233 typeName = "std::string"; 01234 Polynomial_sublist.set("Max Iters",(std::string)("3")); 01235 break; 01236 default: 01237 TEUCHOS_TEST_FOR_EXCEPT(true); 01238 } 01239 01240 // Extract using external validator 01241 01242 if (verbose) { 01243 print_break(); 01244 cout << "Use the external number validator to access a "<<typeName<<" as an int ...\n"; 01245 print_break(); 01246 } 01247 try { 01248 const int 01249 lineserchMaxIters 01250 = linesearchMaxItersValiator->getInt( 01251 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01252 ,"Max Iters",0 01253 ); 01254 const bool 01255 l_result = (lineserchMaxIters == int(3)); 01256 cout 01257 << "Read value = " << lineserchMaxIters << " == 3 : " 01258 << ( l_result ? "passed" : "failed") << "\n"; 01259 if(!l_result) ++FailedTests; 01260 } 01261 catch(const std::exception &e) { 01262 if(verbose) { 01263 std::cerr << "caught unexpected std::exception:\n\n"; 01264 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01265 } 01266 ++FailedTests; 01267 } 01268 01269 if (verbose) { 01270 print_break(); 01271 cout << "Use the external number validator to access a "<<typeName<<" as a double ...\n"; 01272 print_break(); 01273 } 01274 try { 01275 const double 01276 lineserchMaxIters 01277 = linesearchMaxItersValiator->getDouble( 01278 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01279 ,"Max Iters",0.0 01280 ); 01281 const bool 01282 l_result = (lineserchMaxIters == double(3.0)); 01283 cout 01284 << "Read value = " << lineserchMaxIters << " == 3 : " 01285 << ( l_result ? "passed" : "failed") << "\n"; 01286 if(!l_result) ++FailedTests; 01287 } 01288 catch(const std::exception &e) { 01289 if(verbose) { 01290 std::cerr << "caught unexpected std::exception:\n\n"; 01291 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01292 } 01293 ++FailedTests; 01294 } 01295 01296 if (verbose) { 01297 print_break(); 01298 cout << "Use the external number validator to access a "<<typeName<<" as a std::string ...\n"; 01299 print_break(); 01300 } 01301 try { 01302 const std::string 01303 lineserchMaxIters 01304 = linesearchMaxItersValiator->getString( 01305 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01306 ,"Max Iters","0" 01307 ); 01308 const bool 01309 l_result = (lineserchMaxIters == "3"); 01310 cout 01311 << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : " 01312 << ( l_result ? "passed" : "failed") << "\n"; 01313 if(!l_result) ++FailedTests; 01314 } 01315 catch(const std::exception &e) { 01316 if(verbose) { 01317 std::cerr << "caught unexpected std::exception:\n\n"; 01318 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01319 } 01320 ++FailedTests; 01321 } 01322 01323 // Extract using nonmember functions 01324 01325 if (verbose) { 01326 print_break(); 01327 cout << "Use the nomember help function to access a "<<typeName<<" as an int ...\n"; 01328 print_break(); 01329 } 01330 try { 01331 const int 01332 lineserchMaxIters 01333 = Teuchos::getIntParameter( 01334 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01335 ,"Max Iters" 01336 ); 01337 const bool 01338 l_result = (lineserchMaxIters == int(3)); 01339 cout 01340 << "Read value = " << lineserchMaxIters << " == 3 : " 01341 << ( l_result ? "passed" : "failed") << "\n"; 01342 if(!l_result) ++FailedTests; 01343 } 01344 catch(const std::exception &e) { 01345 if(verbose) { 01346 std::cerr << "caught unexpected std::exception:\n\n"; 01347 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01348 } 01349 ++FailedTests; 01350 } 01351 01352 if (verbose) { 01353 print_break(); 01354 cout << "Use the nomember help function to access a "<<typeName<<" as a double ...\n"; 01355 print_break(); 01356 } 01357 try { 01358 const double 01359 lineserchMaxIters 01360 = Teuchos::getDoubleParameter( 01361 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01362 ,"Max Iters" 01363 ); 01364 const bool 01365 l_result = (lineserchMaxIters == double(3.0)); 01366 cout 01367 << "Read value = " << lineserchMaxIters << " == 3 : " 01368 << ( l_result ? "passed" : "failed") << "\n"; 01369 if(!l_result) ++FailedTests; 01370 } 01371 catch(const std::exception &e) { 01372 if(verbose) { 01373 std::cerr << "caught unexpected std::exception:\n\n"; 01374 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01375 } 01376 ++FailedTests; 01377 } 01378 01379 if (verbose) { 01380 print_break(); 01381 cout << "Use the nomember help function to access a "<<typeName<<" as a std::string ...\n"; 01382 print_break(); 01383 } 01384 try { 01385 const std::string 01386 lineserchMaxIters 01387 = Teuchos::getNumericStringParameter( 01388 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01389 ,"Max Iters" 01390 ); 01391 const bool 01392 l_result = (lineserchMaxIters == "3"); 01393 cout 01394 << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : " 01395 << ( l_result ? "passed" : "failed") << "\n"; 01396 if(!l_result) ++FailedTests; 01397 } 01398 catch(const std::exception &e) { 01399 if(verbose) { 01400 std::cerr << "caught unexpected std::exception:\n\n"; 01401 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01402 } 01403 ++FailedTests; 01404 } 01405 01406 } 01407 01408 // 01409 // Testing access of numbers using validator where validator is buried in 01410 // the parameter 01411 // 01412 01413 for( int type_i = 0; type_i < 3; ++type_i ) { 01414 01415 ParameterList &Polynomial_sublist 01416 = PL_Main.sublist("Line Search",true).sublist("Polynomial",true); 01417 01418 std::string typeName; 01419 01420 // Set the input type 01421 01422 switch(type_i) { 01423 case 0: 01424 typeName = "int"; 01425 Teuchos::setIntParameter("Max Iters",3,"",&Polynomial_sublist); 01426 break; 01427 case 1: 01428 typeName = "double"; 01429 Teuchos::setDoubleParameter("Max Iters",3.0,"",&Polynomial_sublist); 01430 break; 01431 case 2: 01432 typeName = "std::string"; 01433 Teuchos::setNumericStringParameter("Max Iters","3","",&Polynomial_sublist); 01434 break; 01435 default: 01436 TEUCHOS_TEST_FOR_EXCEPT(true); 01437 } 01438 01439 // Extract using nonmember functions (which should use the internal validator) 01440 01441 if (verbose) { 01442 print_break(); 01443 cout << "Use the nomember help function to access a "<<typeName<<" as an int ...\n"; 01444 print_break(); 01445 } 01446 try { 01447 const int 01448 lineserchMaxIters 01449 = Teuchos::getIntParameter( 01450 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01451 ,"Max Iters" 01452 ); 01453 const bool 01454 l_result = (lineserchMaxIters == int(3)); 01455 cout 01456 << "Read value = " << lineserchMaxIters << " == 3 : " 01457 << ( l_result ? "passed" : "failed") << "\n"; 01458 if(!l_result) ++FailedTests; 01459 } 01460 catch(const std::exception &e) { 01461 if(verbose) { 01462 std::cerr << "caught unexpected std::exception:\n\n"; 01463 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01464 } 01465 ++FailedTests; 01466 } 01467 01468 if (verbose) { 01469 print_break(); 01470 cout << "Use the nomember help function to access a "<<typeName<<" as a double ...\n"; 01471 print_break(); 01472 } 01473 try { 01474 const double 01475 lineserchMaxIters 01476 = Teuchos::getDoubleParameter( 01477 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01478 ,"Max Iters" 01479 ); 01480 const bool 01481 l_result = (lineserchMaxIters == double(3.0)); 01482 cout 01483 << "Read value = " << lineserchMaxIters << " == 3 : " 01484 << ( l_result ? "passed" : "failed") << "\n"; 01485 if(!l_result) ++FailedTests; 01486 } 01487 catch(const std::exception &e) { 01488 if(verbose) { 01489 std::cerr << "caught unexpected std::exception:\n\n"; 01490 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01491 } 01492 ++FailedTests; 01493 } 01494 01495 if (verbose) { 01496 print_break(); 01497 cout << "Use the nomember help function to access a "<<typeName<<" as a std::string ...\n"; 01498 print_break(); 01499 } 01500 try { 01501 const std::string 01502 lineserchMaxIters 01503 = Teuchos::getNumericStringParameter( 01504 PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01505 ,"Max Iters" 01506 ); 01507 const bool 01508 l_result = (lineserchMaxIters == "3"); 01509 cout 01510 << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : " 01511 << ( l_result ? "passed" : "failed") << "\n"; 01512 if(!l_result) ++FailedTests; 01513 } 01514 catch(const std::exception &e) { 01515 if(verbose) { 01516 std::cerr << "caught unexpected std::exception:\n\n"; 01517 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01518 } 01519 ++FailedTests; 01520 } 01521 01522 } 01523 01524 // 01525 // Testing access of numbers where correct number is set using 01526 // validateParametersAndSetDefaults(...) with no special access. 01527 // 01528 01529 for( int type_i = 0; type_i < 3; ++type_i ) { 01530 01531 ParameterList valid_PL_Main(PL_Main); 01532 01533 ParameterList &Polynomial_sublist 01534 = PL_Main.sublist("Line Search",true).sublist("Polynomial",true); 01535 01536 std::string typeName; 01537 01538 // Set the input type 01539 01540 switch(type_i) { 01541 case 0: 01542 typeName = "int"; 01543 Teuchos::setIntParameter("Max Iters",3,"",&Polynomial_sublist); 01544 break; 01545 case 1: 01546 typeName = "double"; 01547 Teuchos::setDoubleParameter("Max Iters",3.0,"",&Polynomial_sublist); 01548 break; 01549 case 2: 01550 typeName = "std::string"; 01551 Teuchos::setNumericStringParameter("Max Iters","3","",&Polynomial_sublist); 01552 break; 01553 default: 01554 TEUCHOS_TEST_FOR_EXCEPT(true); 01555 } 01556 01557 // Extract using nonmember functions (which should use the internal validator) 01558 01559 if (verbose) { 01560 print_break(); 01561 cout << "Use validateParemetersAndSetDefaults(...) to access a "<<typeName<<" as an int ...\n"; 01562 print_break(); 01563 } 01564 try { 01565 Teuchos::setIntParameter( 01566 "Max Iters", 0, "", 01567 &valid_PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01568 ); 01569 ParameterList copied_PL_Main(PL_Main); 01570 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main); 01571 const int 01572 lineserchMaxIters 01573 = Teuchos::getParameter<int>( 01574 copied_PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01575 ,"Max Iters" 01576 ); 01577 const bool 01578 l_result = (lineserchMaxIters == int(3)); 01579 cout 01580 << "Read value = " << lineserchMaxIters << " == 3 : " 01581 << ( l_result ? "passed" : "failed") << "\n"; 01582 if(!l_result) ++FailedTests; 01583 } 01584 catch(const std::exception &e) { 01585 if(verbose) { 01586 std::cerr << "caught unexpected std::exception:\n\n"; 01587 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01588 } 01589 ++FailedTests; 01590 } 01591 01592 if (verbose) { 01593 print_break(); 01594 cout << "Use validateParemetersAndSetDefaults(...) to access a "<<typeName<<" as a double ...\n"; 01595 print_break(); 01596 } 01597 try { 01598 Teuchos::setDoubleParameter( 01599 "Max Iters", 0.0, "", 01600 &valid_PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01601 ); 01602 ParameterList copied_PL_Main(PL_Main); 01603 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main); 01604 const double 01605 lineserchMaxIters 01606 = Teuchos::getParameter<double>( 01607 copied_PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01608 ,"Max Iters" 01609 ); 01610 const bool 01611 l_result = (lineserchMaxIters == double(3.0)); 01612 cout 01613 << "Read value = " << lineserchMaxIters << " == 3 : " 01614 << ( l_result ? "passed" : "failed") << "\n"; 01615 if(!l_result) ++FailedTests; 01616 } 01617 catch(const std::exception &e) { 01618 if(verbose) { 01619 std::cerr << "caught unexpected std::exception:\n\n"; 01620 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01621 } 01622 ++FailedTests; 01623 } 01624 01625 if (verbose) { 01626 print_break(); 01627 cout << "Use validateParemetersAndSetDefaults(...) to access a "<<typeName<<" as a std::string ...\n"; 01628 print_break(); 01629 } 01630 try { 01631 Teuchos::setNumericStringParameter( 01632 "Max Iters", "0", "", 01633 &valid_PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01634 ); 01635 ParameterList copied_PL_Main(PL_Main); 01636 copied_PL_Main.validateParametersAndSetDefaults(valid_PL_Main); 01637 const std::string 01638 lineserchMaxIters 01639 = Teuchos::getParameter<std::string>( 01640 copied_PL_Main.sublist("Line Search",true).sublist("Polynomial",true) 01641 ,"Max Iters" 01642 ); 01643 const bool 01644 l_result = (lineserchMaxIters == "3"); 01645 cout 01646 << "Read value = \"" << lineserchMaxIters << "\" == \"3\" : " 01647 << ( l_result ? "passed" : "failed") << "\n"; 01648 if(!l_result) ++FailedTests; 01649 } 01650 catch(const std::exception &e) { 01651 if(verbose) { 01652 std::cerr << "caught unexpected std::exception:\n\n"; 01653 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01654 } 01655 ++FailedTests; 01656 } 01657 01658 } 01659 01660 if (verbose) { 01661 print_break(); 01662 cout << "Adding an invalid sublist then validating (should throw a Teuchos::Exceptions::InvalidParameterName std::exception)...\n"; 01663 print_break(); 01664 } 01665 try { 01666 PL_Main.sublist("Line Search").sublist("Polynomials").set("Max Iters",3); // param correct, sublist wrong 01667 PL_Main.validateParameters(PL_Main_valid); 01668 if (verbose) cout << "Did not throw std::exception, error!\n"; 01669 ++FailedTests; 01670 } 01671 catch(const Teuchos::Exceptions::InvalidParameterName &e) { 01672 if(verbose) { 01673 std::cerr << "caught expected Teuchos::Exceptions::InvalidParameterName:\n\n"; 01674 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01675 } 01676 } 01677 catch(const std::exception &e) { 01678 if(verbose) { 01679 std::cerr << "caught unexpected std::exception:\n\n"; 01680 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01681 } 01682 ++FailedTests; 01683 } 01684 PL_Main.sublist("Line Search").remove("Polynomials"); 01685 01686 if (verbose) { 01687 print_break(); 01688 cout << "Validating only the top level list (should not throw std::exception)...\n"; 01689 print_break(); 01690 } 01691 try { 01692 PL_Main.validateParameters(PL_Main_valid,0); 01693 if (verbose) cout << "Did not throw std::exception, success!\n\n"; 01694 } 01695 catch(const std::exception &e) { 01696 if(verbose) { 01697 std::cerr << "caught unexpected std::exception:\n\n"; 01698 OSTab tab(std::cerr); std::cerr << e.what() << std::endl; 01699 } 01700 ++FailedTests; 01701 } 01702 01703 //----------------------------------------------------------- 01704 // Compare lists 01705 //----------------------------------------------------------- 01706 01707 if (verbose) { 01708 print_break(); 01709 cout << "Checking that PL_Main == PL_Main == true : "; 01710 } 01711 result = (PL_Main == PL_Main); 01712 if(!result) 01713 ++FailedTests; 01714 if (verbose) { 01715 cout << ( result ? "passed" : "failed" ) << "\n"; 01716 print_break(); 01717 } 01718 01719 if (verbose) { 01720 print_break(); 01721 cout << "Checking that PL_Main != PL_Main == false : "; 01722 } 01723 result = !(PL_Main != PL_Main); 01724 if(!result) 01725 ++FailedTests; 01726 if (verbose) { 01727 cout << ( result ? "passed" : "failed" ) << "\n"; 01728 print_break(); 01729 } 01730 01731 if (verbose) { 01732 print_break(); 01733 cout << "Checking that PL_Main and PL_Main have the same values : "; 01734 } 01735 result = haveSameValues(PL_Main,PL_Main); 01736 if(!result) 01737 ++FailedTests; 01738 if (verbose) { 01739 cout << ( result ? "passed" : "failed" ) << "\n"; 01740 print_break(); 01741 } 01742 01743 if (verbose) { 01744 print_break(); 01745 cout << "Create copy PL_Main_copy, change PL_Main_copy, and check that PL_Main != PL_Main == true : "; 01746 } 01747 ParameterList PL_Main_copy(PL_Main); 01748 PL_Main_copy.sublist("Line Search",true).sublist("Polynomial",true).set("Max Iters",100); // Not the default! 01749 result = (PL_Main_copy != PL_Main); 01750 if(!result) 01751 ++FailedTests; 01752 if (verbose) { 01753 cout << ( result ? "passed" : "failed" ) << "\n"; 01754 print_break(); 01755 } 01756 01757 //----------------------------------------------------------- 01758 // Print out main list showing the types 01759 //----------------------------------------------------------- 01760 01761 if (verbose) { 01762 print_break(); 01763 cout << "The Final Parameter List with Types and Documentation" << std::endl; 01764 print_break(); 01765 PL_Main.print(cout,PLPrintOptions().showTypes(true).showDoc(true)); 01766 print_break(); 01767 cout << "The unused parameters" << std::endl; 01768 PL_Main.unused(cout); 01769 print_break(); 01770 cout << "Number of Failed Tests : " << FailedTests << std::endl; 01771 print_break(); 01772 } 01773 01774 //----------------------------------------------------------- 01775 // Return -1 if there are any failed tests, 01776 // else 0 will be returned indicating a clean finish! 01777 //----------------------------------------------------------- 01778 01779 } // end try 01780 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose,std::cerr,success); 01781 if(!success) ++FailedTests; 01782 01783 if ( FailedTests > 0 ) { 01784 cout << "End Result: TEST FAILED" << std::endl; 01785 return 1; // Can't return negative numbers from main()! 01786 } 01787 01788 if ( FailedTests == 0 ) 01789 cout << "End Result: TEST PASSED" << std::endl; 01790 01791 return 0; 01792 01793 } 01794
1.7.6.1