summaryrefslogtreecommitdiffstats
path: root/googletest/samples
diff options
context:
space:
mode:
Diffstat (limited to 'googletest/samples')
-rw-r--r--googletest/samples/sample10_unittest.cc2
-rw-r--r--googletest/samples/sample2.cc2
-rw-r--r--googletest/samples/sample2.h10
-rw-r--r--googletest/samples/sample2_unittest.cc6
-rw-r--r--googletest/samples/sample3-inl.h16
-rw-r--r--googletest/samples/sample3_unittest.cc10
-rw-r--r--googletest/samples/sample5_unittest.cc12
-rw-r--r--googletest/samples/sample7_unittest.cc2
-rw-r--r--googletest/samples/sample8_unittest.cc11
9 files changed, 35 insertions, 36 deletions
diff --git a/googletest/samples/sample10_unittest.cc b/googletest/samples/sample10_unittest.cc
index 7ce9550..3da2158 100644
--- a/googletest/samples/sample10_unittest.cc
+++ b/googletest/samples/sample10_unittest.cc
@@ -100,7 +100,7 @@ TEST(ListenersTest, DoesNotLeak) {
// specified.
TEST(ListenersTest, LeaksWater) {
Water* water = new Water;
- EXPECT_TRUE(water != NULL);
+ EXPECT_TRUE(water != nullptr);
}
} // namespace
diff --git a/googletest/samples/sample2.cc b/googletest/samples/sample2.cc
index f3b722f..d8e8723 100644
--- a/googletest/samples/sample2.cc
+++ b/googletest/samples/sample2.cc
@@ -35,7 +35,7 @@
// Clones a 0-terminated C string, allocating memory using new.
const char* MyString::CloneCString(const char* a_c_string) {
- if (a_c_string == NULL) return NULL;
+ if (a_c_string == nullptr) return nullptr;
const size_t len = strlen(a_c_string);
char* const clone = new char[ len + 1 ];
diff --git a/googletest/samples/sample2.h b/googletest/samples/sample2.h
index 58f360f..e9a5a70 100644
--- a/googletest/samples/sample2.h
+++ b/googletest/samples/sample2.h
@@ -50,15 +50,15 @@ class MyString {
// C'tors
// The default c'tor constructs a NULL string.
- MyString() : c_string_(NULL) {}
+ MyString() : c_string_(nullptr) {}
// Constructs a MyString by cloning a 0-terminated C string.
- explicit MyString(const char* a_c_string) : c_string_(NULL) {
+ explicit MyString(const char* a_c_string) : c_string_(nullptr) {
Set(a_c_string);
}
// Copy c'tor
- MyString(const MyString& string) : c_string_(NULL) {
+ MyString(const MyString& string) : c_string_(nullptr) {
Set(string.c_string_);
}
@@ -71,9 +71,7 @@ class MyString {
// Gets the 0-terminated C string this MyString object represents.
const char* c_string() const { return c_string_; }
- size_t Length() const {
- return c_string_ == NULL ? 0 : strlen(c_string_);
- }
+ size_t Length() const { return c_string_ == nullptr ? 0 : strlen(c_string_); }
// Sets the 0-terminated C string this MyString object represents.
void Set(const char* c_string);
diff --git a/googletest/samples/sample2_unittest.cc b/googletest/samples/sample2_unittest.cc
index 0848826..41e31c1 100644
--- a/googletest/samples/sample2_unittest.cc
+++ b/googletest/samples/sample2_unittest.cc
@@ -66,7 +66,7 @@ TEST(MyString, DefaultConstructor) {
// we have to live with this fact.
//
// </TechnicalDetails>
- EXPECT_STREQ(NULL, s.c_string());
+ EXPECT_STREQ(nullptr, s.c_string());
EXPECT_EQ(0u, s.Length());
}
@@ -101,7 +101,7 @@ TEST(MyString, Set) {
EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
// Can we set the MyString to NULL?
- s.Set(NULL);
- EXPECT_STREQ(NULL, s.c_string());
+ s.Set(nullptr);
+ EXPECT_STREQ(nullptr, s.c_string());
}
} // namespace
diff --git a/googletest/samples/sample3-inl.h b/googletest/samples/sample3-inl.h
index 1a29ce9..80ba6b9 100644
--- a/googletest/samples/sample3-inl.h
+++ b/googletest/samples/sample3-inl.h
@@ -58,7 +58,8 @@ class QueueNode {
private:
// Creates a node with a given element value. The next pointer is
// set to NULL.
- explicit QueueNode(const E& an_element) : element_(an_element), next_(NULL) {}
+ explicit QueueNode(const E& an_element)
+ : element_(an_element), next_(nullptr) {}
// We disable the default assignment operator and copy c'tor.
const QueueNode& operator = (const QueueNode&);
@@ -72,7 +73,7 @@ template <typename E> // E is the element type.
class Queue {
public:
// Creates an empty queue.
- Queue() : head_(NULL), last_(NULL), size_(0) {}
+ Queue() : head_(nullptr), last_(nullptr), size_(0) {}
// D'tor. Clears the queue.
~Queue() { Clear(); }
@@ -86,12 +87,12 @@ class Queue {
for (; ;) {
delete node;
node = next;
- if (node == NULL) break;
+ if (node == nullptr) break;
next = node->next();
}
// 2. Resets the member variables.
- head_ = last_ = NULL;
+ head_ = last_ = nullptr;
size_ = 0;
}
}
@@ -128,14 +129,14 @@ class Queue {
// the queue is empty.
E* Dequeue() {
if (size_ == 0) {
- return NULL;
+ return nullptr;
}
const QueueNode<E>* const old_head = head_;
head_ = head_->next_;
size_--;
if (size_ == 0) {
- last_ = NULL;
+ last_ = nullptr;
}
E* element = new E(old_head->element());
@@ -150,7 +151,8 @@ class Queue {
template <typename F>
Queue* Map(F function) const {
Queue* new_queue = new Queue();
- for (const QueueNode<E>* node = head_; node != NULL; node = node->next_) {
+ for (const QueueNode<E>* node = head_; node != nullptr;
+ node = node->next_) {
new_queue->Enqueue(function(node->element()));
}
diff --git a/googletest/samples/sample3_unittest.cc b/googletest/samples/sample3_unittest.cc
index e093c25..97ce55d 100644
--- a/googletest/samples/sample3_unittest.cc
+++ b/googletest/samples/sample3_unittest.cc
@@ -99,8 +99,8 @@ class QueueTestSmpl3 : public testing::Test {
ASSERT_EQ(q->Size(), new_q->Size());
// Verifies the relationship between the elements of the two queues.
- for ( const QueueNode<int> * n1 = q->Head(), * n2 = new_q->Head();
- n1 != NULL; n1 = n1->next(), n2 = n2->next() ) {
+ for (const QueueNode<int>*n1 = q->Head(), *n2 = new_q->Head();
+ n1 != nullptr; n1 = n1->next(), n2 = n2->next()) {
EXPECT_EQ(2 * n1->element(), n2->element());
}
@@ -125,16 +125,16 @@ TEST_F(QueueTestSmpl3, DefaultConstructor) {
// Tests Dequeue().
TEST_F(QueueTestSmpl3, Dequeue) {
int * n = q0_.Dequeue();
- EXPECT_TRUE(n == NULL);
+ EXPECT_TRUE(n == nullptr);
n = q1_.Dequeue();
- ASSERT_TRUE(n != NULL);
+ ASSERT_TRUE(n != nullptr);
EXPECT_EQ(1, *n);
EXPECT_EQ(0u, q1_.Size());
delete n;
n = q2_.Dequeue();
- ASSERT_TRUE(n != NULL);
+ ASSERT_TRUE(n != nullptr);
EXPECT_EQ(2, *n);
EXPECT_EQ(1u, q2_.Size());
delete n;
diff --git a/googletest/samples/sample5_unittest.cc b/googletest/samples/sample5_unittest.cc
index d8a8788..e71b903 100644
--- a/googletest/samples/sample5_unittest.cc
+++ b/googletest/samples/sample5_unittest.cc
@@ -63,15 +63,13 @@ class QuickTest : public testing::Test {
protected:
// Remember that SetUp() is run immediately before a test starts.
// This is a good place to record the start time.
- virtual void SetUp() {
- start_time_ = time(NULL);
- }
+ virtual void SetUp() { start_time_ = time(nullptr); }
// TearDown() is invoked immediately after a test finishes. Here we
// check if the test was too slow.
virtual void TearDown() {
// Gets the time when the test finishes
- const time_t end_time = time(NULL);
+ const time_t end_time = time(nullptr);
// Asserts that the test took no more than ~5 seconds. Did you
// know that you can use assertions in SetUp() and TearDown() as
@@ -176,16 +174,16 @@ TEST_F(QueueTest, DefaultConstructor) {
// Tests Dequeue().
TEST_F(QueueTest, Dequeue) {
int* n = q0_.Dequeue();
- EXPECT_TRUE(n == NULL);
+ EXPECT_TRUE(n == nullptr);
n = q1_.Dequeue();
- EXPECT_TRUE(n != NULL);
+ EXPECT_TRUE(n != nullptr);
EXPECT_EQ(1, *n);
EXPECT_EQ(0u, q1_.Size());
delete n;
n = q2_.Dequeue();
- EXPECT_TRUE(n != NULL);
+ EXPECT_TRUE(n != nullptr);
EXPECT_EQ(2, *n);
EXPECT_EQ(1u, q2_.Size());
delete n;
diff --git a/googletest/samples/sample7_unittest.cc b/googletest/samples/sample7_unittest.cc
index c1ae8bd..e1e09b0 100644
--- a/googletest/samples/sample7_unittest.cc
+++ b/googletest/samples/sample7_unittest.cc
@@ -69,7 +69,7 @@ class PrimeTableTestSmpl7 : public TestWithParam<CreatePrimeTableFunc*> {
virtual void SetUp() { table_ = (*GetParam())(); }
virtual void TearDown() {
delete table_;
- table_ = NULL;
+ table_ = nullptr;
}
protected:
diff --git a/googletest/samples/sample8_unittest.cc b/googletest/samples/sample8_unittest.cc
index ce75cf0..ccf5aed 100644
--- a/googletest/samples/sample8_unittest.cc
+++ b/googletest/samples/sample8_unittest.cc
@@ -50,8 +50,9 @@ class HybridPrimeTable : public PrimeTable {
public:
HybridPrimeTable(bool force_on_the_fly, int max_precalculated)
: on_the_fly_impl_(new OnTheFlyPrimeTable),
- precalc_impl_(force_on_the_fly ? NULL :
- new PreCalculatedPrimeTable(max_precalculated)),
+ precalc_impl_(force_on_the_fly
+ ? nullptr
+ : new PreCalculatedPrimeTable(max_precalculated)),
max_precalculated_(max_precalculated) {}
virtual ~HybridPrimeTable() {
delete on_the_fly_impl_;
@@ -59,7 +60,7 @@ class HybridPrimeTable : public PrimeTable {
}
virtual bool IsPrime(int n) const {
- if (precalc_impl_ != NULL && n < max_precalculated_)
+ if (precalc_impl_ != nullptr && n < max_precalculated_)
return precalc_impl_->IsPrime(n);
else
return on_the_fly_impl_->IsPrime(n);
@@ -67,7 +68,7 @@ class HybridPrimeTable : public PrimeTable {
virtual int GetNextPrime(int p) const {
int next_prime = -1;
- if (precalc_impl_ != NULL && p < max_precalculated_)
+ if (precalc_impl_ != nullptr && p < max_precalculated_)
next_prime = precalc_impl_->GetNextPrime(p);
return next_prime != -1 ? next_prime : on_the_fly_impl_->GetNextPrime(p);
@@ -106,7 +107,7 @@ class PrimeTableTest : public TestWithParam< ::testing::tuple<bool, int> > {
}
virtual void TearDown() {
delete table_;
- table_ = NULL;
+ table_ = nullptr;
}
HybridPrimeTable* table_;
};