proxygen
sample2_unittest.cc File Reference
#include "sample2.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (MyString, DefaultConstructor)
 
 TEST (MyString, ConstructorFromCString)
 
 TEST (MyString, CopyConstructor)
 
 TEST (MyString, Set)
 

Variables

const char kHelloString [] = "Hello, world!"
 

Function Documentation

TEST ( MyString  ,
DefaultConstructor   
)

Definition at line 49 of file sample2_unittest.cc.

References MyString::c_string(), EXPECT_EQ, EXPECT_STREQ, MyString::Length(), and s.

49  {
50  const MyString s;
51 
52  // Asserts that s.c_string() returns NULL.
53  //
54  // <TechnicalDetails>
55  //
56  // If we write NULL instead of
57  //
58  // static_cast<const char *>(NULL)
59  //
60  // in this assertion, it will generate a warning on gcc 3.4. The
61  // reason is that EXPECT_EQ needs to know the types of its
62  // arguments in order to print them when it fails. Since NULL is
63  // #defined as 0, the compiler will use the formatter function for
64  // int to print it. However, gcc thinks that NULL should be used as
65  // a pointer, not an int, and therefore complains.
66  //
67  // The root of the problem is C++'s lack of distinction between the
68  // integer number 0 and the null pointer constant. Unfortunately,
69  // we have to live with this fact.
70  //
71  // </TechnicalDetails>
72  EXPECT_STREQ(NULL, s.c_string());
73 
74  EXPECT_EQ(0u, s.Length());
75 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
size_t Length() const
Definition: sample2.h:76
static set< string > s
const char * c_string() const
Definition: sample2.h:74
TEST ( MyString  ,
ConstructorFromCString   
)

Definition at line 80 of file sample2_unittest.cc.

References MyString::c_string(), EXPECT_EQ, kHelloString, MyString::Length(), and s.

80  {
81  const MyString s(kHelloString);
82  EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
83  EXPECT_EQ(sizeof(kHelloString)/sizeof(kHelloString[0]) - 1,
84  s.Length());
85 }
const char kHelloString[]
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static set< string > s
TEST ( MyString  ,
CopyConstructor   
)

Definition at line 88 of file sample2_unittest.cc.

References MyString::c_string(), EXPECT_EQ, and kHelloString.

88  {
89  const MyString s1(kHelloString);
90  const MyString s2 = s1;
91  EXPECT_EQ(0, strcmp(s2.c_string(), kHelloString));
92 }
const char kHelloString[]
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const char * c_string() const
Definition: sample2.h:74
TEST ( MyString  ,
Set   
)

Definition at line 95 of file sample2_unittest.cc.

References MyString::c_string(), EXPECT_EQ, EXPECT_STREQ, kHelloString, s, and MyString::Set().

95  {
96  MyString s;
97 
98  s.Set(kHelloString);
99  EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
100 
101  // Set should work when the input pointer is the same as the one
102  // already in the MyString object.
103  s.Set(s.c_string());
104  EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
105 
106  // Can we set the MyString to NULL?
107  s.Set(NULL);
108  EXPECT_STREQ(NULL, s.c_string());
109 }
const char kHelloString[]
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
void Set(const char *c_string)
Definition: sample2.cc:51
static set< string > s
const char * c_string() const
Definition: sample2.h:74

Variable Documentation

const char kHelloString[] = "Hello, world!"

Definition at line 77 of file sample2_unittest.cc.