element_ut.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "log.h"
  2. #include "element.h"
  3. #include "stream.h"
  4. #include <util/generic/string.h>
  5. #include <util/stream/str.h>
  6. #include <util/generic/ptr.h>
  7. #include <utility>
  8. #include <library/cpp/testing/unittest/registar.h>
  9. class TLogElementTest: public TTestBase {
  10. UNIT_TEST_SUITE(TLogElementTest);
  11. UNIT_TEST(TestMoveCtor);
  12. UNIT_TEST(TestWith);
  13. UNIT_TEST_SUITE_END();
  14. public:
  15. void TestMoveCtor();
  16. void TestWith();
  17. };
  18. UNIT_TEST_SUITE_REGISTRATION(TLogElementTest);
  19. void TLogElementTest::TestMoveCtor() {
  20. TStringStream output;
  21. TLog log(MakeHolder<TStreamLogBackend>(&output));
  22. THolder<TLogElement> src = MakeHolder<TLogElement>(&log);
  23. TString message = "Hello, World!";
  24. (*src) << message;
  25. THolder<TLogElement> dst = MakeHolder<TLogElement>(std::move(*src));
  26. src.Destroy();
  27. UNIT_ASSERT(output.Str() == "");
  28. dst.Destroy();
  29. UNIT_ASSERT(output.Str() == message);
  30. }
  31. void TLogElementTest::TestWith() {
  32. TStringStream output;
  33. TLog log(MakeHolder<TStreamWithContextLogBackend>(&output));
  34. THolder<TLogElement> src = MakeHolder<TLogElement>(&log);
  35. TString message = "Hello, World!";
  36. (*src).With("Foo", "Bar").With("Foo", "Baz") << message;
  37. src.Destroy();
  38. UNIT_ASSERT(output.Str() == "Hello, World!; Foo=Bar; Foo=Baz; ");
  39. }