ut.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <library/cpp/testing/gtest/gtest.h>
  2. #include <library/cpp/testing/hook/hook.h>
  3. static int HookOrder = 0;
  4. static int PreInitHook1 = 0;
  5. static int PreInitHook2 = 0;
  6. static int PreRunHook1 = 0;
  7. static int PreRunHook2 = 0;
  8. static int PostRunHook1 = 0;
  9. static int PostRunHook2 = 0;
  10. Y_TEST_HOOK_BEFORE_INIT(PreInit1) {
  11. PreInitHook1 = ++HookOrder;
  12. }
  13. Y_TEST_HOOK_BEFORE_INIT(PreInit2) {
  14. PreInitHook2 = ++HookOrder;
  15. }
  16. Y_TEST_HOOK_BEFORE_RUN(PreRun1) {
  17. PreRunHook1 = ++HookOrder;
  18. }
  19. Y_TEST_HOOK_BEFORE_RUN(PreRun2) {
  20. PreRunHook2 = ++HookOrder;
  21. }
  22. Y_TEST_HOOK_AFTER_RUN(PostRun1) {
  23. PostRunHook1 = ++HookOrder;
  24. Cerr << "PostRunHook1" << Endl;
  25. }
  26. Y_TEST_HOOK_AFTER_RUN(PostRun2) {
  27. PostRunHook2 = ++HookOrder;
  28. Cerr << "PostRunHook2" << Endl;
  29. }
  30. TEST(Gtest, HookOrder) {
  31. EXPECT_NEAR(PreInitHook1, PreInitHook2, 1);
  32. EXPECT_NEAR(PreRunHook1, PreRunHook2, 1);
  33. EXPECT_LE(std::max(PreInitHook1, PreInitHook2), std::min(PreRunHook1, PreRunHook2));
  34. EXPECT_EQ(PostRunHook1, 0);
  35. EXPECT_EQ(PostRunHook2, 0);
  36. }
  37. TEST(Gtest, Metrics) {
  38. RecordProperty("Metric1", 10);
  39. }