summaryrefslogtreecommitdiffstats
path: root/googletest/samples
diff options
context:
space:
mode:
authormisterg <misterg@google.com>2018-08-20 18:48:03 (GMT)
committerGennadiy Civil <misterg@google.com>2018-08-20 18:50:41 (GMT)
commit5891bb530736c39568f61ba0bf1a45d60d40f76e (patch)
tree647daff4dfe981d8dd27b4f2d2ed0acd6faef59e /googletest/samples
parent9404c5ae04312630638a95da1435ee8a9c74ffe8 (diff)
downloadgoogletest-5891bb530736c39568f61ba0bf1a45d60d40f76e.zip
googletest-5891bb530736c39568f61ba0bf1a45d60d40f76e.tar.gz
googletest-5891bb530736c39568f61ba0bf1a45d60d40f76e.tar.bz2
googletest export
- 209457486 Import of OSS PR, https://github.com/google/googletest/pu... by misterg <misterg@google.com> PiperOrigin-RevId: 209457486
Diffstat (limited to 'googletest/samples')
-rw-r--r--googletest/samples/sample4.cc10
-rw-r--r--googletest/samples/sample4.h3
-rw-r--r--googletest/samples/sample4_unittest.cc5
3 files changed, 18 insertions, 0 deletions
diff --git a/googletest/samples/sample4.cc b/googletest/samples/sample4.cc
index 2f7c87a..b0ee609 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 fda5f33..e256f40 100644
--- a/googletest/samples/sample4.h
+++ b/googletest/samples/sample4.h
@@ -43,6 +43,9 @@ 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 079a70d..d5144c0 100644
--- a/googletest/samples/sample4_unittest.cc
+++ b/googletest/samples/sample4_unittest.cc
@@ -37,12 +37,17 @@ 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