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>
196 inline void expectLess(
const T& value0,
const T& value1);
209 template <
typename T>
210 inline void expectLess(
const T& value0,
const T& value1,
const char* file,
const int line);
220 template <
typename T>
234 template <
typename T>
235 inline void expectLessEqual(
const T& value0,
const T& value1,
const char* file,
const int line);
245 template <
typename T>
259 template <
typename T>
260 inline void expectGreater(
const T& value0,
const T& value1,
const char* file,
const int line);
270 template <
typename T>
284 template <
typename T>
285 inline void expectGreaterEqual(
const T& value0,
const T& value1,
const char* file,
const int line);
296 template <
typename T>
311 template <
typename T>
312 inline void expectInsideRange(
const T& lower,
const T& value,
const T& upper,
const char* file,
const int line);
327 inline void setFailed(
const char* file,
const int line);
333 [[nodiscard]]
inline bool succeeded()
const;
367 #ifndef OCEAN_EXPECT_TRUE
368 #define OCEAN_EXPECT_TRUE(validation, value) validation.expectTrue(value, __FILE__, __LINE__)
371 #ifndef OCEAN_EXPECT_FALSE
372 #define OCEAN_EXPECT_FALSE(validation, value) validation.expectFalse(value, __FILE__, __LINE__)
375 #ifndef OCEAN_EXPECT_EQUAL
376 #define OCEAN_EXPECT_EQUAL(validation, value0, value1) validation.expectEqual(value0, value1, __FILE__, __LINE__)
379 #ifndef OCEAN_EXPECT_LESS
380 #define OCEAN_EXPECT_LESS(validation, value0, value1) validation.expectLess(value0, value1, __FILE__, __LINE__)
383 #ifndef OCEAN_EXPECT_LESS_EQUAL
384 #define OCEAN_EXPECT_LESS_EQUAL(validation, value0, value1) validation.expectLessEqual(value0, value1, __FILE__, __LINE__)
387 #ifndef OCEAN_EXPECT_GREATER
388 #define OCEAN_EXPECT_GREATER(validation, value0, value1) validation.expectGreater(value0, value1, __FILE__, __LINE__)
391 #ifndef OCEAN_EXPECT_GREATER_EQUAL
392 #define OCEAN_EXPECT_GREATER_EQUAL(validation, value0, value1) validation.expectGreaterEqual(value0, value1, __FILE__, __LINE__)
395 #ifndef OCEAN_EXPECT_INSIDE_RANGE
396 #define OCEAN_EXPECT_INSIDE_RANGE(validation, lower, value, upper) validation.expectInsideRange(lower, value, upper, __FILE__, __LINE__)
399 #ifndef OCEAN_SET_FAILED
400 #define OCEAN_SET_FAILED(validation) validation.setFailed(__FILE__, __LINE__);
404 randomGenerator_(&randomGenerator)
412 ocean_assert(
succeededChecked_ &&
"The validation has not been check for success");
432 ocean_assert(file !=
nullptr);
435 #ifdef OCEAN_USE_GTEST
436 std::cerr <<
"\nValidation::expectTrue() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
460 ocean_assert(file !=
nullptr);
463 #ifdef OCEAN_USE_GTEST
464 std::cerr <<
"\nValidation::expectFalse() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
472 template <
typename T>
475 if (value0 != value1)
479 if constexpr (Log::isSupported<T>())
490 template <
typename T>
493 if (value0 != value1)
497 ocean_assert(file !=
nullptr);
500 #ifdef OCEAN_USE_GTEST
501 if constexpr (Log::isSupported<T, std::ostream>())
503 std::cerr <<
"\nValidation::expectEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
507 std::cerr <<
"\nValidation::expectEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
510 if constexpr (Log::isSupported<T>())
523 template <
typename T>
526 if (!(value0 < value1))
530 if constexpr (Log::isSupported<T>())
541 template <
typename T>
544 if (!(value0 < value1))
548 ocean_assert(file !=
nullptr);
551 #ifdef OCEAN_USE_GTEST
552 if constexpr (Log::isSupported<T, std::ostream>())
554 std::cerr <<
"\nValidation::expectLess(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
558 std::cerr <<
"\nValidation::expectLess() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
561 if constexpr (Log::isSupported<T>())
574 template <
typename T>
577 if (!(value0 <= value1))
581 if constexpr (Log::isSupported<T>())
592 template <
typename T>
595 if (!(value0 <= value1))
599 ocean_assert(file !=
nullptr);
602 #ifdef OCEAN_USE_GTEST
603 if constexpr (Log::isSupported<T, std::ostream>())
605 std::cerr <<
"\nValidation::expectLessEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
609 std::cerr <<
"\nValidation::expectLessEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
612 if constexpr (Log::isSupported<T>())
614 Log::error() <<
"Validation::expectLessEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
625 template <
typename T>
628 if (!(value0 > value1))
632 if constexpr (Log::isSupported<T>())
643 template <
typename T>
646 if (!(value0 > value1))
650 ocean_assert(file !=
nullptr);
653 #ifdef OCEAN_USE_GTEST
654 if constexpr (Log::isSupported<T, std::ostream>())
656 std::cerr <<
"\nValidation::expectGreater(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
660 std::cerr <<
"\nValidation::expectGreater() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
663 if constexpr (Log::isSupported<T>())
665 Log::error() <<
"Validation::expectGreater(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
676 template <
typename T>
679 if (!(value0 >= value1))
683 if constexpr (Log::isSupported<T>())
694 template <
typename T>
697 if (!(value0 >= value1))
701 ocean_assert(file !=
nullptr);
704 #ifdef OCEAN_USE_GTEST
705 if constexpr (Log::isSupported<T, std::ostream>())
707 std::cerr <<
"\nValidation::expectGreaterEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
711 std::cerr <<
"\nValidation::expectGreaterEqual() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
714 if constexpr (Log::isSupported<T>())
716 Log::error() <<
"Validation::expectGreaterEqual(" << value0 <<
", " << value1 <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
727 template <
typename T>
730 if (!(lower <= value && value <= upper))
734 if constexpr (Log::isSupported<T>())
736 Log::debug() <<
"Validation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed at unknown location" <<
randomGeneratorOutput();
745 template <
typename T>
748 if (!(lower <= value && value <= upper))
752 ocean_assert(file !=
nullptr);
755 #ifdef OCEAN_USE_GTEST
756 if constexpr (Log::isSupported<T, std::ostream>())
758 std::cerr <<
"\nValidation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
762 std::cerr <<
"\nValidation::expectInsideRange() failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
765 if constexpr (Log::isSupported<T>())
767 Log::error() <<
"Validation::expectInsideRange(" << lower <<
", " << value <<
", " << upper <<
") failed in '" << file <<
"', in line " << line <<
randomGeneratorOutput();
789 ocean_assert(file !=
nullptr);
792 #ifdef OCEAN_USE_GTEST
793 std::cerr <<
"\nValidation::setFailed() in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
816 return std::string();
828 stream <<
"succeeded.";
838 template <
bool tActive>
841 if (validation.succeeded())
843 messageObject <<
"succeeded.";
847 messageObject <<
"FAILED!";
850 return messageObject;
853 template <
bool tActive>
854 MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const Validation& validation)
856 if (validation.succeeded())
858 messageObject <<
"succeeded.";
862 messageObject <<
"FAILED!";
865 return messageObject;
static MessageObject error()
Returns the message for error messages.
Definition: Messenger.h:1074
static DebugMessageObject debug()
Returns the message for debug messages.
Definition: Messenger.h:1059
Messenger object, one object for each message.
Definition: Messenger.h:427
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:178
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:363
void expectFalse(const bool value)
Informs this validation object that a value is expected to be False.
Definition: Validation.h:444
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:728
~Validation()
Destructs this validation object.
Definition: Validation.h:409
RandomGenerator * randomGenerator_
Optional random generator object which will be used during validation.
Definition: Validation.h:359
bool succeeded() const
Returns if this validation has succeeded.
Definition: Validation.h:800
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:677
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:575
void setSucceededFalse()
Sets the succeeded state to false.
Definition: Validation.h:819
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:473
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:416
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:524
std::string randomGeneratorOutput() const
Returns a string containing the random generator's initial seed, if any.
Definition: Validation.h:809
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:626
void setFailed()
Explicitly sets the validation to be failed.
Definition: Validation.h:778
bool succeeded_
True, if the validation has succeeded; False, if the validation has failed.
Definition: Validation.h:356
std::ostream & operator<<(std::ostream &stream, const Validation &validation)
Definition: Validation.h:824
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15