inline void throw_assert_fail(const char *expr, int line, const char *func, const char *file) { std::stringstream ss; ss << "Assertion failure: "; ss << expr << " in " << func << ", " << file << ":" << line << std::endl; throw AssertionFailure(ss.str()); }
/** * @brief Assertion that BIR binary expression @a expr has two operands, when * both are variables and first is named "arg1" and second is named "arg2". */ AssertionResult TestsWithLLVMValueConverter::areBinaryOperandsInCorrectOrder( ShPtr<BinaryOpExpr> expr) { auto firstOp = cast<Variable>(expr->getFirstOperand()); if (!firstOp || firstOp->getName() != "arg1"s) { return AssertionFailure() << expr << " does not have first operand arg1"; } auto secondOp = cast<Variable>(expr->getSecondOperand()); if (!secondOp || secondOp->getName() != "arg2"s) { return AssertionFailure() << expr << " does not have first operand arg1"; } return AssertionSuccess() << expr << " has first operand arg1 and second operand arg2"; }
AssertionFailure TestCaseSandboxResultDecoderImpl:: readAssertionFailure() { std::string file = channel->readString(); int line = channel->readInt(); std::string reason = channel->readString(); return AssertionFailure(file, line, reason); }
AssertionResult AssertPred1Helper(const char* pred_str, const char* expr1 , PRED pred, T1 val1) { if( (*pred)(val1) ) { return AssertionSuccess(); } return AssertionFailure() << "error: " << pred_str << "(" << expr1 << ") evaluates to false, where " << "\n" << expr1 << " : " << val1; }
AssertionResult AssertPredVariadicHelper(const char* pred_str, const char* params , PRED pred, Args... args) { if( (*pred)(args...) ) { return AssertionSuccess(); } return AssertionFailure() << "error: " << pred_str << "(" << params << ") evaluates to false, where " << "\n" << PrintToStrings("\n", args...); }
AssertionResult Pred_SECFailure(const char* expectedExpr, const char* actualExpr, PRErrorCode expectedErrorCode, SECStatus actual) { if (SECFailure == actual && expectedErrorCode == PR_GetError()) { return AssertionSuccess(); } return AssertionFailure() << "Expected: (" << expectedExpr << ") == (" << actualExpr << "), actual: " << SECFailure << " != " << actual; }
void assertFail(const char* expr, const char* func, const char* file, int line, const String& msg) { String assert = sout() << "ASSERTION FAILED: " << expr << endl << (msg.length() ? String(sout() << msg << endl) : ""); #ifndef FINAL print(sout() << assert << "Function: " << func << endl << "File: " << file << ":" << line << endl); #endif Exception::Raiser() ^ Exception::Source(func, file, line) << AssertionFailure() << assert; }
AssertionResult CmpHelperSTRCASENE(const char* s1_expression, const char* s2_expression, const char* s1, const char* s2) { if (!String::CaseInsensitiveCStringEquals(s1, s2)) { return AssertionSuccess(); } else { return AssertionFailure() << "Expected: (" << s1_expression << ") != (" << s2_expression << ") (ignoring case), actual: \"" << s1 << "\" vs \"" << s2 << "\""; } }
AssertionResult assertMatNear(const char* expr1, const char* expr2, const char* eps_expr, InputArray m1_, InputArray m2_, double eps) { Mat m1 = getMat(m1_); Mat m2 = getMat(m2_); if (m1.size() != m2.size()) { return AssertionFailure() << "Matrices \"" << expr1 << "\" and \"" << expr2 << "\" have different sizes : \"" << expr1 << "\" [" << PrintToString(m1.size()) << "] vs \"" << expr2 << "\" [" << PrintToString(m2.size()) << "]"; } if (m1.type() != m2.type()) { return AssertionFailure() << "Matrices \"" << expr1 << "\" and \"" << expr2 << "\" have different types : \"" << expr1 << "\" [" << PrintToString(MatType(m1.type())) << "] vs \"" << expr2 << "\" [" << PrintToString(MatType(m2.type())) << "]"; } Mat diff; absdiff(m1.reshape(1), m2.reshape(1), diff); double maxVal = 0.0; Point maxLoc; minMaxLocGold(diff, 0, &maxVal, 0, &maxLoc); if (maxVal > eps) { return AssertionFailure() << "The max difference between matrices \"" << expr1 << "\" and \"" << expr2 << "\" is " << maxVal << " at (" << maxLoc.y << ", " << maxLoc.x / m1.channels() << ")" << ", which exceeds \"" << eps_expr << "\", where \"" << expr1 << "\" at (" << maxLoc.y << ", " << maxLoc.x / m1.channels() << ") evaluates to " << printMatVal(m1, maxLoc) << ", \"" << expr2 << "\" at (" << maxLoc.y << ", " << maxLoc.x / m1.channels() << ") evaluates to " << printMatVal(m2, maxLoc) << ", \"" << eps_expr << "\" evaluates to " << eps; } return AssertionSuccess(); }
/** * @brief Assertion that BIR ternary expression @a expr has all operands in * correct order. * * All operands have to be variables, condition operand have to be named "cond", * true value have to be named "true" and false value have to be named "false". */ AssertionResult TestsWithLLVMValueConverter::areTernaryOperandsInCorrectOrder( ShPtr<TernaryOpExpr> expr) { auto cond = cast<Variable>(expr->getCondition()); if (!cond || cond->getName() != "cond"s) { return AssertionFailure() << expr << " does not have condition as variable cond"; } auto trueVal = cast<Variable>(expr->getTrueValue()); if (!trueVal || trueVal->getName() != "true"s) { return AssertionFailure() << expr << " does not have true value as variable true"; } auto falseVal = cast<Variable>(expr->getFalseValue()); if (!falseVal || falseVal->getName() != "false"s) { return AssertionFailure() << expr << " does not have false value as variable false"; } return AssertionSuccess() << expr << " has condition 'cond', true value 'true' and false value 'false'"; }
AssertionResult CheckMPtr( BFProgram& app, size_t expected ) { size_t actual = app.memoryPointerOffset(); if ( expected == actual ) { return AssertionSuccess(); } else { return AssertionFailure() << "Memory pointer was: " << actual << ". Expected: " << expected; } }
AssertionResult CheckIPtr( BFProgram& app, size_t expected ) { size_t actual = app.instructionOffset(); if ( expected == actual ) { return AssertionSuccess(); } else { return AssertionFailure() << "Instruction pointer was: " << actual << ". Expected: " << expected; } }
AssertionResult AssertPred3Helper(const char* pred_str , const char* expr1, const char* expr2, const char* expr3 , PRED pred, T1 val1, T2 val2, T3 val3) { if( (*pred)(val1, val2, val3) ) { return AssertionSuccess(); } return AssertionFailure() << "error: " << pred_str << "(" << expr1 << ", " << expr2 << ", " << expr3 << ") evaluates to false, where " << "\n" << expr1 << " : " << val1 << "\n" << expr2 << " : " << val2 << "\n" << expr3 << " : " << val3; }
AssertionResult CheckMem( BFProgram& app, size_t offset, BlockT expected ) { BlockT actual = app.valueAt( offset ); if ( actual == expected ) { return AssertionSuccess(); } else { return AssertionFailure() << "Value at memory address " << offset << "was: " << actual << ". " << "Expected: " << expected; } }
AssertionResult EqFailure(const char* expected_expression, const char* actual_expression, const GTestString& expected_value, const GTestString& actual_value, bool ignoring_case) { Message msg; msg << "Value of: " << actual_expression; if( !String::CStringEquals(actual_value.c_str(), actual_expression) ) { msg << "\n Actual: " << actual_value; } msg << "\nExpected: " << expected_expression; if (ignoring_case) { msg << " (ignoring case)"; } if( !String::CStringEquals(expected_value.c_str(), expected_expression) ) { msg << "\nWhich is: " << expected_value; } return AssertionFailure() << msg; }
bool invariant(void) { throw AssertionFailure("invariant failed"); return false; }