main.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <library/cpp/testing/unittest/gtest.h>
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <library/cpp/testing/unittest/tests_data.h>
  4. #include <util/generic/set.h>
  5. #include <util/network/sock.h>
  6. #include <util/system/env.h>
  7. #include <util/system/fs.h>
  8. TEST(GTest, Test1) {
  9. UNIT_ASSERT_EQUAL(1, 1);
  10. }
  11. TEST(GTest, Test2) {
  12. UNIT_ASSERT_EQUAL(2, 2);
  13. }
  14. namespace {
  15. struct TFixture : ::testing::Test {
  16. TFixture()
  17. : I(0)
  18. {
  19. }
  20. void SetUp() override {
  21. I = 5;
  22. }
  23. int I;
  24. };
  25. struct TSimpleFixture : public NUnitTest::TBaseFixture {
  26. size_t Value = 24;
  27. };
  28. struct TOtherFixture : public NUnitTest::TBaseFixture {
  29. size_t TheAnswer = 42;
  30. };
  31. struct TSetUpTearDownFixture : public NUnitTest::TBaseFixture {
  32. int Magic = 3;
  33. void SetUp(NUnitTest::TTestContext&) override {
  34. UNIT_ASSERT_VALUES_EQUAL(Magic, 3);
  35. Magic = 17;
  36. }
  37. void TearDown(NUnitTest::TTestContext&) override {
  38. UNIT_ASSERT_VALUES_EQUAL(Magic, 42);
  39. Magic = 100;
  40. }
  41. };
  42. }
  43. TEST_F(TFixture, Test1) {
  44. ASSERT_EQ(I, 5);
  45. }
  46. TEST(ETest, Test1) {
  47. UNIT_CHECK_GENERATED_EXCEPTION(ythrow yexception(), yexception);
  48. UNIT_CHECK_GENERATED_NO_EXCEPTION(true, yexception);
  49. }
  50. Y_UNIT_TEST_SUITE(TestSingleTestFixture)
  51. {
  52. Y_UNIT_TEST_F(Test3, TSimpleFixture) {
  53. UNIT_ASSERT_EQUAL(Value, 24);
  54. }
  55. }
  56. Y_UNIT_TEST_SUITE_F(TestSuiteFixture, TSimpleFixture)
  57. {
  58. Y_UNIT_TEST(Test1) {
  59. UNIT_ASSERT(Value == 24);
  60. Value = 25;
  61. }
  62. Y_UNIT_TEST(Test2) {
  63. UNIT_ASSERT_EQUAL(Value, 24);
  64. }
  65. Y_UNIT_TEST_F(Test3, TOtherFixture) {
  66. UNIT_ASSERT_EQUAL(TheAnswer, 42);
  67. }
  68. }
  69. Y_UNIT_TEST_SUITE(TestSetUpTearDownFixture)
  70. {
  71. Y_UNIT_TEST_F(Test1, TSetUpTearDownFixture) {
  72. UNIT_ASSERT_VALUES_EQUAL(Magic, 17);
  73. Magic = 42;
  74. }
  75. }