Files
revng-revng/tests/unit/ClassSentinel.cpp
2021-12-15 18:03:30 +01:00

42 lines
1015 B
C++

/// \file ClassSentinel.cpp
/// \brief Tests for ClassSentinel
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#define BOOST_TEST_MODULE EarlyFunctionAnalysis
bool init_unit_test();
#include "boost/test/unit_test.hpp"
#include "revng/Support/ClassSentinel.h"
#include "revng/UnitTestHelpers/UnitTestHelpers.h"
struct TestClass {
ClassSentinel Sentinel;
};
BOOST_AUTO_TEST_CASE(Sentinel) {
TestClass *DanglingPointer = nullptr;
{
TestClass Instance;
BOOST_TEST(!Instance.Sentinel.isMoved());
BOOST_TEST(!Instance.Sentinel.isDestroyed());
TestClass OtherInstance = std::move(Instance);
BOOST_TEST(Instance.Sentinel.isMoved());
BOOST_TEST(!Instance.Sentinel.isDestroyed());
DanglingPointer = &Instance;
}
#if !(defined(__OPTIMIZE__) || defined(__SANITIZE_ADDRESS__) \
|| (defined(__has_feature) && __has_feature(address_sanitizer)))
BOOST_TEST(DanglingPointer->Sentinel.isDestroyed());
#else
(void) DanglingPointer;
#endif
}