MCPcopy Create free account
hub / github.com/IBAMR/IBAMR / ThrowTest

Method ThrowTest

ibtk/contrib/muparser/src/muParserTest.cpp:1306–1356  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1304
1305 //---------------------------------------------------------------------------
1306 int ParserTester::ThrowTest(const string_type& a_str, int a_iErrc, bool a_expectedToFail)
1307 {
1308 ParserTester::c_iCount++;
1309
1310 try
1311 {
1312 value_type fVal[] = { 1,1,1 };
1313 Parser p;
1314
1315 p.DefineVar(_T("a"), &fVal[0]);
1316 p.DefineVar(_T("b"), &fVal[1]);
1317 p.DefineVar(_T("c"), &fVal[2]);
1318 p.DefinePostfixOprt(_T("{m}"), Milli);
1319 p.DefinePostfixOprt(_T("m"), Milli);
1320 p.DefineFun(_T("ping"), Ping);
1321 p.DefineFun(_T("valueof"), ValueOf);
1322 p.DefineFun(_T("strfun1"), StrFun1);
1323 p.DefineFun(_T("strfun2"), StrFun2);
1324 p.DefineFun(_T("strfun3"), StrFun3);
1325 p.DefineFun(_T("strfun4"), StrFun4);
1326 p.DefineFun(_T("strfun5"), StrFun5);
1327 p.DefineFun(_T("strfun6"), StrFun6);
1328 p.SetExpr(a_str);
1329 // p.EnableDebugDump(1, 0);
1330 p.Eval();
1331 }
1332 catch (ParserError& e)
1333 {
1334 // output the formula in case of an failed test
1335 if (a_expectedToFail == false || (a_expectedToFail == true && a_iErrc != e.GetCode()))
1336 {
1337 mu::console() << _T("\n ")
1338 << _T("Expression: ") << a_str
1339 << _T(" Code:") << e.GetCode() << _T("(") << e.GetMsg() << _T(")")
1340 << _T(" Expected:") << a_iErrc;
1341 }
1342
1343 return (a_iErrc == e.GetCode()) ? 0 : 1;
1344 }
1345
1346 // if a_expectedToFail == false no exception is expected
1347 bool bRet((a_expectedToFail == false) ? 0 : 1);
1348 if (bRet == 1)
1349 {
1350 mu::console() << _T("\n ")
1351 << _T("Expression: ") << a_str
1352 << _T(" did evaluate; Expected error:") << a_iErrc;
1353 }
1354
1355 return bRet;
1356 }
1357
1358 //---------------------------------------------------------------------------
1359 /** \brief Evaluate a test expression.

Callers

nothing calls this directly

Calls 5

DefineVarMethod · 0.80
DefinePostfixOprtMethod · 0.80
SetExprMethod · 0.80
EvalMethod · 0.80
GetCodeMethod · 0.45

Tested by

no test coverage detected