Loading...
Searching...
No Matches
TestAssert.h
Go to the documentation of this file.
/*
* Robot Testing Framework
*
* Copyright (C) 2015-2019 Istituto Italiano di Tecnologia (IIT)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ROBOTTESTINGFRAMEWORK_TESTASSERT_H
#define ROBOTTESTINGFRAMEWORK_TESTASSERT_H
#if defined(_MSC_VER)
// see https://support.microsoft.com/kb/155196/en-us
# define __ROBOTTESTINGFRAMEWORK_STR2(x) # x
# define __ROBOTTESTINGFRAMEWORK_STR1(x) __ROBOTTESTINGFRAMEWORK_STR2(x)
# define __ROBOTTESTINGFRAMEWORK_LOC __FILE__ "("__STR1__(__LINE__) ")"
# define ROBOTTESTINGFRAMEWORK_COMPILER_MESSAGE(x) __pragma(message(__LOC__ " : msg" # x))
# define ROBOTTESTINGFRAMEWORK_COMPILER_WARNING(x) __pragma(message(__LOC__ " : warning msg" # x))
# define ROBOTTESTINGFRAMEWORK_COMPILER_ERROR(x) __pragma(message(__LOC__ " : error msg" # x))
#elif defined(__GNUC__)
// see https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
# define __ROBOTTESTINGFRAMEWORK_DO_PRAGMA(x) _Pragma(# x)
# define ROBOTTESTINGFRAMEWORK_COMPILER_MESSAGE(x) __ROBOTTESTINGFRAMEWORK_DO_PRAGMA(message # x)
# define ROBOTTESTINGFRAMEWORK_COMPILER_WARNING(x) __ROBOTTESTINGFRAMEWORK_DO_PRAGMA(GCC warning # x)
# define ROBOTTESTINGFRAMEWORK_COMPILER_ERROR(x) __ROBOTTESTINGFRAMEWORK_DO_PRAGMA(GCC error # x)
#else
# define ROBOTTESTINGFRAMEWORK_COMPILER_MESSAGE(x)
# define ROBOTTESTINGFRAMEWORK_COMPILER_WARNING(x)
# define ROBOTTESTINGFRAMEWORK_COMPILER_ERROR(x)
#endif
#include <robottestingframework/Asserter.h>
#define ROBOTTESTINGFRAMEWORK_ASSERT_FAIL(message) \
(::robottestingframework::Asserter::fail(::robottestingframework::TestMessage("asserts failure with exception", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE())))
#define ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_TRUE(condition, message) \
(::robottestingframework::Asserter::fail(!condition, \
::robottestingframework::TestMessage(std::string("asserts failure on (") + std::string(#condition) + ") with exception", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE())))
#define ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_FALSE(condition, message) \
(::robottestingframework::Asserter::fail(condition, \
::robottestingframework::TestMessage(std::string("asserts failure on (") + std::string(#condition) + ") with exception", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE())))
#define ROBOTTESTINGFRAMEWORK_ASSERT_ERROR(message) \
(::robottestingframework::Asserter::error(::robottestingframework::TestMessage("asserts error with exception", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE())))
#define ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_TRUE(condition, message) \
(::robottestingframework::Asserter::error(!condition, \
::robottestingframework::TestMessage(std::string("asserts error on (") + std::string(#condition) + ") with exception", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE())))
#define ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(condition, message) \
(::robottestingframework::Asserter::error(condition, \
::robottestingframework::TestMessage(std::string("asserts error on (") + std::string(#condition) + ") with exception", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE())))
#define ROBOTTESTINGFRAMEWORK_TEST_REPORT(message) \
(::robottestingframework::Asserter::report(::robottestingframework::TestMessage("reports", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE()), \
dynamic_cast<::robottestingframework::TestCase*>(this)))
#define ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(condition, message) \
(::robottestingframework::Asserter::testFail(condition, \
::robottestingframework::TestMessage(std::string("checking (") + std::string(#condition) + ")", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE()), \
dynamic_cast<::robottestingframework::TestCase*>(this)))
#define ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_TRUE(condition, message) \
(::robottestingframework::Asserter::testFail(!condition, \
::robottestingframework::TestMessage(std::string("checking (") + std::string(#condition) + ")", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE()), \
dynamic_cast<::robottestingframework::TestCase*>(this)))
#define ROBOTTESTINGFRAMEWORK_TEST_CHECK(condition, message) \
(::robottestingframework::Asserter::testCheck(condition, \
::robottestingframework::TestMessage("checks", \
message, \
ROBOTTESTINGFRAMEWORK_SOURCEFILE(), \
ROBOTTESTINGFRAMEWORK_SOURCELINE()), \
dynamic_cast<::robottestingframework::TestCase*>(this)))
#endif // ROBOTTESTINGFRAMEWORK_TESTASSERT_H
Asserter.h