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 bool succeeded()
const;
392#ifndef OCEAN_EXPECT_TRUE
393 #define OCEAN_EXPECT_TRUE(validation, ...) validation.expectTrue(__VA_ARGS__, __FILE__, __LINE__)
396#ifndef OCEAN_EXPECT_FALSE
397 #define OCEAN_EXPECT_FALSE(validation, ...) validation.expectFalse(__VA_ARGS__, __FILE__, __LINE__)
400#ifndef OCEAN_EXPECT_EQUAL
401 #define OCEAN_EXPECT_EQUAL(validation, ...) validation.expectEqual(__VA_ARGS__, __FILE__, __LINE__)
404#ifndef OCEAN_EXPECT_NOT_EQUAL
405 #define OCEAN_EXPECT_NOT_EQUAL(validation, ...) validation.expectNotEqual(__VA_ARGS__, __FILE__, __LINE__)
408#ifndef OCEAN_EXPECT_LESS
409 #define OCEAN_EXPECT_LESS(validation, ...) validation.expectLess(__VA_ARGS__, __FILE__, __LINE__)
412#ifndef OCEAN_EXPECT_LESS_EQUAL
413 #define OCEAN_EXPECT_LESS_EQUAL(validation, ...) validation.expectLessEqual(__VA_ARGS__, __FILE__, __LINE__)
416#ifndef OCEAN_EXPECT_GREATER
417 #define OCEAN_EXPECT_GREATER(validation, ...) validation.expectGreater(__VA_ARGS__, __FILE__, __LINE__)
420#ifndef OCEAN_EXPECT_GREATER_EQUAL
421 #define OCEAN_EXPECT_GREATER_EQUAL(validation, ...) validation.expectGreaterEqual(__VA_ARGS__, __FILE__, __LINE__)
424#ifndef OCEAN_EXPECT_INSIDE_RANGE
425 #define OCEAN_EXPECT_INSIDE_RANGE(validation, ...) validation.expectInsideRange(__VA_ARGS__, __FILE__, __LINE__)
428#ifndef OCEAN_SET_FAILED
429 #define OCEAN_SET_FAILED(validation) validation.setFailed(__FILE__, __LINE__);
433 randomGenerator_(&randomGenerator)
441 ocean_assert(
succeededChecked_ &&
"The validation has not been check for success");
461 ocean_assert(file !=
nullptr);
464#ifdef OCEAN_USE_GTEST
465 std::cerr <<
"\nValidation::expectTrue() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
489 ocean_assert(file !=
nullptr);
492#ifdef OCEAN_USE_GTEST
493 std::cerr <<
"\nValidation::expectFalse() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
504 if (value0 != value1)
508 if constexpr (Log::isSupported<T>())
522 if (value0 != value1)
526 ocean_assert(file !=
nullptr);
529#ifdef OCEAN_USE_GTEST
530 if constexpr (Log::isSupported<T, std::ostream>())
532 std::cerr <<
"\nValidation::expectEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
536 std::cerr <<
"\nValidation::expectEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
539 if constexpr (Log::isSupported<T>())
555 if (value0 == value1)
559 if constexpr (Log::isSupported<T>())
573 if (value0 == value1)
577 ocean_assert(file !=
nullptr);
580#ifdef OCEAN_USE_GTEST
581 if constexpr (Log::isSupported<T, std::ostream>())
583 std::cerr <<
"\nValidation::expectNotEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
587 std::cerr <<
"\nValidation::expectNotEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
590 if constexpr (Log::isSupported<T>())
592 Log::error() <<
"Validation::expectNotEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
606 if (!(value0 < value1))
610 if constexpr (Log::isSupported<T>())
624 if (!(value0 < value1))
628 ocean_assert(file !=
nullptr);
631#ifdef OCEAN_USE_GTEST
632 if constexpr (Log::isSupported<T, std::ostream>())
634 std::cerr <<
"\nValidation::expectLess(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
638 std::cerr <<
"\nValidation::expectLess() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
641 if constexpr (Log::isSupported<T>())
657 if (!(value0 <= value1))
661 if constexpr (Log::isSupported<T>())
675 if (!(value0 <= value1))
679 ocean_assert(file !=
nullptr);
682#ifdef OCEAN_USE_GTEST
683 if constexpr (Log::isSupported<T, std::ostream>())
685 std::cerr <<
"\nValidation::expectLessEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
689 std::cerr <<
"\nValidation::expectLessEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
692 if constexpr (Log::isSupported<T>())
694 Log::error() <<
"Validation::expectLessEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
708 if (!(value0 > value1))
712 if constexpr (Log::isSupported<T>())
726 if (!(value0 > value1))
730 ocean_assert(file !=
nullptr);
733#ifdef OCEAN_USE_GTEST
734 if constexpr (Log::isSupported<T, std::ostream>())
736 std::cerr <<
"\nValidation::expectGreater(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
740 std::cerr <<
"\nValidation::expectGreater() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
743 if constexpr (Log::isSupported<T>())
745 Log::error() <<
"Validation::expectGreater(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
759 if (!(value0 >= value1))
763 if constexpr (Log::isSupported<T>())
777 if (!(value0 >= value1))
781 ocean_assert(file !=
nullptr);
784#ifdef OCEAN_USE_GTEST
785 if constexpr (Log::isSupported<T, std::ostream>())
787 std::cerr <<
"\nValidation::expectGreaterEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
791 std::cerr <<
"\nValidation::expectGreaterEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
794 if constexpr (Log::isSupported<T>())
796 Log::error() <<
"Validation::expectGreaterEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
810 if (!(lower <= value && value <= upper))
814 if constexpr (Log::isSupported<T>())
816 Log::debug() <<
"Validation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed at unknown location" <<
randomGeneratorOutput();
828 if (!(lower <= value && value <= upper))
832 ocean_assert(file !=
nullptr);
835#ifdef OCEAN_USE_GTEST
836 if constexpr (Log::isSupported<T, std::ostream>())
838 std::cerr <<
"\nValidation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
842 std::cerr <<
"\nValidation::expectInsideRange() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
845 if constexpr (Log::isSupported<T>())
847 Log::error() <<
"Validation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
869 ocean_assert(file !=
nullptr);
872#ifdef OCEAN_USE_GTEST
873 std::cerr <<
"\nValidation::setFailed() in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
896 return std::string();
908 stream <<
"succeeded.";
918template <
bool tActive>
921 if (validation.succeeded())
923 messageObject <<
"succeeded.";
927 messageObject <<
"FAILED!";
930 return messageObject;
933template <
bool tActive>
934MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const Validation& validation)
936 if (validation.succeeded())
938 messageObject <<
"succeeded.";
942 messageObject <<
"FAILED!";
945 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:388
void expectFalse(const bool value)
Informs this validation object that a value is expected to be False.
Definition Validation.h:473
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:808
~Validation()
Destructs this validation object.
Definition Validation.h:438
RandomGenerator * randomGenerator_
Optional random generator object which will be used during validation.
Definition Validation.h:384
bool succeeded() const
Returns if this validation has succeeded.
Definition Validation.h:880
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:757
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:655
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:553
void setSucceededFalse()
Sets the succeeded state to false.
Definition Validation.h:899
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:502
Validation(const Validation &)=delete
Disabled copy constructor.
Validation()=default
Default constructor, by default the verified has succeeded.
void expectTrue(const bool value)
Informs this validation object that a value is expected to be True.
Definition Validation.h:445
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:604
std::string randomGeneratorOutput() const
Returns a string containing the random generator's initial seed, if any.
Definition Validation.h:889
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:706
void setFailed()
Explicitly sets the validation to be failed.
Definition Validation.h:858
bool succeeded_
True, if the validation has succeeded; False, if the validation has failed.
Definition Validation.h:381
std::ostream & operator<<(std::ostream &stream, const Validation &validation)
Definition Validation.h:904
The namespace covering the entire Ocean framework.
Definition Accessor.h:15