From 408d30a574a587b7bfac553277feb2a73424d7df Mon Sep 17 00:00:00 2001
From: Jeremie Deray <jeremie.deray@pal-robotics.com>
Date: Tue, 4 Oct 2016 19:21:47 +0200
Subject: [PATCH] add dummy gtest as an example

---
 test/CMakeLists.txt    |  3 ++
 test/gtest_example.cpp | 20 +++++++++++
 test/utils_gtest.h     | 82 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+)
 create mode 100644 test/gtest_example.cpp
 create mode 100644 test/utils_gtest.h

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 441c2b428..49df9442a 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 000000000..9c4ae7a14
--- /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 000000000..9e792f5a3
--- /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 */
-- 
GitLab