From d3a398281c6fd1d3672036cb2d63f842d2cb28c5 Mon Sep 17 00:00:00 2001 From: Anton Samokhvalov <pg83@yandex.ru> Date: Thu, 10 Feb 2022 16:45:17 +0300 Subject: Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2. --- library/cpp/logger/log_ut.cpp | 196 +++++++++++++++++++++--------------------- 1 file changed, 98 insertions(+), 98 deletions(-) (limited to 'library/cpp/logger/log_ut.cpp') diff --git a/library/cpp/logger/log_ut.cpp b/library/cpp/logger/log_ut.cpp index 498a667756..8de46f17f5 100644 --- a/library/cpp/logger/log_ut.cpp +++ b/library/cpp/logger/log_ut.cpp @@ -1,83 +1,83 @@ -#include "all.h" - +#include "all.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/system/fs.h> + +#include <util/system/fs.h> #include <util/system/rwlock.h> #include <util/system/yield.h> #include <util/memory/blob.h> -#include <util/stream/file.h> +#include <util/stream/file.h> #include <util/generic/string.h> #include <util/generic/vector.h> - -class TLogTest: public TTestBase { - UNIT_TEST_SUITE(TLogTest); - UNIT_TEST(TestFile) - UNIT_TEST(TestFormat) - UNIT_TEST(TestWrite) - UNIT_TEST(TestThreaded) + +class TLogTest: public TTestBase { + UNIT_TEST_SUITE(TLogTest); + UNIT_TEST(TestFile) + UNIT_TEST(TestFormat) + UNIT_TEST(TestWrite) + UNIT_TEST(TestThreaded) UNIT_TEST(TestThreadedWithOverflow) UNIT_TEST(TestNoFlush) - UNIT_TEST_SUITE_END(); - -private: - void TestFile(); - void TestFormat(); - void TestWrite(); - void TestThreaded(); + UNIT_TEST_SUITE_END(); + +private: + void TestFile(); + void TestFormat(); + void TestWrite(); + void TestThreaded(); void TestThreadedWithOverflow(); void TestNoFlush(); - void SetUp() override; - void TearDown() override; -}; - -UNIT_TEST_SUITE_REGISTRATION(TLogTest); - -#define LOGFILE "tmplogfile" - -void TLogTest::TestFile() { - { - TLog log; - - { - TLog filelog(LOGFILE); - - log = filelog; - } - - int v1 = 12; - unsigned v2 = 34; - double v3 = 3.0; - const char* v4 = "qwqwqw"; - - log.ReopenLog(); - log.AddLog("some useful data %d, %u, %lf, %s\n", v1, v2, v3, v4); - } - + void SetUp() override; + void TearDown() override; +}; + +UNIT_TEST_SUITE_REGISTRATION(TLogTest); + +#define LOGFILE "tmplogfile" + +void TLogTest::TestFile() { + { + TLog log; + + { + TLog filelog(LOGFILE); + + log = filelog; + } + + int v1 = 12; + unsigned v2 = 34; + double v3 = 3.0; + const char* v4 = "qwqwqw"; + + log.ReopenLog(); + log.AddLog("some useful data %d, %u, %lf, %s\n", v1, v2, v3, v4); + } + TBlob data = TBlob::FromFileSingleThreaded(LOGFILE); - + UNIT_ASSERT_EQUAL(TString((const char*)data.Begin(), data.Size()), "some useful data 12, 34, 3.000000, qwqwqw\n"); -} - -void TLogTest::TestThreaded() { - { - TFileLogBackend fb(LOGFILE); +} + +void TLogTest::TestThreaded() { + { + TFileLogBackend fb(LOGFILE); TLog log(THolder(new TThreadedLogBackend(&fb))); - - int v1 = 12; - unsigned v2 = 34; - double v3 = 3.0; - const char* v4 = "qwqwqw"; - - log.ReopenLog(); - log.AddLog("some useful data %d, %u, %lf, %s\n", v1, v2, v3, v4); - } - + + int v1 = 12; + unsigned v2 = 34; + double v3 = 3.0; + const char* v4 = "qwqwqw"; + + log.ReopenLog(); + log.AddLog("some useful data %d, %u, %lf, %s\n", v1, v2, v3, v4); + } + TBlob data = TBlob::FromFileSingleThreaded(LOGFILE); - + UNIT_ASSERT_EQUAL(TString((const char*)data.Begin(), data.Size()), "some useful data 12, 34, 3.000000, qwqwqw\n"); -} - +} + void TLogTest::TestThreadedWithOverflow() { class TFakeLogBackend: public TLogBackend { public: @@ -150,42 +150,42 @@ void TLogTest::TestNoFlush() { UNIT_ASSERT_EQUAL(TString((const char*)data.Begin(), data.Size()), "some useful data 12, 34, 3.000000, qwqwqw\n"); } -void TLogTest::TestFormat() { - TStringStream data; - - { +void TLogTest::TestFormat() { + TStringStream data; + + { TLog log(THolder(new TStreamLogBackend(&data))); - - log << "qw" - << " " - << "1234" << 1234 << " " << 12.3 << 'q' << Endl; - } - - UNIT_ASSERT_EQUAL(data.Str(), "qw 12341234 12.3q\n"); -} - -void TLogTest::TestWrite() { - TStringStream data; + + log << "qw" + << " " + << "1234" << 1234 << " " << 12.3 << 'q' << Endl; + } + + UNIT_ASSERT_EQUAL(data.Str(), "qw 12341234 12.3q\n"); +} + +void TLogTest::TestWrite() { + TStringStream data; TString test; - - { + + { TLog log(THolder(new TStreamLogBackend(&data))); - - for (size_t i = 0; i < 1000; ++i) { + + for (size_t i = 0; i < 1000; ++i) { TVector<char> buf(i, (char)i); - + test.append(buf.data(), buf.size()); log.Write(buf.data(), buf.size()); - } - } - - UNIT_ASSERT_EQUAL(data.Str(), test); -} - -void TLogTest::SetUp() { - TearDown(); -} - -void TLogTest::TearDown() { - NFs::Remove(LOGFILE); -} + } + } + + UNIT_ASSERT_EQUAL(data.Str(), test); +} + +void TLogTest::SetUp() { + TearDown(); +} + +void TLogTest::TearDown() { + NFs::Remove(LOGFILE); +} -- cgit v1.2.3