Trying to use a library
Dependencies: mbed-rtos mbed BlinkLib
Fork of NerfUS by
test/GoogleTestTest.cpp@3:aaf84424abb1, 2017-02-04 (annotated)
- Committer:
- Maxime Dupuis
- Date:
- Sat Feb 04 22:48:36 2017 -0500
- Revision:
- 3:aaf84424abb1
Integrate GoogleTest and GoogleMock
How to build and run the tests:
- mkdir build
- cd build
- cmake ..
- make
- ./run_all_tests
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Maxime Dupuis |
3:aaf84424abb1 | 1 | #include "gtest/gtest.h" |
Maxime Dupuis |
3:aaf84424abb1 | 2 | |
Maxime Dupuis |
3:aaf84424abb1 | 3 | #include <string> |
Maxime Dupuis |
3:aaf84424abb1 | 4 | |
Maxime Dupuis |
3:aaf84424abb1 | 5 | TEST(GoogleTestTest, BasicAssertion) |
Maxime Dupuis |
3:aaf84424abb1 | 6 | { |
Maxime Dupuis |
3:aaf84424abb1 | 7 | ASSERT_TRUE(true); |
Maxime Dupuis |
3:aaf84424abb1 | 8 | ASSERT_FALSE(false); |
Maxime Dupuis |
3:aaf84424abb1 | 9 | } |
Maxime Dupuis |
3:aaf84424abb1 | 10 | |
Maxime Dupuis |
3:aaf84424abb1 | 11 | TEST(GoogleTestTest, BinaryComparison) |
Maxime Dupuis |
3:aaf84424abb1 | 12 | { |
Maxime Dupuis |
3:aaf84424abb1 | 13 | ASSERT_EQ(1, 1); |
Maxime Dupuis |
3:aaf84424abb1 | 14 | ASSERT_NE(1, 2); |
Maxime Dupuis |
3:aaf84424abb1 | 15 | ASSERT_LT(1, 2); |
Maxime Dupuis |
3:aaf84424abb1 | 16 | ASSERT_LE(1, 2); |
Maxime Dupuis |
3:aaf84424abb1 | 17 | ASSERT_GT(3, 2); |
Maxime Dupuis |
3:aaf84424abb1 | 18 | ASSERT_GE(3, 2); |
Maxime Dupuis |
3:aaf84424abb1 | 19 | } |
Maxime Dupuis |
3:aaf84424abb1 | 20 | |
Maxime Dupuis |
3:aaf84424abb1 | 21 | TEST(GoogleTestTest, CStringComparison) |
Maxime Dupuis |
3:aaf84424abb1 | 22 | { |
Maxime Dupuis |
3:aaf84424abb1 | 23 | ASSERT_STREQ("alice", "alice"); |
Maxime Dupuis |
3:aaf84424abb1 | 24 | ASSERT_STRNE("alice", "Alice"); |
Maxime Dupuis |
3:aaf84424abb1 | 25 | ASSERT_STRCASEEQ("alice", "Alice"); |
Maxime Dupuis |
3:aaf84424abb1 | 26 | ASSERT_STRCASENE("alice", "bob"); |
Maxime Dupuis |
3:aaf84424abb1 | 27 | } |
Maxime Dupuis |
3:aaf84424abb1 | 28 | |
Maxime Dupuis |
3:aaf84424abb1 | 29 | TEST(GoogleTestTest, StringComparison) |
Maxime Dupuis |
3:aaf84424abb1 | 30 | { |
Maxime Dupuis |
3:aaf84424abb1 | 31 | ASSERT_EQ(std::string("alice"), std::string("alice")); |
Maxime Dupuis |
3:aaf84424abb1 | 32 | ASSERT_EQ(std::string("alice"), "alice"); |
Maxime Dupuis |
3:aaf84424abb1 | 33 | ASSERT_EQ("alice", std::string("alice")); |
Maxime Dupuis |
3:aaf84424abb1 | 34 | } |
Maxime Dupuis |
3:aaf84424abb1 | 35 | |
Maxime Dupuis |
3:aaf84424abb1 | 36 | TEST(GoogleTestTest, Exceptions) |
Maxime Dupuis |
3:aaf84424abb1 | 37 | { |
Maxime Dupuis |
3:aaf84424abb1 | 38 | ASSERT_THROW(throw std::exception(), std::exception); |
Maxime Dupuis |
3:aaf84424abb1 | 39 | ASSERT_NO_THROW(true); |
Maxime Dupuis |
3:aaf84424abb1 | 40 | } |
Maxime Dupuis |
3:aaf84424abb1 | 41 | |
Maxime Dupuis |
3:aaf84424abb1 | 42 | TEST(GoogleTestTest, FloatingPointsComparison) |
Maxime Dupuis |
3:aaf84424abb1 | 43 | { |
Maxime Dupuis |
3:aaf84424abb1 | 44 | ASSERT_FLOAT_EQ(1.5f, 1.500000000000000000000000001f); |
Maxime Dupuis |
3:aaf84424abb1 | 45 | ASSERT_DOUBLE_EQ(1.5, 1.500000000000000000000000001); |
Maxime Dupuis |
3:aaf84424abb1 | 46 | ASSERT_NEAR(1.5, 1.51, 0.02); |
Maxime Dupuis |
3:aaf84424abb1 | 47 | } |