diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 441c2b4286ee1293f5fff3d57fd0e3a136ad7b4c..49df9442a8180cf23283e61ca49b328513c01657 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,3 +3,6 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/test/gtest) include_directories(${GTEST_INCLUDE_DIRS}) +# Create a specific test executable for gtest_example +wolf_add_gtest(gtest_example gtest_example.cpp) +target_link_libraries(gtest_example ${PROJECT_NAME}) diff --git a/test/gtest_example.cpp b/test/gtest_example.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c4ae7a14daf9d9923ec040dea90629eb5c32b5d --- /dev/null +++ b/test/gtest_example.cpp @@ -0,0 +1,20 @@ +#include "utils_gtest.h" + +TEST(TestTest, DummyTestExample) +{ + EXPECT_FALSE(false); + + ASSERT_TRUE(true); + + int my_int = 5; + + ASSERT_EQ(my_int, 5); + + PRINTF("All good at TestTest::DummyTestExample !\n"); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/utils_gtest.h b/test/utils_gtest.h new file mode 100644 index 0000000000000000000000000000000000000000..9e792f5a33327dc73dcff5c860f1c9fe53a56709 --- /dev/null +++ b/test/utils_gtest.h @@ -0,0 +1,82 @@ +/** + * \file utils_gtest.h + * \brief Some utils for gtest + * \author Jeremie Deray + * Created on: 26/09/2016 + */ + +#ifndef WOLF_UTILS_GTEST_H +#define WOLF_UTILS_GTEST_H + +#include <gtest/gtest.h> + + +// Macros for testing equalities and inequalities. +// +// * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual +// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2 +// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2 +// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2 +// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2 +// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2 + + +// http://stackoverflow.com/a/29155677 + +namespace testing +{ +namespace internal +{ +enum GTestColor +{ + COLOR_DEFAULT, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW +}; + +extern void ColoredPrintf(GTestColor color, const char* fmt, ...); + +#define PRINTF(...) \ + do { testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN,\ + "[ ] "); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, __VA_ARGS__); } \ + while(0) + +// C++ stream interface +class TestCout : public std::stringstream +{ +public: + ~TestCout() + { + PRINTF("%s\n", str().c_str()); + } +}; + +#define TEST_COUT testing::internal::TestCout() + +} // namespace internal +} // namespace testing + +/** Usage : + +TEST(Test, Foo) +{ + // the following works but prints default stream + EXPECT_TRUE(false) << "Testing Stream."; + + // or you can play with AINSI color code + EXPECT_TRUE(false) << "\033[1;31m" << "Testing Stream."; + + // or use the above defined macros + + PRINTF("Hello world"); + + // or + + TEST_COUT << "Hello world"; +} + +*/ + +#endif /* WOLF_UTILS_GTEST_H */