Skip to content
Snippets Groups Projects
Commit 408d30a5 authored by Jeremie Deray's avatar Jeremie Deray
Browse files

add dummy gtest as an example

parent 0916a699
No related branches found
No related tags found
1 merge request!82Gtest
This commit is part of merge request !82. Comments created here will be created in the context of that merge request.
...@@ -3,3 +3,6 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/test/gtest) ...@@ -3,3 +3,6 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/test/gtest)
include_directories(${GTEST_INCLUDE_DIRS}) 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})
#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();
}
/**
* \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 */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment