aboutsummaryrefslogtreecommitdiffstats
path: root/googletest/samples
diff options
context:
space:
mode:
authorGennadiy Civil <misterg@google.com>2018-08-20 14:17:38 -0400
committerGennadiy Civil <misterg@google.com>2018-08-20 14:17:38 -0400
commitcfc0d5fb0c59b6e15a991f21cf970e557a698e22 (patch)
tree6b7118860bf0aef941ef7fcebe8c044ffd465011 /googletest/samples
parent72a810596642bceff31b33ea2588902c66fa8e08 (diff)
downloadgoogletest-cfc0d5fb0c59b6e15a991f21cf970e557a698e22.tar.gz
googletest-cfc0d5fb0c59b6e15a991f21cf970e557a698e22.tar.bz2
googletest-cfc0d5fb0c59b6e15a991f21cf970e557a698e22.zip
Testing, adding a few line to sample4
Diffstat (limited to 'googletest/samples')
-rw-r--r--googletest/samples/sample4.cc10
-rw-r--r--googletest/samples/sample4.h4
-rw-r--r--googletest/samples/sample4_unittest.cc7
3 files changed, 21 insertions, 0 deletions
diff --git a/googletest/samples/sample4.cc b/googletest/samples/sample4.cc
index 2f7c87aa..724bcb54 100644
--- a/googletest/samples/sample4.cc
+++ b/googletest/samples/sample4.cc
@@ -38,6 +38,16 @@ int Counter::Increment() {
return counter_++;
}
+// Returns the current counter value, and decrements it.
+// counter can not be less than 0, return 0 in this case
+ int Counter::Decrement() {
+ if (counter_==0){
+ return counter_;
+ }
+ else
+ return counter_--;
+ }
+
// Prints the current counter value to STDOUT.
void Counter::Print() const {
printf("%d", counter_);
diff --git a/googletest/samples/sample4.h b/googletest/samples/sample4.h
index fda5f335..a9679ff1 100644
--- a/googletest/samples/sample4.h
+++ b/googletest/samples/sample4.h
@@ -43,6 +43,10 @@ class Counter {
// Returns the current counter value, and increments it.
int Increment();
+// Returns the current counter value, and decrements it.
+ int Decrement();
+
+
// Prints the current counter value to STDOUT.
void Print() const;
};
diff --git a/googletest/samples/sample4_unittest.cc b/googletest/samples/sample4_unittest.cc
index 079a70d8..ee655c66 100644
--- a/googletest/samples/sample4_unittest.cc
+++ b/googletest/samples/sample4_unittest.cc
@@ -37,12 +37,19 @@ namespace {
TEST(Counter, Increment) {
Counter c;
+ // Test that counter 0 returns 0
+ EXPECT_EQ(0, c.Decrement());
+
+
// EXPECT_EQ() evaluates its arguments exactly once, so they
// can have side effects.
EXPECT_EQ(0, c.Increment());
EXPECT_EQ(1, c.Increment());
EXPECT_EQ(2, c.Increment());
+
+ EXPECT_EQ(3, c.Decrement());
+
}
} // namespace