probe_ut.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <library/cpp/testing/gtest/gtest.h>
  2. using namespace testing;
  3. TEST(ProbeStateTest, Example) {
  4. // check that our test function does not make a copy of passed argument
  5. auto copyless = [](auto&& x) {
  6. TProbe p(std::move(x));
  7. p.Touch();
  8. return p;
  9. };
  10. TProbeState state;
  11. auto probe = copyless(TProbe(&state));
  12. EXPECT_EQ(1, state.Touches);
  13. EXPECT_THAT(state, HasCopyMoveCounts(0, 2));
  14. }
  15. TEST(ProbeTest, Construct) {
  16. TProbeState state;
  17. {
  18. TProbe probe(&state);
  19. EXPECT_THAT(state, IsAlive());
  20. }
  21. EXPECT_THAT(state, IsDead());
  22. }
  23. TEST(ProbeTest, Copy) {
  24. TProbeState state;
  25. TProbe probe(&state);
  26. TProbe copy(probe);
  27. EXPECT_THAT(state, HasCopyMoveCounts(1, 0));
  28. EXPECT_THAT(state, NoAssignments());
  29. EXPECT_THAT(state, NoMoves());
  30. TProbe copy2 = TProbe::ExplicitlyCreateInvalidProbe();
  31. copy2 = probe;
  32. EXPECT_EQ(1, state.CopyAssignments);
  33. }
  34. TEST(ProbeTest, Move) {
  35. TProbeState state;
  36. TProbe probe(&state);
  37. TProbe probe2(std::move(probe));
  38. EXPECT_FALSE(probe.IsValid());
  39. EXPECT_THAT(state, NoCopies());
  40. EXPECT_THAT(state, HasCopyMoveCounts(0, 1));
  41. TProbe probe3 = TProbe::ExplicitlyCreateInvalidProbe();
  42. probe3 = std::move(probe2);
  43. EXPECT_EQ(1, state.MoveAssignments);
  44. }