diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-10-12 14:50:58 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-10-12 14:50:58 +0200 |
commit | ac6c52c33a7e288e39e876fe031ee4776b11276a (patch) | |
tree | cab71ef4cffc8f17cdba176bbf09ff99559c407d /samples | |
parent | 5f3a8703b307aab697a8fa9045c7135f2c1956c7 (diff) |
Google C++ Testing Framework 1.7.0
Diffstat (limited to 'samples')
-rw-r--r-- | samples/sample10_unittest.cc | 3 | ||||
-rw-r--r-- | samples/sample1_unittest.cc | 2 | ||||
-rw-r--r-- | samples/sample2.h | 1 | ||||
-rw-r--r-- | samples/sample2_unittest.cc | 8 | ||||
-rw-r--r-- | samples/sample3-inl.h | 7 | ||||
-rw-r--r-- | samples/sample5_unittest.cc | 16 |
6 files changed, 17 insertions, 20 deletions
diff --git a/samples/sample10_unittest.cc b/samples/sample10_unittest.cc index 2813d04..0051cd5 100644 --- a/samples/sample10_unittest.cc +++ b/samples/sample10_unittest.cc @@ -89,8 +89,7 @@ class LeakChecker : public EmptyTestEventListener { // You can generate a failure in any event handler except // OnTestPartResult. Just use an appropriate Google Test assertion to do // it. - EXPECT_TRUE(difference <= 0) - << "Leaked " << difference << " unit(s) of Water!"; + EXPECT_LE(difference, 0) << "Leaked " << difference << " unit(s) of Water!"; } int initially_allocated_; diff --git a/samples/sample1_unittest.cc b/samples/sample1_unittest.cc index a8a7c79..aefc4f1 100644 --- a/samples/sample1_unittest.cc +++ b/samples/sample1_unittest.cc @@ -81,7 +81,7 @@ TEST(FactorialTest, Negative) { // test case. EXPECT_EQ(1, Factorial(-5)); EXPECT_EQ(1, Factorial(-1)); - EXPECT_TRUE(Factorial(-10) > 0); + EXPECT_GT(Factorial(-10), 0); // <TechnicalDetails> // diff --git a/samples/sample2.h b/samples/sample2.h index 5b57e60..cb485c7 100644 --- a/samples/sample2.h +++ b/samples/sample2.h @@ -44,7 +44,6 @@ class MyString { const MyString& operator=(const MyString& rhs); public: - // Clones a 0-terminated C string, allocating memory using new. static const char* CloneCString(const char* a_c_string); diff --git a/samples/sample2_unittest.cc b/samples/sample2_unittest.cc index 3792fa5..4fa19b7 100644 --- a/samples/sample2_unittest.cc +++ b/samples/sample2_unittest.cc @@ -79,7 +79,7 @@ const char kHelloString[] = "Hello, world!"; // Tests the c'tor that accepts a C string. TEST(MyString, ConstructorFromCString) { const MyString s(kHelloString); - EXPECT_TRUE(strcmp(s.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); EXPECT_EQ(sizeof(kHelloString)/sizeof(kHelloString[0]) - 1, s.Length()); } @@ -88,7 +88,7 @@ TEST(MyString, ConstructorFromCString) { TEST(MyString, CopyConstructor) { const MyString s1(kHelloString); const MyString s2 = s1; - EXPECT_TRUE(strcmp(s2.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s2.c_string(), kHelloString)); } // Tests the Set method. @@ -96,12 +96,12 @@ TEST(MyString, Set) { MyString s; s.Set(kHelloString); - EXPECT_TRUE(strcmp(s.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); // Set should work when the input pointer is the same as the one // already in the MyString object. s.Set(s.c_string()); - EXPECT_TRUE(strcmp(s.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); // Can we set the MyString to NULL? s.Set(NULL); diff --git a/samples/sample3-inl.h b/samples/sample3-inl.h index 46369a0..7e3084d 100644 --- a/samples/sample3-inl.h +++ b/samples/sample3-inl.h @@ -60,7 +60,7 @@ class QueueNode { private: // Creates a node with a given element value. The next pointer is // set to NULL. - QueueNode(const E& an_element) : element_(an_element), next_(NULL) {} + explicit QueueNode(const E& an_element) : element_(an_element), next_(NULL) {} // We disable the default assignment operator and copy c'tor. const QueueNode& operator = (const QueueNode&); @@ -72,8 +72,7 @@ class QueueNode { template <typename E> // E is the element type. class Queue { -public: - + public: // Creates an empty queue. Queue() : head_(NULL), last_(NULL), size_(0) {} @@ -168,6 +167,6 @@ public: // We disallow copying a queue. Queue(const Queue&); const Queue& operator = (const Queue&); - }; +}; #endif // GTEST_SAMPLES_SAMPLE3_INL_H_ diff --git a/samples/sample5_unittest.cc b/samples/sample5_unittest.cc index e7cab01..43d8e57 100644 --- a/samples/sample5_unittest.cc +++ b/samples/sample5_unittest.cc @@ -101,7 +101,7 @@ TEST_F(IntegerFunctionTest, Factorial) { // Tests factorial of negative numbers. EXPECT_EQ(1, Factorial(-5)); EXPECT_EQ(1, Factorial(-1)); - EXPECT_TRUE(Factorial(-10) > 0); + EXPECT_GT(Factorial(-10), 0); // Tests factorial of 0. EXPECT_EQ(1, Factorial(0)); @@ -117,20 +117,20 @@ TEST_F(IntegerFunctionTest, Factorial) { // Tests IsPrime() TEST_F(IntegerFunctionTest, IsPrime) { // Tests negative input. - EXPECT_TRUE(!IsPrime(-1)); - EXPECT_TRUE(!IsPrime(-2)); - EXPECT_TRUE(!IsPrime(INT_MIN)); + EXPECT_FALSE(IsPrime(-1)); + EXPECT_FALSE(IsPrime(-2)); + EXPECT_FALSE(IsPrime(INT_MIN)); // Tests some trivial cases. - EXPECT_TRUE(!IsPrime(0)); - EXPECT_TRUE(!IsPrime(1)); + EXPECT_FALSE(IsPrime(0)); + EXPECT_FALSE(IsPrime(1)); EXPECT_TRUE(IsPrime(2)); EXPECT_TRUE(IsPrime(3)); // Tests positive input. - EXPECT_TRUE(!IsPrime(4)); + EXPECT_FALSE(IsPrime(4)); EXPECT_TRUE(IsPrime(5)); - EXPECT_TRUE(!IsPrime(6)); + EXPECT_FALSE(IsPrime(6)); EXPECT_TRUE(IsPrime(23)); } |