8#ifndef META_OCEAN_TEST_VALIDATION_H
9#define META_OCEAN_TEST_VALIDATION_H
141 inline void expectTrue(
const bool value,
const char* file,
const int line);
160 inline void expectFalse(
const bool value,
const char* file,
const int line);
170 template <
typename T>
171 inline void expectEqual(
const T& value0,
const T& value1);
184 template <
typename T>
185 inline void expectEqual(
const T& value0,
const T& value1,
const char* file,
const int line);
195 template <
typename T>
209 template <
typename T>
210 inline void expectNotEqual(
const T& value0,
const T& value1,
const char* file,
const int line);
220 template <
typename T>
221 inline void expectLess(
const T& value0,
const T& value1);
234 template <
typename T>
235 inline void expectLess(
const T& value0,
const T& value1,
const char* file,
const int line);
245 template <
typename T>
259 template <
typename T>
260 inline void expectLessEqual(
const T& value0,
const T& value1,
const char* file,
const int line);
270 template <
typename T>
284 template <
typename T>
285 inline void expectGreater(
const T& value0,
const T& value1,
const char* file,
const int line);
295 template <
typename T>
309 template <
typename T>
310 inline void expectGreaterEqual(
const T& value0,
const T& value1,
const char* file,
const int line);
321 template <
typename T>
336 template <
typename T>
337 inline void expectInsideRange(
const T& lower,
const T& value,
const T& upper,
const char* file,
const int line);
352 inline void setFailed(
const char* file,
const int line);
358 [[nodiscard]]
inline virtual bool succeeded()
const;
401#ifndef OCEAN_EXPECT_TRUE
402 #define OCEAN_EXPECT_TRUE(validation, ...) validation.expectTrue(__VA_ARGS__, __FILE__, __LINE__)
405#ifndef OCEAN_EXPECT_FALSE
406 #define OCEAN_EXPECT_FALSE(validation, ...) validation.expectFalse(__VA_ARGS__, __FILE__, __LINE__)
409#ifndef OCEAN_EXPECT_EQUAL
410 #define OCEAN_EXPECT_EQUAL(validation, ...) validation.expectEqual(__VA_ARGS__, __FILE__, __LINE__)
413#ifndef OCEAN_EXPECT_NOT_EQUAL
414 #define OCEAN_EXPECT_NOT_EQUAL(validation, ...) validation.expectNotEqual(__VA_ARGS__, __FILE__, __LINE__)
417#ifndef OCEAN_EXPECT_LESS
418 #define OCEAN_EXPECT_LESS(validation, ...) validation.expectLess(__VA_ARGS__, __FILE__, __LINE__)
421#ifndef OCEAN_EXPECT_LESS_EQUAL
422 #define OCEAN_EXPECT_LESS_EQUAL(validation, ...) validation.expectLessEqual(__VA_ARGS__, __FILE__, __LINE__)
425#ifndef OCEAN_EXPECT_GREATER
426 #define OCEAN_EXPECT_GREATER(validation, ...) validation.expectGreater(__VA_ARGS__, __FILE__, __LINE__)
429#ifndef OCEAN_EXPECT_GREATER_EQUAL
430 #define OCEAN_EXPECT_GREATER_EQUAL(validation, ...) validation.expectGreaterEqual(__VA_ARGS__, __FILE__, __LINE__)
433#ifndef OCEAN_EXPECT_INSIDE_RANGE
434 #define OCEAN_EXPECT_INSIDE_RANGE(validation, ...) validation.expectInsideRange(__VA_ARGS__, __FILE__, __LINE__)
437#ifndef OCEAN_SET_FAILED
438 #define OCEAN_SET_FAILED(validation) validation.setFailed(__FILE__, __LINE__);
442 randomGenerator_(&randomGenerator)
450 ocean_assert(
succeededChecked_ &&
"The validation has not been checked for success");
470 ocean_assert(file !=
nullptr);
473#ifdef OCEAN_USE_GTEST
474 std::cerr <<
"\nValidation::expectTrue() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
498 ocean_assert(file !=
nullptr);
501#ifdef OCEAN_USE_GTEST
502 std::cerr <<
"\nValidation::expectFalse() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
513 if (value0 != value1)
517 if constexpr (Log::isSupported<T>())
531 if (value0 != value1)
535 ocean_assert(file !=
nullptr);
538#ifdef OCEAN_USE_GTEST
539 if constexpr (Log::isSupported<T, std::ostream>())
541 std::cerr <<
"\nValidation::expectEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
545 std::cerr <<
"\nValidation::expectEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
548 if constexpr (Log::isSupported<T>())
564 if (value0 == value1)
568 if constexpr (Log::isSupported<T>())
582 if (value0 == value1)
586 ocean_assert(file !=
nullptr);
589#ifdef OCEAN_USE_GTEST
590 if constexpr (Log::isSupported<T, std::ostream>())
592 std::cerr <<
"\nValidation::expectNotEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
596 std::cerr <<
"\nValidation::expectNotEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
599 if constexpr (Log::isSupported<T>())
601 Log::error() <<
"Validation::expectNotEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
615 if (!(value0 < value1))
619 if constexpr (Log::isSupported<T>())
633 if (!(value0 < value1))
637 ocean_assert(file !=
nullptr);
640#ifdef OCEAN_USE_GTEST
641 if constexpr (Log::isSupported<T, std::ostream>())
643 std::cerr <<
"\nValidation::expectLess(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
647 std::cerr <<
"\nValidation::expectLess() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
650 if constexpr (Log::isSupported<T>())
666 if (!(value0 <= value1))
670 if constexpr (Log::isSupported<T>())
684 if (!(value0 <= value1))
688 ocean_assert(file !=
nullptr);
691#ifdef OCEAN_USE_GTEST
692 if constexpr (Log::isSupported<T, std::ostream>())
694 std::cerr <<
"\nValidation::expectLessEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
698 std::cerr <<
"\nValidation::expectLessEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
701 if constexpr (Log::isSupported<T>())
703 Log::error() <<
"Validation::expectLessEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
717 if (!(value0 > value1))
721 if constexpr (Log::isSupported<T>())
735 if (!(value0 > value1))
739 ocean_assert(file !=
nullptr);
742#ifdef OCEAN_USE_GTEST
743 if constexpr (Log::isSupported<T, std::ostream>())
745 std::cerr <<
"\nValidation::expectGreater(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
749 std::cerr <<
"\nValidation::expectGreater() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
752 if constexpr (Log::isSupported<T>())
754 Log::error() <<
"Validation::expectGreater(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
768 if (!(value0 >= value1))
772 if constexpr (Log::isSupported<T>())
786 if (!(value0 >= value1))
790 ocean_assert(file !=
nullptr);
793#ifdef OCEAN_USE_GTEST
794 if constexpr (Log::isSupported<T, std::ostream>())
796 std::cerr <<
"\nValidation::expectGreaterEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
800 std::cerr <<
"\nValidation::expectGreaterEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
803 if constexpr (Log::isSupported<T>())
805 Log::error() <<
"Validation::expectGreaterEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
819 if (!(lower <= value && value <= upper))
823 if constexpr (Log::isSupported<T>())
825 Log::debug() <<
"Validation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed at unknown location" <<
randomGeneratorOutput();
837 if (!(lower <= value && value <= upper))
841 ocean_assert(file !=
nullptr);
844#ifdef OCEAN_USE_GTEST
845 if constexpr (Log::isSupported<T, std::ostream>())
847 std::cerr <<
"\nValidation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
851 std::cerr <<
"\nValidation::expectInsideRange() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
854 if constexpr (Log::isSupported<T>())
856 Log::error() <<
"Validation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
878 ocean_assert(file !=
nullptr);
881#ifdef OCEAN_USE_GTEST
882 std::cerr <<
"\nValidation::setFailed() in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
910 return std::string();
922 stream <<
"succeeded.";
932template <
bool tActive>
935 if (validation.succeededSoFar())
937 messageObject <<
"succeeded.";
941 messageObject <<
"FAILED!";
944 return messageObject;
947template <
bool tActive>
948MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const Validation& validation)
950 if (validation.succeededSoFar())
952 messageObject <<
"succeeded.";
956 messageObject <<
"FAILED!";
959 return messageObject;
static MessageObject error()
Returns the message for error messages.
Definition Messenger.h:1095
static DebugMessageObject debug()
Returns the message for debug messages.
Definition Messenger.h:1080
Messenger object, one object for each message.
Definition Messenger.h:448
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
unsigned int initialSeed() const
Returns the initial seed value which was used to initialize this random generator.
Definition RandomGenerator.h:192
static std::string toAString(const char value)
Converts a value to a string with 8bit character.
This class implements a helper class to validate tests.
Definition Validation.h:105
bool succeededChecked_
True, if the success state of this validation has been checked.
Definition Validation.h:397
void expectFalse(const bool value)
Informs this validation object that a value is expected to be False.
Definition Validation.h:482
void expectInsideRange(const T &lower, const T &value, const T &upper)
Informs this validation object that a value is expected to be inside a range.
Definition Validation.h:817
bool succeededSoFar() const
Returns whether this validation has succeeded so far.
Definition Validation.h:898
virtual ~Validation()
Destructs this validation object.
Definition Validation.h:447
RandomGenerator * randomGenerator_
Optional random generator object which will be used during validation.
Definition Validation.h:393
virtual bool succeeded() const
Returns if this validation has succeeded.
Definition Validation.h:889
void expectGreaterEqual(const T &value0, const T &value1)
Informs this validation object that a value is expected to be greater than or equal to another value.
Definition Validation.h:766
void expectLessEqual(const T &value0, const T &value1)
Informs this validation object that a value is expected to be less than or equal to another value.
Definition Validation.h:664
void expectNotEqual(const T &value0, const T &value1)
Informs this validation object that a value is expected to be not equal to another value.
Definition Validation.h:562
void setSucceededFalse()
Sets the succeeded state to false.
Definition Validation.h:913
void expectEqual(const T &value0, const T &value1)
Informs this validation object that a value is expected to be equal to another value.
Definition Validation.h:511
Validation(const Validation &)=delete
Disabled copy constructor.
Validation()=default
Default constructor, by default the validation has succeeded.
void expectTrue(const bool value)
Informs this validation object that a value is expected to be True.
Definition Validation.h:454
void expectLess(const T &value0, const T &value1)
Informs this validation object that a value is expected to be less than another value.
Definition Validation.h:613
std::string randomGeneratorOutput() const
Returns a string containing the random generator's initial seed, if any.
Definition Validation.h:903
void expectGreater(const T &value0, const T &value1)
Informs this validation object that a value is expected to be greater than another value.
Definition Validation.h:715
void setFailed()
Explicitly sets the validation to be failed.
Definition Validation.h:867
bool succeeded_
True, if the validation has succeeded; False, if the validation has failed.
Definition Validation.h:390
std::ostream & operator<<(std::ostream &stream, const TestResult &testResult)
Writes a test result to a stream.
Definition TestResult.h:200
The namespace covering the entire Ocean framework.
Definition Accessor.h:15