sample2_unittest.cc (googletest-release-1.11.0) | : | sample2_unittest.cc (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 41 | skipping to change at line 41 | |||
// This sample shows how to write a more complex unit test for a class | // This sample shows how to write a more complex unit test for a class | |||
// that has multiple member functions. | // that has multiple member functions. | |||
// | // | |||
// Usually, it's a good idea to have one test for each method in your | // Usually, it's a good idea to have one test for each method in your | |||
// class. You don't have to do that exactly, but it helps to keep | // class. You don't have to do that exactly, but it helps to keep | |||
// your tests organized. You may also throw in additional tests as | // your tests organized. You may also throw in additional tests as | |||
// needed. | // needed. | |||
#include "sample2.h" | #include "sample2.h" | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
namespace { | namespace { | |||
// In this example, we test the MyString class (a simple string). | // In this example, we test the MyString class (a simple string). | |||
// Tests the default c'tor. | // Tests the default c'tor. | |||
TEST(MyString, DefaultConstructor) { | TEST(MyString, DefaultConstructor) { | |||
const MyString s; | const MyString s; | |||
// Asserts that s.c_string() returns NULL. | // Asserts that s.c_string() returns NULL. | |||
// | // | |||
skipping to change at line 80 | skipping to change at line 81 | |||
EXPECT_EQ(0u, s.Length()); | EXPECT_EQ(0u, s.Length()); | |||
} | } | |||
const char kHelloString[] = "Hello, world!"; | const char kHelloString[] = "Hello, world!"; | |||
// Tests the c'tor that accepts a C string. | // Tests the c'tor that accepts a C string. | |||
TEST(MyString, ConstructorFromCString) { | TEST(MyString, ConstructorFromCString) { | |||
const MyString s(kHelloString); | const MyString s(kHelloString); | |||
EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); | EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); | |||
EXPECT_EQ(sizeof(kHelloString)/sizeof(kHelloString[0]) - 1, | EXPECT_EQ(sizeof(kHelloString) / sizeof(kHelloString[0]) - 1, s.Length()); | |||
s.Length()); | ||||
} | } | |||
// Tests the copy c'tor. | // Tests the copy c'tor. | |||
TEST(MyString, CopyConstructor) { | TEST(MyString, CopyConstructor) { | |||
const MyString s1(kHelloString); | const MyString s1(kHelloString); | |||
const MyString s2 = s1; | const MyString s2 = s1; | |||
EXPECT_EQ(0, strcmp(s2.c_string(), kHelloString)); | EXPECT_EQ(0, strcmp(s2.c_string(), kHelloString)); | |||
} | } | |||
// Tests the Set method. | // Tests the Set method. | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added |