aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/unittest/ut
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/testing/unittest/ut
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/testing/unittest/ut')
-rw-r--r--library/cpp/testing/unittest/ut/main.cpp93
-rw-r--r--library/cpp/testing/unittest/ut/ya.make10
2 files changed, 103 insertions, 0 deletions
diff --git a/library/cpp/testing/unittest/ut/main.cpp b/library/cpp/testing/unittest/ut/main.cpp
new file mode 100644
index 0000000000..e303e21e30
--- /dev/null
+++ b/library/cpp/testing/unittest/ut/main.cpp
@@ -0,0 +1,93 @@
+#include <library/cpp/testing/unittest/gtest.h>
+#include <library/cpp/testing/unittest/registar.h>
+#include <library/cpp/testing/unittest/tests_data.h>
+
+#include <util/generic/set.h>
+#include <util/network/sock.h>
+#include <util/system/env.h>
+#include <util/system/fs.h>
+
+TEST(GTest, Test1) {
+ UNIT_ASSERT_EQUAL(1, 1);
+}
+
+TEST(GTest, Test2) {
+ UNIT_ASSERT_EQUAL(2, 2);
+}
+
+namespace {
+ struct TFixture : ::testing::Test {
+ TFixture()
+ : I(0)
+ {
+ }
+
+ void SetUp() override {
+ I = 5;
+ }
+
+ int I;
+ };
+
+ struct TSimpleFixture : public NUnitTest::TBaseFixture {
+ size_t Value = 24;
+ };
+
+ struct TOtherFixture : public NUnitTest::TBaseFixture {
+ size_t TheAnswer = 42;
+ };
+
+ struct TSetUpTearDownFixture : public NUnitTest::TBaseFixture {
+ int Magic = 3;
+
+ void SetUp(NUnitTest::TTestContext&) override {
+ UNIT_ASSERT_VALUES_EQUAL(Magic, 3);
+ Magic = 17;
+ }
+
+ void TearDown(NUnitTest::TTestContext&) override {
+ UNIT_ASSERT_VALUES_EQUAL(Magic, 42);
+ Magic = 100;
+ }
+ };
+}
+
+TEST_F(TFixture, Test1) {
+ ASSERT_EQ(I, 5);
+}
+
+TEST(ETest, Test1) {
+ UNIT_CHECK_GENERATED_EXCEPTION(ythrow yexception(), yexception);
+ UNIT_CHECK_GENERATED_NO_EXCEPTION(true, yexception);
+}
+
+Y_UNIT_TEST_SUITE(TestSingleTestFixture)
+{
+ Y_UNIT_TEST_F(Test3, TSimpleFixture) {
+ UNIT_ASSERT_EQUAL(Value, 24);
+ }
+}
+
+Y_UNIT_TEST_SUITE_F(TestSuiteFixture, TSimpleFixture)
+{
+ Y_UNIT_TEST(Test1) {
+ UNIT_ASSERT(Value == 24);
+ Value = 25;
+ }
+
+ Y_UNIT_TEST(Test2) {
+ UNIT_ASSERT_EQUAL(Value, 24);
+ }
+
+ Y_UNIT_TEST_F(Test3, TOtherFixture) {
+ UNIT_ASSERT_EQUAL(TheAnswer, 42);
+ }
+}
+
+Y_UNIT_TEST_SUITE(TestSetUpTearDownFixture)
+{
+ Y_UNIT_TEST_F(Test1, TSetUpTearDownFixture) {
+ UNIT_ASSERT_VALUES_EQUAL(Magic, 17);
+ Magic = 42;
+ }
+}
diff --git a/library/cpp/testing/unittest/ut/ya.make b/library/cpp/testing/unittest/ut/ya.make
new file mode 100644
index 0000000000..6d4c0959cc
--- /dev/null
+++ b/library/cpp/testing/unittest/ut/ya.make
@@ -0,0 +1,10 @@
+UNITTEST_FOR(library/cpp/testing/unittest)
+
+OWNER(snowball)
+
+SRCS(
+ main.cpp
+ registar_ut.cpp
+)
+
+END()