123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include "sample2.h"
- #include "gtest/gtest.h"
- namespace {
- TEST(MyString, DefaultConstructor) {
- const MyString s;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- EXPECT_STREQ(nullptr, s.c_string());
- EXPECT_EQ(0u, s.Length());
- }
- const char kHelloString[] = "Hello, world!";
- TEST(MyString, ConstructorFromCString) {
- const MyString s(kHelloString);
- EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
- EXPECT_EQ(sizeof(kHelloString)/sizeof(kHelloString[0]) - 1,
- s.Length());
- }
- TEST(MyString, CopyConstructor) {
- const MyString s1(kHelloString);
- const MyString s2 = s1;
- EXPECT_EQ(0, strcmp(s2.c_string(), kHelloString));
- }
- TEST(MyString, Set) {
- MyString s;
- s.Set(kHelloString);
- EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
-
-
- s.Set(s.c_string());
- EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
-
- s.Set(nullptr);
- EXPECT_STREQ(nullptr, s.c_string());
- }
- }
|