aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp
diff options
context:
space:
mode:
authorVasily Gerasimov <UgnineSirdis@gmail.com>2022-02-10 16:49:10 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:10 +0300
commit1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp
parent6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff)
downloadydb-1eb755fbca92172a6aec2f57371b2b3a19dfab43.tar.gz
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp')
-rw-r--r--library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp182
1 files changed, 91 insertions, 91 deletions
diff --git a/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp b/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp
index a6c12b3e5a..97f19050e4 100644
--- a/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp
+++ b/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp
@@ -1,105 +1,105 @@
#include <library/cpp/testing/gmock_in_unittest/gmock.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/generic/string.h>
-
-// Set this variable to true if you want to see failures
-/////////////////////////////////////////////////////////
-static const bool fail = false;
-/////////////////////////////////////////////////////////
-
-class ITestIface {
-public:
- virtual ~ITestIface() {
- }
-
- virtual void Func1() = 0;
-
+
+// Set this variable to true if you want to see failures
+/////////////////////////////////////////////////////////
+static const bool fail = false;
+/////////////////////////////////////////////////////////
+
+class ITestIface {
+public:
+ virtual ~ITestIface() {
+ }
+
+ virtual void Func1() = 0;
+
virtual int Func2(const TString&) const = 0;
-};
-
-class TTestMock: public ITestIface {
-public:
+};
+
+class TTestMock: public ITestIface {
+public:
MOCK_METHOD(void, Func1, (), (override));
MOCK_METHOD(int, Func2, (const TString&), (const, override));
-};
-
-using namespace testing;
-
+};
+
+using namespace testing;
+
Y_UNIT_TEST_SUITE(TExampleGMockTest) {
Y_UNIT_TEST(TSimpleTest) {
- TTestMock mock;
- EXPECT_CALL(mock, Func1())
- .Times(AtLeast(1));
-
- if (!fail) {
- mock.Func1();
- }
- }
-
+ TTestMock mock;
+ EXPECT_CALL(mock, Func1())
+ .Times(AtLeast(1));
+
+ if (!fail) {
+ mock.Func1();
+ }
+ }
+
Y_UNIT_TEST(TNonExpectedCallTest) {
- TTestMock mock;
- EXPECT_CALL(mock, Func1())
- .Times(AtMost(1));
- mock.Func1();
- if (fail) {
- mock.Func1();
- }
- }
-
+ TTestMock mock;
+ EXPECT_CALL(mock, Func1())
+ .Times(AtMost(1));
+ mock.Func1();
+ if (fail) {
+ mock.Func1();
+ }
+ }
+
Y_UNIT_TEST(TReturnValuesTest) {
- TTestMock mock;
+ TTestMock mock;
EXPECT_CALL(mock, Func2(TString("1")))
- .WillOnce(Return(1))
- .WillRepeatedly(Return(42));
-
+ .WillOnce(Return(1))
+ .WillRepeatedly(Return(42));
+
EXPECT_CALL(mock, Func2(TString("hello")))
- .WillOnce(Return(-1));
-
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("hello"), -1);
-
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 1);
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
-
- if (fail) {
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("hello"), -1); // expected to return -1 only once
- }
- }
-
+ .WillOnce(Return(-1));
+
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("hello"), -1);
+
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 1);
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("1"), 42);
+
+ if (fail) {
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("hello"), -1); // expected to return -1 only once
+ }
+ }
+
Y_UNIT_TEST(TStrictCallSequenceTest) {
- TTestMock mock;
- {
- InSequence seq;
- EXPECT_CALL(mock, Func1())
- .Times(1);
- EXPECT_CALL(mock, Func2(_))
- .Times(2)
- .WillOnce(Return(1))
- .WillOnce(Return(2));
- EXPECT_CALL(mock, Func1());
- }
- mock.Func1();
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2("sample"), 1);
- if (fail) {
- mock.Func1();
- }
- UNIT_ASSERT_VALUES_EQUAL(mock.Func2(""), 2);
- if (!fail) {
- mock.Func1();
- }
- }
-
+ TTestMock mock;
+ {
+ InSequence seq;
+ EXPECT_CALL(mock, Func1())
+ .Times(1);
+ EXPECT_CALL(mock, Func2(_))
+ .Times(2)
+ .WillOnce(Return(1))
+ .WillOnce(Return(2));
+ EXPECT_CALL(mock, Func1());
+ }
+ mock.Func1();
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2("sample"), 1);
+ if (fail) {
+ mock.Func1();
+ }
+ UNIT_ASSERT_VALUES_EQUAL(mock.Func2(""), 2);
+ if (!fail) {
+ mock.Func1();
+ }
+ }
+
Y_UNIT_TEST(TUninterestingMethodIsFailureTest) {
- StrictMock<TTestMock> mock;
- EXPECT_CALL(mock, Func1())
- .Times(1);
- mock.Func1();
- if (fail) {
- mock.Func1();
- }
- }
-}
+ StrictMock<TTestMock> mock;
+ EXPECT_CALL(mock, Func1())
+ .Times(1);
+ mock.Func1();
+ if (fail) {
+ mock.Func1();
+ }
+ }
+}