diff --git a/CMakeLists.txt b/CMakeLists.txt index dc42b17a5af8ed0d4735c2bcf6aee13f35fbf94f..96d6befb38178083ec9930d531c11fc9923998d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,9 @@ include(CheckCompiler) if(ZERO_TOLERANCE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wfatal-errors") endif() +if(BORNAGAIN_GUI) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_MESSAGELOGCONTEXT=ON") +endif() include(BornAgainConfiguration) include(BornAgainPolicy) include(GeneratePythonDocs) diff --git a/Core/Basics/Assert.h b/Core/Basics/Assert.h new file mode 100644 index 0000000000000000000000000000000000000000..b9a2d457f1d8484fc83186190020c828ada6f557 --- /dev/null +++ b/Core/Basics/Assert.h @@ -0,0 +1,36 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Core/Basics/Assert.h +//! @brief Defines the macro ASSERT. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************** // + +#ifndef BORNAGAIN_CORE_BASICS_ASSERT_H +#define BORNAGAIN_CORE_BASICS_ASSERT_H + +#ifdef BORNAGAIN_GUI + +#include <QtGlobal> +#define ASSERT(condition) \ + if (!(condition)) \ + qFatal("assertion failed"); + +#else // The non-GUI case is used by our test suite + +#include <iostream> +#define ASSERT(condition) \ + if (!(condition)) { \ + std::cerr << "assertion failed" << std::endl; \ + exit(1); \ + } + +#endif // BORNAGAIN_GUI + +#endif // BORNAGAIN_CORE_BASICS_ASSERT_H diff --git a/Tests/UnitTests/Core/Basics/TestAssert.cpp b/Tests/UnitTests/Core/Basics/TestAssert.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e52a734c12d74501563bae4c015bb98dc5463ece --- /dev/null +++ b/Tests/UnitTests/Core/Basics/TestAssert.cpp @@ -0,0 +1,12 @@ +#include "Core/Basics/Assert.h" +#include "Tests/GTestWrapper/google_test.h" + +class TestAssert : public ::testing::Test +{ +}; + +TEST_F(TestAssert, Assert) +{ + EXPECT_NO_THROW(ASSERT(1)); + EXPECT_EXIT(ASSERT(0), ::testing::ExitedWithCode(1), "assertion failed"); +}