diff options
author | stanly <stanly@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
commit | cde218e65dfef5ce03a48d641fd8f7913cf17b2d (patch) | |
tree | d3349caea4095825a55b5ba24fe758067b29ce6f /library | |
parent | 9f813499b4ef585cb3c2bb93de93ef003daf4fc4 (diff) | |
download | ydb-cde218e65dfef5ce03a48d641fd8f7913cf17b2d.tar.gz |
Restoring authorship annotation for <stanly@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library')
62 files changed, 784 insertions, 784 deletions
diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h index ed29bd14b9..35008ff9be 100644 --- a/library/cpp/actors/core/actor.h +++ b/library/cpp/actors/core/actor.h @@ -98,10 +98,10 @@ namespace NActors { } bool Send(const TActorId& recipient, IEventBase* ev, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}) const; - template <typename TEvent> + template <typename TEvent> bool Send(const TActorId& recipient, THolder<TEvent> ev, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}) const { - return Send(recipient, static_cast<IEventBase*>(ev.Release()), flags, cookie, std::move(traceId)); - } + return Send(recipient, static_cast<IEventBase*>(ev.Release()), flags, cookie, std::move(traceId)); + } bool Send(TAutoPtr<IEventHandle> ev) const; TInstant Now() const; @@ -351,10 +351,10 @@ namespace NActors { protected: void Describe(IOutputStream&) const noexcept override; bool Send(const TActorId& recipient, IEventBase* ev, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}) const noexcept final; - template <typename TEvent> + template <typename TEvent> bool Send(const TActorId& recipient, THolder<TEvent> ev, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}) const{ - return Send(recipient, static_cast<IEventBase*>(ev.Release()), flags, cookie, std::move(traceId)); - } + return Send(recipient, static_cast<IEventBase*>(ev.Release()), flags, cookie, std::move(traceId)); + } template <class TEvent, class ... TEventArgs> bool Send(TActorId recipient, TEventArgs&& ... args) const { diff --git a/library/cpp/actors/core/event_pb.h b/library/cpp/actors/core/event_pb.h index d7546b901a..9713d0a85d 100644 --- a/library/cpp/actors/core/event_pb.h +++ b/library/cpp/actors/core/event_pb.h @@ -144,12 +144,12 @@ namespace NActors { { Record = rec; } - + explicit TEventPBBase(TRecord&& rec) { Record = std::move(rec); } - + TString ToStringHeader() const override { return Record.GetTypeName(); } @@ -216,7 +216,7 @@ namespace NActors { return Record.SerializeToZeroCopyStream(chunker); } - ui32 CalculateSerializedSize() const override { + ui32 CalculateSerializedSize() const override { ssize_t result = Record.ByteSize(); if (result >= 0 && Payload) { ++result; // marker diff --git a/library/cpp/coroutine/listener/listen.cpp b/library/cpp/coroutine/listener/listen.cpp index 3d4e711d1d..fa8a6085a3 100644 --- a/library/cpp/coroutine/listener/listen.cpp +++ b/library/cpp/coroutine/listener/listen.cpp @@ -139,9 +139,9 @@ private: if (err == ECANCELED) { break; } - if (errno == EMFILE) { - C_->SleepT(TDuration::MilliSeconds(1)); - } + if (errno == EMFILE) { + C_->SleepT(TDuration::MilliSeconds(1)); + } ythrow TSystemError(err) << "can not accept"; } diff --git a/library/cpp/coroutine/ya.make b/library/cpp/coroutine/ya.make index 34e30f2b25..ce4cffb72f 100644 --- a/library/cpp/coroutine/ya.make +++ b/library/cpp/coroutine/ya.make @@ -7,5 +7,5 @@ RECURSE( listener test ut - util + util ) diff --git a/library/cpp/dbg_output/ut/dbg_output_ut.cpp b/library/cpp/dbg_output/ut/dbg_output_ut.cpp index 7b285c84cb..54ba4416ec 100644 --- a/library/cpp/dbg_output/ut/dbg_output_ut.cpp +++ b/library/cpp/dbg_output/ut/dbg_output_ut.cpp @@ -55,7 +55,7 @@ Y_UNIT_TEST_SUITE(TContainerPrintersTest) { TStringStream out; TVector<TVector<wchar16>> vec(2); vec[0].push_back(0); - vec[1] = {wchar16('a')}; + vec[1] = {wchar16('a')}; out << DbgDump(vec); UNIT_ASSERT_STRINGS_EQUAL(out.Str(), "[[w'\\0'], [w'a']]"); } diff --git a/library/cpp/deprecated/kmp/kmp.h b/library/cpp/deprecated/kmp/kmp.h index a7f72eece6..48df76df18 100644 --- a/library/cpp/deprecated/kmp/kmp.h +++ b/library/cpp/deprecated/kmp/kmp.h @@ -86,7 +86,7 @@ public: ComputePrefixFunction(patternBegin, patternEnd, &pf); PrefixFunction.Reset(pf); } - + void Push(const T& symbol) { while ((State >= 0) && (Pattern[State] != symbol)) { Y_ASSERT(State <= (ssize_t) Pattern.size()); diff --git a/library/cpp/deprecated/kmp/kmp_ut.cpp b/library/cpp/deprecated/kmp/kmp_ut.cpp index c2eda83c57..3fa94c02d8 100644 --- a/library/cpp/deprecated/kmp/kmp_ut.cpp +++ b/library/cpp/deprecated/kmp/kmp_ut.cpp @@ -27,11 +27,11 @@ public: void Test() { TVector<int> ans = {0, 2}; UNIT_ASSERT_EQUAL(FindAll("a", "aba"), ans); - ans = {0}; + ans = {0}; UNIT_ASSERT_EQUAL(FindAll("aba", "aba"), ans); ans.clear(); UNIT_ASSERT_EQUAL(FindAll("abad", "aba"), ans); - ans = {0, 2}; + ans = {0, 2}; UNIT_ASSERT_EQUAL(FindAll("ab", "abab"), ans); } diff --git a/library/cpp/deprecated/split/delim_string_iter.h b/library/cpp/deprecated/split/delim_string_iter.h index 8e4ca171a0..bcfe07abc6 100644 --- a/library/cpp/deprecated/split/delim_string_iter.h +++ b/library/cpp/deprecated/split/delim_string_iter.h @@ -1,8 +1,8 @@ #pragma once -#include <util/generic/algorithm.h> -#include <util/generic/strbuf.h> -#include <util/generic/yexception.h> +#include <util/generic/algorithm.h> +#include <util/generic/strbuf.h> +#include <util/generic/yexception.h> #include <util/string/cast.h> #include <util/system/yassert.h> @@ -35,9 +35,9 @@ public: } inline explicit operator bool() const { - return IsValid; - } - + return IsValid; + } + // NOTE: this is a potentially unsafe operation (no overrun check) inline TDelimStringIter& operator++() { if (Current.end() != Str.end()) { @@ -51,7 +51,7 @@ public: return *this; } - inline void operator+=(size_t n) { + inline void operator+=(size_t n) { for (; n > 0; --n) { ++(*this); } @@ -65,17 +65,17 @@ public: return !(*this == rhs); } - inline TStringBuf operator*() const { + inline TStringBuf operator*() const { return Current; } - inline const TStringBuf* operator->() const { + inline const TStringBuf* operator->() const { return &Current; } - // Get & advance + // Get & advance template <class T> - inline bool TryNext(T& t) { + inline bool TryNext(T& t) { if (IsValid) { t = FromString<T>(Current); operator++(); @@ -94,46 +94,46 @@ public: } template <class T> - inline T GetNext() { + inline T GetNext() { T res; Next(res); return res; } - inline const char* GetBegin() const { + inline const char* GetBegin() const { return Current.begin(); } - inline const char* GetEnd() const { + inline const char* GetEnd() const { return Current.end(); } - inline bool Valid() const { + inline bool Valid() const { return IsValid; } // contents from next token to the end of string - inline TStringBuf Cdr() const { + inline TStringBuf Cdr() const { return Str.SubStr(Current.length() + Delim.length()); } inline TDelimStringIter IterEnd() const { return TDelimStringIter(); } - -private: - inline void UpdateCurrent() { - // it is much faster than TStringBuf::find + +private: + inline void UpdateCurrent() { + // it is much faster than TStringBuf::find size_t pos = std::search(Str.begin(), Str.end(), Delim.begin(), Delim.end()) - Str.begin(); - Current = Str.Head(pos); - } - -private: - bool IsValid; - - TStringBuf Str; - TStringBuf Current; - TStringBuf Delim; + Current = Str.Head(pos); + } + +private: + bool IsValid; + + TStringBuf Str; + TStringBuf Current; + TStringBuf Delim; }; //example: for (TStringBuf field: TDelimStroka(line, "@@")) { ... } @@ -141,7 +141,7 @@ struct TDelimStroka { TStringBuf S; TStringBuf Delim; - inline TDelimStroka(TStringBuf s, TStringBuf delim) + inline TDelimStroka(TStringBuf s, TStringBuf delim) : S(s) , Delim(delim) { diff --git a/library/cpp/deprecated/split/delim_string_iter_ut.cpp b/library/cpp/deprecated/split/delim_string_iter_ut.cpp index 18a8b2a160..da0ab5c0fd 100644 --- a/library/cpp/deprecated/split/delim_string_iter_ut.cpp +++ b/library/cpp/deprecated/split/delim_string_iter_ut.cpp @@ -9,7 +9,7 @@ static void AssertStringSplit(const TString& str, const TString& delim, const TV // test iterator invariants for (const auto& expectedString : expected) { UNIT_ASSERT(it.Valid()); - UNIT_ASSERT(bool(it)); + UNIT_ASSERT(bool(it)); UNIT_ASSERT_STRINGS_EQUAL(it->ToString(), expectedString); ++it; } diff --git a/library/cpp/deprecated/ya.make b/library/cpp/deprecated/ya.make index 6c753f68a9..04bff040c6 100644 --- a/library/cpp/deprecated/ya.make +++ b/library/cpp/deprecated/ya.make @@ -4,7 +4,7 @@ RECURSE( accessors accessors/ut autoarray - base64 + base64 datafile dater_old dater_old/ut diff --git a/library/cpp/diff/diff.cpp b/library/cpp/diff/diff.cpp index be57da7f39..0598f005b0 100644 --- a/library/cpp/diff/diff.cpp +++ b/library/cpp/diff/diff.cpp @@ -58,18 +58,18 @@ struct TCollection<wchar16>: public TCollectionImpl<wchar16> { } }; -size_t NDiff::InlineDiff(TVector<TChunk<char>>& chunks, const TStringBuf& left, const TStringBuf& right, const TString& delims) { +size_t NDiff::InlineDiff(TVector<TChunk<char>>& chunks, const TStringBuf& left, const TStringBuf& right, const TString& delims) { if (delims.empty()) { return InlineDiff<char>(chunks, TConstArrayRef<char>(left.data(), left.size()), TConstArrayRef<char>(right.data(), right.size())); } TCollection<char> c1(left, delims); TCollection<char> c2(right, delims); TVector<TChunk<ui64>> diff; - const size_t dist = InlineDiff<ui64>(diff, c1.GetKeys(), c2.GetKeys()); + const size_t dist = InlineDiff<ui64>(diff, c1.GetKeys(), c2.GetKeys()); for (const auto& it : diff) { chunks.push_back(TChunk<char>(c1.Remap(it.Left), c2.Remap(it.Right), c1.Remap(it.Common))); } - return dist; + return dist; } size_t NDiff::InlineDiff(TVector<TChunk<wchar16>>& chunks, const TWtringBuf& left, const TWtringBuf& right, const TUtf16String& delims) { @@ -79,9 +79,9 @@ size_t NDiff::InlineDiff(TVector<TChunk<wchar16>>& chunks, const TWtringBuf& lef TCollection<wchar16> c1(left, delims); TCollection<wchar16> c2(right, delims); TVector<TChunk<ui64>> diff; - const size_t dist = InlineDiff<ui64>(diff, c1.GetKeys(), c2.GetKeys()); + const size_t dist = InlineDiff<ui64>(diff, c1.GetKeys(), c2.GetKeys()); for (const auto& it : diff) { chunks.push_back(TChunk<wchar16>(c1.Remap(it.Left), c2.Remap(it.Right), c1.Remap(it.Common))); } - return dist; + return dist; } diff --git a/library/cpp/diff/diff.h b/library/cpp/diff/diff.h index 94fb00cd0b..aded9022ad 100644 --- a/library/cpp/diff/diff.h +++ b/library/cpp/diff/diff.h @@ -27,7 +27,7 @@ namespace NDiff { }; template <typename T> - size_t InlineDiff(TVector<TChunk<T>>& chunks, const TConstArrayRef<T>& left, const TConstArrayRef<T>& right) { + size_t InlineDiff(TVector<TChunk<T>>& chunks, const TConstArrayRef<T>& left, const TConstArrayRef<T>& right) { TConstArrayRef<T> s1(left); TConstArrayRef<T> s2(right); @@ -53,8 +53,8 @@ namespace NDiff { const T* e1 = s1.begin(); const T* e2 = s2.begin(); - size_t dist = s1.size() - lcs.size(); - + size_t dist = s1.size() - lcs.size(); + const size_t n = ctx.ResultBuffer.size(); for (size_t i = 0; i <= n && (e1 != s1.end() || e2 != s2.end());) { if (i < n) { @@ -86,8 +86,8 @@ namespace NDiff { d1 = e1; d2 = e2; } - - return dist; + + return dist; } template <typename TFormatter, typename T> @@ -106,7 +106,7 @@ namespace NDiff { // Without delimiters calculates character-wise diff // With delimiters calculates token-wise diff - size_t InlineDiff(TVector<TChunk<char>>& chunks, const TStringBuf& left, const TStringBuf& right, const TString& delims = TString()); + size_t InlineDiff(TVector<TChunk<char>>& chunks, const TStringBuf& left, const TStringBuf& right, const TString& delims = TString()); size_t InlineDiff(TVector<TChunk<wchar16>>& chunks, const TWtringBuf& left, const TWtringBuf& right, const TUtf16String& delims = TUtf16String()); } diff --git a/library/cpp/diff/diff_ut.cpp b/library/cpp/diff/diff_ut.cpp index b82a7b000e..42285d228f 100644 --- a/library/cpp/diff/diff_ut.cpp +++ b/library/cpp/diff/diff_ut.cpp @@ -37,18 +37,18 @@ struct TDiffTester { }; Y_UNIT_TEST_SUITE(DiffTokens) { - Y_UNIT_TEST(ReturnValue) { - TVector<TChunk<char>> res; - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aaa"), 0); - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aa"), 1); - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "a"), 2); - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "abc"), 2); - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aba"), 1); - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "", "aba"), 3); - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aaaa"), 1); - UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "abc", "xyz"), 3); - } - + Y_UNIT_TEST(ReturnValue) { + TVector<TChunk<char>> res; + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aaa"), 0); + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aa"), 1); + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "a"), 2); + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "abc"), 2); + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aba"), 1); + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "", "aba"), 3); + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "aaa", "aaaa"), 1); + UNIT_ASSERT_VALUES_EQUAL(InlineDiff(res, "abc", "xyz"), 3); + } + Y_UNIT_TEST(EqualStringsOneToken) { TDiffTester tester; diff --git a/library/cpp/html/escape/escape.cpp b/library/cpp/html/escape/escape.cpp index 5b8ed60f04..f6fc8dbb20 100644 --- a/library/cpp/html/escape/escape.cpp +++ b/library/cpp/html/escape/escape.cpp @@ -1,23 +1,23 @@ -#include "escape.h" - -#include <util/generic/array_size.h> -#include <util/generic/strbuf.h> - -namespace NHtml { +#include "escape.h" + +#include <util/generic/array_size.h> +#include <util/generic/strbuf.h> + +namespace NHtml { namespace { struct TReplace { char Char; bool ForText; TStringBuf Entity; }; - + TReplace Escapable[] = { {'"', false, TStringBuf(""")}, {'&', true, TStringBuf("&")}, {'<', true, TStringBuf("<")}, {'>', true, TStringBuf(">")}, }; - + TString EscapeImpl(const TString& value, bool isText) { auto ci = value.begin(); // Looking for escapable characters. @@ -27,17 +27,17 @@ namespace NHtml { goto escape; } } - } - + } + // There is no escapable characters, so return original value. return value; - + escape: TString tmp = TString(value.begin(), ci); - + for (; ci != value.end(); ++ci) { size_t i = (isText ? 1 : 0); - + for (; i < Y_ARRAY_SIZE(Escapable); ++i) { if (*ci == Escapable[i].Char) { tmp += Escapable[i].Entity; @@ -48,19 +48,19 @@ namespace NHtml { if (i == Y_ARRAY_SIZE(Escapable)) { tmp += *ci; } - } + } return tmp; - } - - } - + } + + } + TString EscapeAttributeValue(const TString& value) { return EscapeImpl(value, false); } - + TString EscapeText(const TString& value) { return EscapeImpl(value, true); } - -} + +} diff --git a/library/cpp/html/escape/escape.h b/library/cpp/html/escape/escape.h index 1c45fc5193..cb9b0c860c 100644 --- a/library/cpp/html/escape/escape.h +++ b/library/cpp/html/escape/escape.h @@ -1,9 +1,9 @@ -#pragma once - +#pragma once + #include <util/generic/string.h> - -namespace NHtml { + +namespace NHtml { TString EscapeAttributeValue(const TString& value); TString EscapeText(const TString& value); - + } diff --git a/library/cpp/html/escape/ut/escape_ut.cpp b/library/cpp/html/escape/ut/escape_ut.cpp index cd7b955138..436f3b6a28 100644 --- a/library/cpp/html/escape/ut/escape_ut.cpp +++ b/library/cpp/html/escape/ut/escape_ut.cpp @@ -1,16 +1,16 @@ #include <library/cpp/html/escape/escape.h> #include <library/cpp/testing/unittest/registar.h> - -using namespace NHtml; - + +using namespace NHtml; + Y_UNIT_TEST_SUITE(TEscapeHtml) { Y_UNIT_TEST(Escape) { - UNIT_ASSERT_EQUAL(EscapeText("in & out"), "in & out"); - UNIT_ASSERT_EQUAL(EscapeText("&&"), "&&"); - UNIT_ASSERT_EQUAL(EscapeText("&"), "&amp;"); - - UNIT_ASSERT_EQUAL(EscapeText("<script>"), "<script>"); - - UNIT_ASSERT_EQUAL(EscapeText("text"), "text"); - } -} + UNIT_ASSERT_EQUAL(EscapeText("in & out"), "in & out"); + UNIT_ASSERT_EQUAL(EscapeText("&&"), "&&"); + UNIT_ASSERT_EQUAL(EscapeText("&"), "&amp;"); + + UNIT_ASSERT_EQUAL(EscapeText("<script>"), "<script>"); + + UNIT_ASSERT_EQUAL(EscapeText("text"), "text"); + } +} diff --git a/library/cpp/html/escape/ut/ya.make b/library/cpp/html/escape/ut/ya.make index 27d3a3d65a..4a0e12388d 100644 --- a/library/cpp/html/escape/ut/ya.make +++ b/library/cpp/html/escape/ut/ya.make @@ -1,13 +1,13 @@ -UNITTEST() - -OWNER(stanly) - -SRCS( - escape_ut.cpp -) - -PEERDIR( +UNITTEST() + +OWNER(stanly) + +SRCS( + escape_ut.cpp +) + +PEERDIR( library/cpp/html/escape -) - -END() +) + +END() diff --git a/library/cpp/html/escape/ya.make b/library/cpp/html/escape/ya.make index 93a31e33d6..980481dfae 100644 --- a/library/cpp/html/escape/ya.make +++ b/library/cpp/html/escape/ya.make @@ -1,9 +1,9 @@ -LIBRARY() +LIBRARY() -OWNER(stanly) - -SRCS( - escape.cpp -) - -END() +OWNER(stanly) + +SRCS( + escape.cpp +) + +END() diff --git a/library/cpp/http/fetch/httpfetcher.h b/library/cpp/http/fetch/httpfetcher.h index 7fc251afd2..9c439ab60b 100644 --- a/library/cpp/http/fetch/httpfetcher.h +++ b/library/cpp/http/fetch/httpfetcher.h @@ -35,7 +35,7 @@ public: static const size_t TCP_MIN = 1500; static int TerminateNow; - THttpFetcher() + THttpFetcher() : THttpParser<TCheck>() , TAlloc() , TWriter() @@ -55,15 +55,15 @@ public: size_t schemelen = strlen(scheme); if (*path == '/') { header->base = TStringBuf(scheme, schemelen); - header->base += TStringBuf("://", 3); - header->base += TStringBuf(TAgent::pHostBeg, TAgent::pHostEnd - TAgent::pHostBeg); - header->base += path; + header->base += TStringBuf("://", 3); + header->base += TStringBuf(TAgent::pHostBeg, TAgent::pHostEnd - TAgent::pHostBeg); + header->base += path; } else { - if (strlen(path) >= FETCHER_URL_MAX) { - header->error = HTTP_URL_TOO_LARGE; - return 0; - } - header->base = path; + if (strlen(path) >= FETCHER_URL_MAX) { + header->error = HTTP_URL_TOO_LARGE; + return 0; + } + header->base = path; } if ((ret = TAgent::RequestGet(path, headers, persistent, head_request))) { diff --git a/library/cpp/http/fetch/httpfsm.rl6 b/library/cpp/http/fetch/httpfsm.rl6 index eab0328b18..d3b1425321 100644 --- a/library/cpp/http/fetch/httpfsm.rl6 +++ b/library/cpp/http/fetch/httpfsm.rl6 @@ -86,10 +86,10 @@ response_status_line = http_version ws+ status_code reason_phrase? eol %set_stat ############ request status line ################# action set_request_uri { if (request_hd && buflen < FETCHER_URL_MAX) { - if (!request_hd->request_uri.empty()) { + if (!request_hd->request_uri.empty()) { return -2; } - request_hd->request_uri =TStringBuf(buf, buflen); + request_hd->request_uri =TStringBuf(buf, buflen); } } action set_http_method { @@ -225,8 +225,8 @@ mime_type = "text/plain"i %{c(MIME_TEXT)} | "application/x-bzip2"i | "application/x-rar"i ) %{c(MIME_ARCHIVE)} | "application/x-dosexec"i %{c(MIME_EXE)} | "application/x-gzip"i %{c(MIME_GZIP)} - | "application/json"i %{c(MIME_JSON)} - | ("application/javascript"i | "text/javascript"i) %{c(MIME_JAVASCRIPT)} + | "application/json"i %{c(MIME_JSON)} + | ("application/javascript"i | "text/javascript"i) %{c(MIME_JAVASCRIPT)} | "application/vnd.android.package-archive"i %{c(MIME_APK)} | ("image/x-icon"i | "image/vnd.microsoft.icon"i) %{c(MIME_IMAGE_ICON)} ; @@ -253,7 +253,7 @@ action set_location { buflen --; } if (hd && buflen < FETCHER_URL_MAX) { - hd->location = TStringBuf(buf, buflen); + hd->location = TStringBuf(buf, buflen); } } @@ -304,7 +304,7 @@ x_robots_tag = "x-robots-tag"i def >{ AcceptingXRobots = true; } x_robots_value ################# rel_canonical ############### action set_canonical { if (hd && buflen < FETCHER_URL_MAX) { - hd->rel_canonical = TStringBuf(buf, buflen); + hd->rel_canonical = TStringBuf(buf, buflen); } } diff --git a/library/cpp/http/fetch/httpfsm_ut.cpp b/library/cpp/http/fetch/httpfsm_ut.cpp index b018e80101..a581d87773 100644 --- a/library/cpp/http/fetch/httpfsm_ut.cpp +++ b/library/cpp/http/fetch/httpfsm_ut.cpp @@ -82,7 +82,7 @@ void THttpHeaderParserTestSuite::TestRequestHeader() { UNIT_ASSERT_EQUAL(result, 2); UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET); UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0); - UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi"); + UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi"); UNIT_ASSERT_EQUAL(httpRequestHeader.GetUrl(), "http://www.google.ru:8080/search?q=hi"); UNIT_ASSERT_EQUAL(httpHeaderParser->lastchar - request + 1, (i32)strlen(request)); @@ -123,7 +123,7 @@ void THttpHeaderParserTestSuite::TestSplitRequestHeader() { UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET); UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0); - UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi"); + UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi"); } } @@ -143,7 +143,7 @@ void THttpHeaderParserTestSuite::TestTrailingData() { UNIT_ASSERT_EQUAL(result, 2); UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET); UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0); - UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi"); + UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi"); UNIT_ASSERT_EQUAL(TString(httpHeaderParser->lastchar + 1), "high.ru"); UNIT_ASSERT_EQUAL(httpRequestHeader.http_minor, 1); UNIT_ASSERT_EQUAL(httpRequestHeader.transfer_chunked, -1); @@ -178,10 +178,10 @@ void THttpHeaderParserTestSuite::TestProxyRequestHeader() { UNIT_ASSERT_EQUAL(httpRequestHeader.max_age, 100); UNIT_ASSERT_VALUES_EQUAL(httpRequestHeader.if_modified_since, TInstant::ParseIso8601Deprecated("1994-10-29 19:43:31Z").TimeT()); - UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, + UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "http://www.google.ru:8080/search?q=hi"); UNIT_ASSERT(httpRequestHeader.GetUrl() == - "http://www.google.ru:8080/search?q=hi"); + "http://www.google.ru:8080/search?q=hi"); UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, ""), 0); UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.from, "webadmin@yandex.ru"), 0); UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.user_agent, @@ -420,7 +420,7 @@ void THttpHeaderParserTestSuite::TestRelCanonical() { "Link: <http://yandex.ru>; rel = \"canonical\"\r\n\r\n"; i32 result = httpHeaderParser->Execute(headers, strlen(headers)); UNIT_ASSERT_EQUAL(result, 2); - UNIT_ASSERT_EQUAL(httpHeader.rel_canonical, "http://yandex.ru"); + UNIT_ASSERT_EQUAL(httpHeader.rel_canonical, "http://yandex.ru"); TestFinish(); } diff --git a/library/cpp/http/fetch/httpheader.h b/library/cpp/http/fetch/httpheader.h index b2810bbd41..b2804c9689 100644 --- a/library/cpp/http/fetch/httpheader.h +++ b/library/cpp/http/fetch/httpheader.h @@ -1,9 +1,9 @@ #pragma once -#include "exthttpcodes.h" - +#include "exthttpcodes.h" + #include <library/cpp/mime/types/mime.h> - + #include <util/system/defaults.h> #include <util/system/compat.h> #include <util/generic/string.h> @@ -24,10 +24,10 @@ extern const i64 DEFAULT_IF_MODIFIED_SINCE; /// == -1 extern const i32 DEFAULT_MAX_AGE; /// == -1 extern const i8 DEFAULT_REQUEST_PRIORITY; /// == -1 extern const i32 DEFAULT_RESPONSE_TIMEOUT; /// == -1 - + #define HTTP_PREFIX "http://" #define MAX_LANGREGION_LEN 4 -#define MAXWORD_LEN 55 +#define MAXWORD_LEN 55 enum HTTP_COMPRESSION { HTTP_COMPRESSION_UNSET = 0, @@ -75,7 +75,7 @@ public: i8 compression_method; i8 transfer_chunked; i8 connection_closed; - TString base; + TString base; public: void Init() { @@ -93,7 +93,7 @@ public: content_range_start = -1; content_range_end = -1; content_range_entity_length = -1; - base.clear(); + base.clear(); } void Print() const { @@ -108,19 +108,19 @@ public: printf("content_range_start: %" PRIi64 "\n", content_range_start); printf("content_range_end: %" PRIi64 "\n", content_range_end); printf("content_range_entity_length: %" PRIi64 "\n", content_range_entity_length); - printf("base: \"%s\"\n", base.c_str()); + printf("base: \"%s\"\n", base.c_str()); printf("error: %" PRIi16 "\n", error); } int SetBase(const char* path, const char* hostNamePtr = nullptr, int hostNameLength = 0) { - if (*path == '/') { - base = "http://"; - base += TStringBuf(hostNamePtr, hostNameLength); - base += path; + if (*path == '/') { + base = "http://"; + base += TStringBuf(hostNamePtr, hostNameLength); + base += path; } else { - base = path; + base = path; } return error; } @@ -134,8 +134,8 @@ public: i8 squid_error; i8 x_robots_tag; // deprecated, use x_robots_state instead i16 http_status; - TString location; - TString rel_canonical; + TString location; + TString rel_canonical; char hreflangs[HREFLANG_MAX]; i64 retry_after; TString x_robots_state; // 'xxxxx' format, see `library/html/zoneconf/parsefunc.cpp` @@ -146,9 +146,9 @@ public: accept_ranges = -1; squid_error = 0; x_robots_tag = 0; - rel_canonical.clear(); + rel_canonical.clear(); http_status = -1; - location.clear(); + location.clear(); hreflangs[0] = 0; retry_after = DEFAULT_RETRY_AFTER; x_robots_state = "xxxxx"; @@ -159,14 +159,14 @@ public: printf("http_status: %" PRIi16 "\n", http_status); printf("squid_error: %" PRIi8 "\n", squid_error); printf("accept_ranges: %" PRIi8 "\n", accept_ranges); - printf("location: \"%s\"\n", location.c_str()); + printf("location: \"%s\"\n", location.c_str()); printf("retry_after: %" PRIi64 "\n", retry_after); } }; struct THttpRequestHeader: public THttpBaseHeader { public: - TString request_uri; + TString request_uri; char host[HOST_MAX]; char from[MAXWORD_LEN]; char user_agent[MAXWORD_LEN]; @@ -186,7 +186,7 @@ public: } void Init() { - request_uri.clear(); + request_uri.clear(); host[0] = 0; from[0] = 0; user_agent[0] = 0; @@ -204,7 +204,7 @@ public: void Print() const { THttpBaseHeader::Print(); - printf("request_uri: \"%s\"\n", request_uri.c_str()); + printf("request_uri: \"%s\"\n", request_uri.c_str()); printf("host: \"%s\"\n", host); printf("from: \"%s\"\n", from); printf("user_agent: \"%s\"\n", user_agent); @@ -231,9 +231,9 @@ public: char* GetUrl(char* buffer, size_t size) { if (host[0] == 0 || !strcmp(host, "")) { - strlcpy(buffer, request_uri.c_str(), size); + strlcpy(buffer, request_uri.c_str(), size); } else { - snprintf(buffer, size, "http://%s%s", host, request_uri.c_str()); + snprintf(buffer, size, "http://%s%s", host, request_uri.c_str()); } return buffer; } diff --git a/library/cpp/http/fetch/ya.make b/library/cpp/http/fetch/ya.make index 7737127463..f5ed6fbcd7 100644 --- a/library/cpp/http/fetch/ya.make +++ b/library/cpp/http/fetch/ya.make @@ -35,4 +35,4 @@ SET(RAGEL6_FLAGS -CF1) END() -RECURSE_FOR_TESTS(ut) +RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/http/misc/ya.make b/library/cpp/http/misc/ya.make index fceb3cf79c..db4d848571 100644 --- a/library/cpp/http/misc/ya.make +++ b/library/cpp/http/misc/ya.make @@ -20,5 +20,5 @@ PEERDIR( ) END() - -RECURSE_FOR_TESTS(ut) + +RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 38eda0e5e7..cfcf9ba330 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -70,11 +70,11 @@ public: /// Default interface name to bind the server. Used when none of BindAddress are provided. inline THttpServerOptions& SetHost(const TString& host) noexcept { - Host = host; - - return *this; - } - + Host = host; + + return *this; + } + /// Default port to bind the server. Used when none of BindAddress are provided. inline THttpServerOptions& SetPort(ui16 port) noexcept { Port = port; diff --git a/library/cpp/http/server/ya.make b/library/cpp/http/server/ya.make index bae6f33306..da2c664741 100644 --- a/library/cpp/http/server/ya.make +++ b/library/cpp/http/server/ya.make @@ -23,5 +23,5 @@ PEERDIR( ) END() - -RECURSE_FOR_TESTS(ut) + +RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/logger/global/global.h b/library/cpp/logger/global/global.h index cbe71b16ea..8a274cbc1b 100644 --- a/library/cpp/logger/global/global.h +++ b/library/cpp/logger/global/global.h @@ -24,8 +24,8 @@ public: { } - TGlobalLog(THolder<TLogBackend> backend) - : TLog(std::move(backend)) + TGlobalLog(THolder<TLogBackend> backend) + : TLog(std::move(backend)) { } }; @@ -40,8 +40,8 @@ public: { } - TNullLog(THolder<TLogBackend> backend) - : TLog(std::move(backend)) + TNullLog(THolder<TLogBackend> backend) + : TLog(std::move(backend)) { } }; diff --git a/library/cpp/logger/log.cpp b/library/cpp/logger/log.cpp index e1d70cc3d2..57e1b16475 100644 --- a/library/cpp/logger/log.cpp +++ b/library/cpp/logger/log.cpp @@ -12,17 +12,17 @@ #include <util/generic/scope.h> #include <util/generic/yexception.h> -THolder<TLogBackend> CreateLogBackend(const TString& fname, ELogPriority priority, bool threaded) { +THolder<TLogBackend> CreateLogBackend(const TString& fname, ELogPriority priority, bool threaded) { TLogBackendCreatorUninitialized creator; creator.InitCustom(fname, priority, threaded); return creator.CreateLogBackend(); } -THolder<TLogBackend> CreateFilteredOwningThreadedLogBackend(const TString& fname, ELogPriority priority, size_t queueLen) { +THolder<TLogBackend> CreateFilteredOwningThreadedLogBackend(const TString& fname, ELogPriority priority, size_t queueLen) { return MakeHolder<TFilteredLogBackend>(CreateOwningThreadedLogBackend(fname, queueLen), priority); } -THolder<TOwningThreadedLogBackend> CreateOwningThreadedLogBackend(const TString& fname, size_t queueLen) { +THolder<TOwningThreadedLogBackend> CreateOwningThreadedLogBackend(const TString& fname, size_t queueLen) { return MakeHolder<TOwningThreadedLogBackend>(CreateLogBackend(fname, LOG_MAX_PRIORITY, false).Release(), queueLen); } @@ -45,7 +45,7 @@ class TLog::TImpl: public TAtomicRefCount<TImpl> { }; public: - inline TImpl(THolder<TLogBackend> backend) + inline TImpl(THolder<TLogBackend> backend) : Backend_(std::move(backend)) { } @@ -76,11 +76,11 @@ public: Printf(ls, format, args); } - inline void ResetBackend(THolder<TLogBackend> backend) noexcept { + inline void ResetBackend(THolder<TLogBackend> backend) noexcept { Backend_ = std::move(backend); } - inline THolder<TLogBackend> ReleaseBackend() noexcept { + inline THolder<TLogBackend> ReleaseBackend() noexcept { return std::move(Backend_); } @@ -135,7 +135,7 @@ TLog::TLog(const TString& fname, ELogPriority priority) { } -TLog::TLog(THolder<TLogBackend> backend) +TLog::TLog(THolder<TLogBackend> backend) : Impl_(MakeIntrusive<TImpl>(std::move(backend))) { } @@ -214,15 +214,15 @@ bool TLog::OpenLog(const char* path, ELogPriority lp) { return true; } -void TLog::ResetBackend(THolder<TLogBackend> backend) noexcept { - Impl_->ResetBackend(std::move(backend)); +void TLog::ResetBackend(THolder<TLogBackend> backend) noexcept { + Impl_->ResetBackend(std::move(backend)); } bool TLog::IsNullLog() const noexcept { return Impl_->IsNullLog(); } -THolder<TLogBackend> TLog::ReleaseBackend() noexcept { +THolder<TLogBackend> TLog::ReleaseBackend() noexcept { return Impl_->ReleaseBackend(); } @@ -235,10 +235,10 @@ void TLog::Write(ELogPriority priority, const char* data, size_t len) const { } } -void TLog::Write(ELogPriority priority, const TStringBuf data) const { - Write(priority, data.data(), data.size()); -} - +void TLog::Write(ELogPriority priority, const TStringBuf data) const { + Write(priority, data.data(), data.size()); +} + void TLog::Write(const char* data, size_t len) const { Write(Impl_->DefaultPriority(), data, len); } diff --git a/library/cpp/logger/log.h b/library/cpp/logger/log.h index 8be984ccc8..59409b4778 100644 --- a/library/cpp/logger/log.h +++ b/library/cpp/logger/log.h @@ -8,7 +8,7 @@ #include <util/generic/fwd.h> #include <util/generic/ptr.h> - + #include <functional> #include <cstdarg> @@ -37,7 +37,7 @@ public: // Construct file logger. TLog(const TString& fname, ELogPriority priority = LOG_MAX_PRIORITY); // Construct any type of logger - TLog(THolder<TLogBackend> backend); + TLog(THolder<TLogBackend> backend); TLog(const TLog&); TLog(TLog&&); @@ -47,10 +47,10 @@ public: // Change underlying backend. // NOTE: not thread safe. - void ResetBackend(THolder<TLogBackend> backend) noexcept; + void ResetBackend(THolder<TLogBackend> backend) noexcept; // Reset underlying backend, `IsNullLog()` will return `true` after this call. // NOTE: not thread safe. - THolder<TLogBackend> ReleaseBackend() noexcept; + THolder<TLogBackend> ReleaseBackend() noexcept; // Check if underlying backend is defined and is not null. // NOTE: not thread safe with respect to `ResetBackend` and `ReleaseBackend`. bool IsNullLog() const noexcept; @@ -110,6 +110,6 @@ private: TLogFormatter Formatter_; }; -THolder<TLogBackend> CreateLogBackend(const TString& fname, ELogPriority priority = LOG_MAX_PRIORITY, bool threaded = false); -THolder<TLogBackend> CreateFilteredOwningThreadedLogBackend(const TString& fname, ELogPriority priority = LOG_MAX_PRIORITY, size_t queueLen = 0); -THolder<TOwningThreadedLogBackend> CreateOwningThreadedLogBackend(const TString& fname, size_t queueLen = 0); +THolder<TLogBackend> CreateLogBackend(const TString& fname, ELogPriority priority = LOG_MAX_PRIORITY, bool threaded = false); +THolder<TLogBackend> CreateFilteredOwningThreadedLogBackend(const TString& fname, ELogPriority priority = LOG_MAX_PRIORITY, size_t queueLen = 0); +THolder<TOwningThreadedLogBackend> CreateOwningThreadedLogBackend(const TString& fname, size_t queueLen = 0); diff --git a/library/cpp/messagebus/actor/executor.cpp b/library/cpp/messagebus/actor/executor.cpp index 7a2227a458..6325dd3821 100644 --- a/library/cpp/messagebus/actor/executor.cpp +++ b/library/cpp/messagebus/actor/executor.cpp @@ -233,7 +233,7 @@ void TExecutor::EnqueueWork(TArrayRef<IWorkItem* const> wis) { } } -size_t TExecutor::GetWorkQueueSize() const { +size_t TExecutor::GetWorkQueueSize() const { return WorkItems.Size(); } @@ -259,7 +259,7 @@ TString TExecutor::GetStatusSingleLine() const { return ss.Str(); } -TExecutorStatus TExecutor::GetStatusRecordInternal() const { +TExecutorStatus TExecutor::GetStatusRecordInternal() const { TExecutorStatus r; r.WorkQueueSize = GetWorkQueueSize(); @@ -279,7 +279,7 @@ TExecutorStatus TExecutor::GetStatusRecordInternal() const { return r; } -bool TExecutor::IsInExecutorThread() const { +bool TExecutor::IsInExecutorThread() const { return ThreadCurrentExecutor == this; } diff --git a/library/cpp/messagebus/base.h b/library/cpp/messagebus/base.h index 79fccc312e..7448e6ede1 100644 --- a/library/cpp/messagebus/base.h +++ b/library/cpp/messagebus/base.h @@ -1,7 +1,7 @@ #pragma once -#include <util/system/defaults.h> - +#include <util/system/defaults.h> + namespace NBus { /// millis since epoch using TBusInstant = ui64; diff --git a/library/cpp/messagebus/config/netaddr.cpp b/library/cpp/messagebus/config/netaddr.cpp index 962ac538e2..f82378c345 100644 --- a/library/cpp/messagebus/config/netaddr.cpp +++ b/library/cpp/messagebus/config/netaddr.cpp @@ -4,7 +4,7 @@ #include <cstdlib> -namespace NBus { +namespace NBus { const char* ToCString(EIpVersion ipVersion) { switch (ipVersion) { case EIP_VERSION_ANY: @@ -37,12 +37,12 @@ namespace NBus { { } }; - + static bool Compare(const IRemoteAddr& l, const IRemoteAddr& r) noexcept { if (l.Addr()->sa_family != r.Addr()->sa_family) { return false; } - + switch (l.Addr()->sa_family) { case AF_INET: { return memcmp(&(((const sockaddr_in*)l.Addr())->sin_addr), &(((const sockaddr_in*)r.Addr())->sin_addr), sizeof(in_addr)) == 0 && @@ -53,25 +53,25 @@ namespace NBus { return memcmp(&(((const sockaddr_in6*)l.Addr())->sin6_addr), &(((const sockaddr_in6*)r.Addr())->sin6_addr), sizeof(in6_addr)) == 0 && ((const sockaddr_in6*)l.Addr())->sin6_port == ((const sockaddr_in6*)r.Addr())->sin6_port; } - } - + } + return memcmp(l.Addr(), r.Addr(), Min<size_t>(l.Len(), r.Len())) == 0; - } - + } + TNetAddr::TNetAddr() : Ptr(new TOpaqueAddr) { } - + TNetAddr::TNetAddr(TAutoPtr<IRemoteAddr> addr) : Ptr(addr) { Y_VERIFY(!!Ptr); } - + namespace { using namespace NAddr; - + const char* Describe(EIpVersion version) { switch (version) { case EIP_VERSION_4: @@ -150,7 +150,7 @@ namespace NBus { socklen_t TNetAddr::Len() const { return Ptr->Len(); } - + int TNetAddr::GetPort() const { switch (Ptr->Addr()->sa_family) { case AF_INET: @@ -162,11 +162,11 @@ namespace NBus { throw 1; } } - + bool TNetAddr::IsIpv4() const { return Ptr->Addr()->sa_family == AF_INET; } - + bool TNetAddr::IsIpv6() const { return Ptr->Addr()->sa_family == AF_INET6; } @@ -177,7 +177,7 @@ namespace NBus { } -template <> +template <> void Out<NBus::TNetAddr>(IOutputStream& out, const NBus::TNetAddr& addr) { - Out<NAddr::IRemoteAddr>(out, addr); -} + Out<NAddr::IRemoteAddr>(out, addr); +} diff --git a/library/cpp/messagebus/config/netaddr.h b/library/cpp/messagebus/config/netaddr.h index b79c0cc355..2e40f1464b 100644 --- a/library/cpp/messagebus/config/netaddr.h +++ b/library/cpp/messagebus/config/netaddr.h @@ -1,22 +1,22 @@ -#pragma once - +#pragma once + #include <util/digest/numeric.h> #include <util/generic/hash.h> -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/generic/strbuf.h> -#include <util/generic/vector.h> -#include <util/network/address.h> - -namespace NBus { +#include <util/generic/vector.h> +#include <util/network/address.h> + +namespace NBus { using namespace NAddr; - + /// IP protocol version. enum EIpVersion { EIP_VERSION_4 = 1, EIP_VERSION_6 = 2, EIP_VERSION_ANY = EIP_VERSION_4 | EIP_VERSION_6, }; - + inline bool IsFamilyAllowed(ui16 sa_family, EIpVersion ipVersion) { if (ipVersion == EIP_VERSION_4 && sa_family != AF_INET) { return false; @@ -51,26 +51,26 @@ namespace NBus { inline explicit operator bool() const noexcept { return !!Ptr; } - + const sockaddr* Addr() const override; socklen_t Len() const override; - + bool IsIpv4() const; bool IsIpv6() const; int GetPort() const; - + private: TAtomicSharedPtr<IRemoteAddr> Ptr; }; using TSockAddrInVector = TVector<TNetAddr>; - + struct TNetAddrHostPortHash { inline size_t operator()(const TNetAddr& a) const { const sockaddr* s = a.Addr(); const sockaddr_in* const sa = reinterpret_cast<const sockaddr_in*>(s); const sockaddr_in6* const sa6 = reinterpret_cast<const sockaddr_in6*>(s); - + switch (s->sa_family) { case AF_INET: return CombineHashes<size_t>(ComputeHash(TStringBuf(reinterpret_cast<const char*>(&sa->sin_addr), sizeof(sa->sin_addr))), IntHashImpl(sa->sin_port)); diff --git a/library/cpp/messagebus/coreconn.cpp b/library/cpp/messagebus/coreconn.cpp index d9411bb5db..75b355d4a1 100644 --- a/library/cpp/messagebus/coreconn.cpp +++ b/library/cpp/messagebus/coreconn.cpp @@ -1,7 +1,7 @@ -#include "coreconn.h" +#include "coreconn.h" #include "remote_connection.h" - + #include <util/datetime/base.h> #include <util/generic/yexception.h> #include <util/network/socket.h> diff --git a/library/cpp/messagebus/coreconn.h b/library/cpp/messagebus/coreconn.h index fca228d82e..39e085bf31 100644 --- a/library/cpp/messagebus/coreconn.h +++ b/library/cpp/messagebus/coreconn.h @@ -4,10 +4,10 @@ /// \file /// \brief Definitions for asynchonous connection queue -#include "base.h" +#include "base.h" #include "event_loop.h" -#include "netaddr.h" - +#include "netaddr.h" + #include <util/datetime/base.h> #include <util/generic/algorithm.h> #include <util/generic/list.h> @@ -15,7 +15,7 @@ #include <util/generic/set.h> #include <util/generic/string.h> #include <util/generic/vector.h> -#include <util/network/address.h> +#include <util/network/address.h> #include <util/network/ip.h> #include <util/network/poller.h> #include <util/string/util.h> @@ -58,7 +58,7 @@ namespace NBus { exc << maxConnect; } }; - + enum EPollType { POLL_READ, POLL_WRITE diff --git a/library/cpp/messagebus/locator.cpp b/library/cpp/messagebus/locator.cpp index e38a35c426..242b9b3120 100644 --- a/library/cpp/messagebus/locator.cpp +++ b/library/cpp/messagebus/locator.cpp @@ -7,8 +7,8 @@ #include "ybus.h" #include <util/generic/hash_set.h> -#include <util/system/hostname.h> - +#include <util/system/hostname.h> + namespace NBus { using namespace NAddr; @@ -17,7 +17,7 @@ namespace NBus { case AF_INET: { return ntohs(((const sockaddr_in*)addr.Addr())->sin_port); } - + case AF_INET6: { return ntohs(((const sockaddr_in6*)addr.Addr())->sin6_port); } @@ -26,9 +26,9 @@ namespace NBus { ythrow yexception() << "not implemented"; break; } - } + } } - + static inline bool GetIp6AddressFromVector(const TVector<TNetAddr>& addrs, TNetAddr* addr) { for (size_t i = 1; i < addrs.size(); ++i) { if (addrs[i - 1].Addr()->sa_family == addrs[i].Addr()->sa_family) { @@ -38,18 +38,18 @@ namespace NBus { if (GetAddrPort(addrs[i - 1]) != GetAddrPort(addrs[i])) { return false; } - } - + } + for (size_t i = 0; i < addrs.size(); ++i) { if (addrs[i].Addr()->sa_family == AF_INET6) { *addr = addrs[i]; return true; } - } + } return false; - } - + } + EMessageStatus TBusProtocol::GetDestination(const TBusClientSession*, TBusMessage* mess, TBusLocator* locator, TNetAddr* addr) { TBusService service = GetService(); TBusKey key = GetKey(mess); @@ -61,8 +61,8 @@ namespace NBus { } else { /// lookup address/port in the locator table locator->LocateAll(service, key, addrs); - } - + } + if (addrs.size() == 0) { return MESSAGE_SERVICE_UNKNOWN; } else if (addrs.size() == 1) { @@ -73,15 +73,15 @@ namespace NBus { /// to implement custom routing strategy for your service. return MESSAGE_SERVICE_TOOMANY; } - } + } return MESSAGE_OK; - } - + } + static const sockaddr_in* SockAddrIpV4(const IRemoteAddr& a) { return (const sockaddr_in*)a.Addr(); - } - + } + static const sockaddr_in6* SockAddrIpV6(const IRemoteAddr& a) { return (const sockaddr_in6*)a.Addr(); } @@ -96,7 +96,7 @@ namespace NBus { } return false; } - + TBusLocator::TBusLocator() : MyInterfaces(GetNetworkInterfaces()) { @@ -137,7 +137,7 @@ namespace NBus { const char* c = ServiceIdSet.insert(name).first->c_str(); return (ui64)c; } - + int TBusLocator::RegisterBreak(TBusService service, const TVector<TBusKey>& starts, const TNetAddr& addr) { TGuard<TMutex> G(Lock); @@ -399,7 +399,7 @@ namespace NBus { TServiceId serviceId = GetServiceId(service); TItems::const_iterator it; - + TItem itemToReg(serviceId, start, end, addr); for (it = Items.lower_bound(TItem(serviceId, 0, start, TNetAddr())); it != Items.end() && it->ServiceId == serviceId; diff --git a/library/cpp/messagebus/messqueue.cpp b/library/cpp/messagebus/messqueue.cpp index 3474d62705..e0e3d5f296 100644 --- a/library/cpp/messagebus/messqueue.cpp +++ b/library/cpp/messagebus/messqueue.cpp @@ -78,7 +78,7 @@ bool TBusMessageQueue::IsRunning() { return AtomicGet(Running); } -TBusMessageQueueStatus TBusMessageQueue::GetStatusRecordInternal() const { +TBusMessageQueueStatus TBusMessageQueue::GetStatusRecordInternal() const { TBusMessageQueueStatus r; r.ExecutorStatus = WorkQueue->GetStatusRecordInternal(); r.Config = Config; diff --git a/library/cpp/messagebus/netaddr.h b/library/cpp/messagebus/netaddr.h index f915c8c574..f5c441b12f 100644 --- a/library/cpp/messagebus/netaddr.h +++ b/library/cpp/messagebus/netaddr.h @@ -1,4 +1,4 @@ -#pragma once - +#pragma once + #include <library/cpp/messagebus/config/netaddr.h> - + diff --git a/library/cpp/messagebus/rain_check/core/task.cpp b/library/cpp/messagebus/rain_check/core/task.cpp index a098437d53..f0ba062d8e 100644 --- a/library/cpp/messagebus/rain_check/core/task.cpp +++ b/library/cpp/messagebus/rain_check/core/task.cpp @@ -211,6 +211,6 @@ TString TTaskRunnerBase::GetStatusSingleLine() { return TypeName(*Impl); } -bool NRainCheck::AreWeInsideTask() { +bool NRainCheck::AreWeInsideTask() { return ThreadCurrentTask != nullptr; -} +} diff --git a/library/cpp/messagebus/rain_check/core/task.h b/library/cpp/messagebus/rain_check/core/task.h index 7d8778bcda..2eebd6e01c 100644 --- a/library/cpp/messagebus/rain_check/core/task.h +++ b/library/cpp/messagebus/rain_check/core/task.h @@ -178,7 +178,7 @@ namespace NRainCheck { } }; - // Check that current method executed inside some task. - bool AreWeInsideTask(); - + // Check that current method executed inside some task. + bool AreWeInsideTask(); + } diff --git a/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h b/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h index 1334f05fe4..429c8e34d0 100644 --- a/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h +++ b/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h @@ -5,7 +5,7 @@ #include <library/cpp/messagebus/ybus.h> -#include <util/system/yassert.h> +#include <util/system/yassert.h> namespace NRainCheck { class TBusTaskStarter: public NBus::IBusServerHandler { diff --git a/library/cpp/messagebus/session.cpp b/library/cpp/messagebus/session.cpp index 46a7ece6a8..78f848beb2 100644 --- a/library/cpp/messagebus/session.cpp +++ b/library/cpp/messagebus/session.cpp @@ -24,11 +24,11 @@ namespace NBus { case AF_INET6: { return memcmp(&(((const sockaddr_in6*)l.Addr())->sin6_addr), &(((const sockaddr_in6*)r.Addr())->sin6_addr), sizeof(in6_addr)); } - } - + } + return memcmp(l.Addr(), r.Addr(), Min<size_t>(l.Len(), r.Len())); - } - + } + bool operator<(const TNetAddr& a1, const TNetAddr& a2) { return CompareByHost(a1, a2) < 0; } diff --git a/library/cpp/messagebus/ybus.h b/library/cpp/messagebus/ybus.h index de21ad8521..f1a32de69d 100644 --- a/library/cpp/messagebus/ybus.h +++ b/library/cpp/messagebus/ybus.h @@ -3,7 +3,7 @@ /// Asynchronous Messaging Library implements framework for sending and /// receiving messages between loosely connected processes. -#include "coreconn.h" +#include "coreconn.h" #include "defs.h" #include "handler.h" #include "handler_impl.h" @@ -17,7 +17,7 @@ #include "session.h" #include "session_config.h" #include "socket_addr.h" - + #include <library/cpp/messagebus/actor/executor.h> #include <library/cpp/messagebus/scheduler/scheduler.h> diff --git a/library/cpp/mime/types/mime.cpp b/library/cpp/mime/types/mime.cpp index 706d776b24..4223a4f7d5 100644 --- a/library/cpp/mime/types/mime.cpp +++ b/library/cpp/mime/types/mime.cpp @@ -1,4 +1,4 @@ -#include "mime.h" +#include "mime.h" #include <util/system/defaults.h> #include <util/generic/hash.h> @@ -59,7 +59,7 @@ const TMimeTypes::TRecord TMimeTypes::Records[] = { {MIME_RTF, "text/rtf\0application/rtf\0", "rtf\0"}, {MIME_DOC, "application/msword\0", "doc\0"}, {MIME_MPEG, "audio/mpeg\0", "mp3\0mpa\0m2a\0mp2\0mpg\0mpga\0"}, - {MIME_XML, "text/xml\0application/xml\0", "xml\0"}, + {MIME_XML, "text/xml\0application/xml\0", "xml\0"}, {MIME_WML, "text/vnd.wap.wml\0", "wml\0"}, {MIME_SWF, "application/x-shockwave-flash\0", "swf\0"}, {MIME_XLS, "application/vnd.ms-excel\0", "xls\0"}, @@ -85,7 +85,7 @@ const TMimeTypes::TRecord TMimeTypes::Records[] = { {MIME_EPUB, "application/epub+zip\0", "epub\0"}, {MIME_TEX, "application/x-tex\0application/x-latex\0text/x-tex\0", "tex\0"}, {MIME_JSON, "application/json\0", "json\0"}, - {MIME_APK, "application/vnd.android.package-archive\0", "apk\0"}, + {MIME_APK, "application/vnd.android.package-archive\0", "apk\0"}, {MIME_CSS, "text/css\0", "css\0"}, {MIME_IMAGE_WEBP, "image/webp\0", "webp\0"}, {MIME_DJVU, "image/vnd.djvu\0image/x-djvu\0", "djvu\0djv\0"}, @@ -235,8 +235,8 @@ const char* MimeNames[MIME_MAX] = { "js", // MIME_JAVASCRIPT // 29 "epub", // MIME_EPUB // 30 "tex", // MIME_TEX // 31 - "json", // MIME_JSON // 32 - "apk", // MIME_APK // 33 + "json", // MIME_JSON // 32 + "apk", // MIME_APK // 33 "css", // MIME_CSS // 34 "webp", // MIME_IMAGE_WEBP // 35 "djvu", // MIME_DJVU // 36 diff --git a/library/cpp/mime/types/mime.h b/library/cpp/mime/types/mime.h index 05da389ea9..778f244445 100644 --- a/library/cpp/mime/types/mime.h +++ b/library/cpp/mime/types/mime.h @@ -44,7 +44,7 @@ enum MimeTypes { MIME_EPUB = 30, MIME_TEX = 31, MIME_JSON = 32, - MIME_APK = 33, + MIME_APK = 33, MIME_CSS = 34, MIME_IMAGE_WEBP = 35, MIME_DJVU = 36, @@ -67,6 +67,6 @@ const char* mimetypeByExt(const char* fname, const char* check_ext = nullptr); MimeTypes mimeByStr(const char* mimeStr); MimeTypes mimeByStr(const TStringBuf& mimeStr); const char* strByMime(MimeTypes mime); - -// autogenerated with GENERATE_ENUM_SERIALIZATION + +// autogenerated with GENERATE_ENUM_SERIALIZATION const TString& ToString(MimeTypes x); diff --git a/library/cpp/mime/types/ya.make b/library/cpp/mime/types/ya.make index a7f58aab3e..ee19420b14 100644 --- a/library/cpp/mime/types/ya.make +++ b/library/cpp/mime/types/ya.make @@ -1,11 +1,11 @@ -LIBRARY() - -OWNER(stanly) - -SRCS( - mime.cpp -) - -GENERATE_ENUM_SERIALIZATION(mime.h) - -END() +LIBRARY() + +OWNER(stanly) + +SRCS( + mime.cpp +) + +GENERATE_ENUM_SERIALIZATION(mime.h) + +END() diff --git a/library/cpp/mime/ya.make b/library/cpp/mime/ya.make index 8ce42f207d..0bddced9d0 100644 --- a/library/cpp/mime/ya.make +++ b/library/cpp/mime/ya.make @@ -1,5 +1,5 @@ -RECURSE( - detect +RECURSE( + detect detect_ut - types -) + types +) diff --git a/library/cpp/monlib/counters/counters.h b/library/cpp/monlib/counters/counters.h index 038b55f0c8..d30b78e12c 100644 --- a/library/cpp/monlib/counters/counters.h +++ b/library/cpp/monlib/counters/counters.h @@ -80,7 +80,7 @@ namespace NMonitoring { TValueBase Sub(const TValue val) { return AtomicAdd(Value, -val); } - + // operator overloads convinient void operator++() { Inc(); @@ -107,7 +107,7 @@ namespace NMonitoring { AtomicSwap(&Value, rhs); return rhs; } - + bool operator!() const { return AtomicGet(Value) == 0; } diff --git a/library/cpp/monlib/service/service.cpp b/library/cpp/monlib/service/service.cpp index 929efbf816..d61d0782fa 100644 --- a/library/cpp/monlib/service/service.cpp +++ b/library/cpp/monlib/service/service.cpp @@ -55,7 +55,7 @@ namespace NMonitoring { } const char* GetURI() const override { - return Header.request_uri.c_str(); + return Header.request_uri.c_str(); } const char* GetPath() const override { return Url.Get(THttpURL::FieldPath); diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp index 05c201f0de..92060ad00f 100644 --- a/library/cpp/string_utils/base64/base64.cpp +++ b/library/cpp/string_utils/base64/base64.cpp @@ -246,14 +246,14 @@ size_t Base64Decode(void* dst, const char* b, const char* e) { } TString Base64DecodeUneven(const TStringBuf s) { - if (s.length() % 4 == 0) { - return Base64Decode(s); - } - - // padding to 4 + if (s.length() % 4 == 0) { + return Base64Decode(s); + } + + // padding to 4 return Base64Decode(TString(s) + TString(4 - (s.length() % 4), '=')); -} - +} + char* Base64Encode(char* outstr, const unsigned char* instr, size_t len) { static const TImpl IMPL = GetImpl(); if (Y_LIKELY(len < 8)) { diff --git a/library/cpp/string_utils/base64/base64.h b/library/cpp/string_utils/base64/base64.h index f778a6425a..7941dd4d03 100644 --- a/library/cpp/string_utils/base64/base64.h +++ b/library/cpp/string_utils/base64/base64.h @@ -88,9 +88,9 @@ inline TString Base64StrictDecode(const TStringBuf src) { } /// @} -/// Works with strings which length is not divisible by 4. +/// Works with strings which length is not divisible by 4. TString Base64DecodeUneven(const TStringBuf s); - + //encode constexpr size_t Base64EncodeBufSize(const size_t len) noexcept { return (len + 2) / 3 * 4 + 1; diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index e523350b80..672e122d3d 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -276,14 +276,14 @@ TString UrlUnescapeRet(const TStringBuf from) { return to; } -char* UrlEscape(char* to, const char* from, bool forceEscape) { +char* UrlEscape(char* to, const char* from, bool forceEscape) { from = FixZero(from); while (*from) { - const bool escapePercent = (*from == '%') && - (forceEscape || !((*(from + 1) && IsAsciiHex(*(from + 1)) && *(from + 2) && IsAsciiHex(*(from + 2))))); - - if (escapePercent || (unsigned char)*from <= ' ' || (unsigned char)*from > '~') { + const bool escapePercent = (*from == '%') && + (forceEscape || !((*(from + 1) && IsAsciiHex(*(from + 1)) && *(from + 2) && IsAsciiHex(*(from + 2))))); + + if (escapePercent || (unsigned char)*from <= ' ' || (unsigned char)*from > '~') { *to++ = '%'; *to++ = d2x((unsigned char)*from >> 4); *to++ = d2x((unsigned char)*from & 0xF); @@ -297,7 +297,7 @@ char* UrlEscape(char* to, const char* from, bool forceEscape) { return to; } -void UrlEscape(TString& url, bool forceEscape) { +void UrlEscape(TString& url, bool forceEscape) { TTempBuf tempBuf(CgiEscapeBufLen(url.size())); char* to = tempBuf.Data(); url.AssignNoAlias(to, UrlEscape(to, url.data(), forceEscape)); diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h index 3b7221154e..9163769fc4 100644 --- a/library/cpp/string_utils/quote/quote.h +++ b/library/cpp/string_utils/quote/quote.h @@ -48,11 +48,11 @@ void Quote(TString& url, const char* safe = "/"); //UrlEscape: // Can't be used for cgi parameters ('&' character is not escaped)! -// escapes only '%' not followed by two hex-digits or if forceEscape set to ture, -// and chars outside [32, 126] range. +// escapes only '%' not followed by two hex-digits or if forceEscape set to ture, +// and chars outside [32, 126] range. // Can't handle '\0'-chars in TString. -char* UrlEscape(char* to, const char* from, bool forceEscape = false); -void UrlEscape(TString& url, bool forceEscape = false); +char* UrlEscape(char* to, const char* from, bool forceEscape = false); +void UrlEscape(TString& url, bool forceEscape = false); TString UrlEscapeRet(const TStringBuf from, bool forceEscape = false); //UrlUnescape: diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp index 6c552b279e..5f6fb583a3 100644 --- a/library/cpp/string_utils/quote/quote_ut.cpp +++ b/library/cpp/string_utils/quote/quote_ut.cpp @@ -178,25 +178,25 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { } } -Y_UNIT_TEST_SUITE(TUrlEscapeTest) { - Y_UNIT_TEST(EscapeEscaped) { - TString s; - - s = "hello%3dworld"; +Y_UNIT_TEST_SUITE(TUrlEscapeTest) { + Y_UNIT_TEST(EscapeEscaped) { + TString s; + + s = "hello%3dworld"; UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s), "hello%3dworld"); - UrlEscape(s); - UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); - } - - Y_UNIT_TEST(EscapeUnescape) { - TString s; - - s = "hello%3dworld"; - UrlEscape(s); - UrlUnescape(s); - UNIT_ASSERT_VALUES_EQUAL(s, "hello=world"); - } - + UrlEscape(s); + UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); + } + + Y_UNIT_TEST(EscapeUnescape) { + TString s; + + s = "hello%3dworld"; + UrlEscape(s); + UrlUnescape(s); + UNIT_ASSERT_VALUES_EQUAL(s, "hello=world"); + } + Y_UNIT_TEST(EscapeUnescapeRet) { TString s; @@ -204,23 +204,23 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s)), "hello=world"); } - Y_UNIT_TEST(EscapeEscapedForce) { - TString s; - - s = "hello%3dworld"; + Y_UNIT_TEST(EscapeEscapedForce) { + TString s; + + s = "hello%3dworld"; UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s, true), "hello%253dworld"); - UrlEscape(s, true); - UNIT_ASSERT_VALUES_EQUAL(s, "hello%253dworld"); - } - - Y_UNIT_TEST(EscapeUnescapeForce) { - TString s; - - s = "hello%3dworld"; - UrlEscape(s, true); - UrlUnescape(s); - UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); - } + UrlEscape(s, true); + UNIT_ASSERT_VALUES_EQUAL(s, "hello%253dworld"); + } + + Y_UNIT_TEST(EscapeUnescapeForce) { + TString s; + + s = "hello%3dworld"; + UrlEscape(s, true); + UrlUnescape(s); + UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); + } Y_UNIT_TEST(EscapeUnescapeForceRet) { TString s; @@ -228,8 +228,8 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { s = "hello%3dworld"; UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s, true)), "hello%3dworld"); } -} - +} + Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { Y_UNIT_TEST(StrokaOutParameterInplace) { TString s; diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp index 1588013893..a103661002 100644 --- a/library/cpp/string_utils/url/url_ut.cpp +++ b/library/cpp/string_utils/url/url_ut.cpp @@ -97,7 +97,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("ftp://ya.ru", CutHttpPrefix("ftp://ya.ru")); UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz", true)); + UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz", true)); UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz")); UNIT_ASSERT_VALUES_EQUAL("https://ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz", true)); UNIT_ASSERT_VALUES_EQUAL("", CutHttpPrefix("https://")); // is that right? diff --git a/library/cpp/testing/unittest/registar.cpp b/library/cpp/testing/unittest/registar.cpp index 3679b768ed..b43f9c6a4f 100644 --- a/library/cpp/testing/unittest/registar.cpp +++ b/library/cpp/testing/unittest/registar.cpp @@ -155,189 +155,189 @@ TString NUnitTest::ColoredDiff(TStringBuf s1, TStringBuf s2, const TString& deli } return res.Str(); } - -static TString MakeTestName(const NUnitTest::ITestSuiteProcessor::TTest& test) { - return TStringBuilder() << test.unit->name << "::" << test.name; -} - + +static TString MakeTestName(const NUnitTest::ITestSuiteProcessor::TTest& test) { + return TStringBuilder() << test.unit->name << "::" << test.name; +} + static size_t CountTests(const TMap<TString, size_t>& testErrors, bool succeeded) { - size_t cnt = 0; - for (const auto& t : testErrors) { - if (succeeded && t.second == 0) { - ++cnt; - } else if (!succeeded && t.second > 0) { - ++cnt; - } - } - return cnt; -} - -NUnitTest::ITestSuiteProcessor::ITestSuiteProcessor() = default; - -NUnitTest::ITestSuiteProcessor::~ITestSuiteProcessor() = default; - -void NUnitTest::ITestSuiteProcessor::Start() { - OnStart(); -} - -void NUnitTest::ITestSuiteProcessor::End() { - OnEnd(); -} - -void NUnitTest::ITestSuiteProcessor::UnitStart(const TUnit& unit) { - CurTestErrors_.clear(); - - OnUnitStart(&unit); -} - -void NUnitTest::ITestSuiteProcessor::UnitStop(const TUnit& unit) { - OnUnitStop(&unit); -} - -void NUnitTest::ITestSuiteProcessor::Error(const TError& descr) { - AddTestError(*descr.test); - - OnError(&descr); -} - -void NUnitTest::ITestSuiteProcessor::BeforeTest(const TTest& test) { - OnBeforeTest(&test); -} - -void NUnitTest::ITestSuiteProcessor::Finish(const TFinish& descr) { - AddTestFinish(*descr.test); - - OnFinish(&descr); -} - -unsigned NUnitTest::ITestSuiteProcessor::GoodTests() const noexcept { - return CountTests(TestErrors_, true); -} - -unsigned NUnitTest::ITestSuiteProcessor::FailTests() const noexcept { - return CountTests(TestErrors_, false); -} - -unsigned NUnitTest::ITestSuiteProcessor::GoodTestsInCurrentUnit() const noexcept { - return CountTests(CurTestErrors_, true); -} - -unsigned NUnitTest::ITestSuiteProcessor::FailTestsInCurrentUnit() const noexcept { - return CountTests(CurTestErrors_, false); -} - -bool NUnitTest::ITestSuiteProcessor::CheckAccess(TString /*name*/, size_t /*num*/) { - return true; -} - -bool NUnitTest::ITestSuiteProcessor::CheckAccessTest(TString /*suite*/, const char* /*name*/) { - return true; -} - + size_t cnt = 0; + for (const auto& t : testErrors) { + if (succeeded && t.second == 0) { + ++cnt; + } else if (!succeeded && t.second > 0) { + ++cnt; + } + } + return cnt; +} + +NUnitTest::ITestSuiteProcessor::ITestSuiteProcessor() = default; + +NUnitTest::ITestSuiteProcessor::~ITestSuiteProcessor() = default; + +void NUnitTest::ITestSuiteProcessor::Start() { + OnStart(); +} + +void NUnitTest::ITestSuiteProcessor::End() { + OnEnd(); +} + +void NUnitTest::ITestSuiteProcessor::UnitStart(const TUnit& unit) { + CurTestErrors_.clear(); + + OnUnitStart(&unit); +} + +void NUnitTest::ITestSuiteProcessor::UnitStop(const TUnit& unit) { + OnUnitStop(&unit); +} + +void NUnitTest::ITestSuiteProcessor::Error(const TError& descr) { + AddTestError(*descr.test); + + OnError(&descr); +} + +void NUnitTest::ITestSuiteProcessor::BeforeTest(const TTest& test) { + OnBeforeTest(&test); +} + +void NUnitTest::ITestSuiteProcessor::Finish(const TFinish& descr) { + AddTestFinish(*descr.test); + + OnFinish(&descr); +} + +unsigned NUnitTest::ITestSuiteProcessor::GoodTests() const noexcept { + return CountTests(TestErrors_, true); +} + +unsigned NUnitTest::ITestSuiteProcessor::FailTests() const noexcept { + return CountTests(TestErrors_, false); +} + +unsigned NUnitTest::ITestSuiteProcessor::GoodTestsInCurrentUnit() const noexcept { + return CountTests(CurTestErrors_, true); +} + +unsigned NUnitTest::ITestSuiteProcessor::FailTestsInCurrentUnit() const noexcept { + return CountTests(CurTestErrors_, false); +} + +bool NUnitTest::ITestSuiteProcessor::CheckAccess(TString /*name*/, size_t /*num*/) { + return true; +} + +bool NUnitTest::ITestSuiteProcessor::CheckAccessTest(TString /*suite*/, const char* /*name*/) { + return true; +} + void NUnitTest::ITestSuiteProcessor::Run(std::function<void()> f, const TString& /*suite*/, const char* /*name*/, const bool /*forceFork*/) { - f(); -} - -bool NUnitTest::ITestSuiteProcessor::GetIsForked() const { - return false; -} - -bool NUnitTest::ITestSuiteProcessor::GetForkTests() const { - return false; -} - -void NUnitTest::ITestSuiteProcessor::OnStart() { -} - -void NUnitTest::ITestSuiteProcessor::OnEnd() { -} - -void NUnitTest::ITestSuiteProcessor::OnUnitStart(const TUnit* /*unit*/) { -} - -void NUnitTest::ITestSuiteProcessor::OnUnitStop(const TUnit* /*unit*/) { -} - -void NUnitTest::ITestSuiteProcessor::OnError(const TError* /*error*/) { -} - -void NUnitTest::ITestSuiteProcessor::OnFinish(const TFinish* /*finish*/) { -} - -void NUnitTest::ITestSuiteProcessor::OnBeforeTest(const TTest* /*test*/) { -} - -void NUnitTest::ITestSuiteProcessor::AddTestError(const TTest& test) { - const TString name = MakeTestName(test); - ++TestErrors_[name]; - ++CurTestErrors_[name]; -} - -void NUnitTest::ITestSuiteProcessor::AddTestFinish(const TTest& test) { - const TString name = MakeTestName(test); - TestErrors_[name]; // zero errors if not touched - CurTestErrors_[name]; // zero errors if not touched -} - -NUnitTest::ITestBaseFactory::ITestBaseFactory() { - Register(); -} - -NUnitTest::ITestBaseFactory::~ITestBaseFactory() = default; - -void NUnitTest::ITestBaseFactory::Register() noexcept { - TTestFactory::Instance().Register(this); -} - -NUnitTest::TTestBase::TTestBase() noexcept + f(); +} + +bool NUnitTest::ITestSuiteProcessor::GetIsForked() const { + return false; +} + +bool NUnitTest::ITestSuiteProcessor::GetForkTests() const { + return false; +} + +void NUnitTest::ITestSuiteProcessor::OnStart() { +} + +void NUnitTest::ITestSuiteProcessor::OnEnd() { +} + +void NUnitTest::ITestSuiteProcessor::OnUnitStart(const TUnit* /*unit*/) { +} + +void NUnitTest::ITestSuiteProcessor::OnUnitStop(const TUnit* /*unit*/) { +} + +void NUnitTest::ITestSuiteProcessor::OnError(const TError* /*error*/) { +} + +void NUnitTest::ITestSuiteProcessor::OnFinish(const TFinish* /*finish*/) { +} + +void NUnitTest::ITestSuiteProcessor::OnBeforeTest(const TTest* /*test*/) { +} + +void NUnitTest::ITestSuiteProcessor::AddTestError(const TTest& test) { + const TString name = MakeTestName(test); + ++TestErrors_[name]; + ++CurTestErrors_[name]; +} + +void NUnitTest::ITestSuiteProcessor::AddTestFinish(const TTest& test) { + const TString name = MakeTestName(test); + TestErrors_[name]; // zero errors if not touched + CurTestErrors_[name]; // zero errors if not touched +} + +NUnitTest::ITestBaseFactory::ITestBaseFactory() { + Register(); +} + +NUnitTest::ITestBaseFactory::~ITestBaseFactory() = default; + +void NUnitTest::ITestBaseFactory::Register() noexcept { + TTestFactory::Instance().Register(this); +} + +NUnitTest::TTestBase::TTestBase() noexcept : Parent_(nullptr) , TestErrors_() , CurrentSubtest_() { -} - -NUnitTest::TTestBase::~TTestBase() = default; - -TString NUnitTest::TTestBase::TypeId() const { +} + +NUnitTest::TTestBase::~TTestBase() = default; + +TString NUnitTest::TTestBase::TypeId() const { return TypeName(*this); -} - -void NUnitTest::TTestBase::SetUp() { -} - -void NUnitTest::TTestBase::TearDown() { -} - +} + +void NUnitTest::TTestBase::SetUp() { +} + +void NUnitTest::TTestBase::TearDown() { +} + void NUnitTest::TTestBase::AddError(const char* msg, const TString& backtrace, TTestContext* context) { - ++TestErrors_; - const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; - const NUnitTest::ITestSuiteProcessor::TTest test = {&unit, CurrentSubtest_}; - const NUnitTest::ITestSuiteProcessor::TError err = {&test, msg, backtrace, context}; - - Processor()->Error(err); -} - + ++TestErrors_; + const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; + const NUnitTest::ITestSuiteProcessor::TTest test = {&unit, CurrentSubtest_}; + const NUnitTest::ITestSuiteProcessor::TError err = {&test, msg, backtrace, context}; + + Processor()->Error(err); +} + void NUnitTest::TTestBase::AddError(const char* msg, TTestContext* context) { - AddError(msg, TString(), context); -} - + AddError(msg, TString(), context); +} + void NUnitTest::TTestBase::RunAfterTest(std::function<void()> f) { with_lock (AfterTestFunctionsLock_) { AfterTestFunctions_.emplace_back(std::move(f)); } } -bool NUnitTest::TTestBase::CheckAccessTest(const char* test) { - return Processor()->CheckAccessTest(Name(), test); -} - -void NUnitTest::TTestBase::BeforeTest(const char* func) { - const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; - const NUnitTest::ITestSuiteProcessor::TTest test = {&unit, func}; +bool NUnitTest::TTestBase::CheckAccessTest(const char* test) { + return Processor()->CheckAccessTest(Name(), test); +} + +void NUnitTest::TTestBase::BeforeTest(const char* func) { + const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; + const NUnitTest::ITestSuiteProcessor::TTest test = {&unit, func}; rusage.Fill(); - Processor()->BeforeTest(test); -} - + Processor()->BeforeTest(test); +} + void NUnitTest::TTestBase::Finish(const char* func, TTestContext* context) { TRusage finishRusage = TRusage::Get(); context->Metrics["ru_rss"] = finishRusage.MaxRss - rusage.MaxRss; @@ -345,37 +345,37 @@ void NUnitTest::TTestBase::Finish(const char* func, TTestContext* context) { context->Metrics["ru_utime"] = (finishRusage.Utime - rusage.Utime).MicroSeconds(); context->Metrics["ru_stime"] = (finishRusage.Stime - rusage.Stime).MicroSeconds(); - const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; - const NUnitTest::ITestSuiteProcessor::TTest test = {&unit, func}; - const NUnitTest::ITestSuiteProcessor::TFinish finish = {&test, context, TestErrors_ == 0}; - - Processor()->Finish(finish); -} - -void NUnitTest::TTestBase::AtStart() { - const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; - - Processor()->UnitStart(unit); -} - -void NUnitTest::TTestBase::AtEnd() { - const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; - - Processor()->UnitStop(unit); -} - + const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; + const NUnitTest::ITestSuiteProcessor::TTest test = {&unit, func}; + const NUnitTest::ITestSuiteProcessor::TFinish finish = {&test, context, TestErrors_ == 0}; + + Processor()->Finish(finish); +} + +void NUnitTest::TTestBase::AtStart() { + const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; + + Processor()->UnitStart(unit); +} + +void NUnitTest::TTestBase::AtEnd() { + const NUnitTest::ITestSuiteProcessor::TUnit unit = {Name()}; + + Processor()->UnitStop(unit); +} + void NUnitTest::TTestBase::Run(std::function<void()> f, const TString& suite, const char* name, const bool forceFork) { - TestErrors_ = 0; - CurrentSubtest_ = name; - Processor()->Run(f, suite, name, forceFork); -} - -void NUnitTest::TTestBase::BeforeTest() { - SetUp(); -} - -void NUnitTest::TTestBase::AfterTest() { - TearDown(); + TestErrors_ = 0; + CurrentSubtest_ = name; + Processor()->Run(f, suite, name, forceFork); +} + +void NUnitTest::TTestBase::BeforeTest() { + SetUp(); +} + +void NUnitTest::TTestBase::AfterTest() { + TearDown(); TVector<std::function<void()>> afterTestFunctions; with_lock (AfterTestFunctionsLock_) { @@ -388,126 +388,126 @@ void NUnitTest::TTestBase::AfterTest() { f(); } } -} - -bool NUnitTest::TTestBase::GetIsForked() const { - return Processor()->GetIsForked(); -} - -bool NUnitTest::TTestBase::GetForkTests() const { - return Processor()->GetForkTests(); -} - -NUnitTest::ITestSuiteProcessor* NUnitTest::TTestBase::Processor() const noexcept { - return Parent_->Processor(); -} - -NUnitTest::TTestBase::TCleanUp::TCleanUp(TTestBase* base) - : Base_(base) -{ - ::NUnitTest::NPrivate::SetCurrentTest(base); - ::NUnitTest::NPrivate::SetUnittestThread(true); - Base_->BeforeTest(); -} - -NUnitTest::TTestBase::TCleanUp::~TCleanUp() { - try { - Base_->AfterTest(); - } catch (...) { +} + +bool NUnitTest::TTestBase::GetIsForked() const { + return Processor()->GetIsForked(); +} + +bool NUnitTest::TTestBase::GetForkTests() const { + return Processor()->GetForkTests(); +} + +NUnitTest::ITestSuiteProcessor* NUnitTest::TTestBase::Processor() const noexcept { + return Parent_->Processor(); +} + +NUnitTest::TTestBase::TCleanUp::TCleanUp(TTestBase* base) + : Base_(base) +{ + ::NUnitTest::NPrivate::SetCurrentTest(base); + ::NUnitTest::NPrivate::SetUnittestThread(true); + Base_->BeforeTest(); +} + +NUnitTest::TTestBase::TCleanUp::~TCleanUp() { + try { + Base_->AfterTest(); + } catch (...) { Base_->AddError(CurrentExceptionMessage().data()); - } - ::NUnitTest::NPrivate::SetUnittestThread(false); - ::NUnitTest::NPrivate::SetCurrentTest(nullptr); -} - -namespace { - /* - * by default do nothing - */ - class TCommonProcessor: public NUnitTest::ITestSuiteProcessor { - public: - TCommonProcessor() = default; - - ~TCommonProcessor() override = default; - }; - - struct TCmp { - template <class T> - inline bool operator()(const T& l, const T& r) const noexcept { + } + ::NUnitTest::NPrivate::SetUnittestThread(false); + ::NUnitTest::NPrivate::SetCurrentTest(nullptr); +} + +namespace { + /* + * by default do nothing + */ + class TCommonProcessor: public NUnitTest::ITestSuiteProcessor { + public: + TCommonProcessor() = default; + + ~TCommonProcessor() override = default; + }; + + struct TCmp { + template <class T> + inline bool operator()(const T& l, const T& r) const noexcept { return stricmp(Fix(l.Name().data()), Fix(r.Name().data())) < 0; - } - - static inline const char* Fix(const char* n) noexcept { - if (*n == 'T') { - return n + 1; - } - - return n; - } - }; -} - -NUnitTest::TTestFactory::TTestFactory(ITestSuiteProcessor* processor) - : Processor_(processor) -{ -} - -NUnitTest::TTestFactory::~TTestFactory() = default; - -NUnitTest::TTestFactory& NUnitTest::TTestFactory::Instance() { - static TCommonProcessor p; - static TTestFactory f(&p); - - return f; -} - -unsigned NUnitTest::TTestFactory::Execute() { - Items_.QuickSort(TCmp()); - Processor_->Start(); - + } + + static inline const char* Fix(const char* n) noexcept { + if (*n == 'T') { + return n + 1; + } + + return n; + } + }; +} + +NUnitTest::TTestFactory::TTestFactory(ITestSuiteProcessor* processor) + : Processor_(processor) +{ +} + +NUnitTest::TTestFactory::~TTestFactory() = default; + +NUnitTest::TTestFactory& NUnitTest::TTestFactory::Instance() { + static TCommonProcessor p; + static TTestFactory f(&p); + + return f; +} + +unsigned NUnitTest::TTestFactory::Execute() { + Items_.QuickSort(TCmp()); + Processor_->Start(); + TSet<TString> types; - size_t cnt = 0; - - for (TIntrusiveList<ITestBaseFactory>::TIterator factory = Items_.Begin(); factory != Items_.End(); ++factory) { - if (!Processor_->CheckAccess(factory->Name(), cnt++)) { - continue; - } - - THolder<TTestBase> test(factory->ConstructTest()); - -#ifdef _unix_ // on Windows RTTI causes memory leaks - TString type = test->TypeId(); - if (types.insert(type).second == false) { + size_t cnt = 0; + + for (TIntrusiveList<ITestBaseFactory>::TIterator factory = Items_.Begin(); factory != Items_.End(); ++factory) { + if (!Processor_->CheckAccess(factory->Name(), cnt++)) { + continue; + } + + THolder<TTestBase> test(factory->ConstructTest()); + +#ifdef _unix_ // on Windows RTTI causes memory leaks + TString type = test->TypeId(); + if (types.insert(type).second == false) { warnx("Duplicate suite found: %s (%s). Probably you have copy-pasted suite without changing it name", factory->Name().c_str(), type.c_str()); - return 1; - } -#endif // _unix_ - - test->Parent_ = this; - + return 1; + } +#endif // _unix_ + + test->Parent_ = this; + #ifdef UT_SKIP_EXCEPTIONS - try { -#endif - test->Execute(); + try { +#endif + test->Execute(); #ifdef UT_SKIP_EXCEPTIONS - } catch (...) { - } -#endif - } - - Processor_->End(); - + } catch (...) { + } +#endif + } + + Processor_->End(); + return bool(Processor_->FailTests()); -} - -void NUnitTest::TTestFactory::SetProcessor(ITestSuiteProcessor* processor) { - Processor_ = processor; -} - -void NUnitTest::TTestFactory::Register(ITestBaseFactory* b) noexcept { - Items_.PushBack(b); -} - -NUnitTest::ITestSuiteProcessor* NUnitTest::TTestFactory::Processor() const noexcept { - return Processor_; -} +} + +void NUnitTest::TTestFactory::SetProcessor(ITestSuiteProcessor* processor) { + Processor_ = processor; +} + +void NUnitTest::TTestFactory::Register(ITestBaseFactory* b) noexcept { + Items_.PushBack(b); +} + +NUnitTest::ITestSuiteProcessor* NUnitTest::TTestFactory::Processor() const noexcept { + return Processor_; +} diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index 44517a0092..3aaf80ebe9 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -3,13 +3,13 @@ #include <library/cpp/dbg_output/dump.h> #include <util/generic/bt_exception.h> -#include <util/generic/hash.h> +#include <util/generic/hash.h> #include <util/generic/intrlist.h> -#include <util/generic/map.h> +#include <util/generic/map.h> #include <util/generic/ptr.h> #include <util/generic/set.h> #include <util/generic/typetraits.h> -#include <util/generic/vector.h> +#include <util/generic/vector.h> #include <util/generic/yexception.h> #include <util/string/builder.h> @@ -103,64 +103,64 @@ namespace NUnitTest { bool Success; }; - ITestSuiteProcessor(); + ITestSuiteProcessor(); - virtual ~ITestSuiteProcessor(); + virtual ~ITestSuiteProcessor(); - void Start(); + void Start(); - void End(); + void End(); - void UnitStart(const TUnit& unit); + void UnitStart(const TUnit& unit); - void UnitStop(const TUnit& unit); + void UnitStop(const TUnit& unit); - void Error(const TError& descr); + void Error(const TError& descr); - void BeforeTest(const TTest& test); + void BeforeTest(const TTest& test); - void Finish(const TFinish& descr); + void Finish(const TFinish& descr); - unsigned GoodTests() const noexcept; + unsigned GoodTests() const noexcept; - unsigned FailTests() const noexcept; + unsigned FailTests() const noexcept; - unsigned GoodTestsInCurrentUnit() const noexcept; + unsigned GoodTestsInCurrentUnit() const noexcept; - unsigned FailTestsInCurrentUnit() const noexcept; + unsigned FailTestsInCurrentUnit() const noexcept; // Should execute test suite? - virtual bool CheckAccess(TString /*name*/, size_t /*num*/); + virtual bool CheckAccess(TString /*name*/, size_t /*num*/); // Should execute a test whitin suite? - virtual bool CheckAccessTest(TString /*suite*/, const char* /*name*/); + virtual bool CheckAccessTest(TString /*suite*/, const char* /*name*/); virtual void Run(std::function<void()> f, const TString& /*suite*/, const char* /*name*/, bool /*forceFork*/); // This process is forked for current test - virtual bool GetIsForked() const; - + virtual bool GetIsForked() const; + // --fork-tests is set (warning: this may be false, but never the less test will be forked if called inside UNIT_FORKED_TEST) - virtual bool GetForkTests() const; + virtual bool GetForkTests() const; private: - virtual void OnStart(); + virtual void OnStart(); - virtual void OnEnd(); + virtual void OnEnd(); - virtual void OnUnitStart(const TUnit* /*unit*/); + virtual void OnUnitStart(const TUnit* /*unit*/); - virtual void OnUnitStop(const TUnit* /*unit*/); + virtual void OnUnitStop(const TUnit* /*unit*/); - virtual void OnError(const TError* /*error*/); + virtual void OnError(const TError* /*error*/); - virtual void OnFinish(const TFinish* /*finish*/); + virtual void OnFinish(const TFinish* /*finish*/); - virtual void OnBeforeTest(const TTest* /*test*/); + virtual void OnBeforeTest(const TTest* /*test*/); - void AddTestError(const TTest& test); + void AddTestError(const TTest& test); - void AddTestFinish(const TTest& test); + void AddTestFinish(const TTest& test); private: TMap<TString, size_t> TestErrors_; @@ -172,16 +172,16 @@ namespace NUnitTest { class ITestBaseFactory: public TIntrusiveListItem<ITestBaseFactory> { public: - ITestBaseFactory(); + ITestBaseFactory(); - virtual ~ITestBaseFactory(); + virtual ~ITestBaseFactory(); // name of test suite virtual TString Name() const noexcept = 0; virtual TTestBase* ConstructTest() = 0; private: - void Register() noexcept; + void Register() noexcept; }; class TTestBase { @@ -189,18 +189,18 @@ namespace NUnitTest { TRusage rusage; public: - TTestBase() noexcept; + TTestBase() noexcept; - virtual ~TTestBase(); + virtual ~TTestBase(); - virtual TString TypeId() const; + virtual TString TypeId() const; virtual TString Name() const noexcept = 0; virtual void Execute() = 0; - virtual void SetUp(); + virtual void SetUp(); - virtual void TearDown(); + virtual void TearDown(); void AddError(const char* msg, const TString& backtrace = TString(), TTestContext* context = nullptr); @@ -209,15 +209,15 @@ namespace NUnitTest { void RunAfterTest(std::function<void()> f); // function like atexit to run after current unit test protected: - bool CheckAccessTest(const char* test); + bool CheckAccessTest(const char* test); - void BeforeTest(const char* func); + void BeforeTest(const char* func); void Finish(const char* func, TTestContext* context); - void AtStart(); + void AtStart(); - void AtEnd(); + void AtEnd(); void Run(std::function<void()> f, const TString& suite, const char* name, bool forceFork); @@ -225,21 +225,21 @@ namespace NUnitTest { public: explicit TCleanUp(TTestBase* base); - ~TCleanUp(); + ~TCleanUp(); private: TTestBase* Base_; }; - void BeforeTest(); - - void AfterTest(); + void BeforeTest(); - bool GetIsForked() const; + void AfterTest(); - bool GetForkTests() const; + bool GetIsForked() const; - ITestSuiteProcessor* Processor() const noexcept; + bool GetForkTests() const; + + ITestSuiteProcessor* Processor() const noexcept; private: TTestFactory* Parent_; @@ -759,21 +759,21 @@ public: \ friend class ITestBaseFactory; public: - static TTestFactory& Instance(); + static TTestFactory& Instance(); - unsigned Execute(); + unsigned Execute(); - void SetProcessor(ITestSuiteProcessor* processor); + void SetProcessor(ITestSuiteProcessor* processor); private: - void Register(ITestBaseFactory* b) noexcept; + void Register(ITestBaseFactory* b) noexcept; - ITestSuiteProcessor* Processor() const noexcept; + ITestSuiteProcessor* Processor() const noexcept; private: explicit TTestFactory(ITestSuiteProcessor* processor); - ~TTestFactory(); + ~TTestFactory(); private: TIntrusiveList<ITestBaseFactory> Items_; @@ -783,13 +783,13 @@ public: \ template <class T> class TTestBaseFactory: public ITestBaseFactory { public: - ~TTestBaseFactory() override = default; + ~TTestBaseFactory() override = default; - inline TTestBase* ConstructTest() override { + inline TTestBase* ConstructTest() override { return new T; } - inline TString Name() const noexcept override { + inline TString Name() const noexcept override { return T::StaticName(); } }; @@ -804,7 +804,7 @@ public: \ : TBaseTestCase(nullptr, nullptr, false) { } - + inline TBaseTestCase(const char* name, std::function<void(TTestContext&)> body, bool forceFork) : Name_(name) , Body_(std::move(body)) diff --git a/library/cpp/uri/location.cpp b/library/cpp/uri/location.cpp index a6a4d11ffa..e5df7a3858 100644 --- a/library/cpp/uri/location.cpp +++ b/library/cpp/uri/location.cpp @@ -1,15 +1,15 @@ -#include "location.h" -#include "uri.h" - -namespace NUri { +#include "location.h" +#include "uri.h" + +namespace NUri { static const int URI_PARSE_FLAGS = (TFeature::FeaturesRecommended | TFeature::FeatureConvertHostIDN | TFeature::FeatureEncodeExtendedDelim | TFeature::FeatureEncodePercent) & ~TFeature::FeatureHashBangToEscapedFragment; - + TString ResolveRedirectLocation(const TStringBuf& baseUrl, const TStringBuf& location) { TUri baseUri; TUri locationUri; - + // Parse base URL. if (baseUri.Parse(baseUrl, URI_PARSE_FLAGS) != NUri::TState::ParsedOK) { return ""; @@ -26,6 +26,6 @@ namespace NUri { TString res; locationUri.Print(res, NUri::TField::FlagAllFields); return res; - } - -} + } + +} diff --git a/library/cpp/uri/location.h b/library/cpp/uri/location.h index 0f533fe0b5..ece4def07a 100644 --- a/library/cpp/uri/location.h +++ b/library/cpp/uri/location.h @@ -1,13 +1,13 @@ -#pragma once - -#include <util/generic/string.h> - -namespace NUri { +#pragma once + +#include <util/generic/string.h> + +namespace NUri { /** - * Resolve Location header according to https://tools.ietf.org/html/rfc7231#section-7.1.2 - * - * @return Resolved location's url or empty string in case of any error. - */ + * Resolve Location header according to https://tools.ietf.org/html/rfc7231#section-7.1.2 + * + * @return Resolved location's url or empty string in case of any error. + */ TString ResolveRedirectLocation(const TStringBuf& baseUrl, const TStringBuf& location); - -} + +} diff --git a/library/cpp/uri/location_ut.cpp b/library/cpp/uri/location_ut.cpp index 26a0f64471..58d1578a7d 100644 --- a/library/cpp/uri/location_ut.cpp +++ b/library/cpp/uri/location_ut.cpp @@ -1,40 +1,40 @@ -#include "location.h" - +#include "location.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TResolveRedirectTests) { Y_UNIT_TEST(Absolute) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com", "http://redir-example.com/sub"), "http://redir-example.com/sub"); - } + } Y_UNIT_TEST(AbsWithFragment) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com", "http://redir-example.com/sub#Hello"), "http://redir-example.com/sub#Hello"); - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com/#Hello", "http://redir-example.com/sub"), "http://redir-example.com/sub#Hello"); - } + } Y_UNIT_TEST(Rel) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com", "/sub"), "http://example.com/sub"); - } + } Y_UNIT_TEST(RelWithFragment) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com", "/sub#Hello"), "http://example.com/sub#Hello"); - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com/#Hello", "/sub"), "http://example.com/sub#Hello"); - } + } Y_UNIT_TEST(WrongLocation) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com", ""), ""); - } + } Y_UNIT_TEST(WrongBase) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("", "http://example.com"), ""); - } + } Y_UNIT_TEST(HashBangIsNothingSpecial) { - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com", "http://redir-example.com/sub#!Hello"), "http://redir-example.com/sub#!Hello"); - UNIT_ASSERT_EQUAL( + UNIT_ASSERT_EQUAL( NUri::ResolveRedirectLocation("http://example.com/#!Hello", "http://redir-example.com/sub"), "http://redir-example.com/sub#!Hello"); - } -} + } +} diff --git a/library/cpp/uri/ut/ya.make b/library/cpp/uri/ut/ya.make index b2b2c1291a..9f61239ab4 100644 --- a/library/cpp/uri/ut/ya.make +++ b/library/cpp/uri/ut/ya.make @@ -11,7 +11,7 @@ PEERDIR( ) SRCS( - location_ut.cpp + location_ut.cpp uri-ru_ut.cpp uri_ut.cpp ) diff --git a/library/cpp/uri/ya.make b/library/cpp/uri/ya.make index 8fc808a6af..ec2daed7c0 100644 --- a/library/cpp/uri/ya.make +++ b/library/cpp/uri/ya.make @@ -10,7 +10,7 @@ SRCS( common.cpp encode.cpp http_url.h - location.cpp + location.cpp other.cpp parse.cpp qargs.cpp |