diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
commit | 9abfb1a53b7f7b791444d1378e645d8fad9b06ed (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/string_utils | |
parent | 8cbc307de0221f84c80c42dcbe07d40727537e2c (diff) | |
download | ydb-9abfb1a53b7f7b791444d1378e645d8fad9b06ed.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/string_utils')
24 files changed, 862 insertions, 862 deletions
diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp index 9e90ed7bb1..05c201f0de 100644 --- a/library/cpp/string_utils/base64/base64.cpp +++ b/library/cpp/string_utils/base64/base64.cpp @@ -1,36 +1,36 @@ #include "base64.h" -#include <contrib/libs/base64/avx2/libbase64.h> -#include <contrib/libs/base64/ssse3/libbase64.h> -#include <contrib/libs/base64/neon32/libbase64.h> -#include <contrib/libs/base64/neon64/libbase64.h> -#include <contrib/libs/base64/plain32/libbase64.h> -#include <contrib/libs/base64/plain64/libbase64.h> - +#include <contrib/libs/base64/avx2/libbase64.h> +#include <contrib/libs/base64/ssse3/libbase64.h> +#include <contrib/libs/base64/neon32/libbase64.h> +#include <contrib/libs/base64/neon64/libbase64.h> +#include <contrib/libs/base64/plain32/libbase64.h> +#include <contrib/libs/base64/plain64/libbase64.h> + #include <util/generic/yexception.h> -#include <util/system/cpu_id.h> -#include <util/system/platform.h> - -#include <cstdlib> - -namespace { - struct TImpl { - void (*Encode)(const char* src, size_t srclen, char* out, size_t* outlen); - int (*Decode)(const char* src, size_t srclen, char* out, size_t* outlen); - - TImpl() { -#if defined(_arm32_) - const bool haveNEON32 = true; -#else - const bool haveNEON32 = false; -#endif - -#if defined(_arm64_) - const bool haveNEON64 = true; -#else - const bool haveNEON64 = false; -#endif - +#include <util/system/cpu_id.h> +#include <util/system/platform.h> + +#include <cstdlib> + +namespace { + struct TImpl { + void (*Encode)(const char* src, size_t srclen, char* out, size_t* outlen); + int (*Decode)(const char* src, size_t srclen, char* out, size_t* outlen); + + TImpl() { +#if defined(_arm32_) + const bool haveNEON32 = true; +#else + const bool haveNEON32 = false; +#endif + +#if defined(_arm64_) + const bool haveNEON64 = true; +#else + const bool haveNEON64 = false; +#endif + # ifdef _windows_ // msvc does something wrong in release-build, so we temprorary disable this branch on windows // https://developercommunity.visualstudio.com/content/problem/334085/release-build-has-made-wrong-optimizaion-in-base64.html @@ -39,59 +39,59 @@ namespace { const bool isWin = false; # endif if (!isWin && NX86::HaveAVX() && NX86::HaveAVX2()) { - Encode = avx2_base64_encode; - Decode = avx2_base64_decode; - } else if (NX86::HaveSSSE3()) { - Encode = ssse3_base64_encode; - Decode = ssse3_base64_decode; - } else if (haveNEON64) { - Encode = neon64_base64_encode; - Decode = neon64_base64_decode; - } else if (haveNEON32) { - Encode = neon32_base64_encode; - Decode = neon32_base64_decode; - } else if (sizeof(void*) == 8) { - // running on a 64 bit platform - Encode = plain64_base64_encode; - Decode = plain64_base64_decode; - } else if (sizeof(void*) == 4) { - // running on a 32 bit platform (actually impossible in Arcadia) - Encode = plain32_base64_encode; - Decode = plain32_base64_decode; - } else { - // failed to find appropriate implementation - std::abort(); - } - } - }; - + Encode = avx2_base64_encode; + Decode = avx2_base64_decode; + } else if (NX86::HaveSSSE3()) { + Encode = ssse3_base64_encode; + Decode = ssse3_base64_decode; + } else if (haveNEON64) { + Encode = neon64_base64_encode; + Decode = neon64_base64_decode; + } else if (haveNEON32) { + Encode = neon32_base64_encode; + Decode = neon32_base64_decode; + } else if (sizeof(void*) == 8) { + // running on a 64 bit platform + Encode = plain64_base64_encode; + Decode = plain64_base64_decode; + } else if (sizeof(void*) == 4) { + // running on a 32 bit platform (actually impossible in Arcadia) + Encode = plain32_base64_encode; + Decode = plain32_base64_decode; + } else { + // failed to find appropriate implementation + std::abort(); + } + } + }; + const TImpl GetImpl() { - static const TImpl IMPL; - return IMPL; - } -} - + static const TImpl IMPL; + return IMPL; + } +} + static const char base64_etab_std[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const char base64_bkw[] = { - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', // 0..15 - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', // 16..31 - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\76', '\0', '\76', '\0', '\77', // 32.47 - '\64', '\65', '\66', '\67', '\70', '\71', '\72', '\73', '\74', '\75', '\0', '\0', '\0', '\0', '\0', '\0', // 48..63 - '\0', '\0', '\1', '\2', '\3', '\4', '\5', '\6', '\7', '\10', '\11', '\12', '\13', '\14', '\15', '\16', // 64..79 - '\17', '\20', '\21', '\22', '\23', '\24', '\25', '\26', '\27', '\30', '\31', '\0', '\0', '\0', '\0', '\77', // 80..95 - '\0', '\32', '\33', '\34', '\35', '\36', '\37', '\40', '\41', '\42', '\43', '\44', '\45', '\46', '\47', '\50', // 96..111 - '\51', '\52', '\53', '\54', '\55', '\56', '\57', '\60', '\61', '\62', '\63', '\0', '\0', '\0', '\0', '\0', // 112..127 - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', // 128..143 - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}; - -static_assert(Y_ARRAY_SIZE(base64_bkw) == 256, "wrong size"); - +static const char base64_bkw[] = { + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', // 0..15 + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', // 16..31 + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\76', '\0', '\76', '\0', '\77', // 32.47 + '\64', '\65', '\66', '\67', '\70', '\71', '\72', '\73', '\74', '\75', '\0', '\0', '\0', '\0', '\0', '\0', // 48..63 + '\0', '\0', '\1', '\2', '\3', '\4', '\5', '\6', '\7', '\10', '\11', '\12', '\13', '\14', '\15', '\16', // 64..79 + '\17', '\20', '\21', '\22', '\23', '\24', '\25', '\26', '\27', '\30', '\31', '\0', '\0', '\0', '\0', '\77', // 80..95 + '\0', '\32', '\33', '\34', '\35', '\36', '\37', '\40', '\41', '\42', '\43', '\44', '\45', '\46', '\47', '\50', // 96..111 + '\51', '\52', '\53', '\54', '\55', '\56', '\57', '\60', '\61', '\62', '\63', '\0', '\0', '\0', '\0', '\0', // 112..127 + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', // 128..143 + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}; + +static_assert(Y_ARRAY_SIZE(base64_bkw) == 256, "wrong size"); + // Base64 for url encoding, RFC3548 static const char base64_etab_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; @@ -141,7 +141,7 @@ static inline char* Base64EncodeImpl(char* outstr, const unsigned char* instr, s return outstr; } -static char* Base64EncodePlain(char* outstr, const unsigned char* instr, size_t len) { +static char* Base64EncodePlain(char* outstr, const unsigned char* instr, size_t len) { return Base64EncodeImpl<false>(outstr, instr, len); } @@ -155,7 +155,7 @@ inline void uudecode_1(char* dst, unsigned char* src) { dst[2] = char((base64_bkw[src[2]] << 6) | base64_bkw[src[3]]); } -static size_t Base64DecodePlain(void* dst, const char* b, const char* e) { +static size_t Base64DecodePlain(void* dst, const char* b, const char* e) { size_t n = 0; while (b < e) { uudecode_1((char*)dst + n, (unsigned char*)b); @@ -193,7 +193,7 @@ size_t Base64StrictDecode(void* out, const char* b, const char* e) { const unsigned char* src = (unsigned char*)b; const unsigned char* const end = (unsigned char*)e; - Y_ENSURE(!((e - b) % 4), "incorrect input length for base64 decode"); + Y_ENSURE(!((e - b) % 4), "incorrect input length for base64 decode"); while (src < end) { const char zeroth = base64_bkw_strict[src[0]]; @@ -203,10 +203,10 @@ size_t Base64StrictDecode(void* out, const char* b, const char* e) { constexpr char invalid = 64; constexpr char padding = 65; - if (Y_UNLIKELY(zeroth == invalid || first == invalid || - second == invalid || third == invalid || - zeroth == padding || first == padding)) - { + if (Y_UNLIKELY(zeroth == invalid || first == invalid || + second == invalid || third == invalid || + zeroth == padding || first == padding)) + { ythrow yexception() << "invalid character in input"; } @@ -223,28 +223,28 @@ size_t Base64StrictDecode(void* out, const char* b, const char* e) { if (src[-2] == ',' || src[-2] == '=') { --dst; } - } else if (Y_UNLIKELY(src[-2] == ',' || src[-2] == '=')) { + } else if (Y_UNLIKELY(src[-2] == ',' || src[-2] == '=')) { ythrow yexception() << "incorrect padding"; } } return dst - (char*)out; } - -size_t Base64Decode(void* dst, const char* b, const char* e) { - static const TImpl IMPL = GetImpl(); - const auto size = e - b; - Y_ENSURE(!(size % 4), "incorrect input length for base64 decode"); - if (Y_LIKELY(size < 8)) { - return Base64DecodePlain(dst, b, e); - } - - size_t outLen; - IMPL.Decode(b, size, (char*)dst, &outLen); - - return outLen; -} - + +size_t Base64Decode(void* dst, const char* b, const char* e) { + static const TImpl IMPL = GetImpl(); + const auto size = e - b; + Y_ENSURE(!(size % 4), "incorrect input length for base64 decode"); + if (Y_LIKELY(size < 8)) { + return Base64DecodePlain(dst, b, e); + } + + size_t outLen; + IMPL.Decode(b, size, (char*)dst, &outLen); + + return outLen; +} + TString Base64DecodeUneven(const TStringBuf s) { if (s.length() % 4 == 0) { return Base64Decode(s); @@ -254,15 +254,15 @@ TString Base64DecodeUneven(const TStringBuf s) { 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)) { - return Base64EncodePlain(outstr, instr, len); - } - - size_t outLen; - IMPL.Encode((char*)instr, len, outstr, &outLen); - - *(outstr + outLen) = '\0'; - return outstr + outLen; -} +char* Base64Encode(char* outstr, const unsigned char* instr, size_t len) { + static const TImpl IMPL = GetImpl(); + if (Y_LIKELY(len < 8)) { + return Base64EncodePlain(outstr, instr, len); + } + + size_t outLen; + IMPL.Encode((char*)instr, len, outstr, &outLen); + + *(outstr + outLen) = '\0'; + return outstr + outLen; +} diff --git a/library/cpp/string_utils/base64/base64.h b/library/cpp/string_utils/base64/base64.h index 57a121537d..f778a6425a 100644 --- a/library/cpp/string_utils/base64/base64.h +++ b/library/cpp/string_utils/base64/base64.h @@ -4,26 +4,26 @@ #include <util/generic/strbuf.h> #include <util/generic/string.h> -/* @return Size of the buffer required to decode Base64 encoded data of size `len`. - */ -constexpr size_t Base64DecodeBufSize(const size_t len) noexcept { - return (len + 3) / 4 * 3; +/* @return Size of the buffer required to decode Base64 encoded data of size `len`. + */ +constexpr size_t Base64DecodeBufSize(const size_t len) noexcept { + return (len + 3) / 4 * 3; } -/* Decode Base64 encoded data. Can decode both regular Base64 and Base64URL encoded data. Can decode - * only valid Base64[URL] data, behaviour for invalid data is unspecified. - * - * @throws Throws exception in case of incorrect padding. - * - * @param dst memory for writing output. - * @param b pointer to the beginning of base64 encoded string. - * @param a pointer to the end of base64 encoded string - * - * @return Return number of bytes decoded. - */ +/* Decode Base64 encoded data. Can decode both regular Base64 and Base64URL encoded data. Can decode + * only valid Base64[URL] data, behaviour for invalid data is unspecified. + * + * @throws Throws exception in case of incorrect padding. + * + * @param dst memory for writing output. + * @param b pointer to the beginning of base64 encoded string. + * @param a pointer to the end of base64 encoded string + * + * @return Return number of bytes decoded. + */ size_t Base64Decode(void* dst, const char* b, const char* e); -inline TStringBuf Base64Decode(const TStringBuf src, void* dst) { +inline TStringBuf Base64Decode(const TStringBuf src, void* dst) { return TStringBuf((const char*)dst, Base64Decode(dst, src.begin(), src.end())); } @@ -63,7 +63,7 @@ size_t Base64StrictDecode(void* dst, const char* b, const char* e); /// /// @return Returns dst wrapped into TStringBuf. /// -inline TStringBuf Base64StrictDecode(const TStringBuf src, void* dst) { +inline TStringBuf Base64StrictDecode(const TStringBuf src, void* dst) { return TStringBuf((const char*)dst, Base64StrictDecode(dst, src.begin(), src.end())); } @@ -92,18 +92,18 @@ inline TString Base64StrictDecode(const TStringBuf src) { TString Base64DecodeUneven(const TStringBuf s); //encode -constexpr size_t Base64EncodeBufSize(const size_t len) noexcept { - return (len + 2) / 3 * 4 + 1; +constexpr size_t Base64EncodeBufSize(const size_t len) noexcept { + return (len + 2) / 3 * 4 + 1; } char* Base64Encode(char* outstr, const unsigned char* instr, size_t len); char* Base64EncodeUrl(char* outstr, const unsigned char* instr, size_t len); -inline TStringBuf Base64Encode(const TStringBuf src, void* tmp) { +inline TStringBuf Base64Encode(const TStringBuf src, void* tmp) { return TStringBuf((const char*)tmp, Base64Encode((char*)tmp, (const unsigned char*)src.data(), src.size())); } -inline TStringBuf Base64EncodeUrl(const TStringBuf src, void* tmp) { +inline TStringBuf Base64EncodeUrl(const TStringBuf src, void* tmp) { return TStringBuf((const char*)tmp, Base64EncodeUrl((char*)tmp, (const unsigned char*)src.data(), src.size())); } diff --git a/library/cpp/string_utils/base64/base64_ut.cpp b/library/cpp/string_utils/base64/base64_ut.cpp index 2873706301..bcc1e65879 100644 --- a/library/cpp/string_utils/base64/base64_ut.cpp +++ b/library/cpp/string_utils/base64/base64_ut.cpp @@ -1,168 +1,168 @@ #include "base64.h" -#include <contrib/libs/base64/avx2/libbase64.h> -#include <contrib/libs/base64/neon32/libbase64.h> -#include <contrib/libs/base64/neon64/libbase64.h> -#include <contrib/libs/base64/plain32/libbase64.h> -#include <contrib/libs/base64/plain64/libbase64.h> -#include <contrib/libs/base64/ssse3/libbase64.h> - +#include <contrib/libs/base64/avx2/libbase64.h> +#include <contrib/libs/base64/neon32/libbase64.h> +#include <contrib/libs/base64/neon64/libbase64.h> +#include <contrib/libs/base64/plain32/libbase64.h> +#include <contrib/libs/base64/plain64/libbase64.h> +#include <contrib/libs/base64/ssse3/libbase64.h> + #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/vector.h> -#include <util/random/fast.h> -#include <util/system/cpu_id.h> -#include <util/system/platform.h> - -#include <array> - +#include <util/generic/vector.h> +#include <util/random/fast.h> +#include <util/system/cpu_id.h> +#include <util/system/platform.h> + +#include <array> + using namespace std::string_view_literals; -#define BASE64_UT_DECLARE_BASE64_IMPL(prefix, encFunction, decFunction) \ - Y_DECLARE_UNUSED \ - static size_t prefix##Base64Decode(void* dst, const char* b, const char* e) { \ - const auto size = e - b; \ - Y_ENSURE(!(size % 4), "incorrect input length for base64 decode"); \ - \ - size_t outLen; \ - decFunction(b, size, (char*)dst, &outLen); \ - return outLen; \ - } \ - \ - Y_DECLARE_UNUSED \ - static inline TStringBuf prefix##Base64Decode(const TStringBuf& src, void* dst) { \ - return TStringBuf((const char*)dst, ::NB64Etalon::prefix##Base64Decode(dst, src.begin(), src.end())); \ - } \ - \ - Y_DECLARE_UNUSED \ - static inline void prefix##Base64Decode(const TStringBuf& src, TString& dst) { \ - dst.ReserveAndResize(Base64DecodeBufSize(src.size())); \ - dst.resize(::NB64Etalon::prefix##Base64Decode(src, dst.begin()).size()); \ - } \ - \ - Y_DECLARE_UNUSED \ - static inline TString prefix##Base64Decode(const TStringBuf& s) { \ - TString ret; \ - prefix##Base64Decode(s, ret); \ - return ret; \ - } \ - \ - Y_DECLARE_UNUSED \ - static char* prefix##Base64Encode(char* outstr, const unsigned char* instr, size_t len) { \ - size_t outLen; \ - encFunction((char*)instr, len, outstr, &outLen); \ - *(outstr + outLen) = '\0'; \ - return outstr + outLen; \ - } \ - \ - Y_DECLARE_UNUSED \ - static inline TStringBuf prefix##Base64Encode(const TStringBuf& src, void* tmp) { \ +#define BASE64_UT_DECLARE_BASE64_IMPL(prefix, encFunction, decFunction) \ + Y_DECLARE_UNUSED \ + static size_t prefix##Base64Decode(void* dst, const char* b, const char* e) { \ + const auto size = e - b; \ + Y_ENSURE(!(size % 4), "incorrect input length for base64 decode"); \ + \ + size_t outLen; \ + decFunction(b, size, (char*)dst, &outLen); \ + return outLen; \ + } \ + \ + Y_DECLARE_UNUSED \ + static inline TStringBuf prefix##Base64Decode(const TStringBuf& src, void* dst) { \ + return TStringBuf((const char*)dst, ::NB64Etalon::prefix##Base64Decode(dst, src.begin(), src.end())); \ + } \ + \ + Y_DECLARE_UNUSED \ + static inline void prefix##Base64Decode(const TStringBuf& src, TString& dst) { \ + dst.ReserveAndResize(Base64DecodeBufSize(src.size())); \ + dst.resize(::NB64Etalon::prefix##Base64Decode(src, dst.begin()).size()); \ + } \ + \ + Y_DECLARE_UNUSED \ + static inline TString prefix##Base64Decode(const TStringBuf& s) { \ + TString ret; \ + prefix##Base64Decode(s, ret); \ + return ret; \ + } \ + \ + Y_DECLARE_UNUSED \ + static char* prefix##Base64Encode(char* outstr, const unsigned char* instr, size_t len) { \ + size_t outLen; \ + encFunction((char*)instr, len, outstr, &outLen); \ + *(outstr + outLen) = '\0'; \ + return outstr + outLen; \ + } \ + \ + Y_DECLARE_UNUSED \ + static inline TStringBuf prefix##Base64Encode(const TStringBuf& src, void* tmp) { \ return TStringBuf((const char*)tmp, ::NB64Etalon::prefix##Base64Encode((char*)tmp, (const unsigned char*)src.data(), src.size())); \ - } \ - \ - Y_DECLARE_UNUSED \ - static inline void prefix##Base64Encode(const TStringBuf& src, TString& dst) { \ - dst.ReserveAndResize(Base64EncodeBufSize(src.size())); \ - dst.resize(::NB64Etalon::prefix##Base64Encode(src, dst.begin()).size()); \ - } \ - \ - Y_DECLARE_UNUSED \ - static inline TString prefix##Base64Encode(const TStringBuf& s) { \ - TString ret; \ - prefix##Base64Encode(s, ret); \ - return ret; \ - } - -namespace NB64Etalon { - BASE64_UT_DECLARE_BASE64_IMPL(PLAIN32, plain32_base64_encode, plain32_base64_decode); - BASE64_UT_DECLARE_BASE64_IMPL(PLAIN64, plain64_base64_encode, plain64_base64_decode); - BASE64_UT_DECLARE_BASE64_IMPL(NEON32, neon32_base64_encode, neon32_base64_decode); - BASE64_UT_DECLARE_BASE64_IMPL(NEON64, neon64_base64_encode, neon64_base64_decode); - BASE64_UT_DECLARE_BASE64_IMPL(AVX2, avx2_base64_encode, avx2_base64_decode); - BASE64_UT_DECLARE_BASE64_IMPL(SSSE3, ssse3_base64_encode, ssse3_base64_decode); - -#undef BASE64_UT_DECLARE_BASE64_IMPL - - struct TImpls { - enum EImpl : size_t { - PLAIN32_IMPL, - PLAIN64_IMPL, - NEON32_IMPL, - NEON64_IMPL, - AVX2_IMPL, - SSSE3_IMPL, - MAX_IMPL - }; - + } \ + \ + Y_DECLARE_UNUSED \ + static inline void prefix##Base64Encode(const TStringBuf& src, TString& dst) { \ + dst.ReserveAndResize(Base64EncodeBufSize(src.size())); \ + dst.resize(::NB64Etalon::prefix##Base64Encode(src, dst.begin()).size()); \ + } \ + \ + Y_DECLARE_UNUSED \ + static inline TString prefix##Base64Encode(const TStringBuf& s) { \ + TString ret; \ + prefix##Base64Encode(s, ret); \ + return ret; \ + } + +namespace NB64Etalon { + BASE64_UT_DECLARE_BASE64_IMPL(PLAIN32, plain32_base64_encode, plain32_base64_decode); + BASE64_UT_DECLARE_BASE64_IMPL(PLAIN64, plain64_base64_encode, plain64_base64_decode); + BASE64_UT_DECLARE_BASE64_IMPL(NEON32, neon32_base64_encode, neon32_base64_decode); + BASE64_UT_DECLARE_BASE64_IMPL(NEON64, neon64_base64_encode, neon64_base64_decode); + BASE64_UT_DECLARE_BASE64_IMPL(AVX2, avx2_base64_encode, avx2_base64_decode); + BASE64_UT_DECLARE_BASE64_IMPL(SSSE3, ssse3_base64_encode, ssse3_base64_decode); + +#undef BASE64_UT_DECLARE_BASE64_IMPL + + struct TImpls { + enum EImpl : size_t { + PLAIN32_IMPL, + PLAIN64_IMPL, + NEON32_IMPL, + NEON64_IMPL, + AVX2_IMPL, + SSSE3_IMPL, + MAX_IMPL + }; + using TEncodeF = void (*)(const TStringBuf&, TString&); using TDecodeF = void (*)(const TStringBuf&, TString&); - - struct TImpl { - TEncodeF Encode = nullptr; - TDecodeF Decode = nullptr; - }; - - std::array<TImpl, MAX_IMPL> Impl; - - TImpls() { - Impl[PLAIN32_IMPL].Encode = PLAIN32Base64Encode; - Impl[PLAIN32_IMPL].Decode = PLAIN32Base64Decode; - Impl[PLAIN64_IMPL].Encode = PLAIN64Base64Encode; - Impl[PLAIN64_IMPL].Decode = PLAIN64Base64Decode; -#if defined(_arm32_) - Impl[NEON32_IMPL].Encode = NEON32Base64Encode; - Impl[NEON32_IMPL].Decode = NEON32Base64Decode; -#elif defined(_arm64_) - Impl[NEON64_IMPL].Encode = NEON64Base64Encode; - Impl[NEON64_IMPL].Decode = NEON64Base64Decode; -#elif defined(_x86_64_) - if (NX86::HaveSSSE3()) { - Impl[SSSE3_IMPL].Encode = SSSE3Base64Encode; - Impl[SSSE3_IMPL].Decode = SSSE3Base64Decode; - } - - if (NX86::HaveAVX2()) { - Impl[AVX2_IMPL].Encode = AVX2Base64Encode; - Impl[AVX2_IMPL].Decode = AVX2Base64Decode; - } -#else - ythrow yexception() << "Failed to identify the platform"; -#endif - } - }; - - TImpls GetImpls() { - static const TImpls IMPLS; - return IMPLS; - } -} - -template <> -void Out<NB64Etalon::TImpls::EImpl>(IOutputStream& o, typename TTypeTraits<NB64Etalon::TImpls::EImpl>::TFuncParam v) { - switch (v) { - case NB64Etalon::TImpls::PLAIN32_IMPL: - o << TStringBuf{"PLAIN32"}; - return; - case NB64Etalon::TImpls::PLAIN64_IMPL: - o << TStringBuf{"PLAIN64"}; - return; - case NB64Etalon::TImpls::NEON64_IMPL: - o << TStringBuf{"NEON64"}; - return; - case NB64Etalon::TImpls::NEON32_IMPL: - o << TStringBuf{"NEON32"}; - return; - case NB64Etalon::TImpls::SSSE3_IMPL: - o << TStringBuf{"SSSE3"}; - return; - case NB64Etalon::TImpls::AVX2_IMPL: - o << TStringBuf{"AVX2"}; - return; - default: - ythrow yexception() << "invalid"; - } -} - + + struct TImpl { + TEncodeF Encode = nullptr; + TDecodeF Decode = nullptr; + }; + + std::array<TImpl, MAX_IMPL> Impl; + + TImpls() { + Impl[PLAIN32_IMPL].Encode = PLAIN32Base64Encode; + Impl[PLAIN32_IMPL].Decode = PLAIN32Base64Decode; + Impl[PLAIN64_IMPL].Encode = PLAIN64Base64Encode; + Impl[PLAIN64_IMPL].Decode = PLAIN64Base64Decode; +#if defined(_arm32_) + Impl[NEON32_IMPL].Encode = NEON32Base64Encode; + Impl[NEON32_IMPL].Decode = NEON32Base64Decode; +#elif defined(_arm64_) + Impl[NEON64_IMPL].Encode = NEON64Base64Encode; + Impl[NEON64_IMPL].Decode = NEON64Base64Decode; +#elif defined(_x86_64_) + if (NX86::HaveSSSE3()) { + Impl[SSSE3_IMPL].Encode = SSSE3Base64Encode; + Impl[SSSE3_IMPL].Decode = SSSE3Base64Decode; + } + + if (NX86::HaveAVX2()) { + Impl[AVX2_IMPL].Encode = AVX2Base64Encode; + Impl[AVX2_IMPL].Decode = AVX2Base64Decode; + } +#else + ythrow yexception() << "Failed to identify the platform"; +#endif + } + }; + + TImpls GetImpls() { + static const TImpls IMPLS; + return IMPLS; + } +} + +template <> +void Out<NB64Etalon::TImpls::EImpl>(IOutputStream& o, typename TTypeTraits<NB64Etalon::TImpls::EImpl>::TFuncParam v) { + switch (v) { + case NB64Etalon::TImpls::PLAIN32_IMPL: + o << TStringBuf{"PLAIN32"}; + return; + case NB64Etalon::TImpls::PLAIN64_IMPL: + o << TStringBuf{"PLAIN64"}; + return; + case NB64Etalon::TImpls::NEON64_IMPL: + o << TStringBuf{"NEON64"}; + return; + case NB64Etalon::TImpls::NEON32_IMPL: + o << TStringBuf{"NEON32"}; + return; + case NB64Etalon::TImpls::SSSE3_IMPL: + o << TStringBuf{"SSSE3"}; + return; + case NB64Etalon::TImpls::AVX2_IMPL: + o << TStringBuf{"AVX2"}; + return; + default: + ythrow yexception() << "invalid"; + } +} + static void TestEncodeDecodeIntoString(const TString& plain, const TString& encoded, const TString& encodedUrl) { TString a, b; @@ -195,15 +195,15 @@ static void TestEncodeStrictDecodeIntoString(const TString& plain, const TString UNIT_ASSERT_VALUES_EQUAL(b, plain); } -Y_UNIT_TEST_SUITE(TBase64) { - Y_UNIT_TEST(TestEncode) { +Y_UNIT_TEST_SUITE(TBase64) { + Y_UNIT_TEST(TestEncode) { UNIT_ASSERT_VALUES_EQUAL(Base64Encode("12z"), "MTJ6"); UNIT_ASSERT_VALUES_EQUAL(Base64Encode("123"), "MTIz"); UNIT_ASSERT_VALUES_EQUAL(Base64Encode("12"), "MTI="); UNIT_ASSERT_VALUES_EQUAL(Base64Encode("1"), "MQ=="); } - Y_UNIT_TEST(TestIntoString) { + Y_UNIT_TEST(TestIntoString) { { TString str; for (size_t i = 0; i < 256; ++i) @@ -241,7 +241,7 @@ Y_UNIT_TEST_SUITE(TBase64) { } } - Y_UNIT_TEST(TestDecode) { + Y_UNIT_TEST(TestDecode) { UNIT_ASSERT_EXCEPTION(Base64Decode("a"), yexception); UNIT_ASSERT_EXCEPTION(Base64StrictDecode("a"), yexception); @@ -285,7 +285,7 @@ Y_UNIT_TEST_SUITE(TBase64) { UNIT_ASSERT_VALUES_EQUAL(Base64DecodeUneven("dnluZHg"), "vyndx"); } - Y_UNIT_TEST(TestDecodeRandom) { + Y_UNIT_TEST(TestDecodeRandom) { TString input; constexpr size_t testSize = 240000; for (size_t i = 0; i < testSize; ++i) { @@ -296,202 +296,202 @@ Y_UNIT_TEST_SUITE(TBase64) { UNIT_ASSERT_VALUES_EQUAL(Base64Decode(encoded), input); UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode(encoded), input); } - - Y_UNIT_TEST(TestAllPossibleOctets) { + + Y_UNIT_TEST(TestAllPossibleOctets) { const TString x("\0\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7F"sv); const TString xEnc = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn8="; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestTwoPaddingCharacters) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestTwoPaddingCharacters) { const TString x("a"); const TString xEnc = "YQ=="; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestOnePaddingCharacter) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestOnePaddingCharacter) { const TString x("aa"); const TString xEnc = "YWE="; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestNoPaddingCharacters) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestNoPaddingCharacters) { const TString x("aaa"); const TString xEnc = "YWFh"; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestTrailingZero) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestTrailingZero) { const TString x("foo\0"sv); const TString xEnc = "Zm9vAA=="; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestTwoTrailingZeroes) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestTwoTrailingZeroes) { const TString x("foo\0\0"sv); const TString xEnc = "Zm9vAAA="; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestZero) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestZero) { const TString x("\0"sv); const TString xEnc = "AA=="; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestSymbolsAfterZero) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestSymbolsAfterZero) { const TString x("\0a"sv); const TString xEnc = "AGE="; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestEmptyString) { + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestEmptyString) { const TString x = ""; const TString xEnc = ""; const TString y = Base64Decode(xEnc); const TString yEnc = Base64Encode(x); - UNIT_ASSERT_VALUES_EQUAL(x, y); - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - } - - Y_UNIT_TEST(TestBackendsConsistencyOnRandomData) { - constexpr size_t TEST_CASES_COUNT = 1000; - constexpr size_t MAX_DATA_SIZE = 1000; - TFastRng<ui32> prng{42}; + UNIT_ASSERT_VALUES_EQUAL(x, y); + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + } + + Y_UNIT_TEST(TestBackendsConsistencyOnRandomData) { + constexpr size_t TEST_CASES_COUNT = 1000; + constexpr size_t MAX_DATA_SIZE = 1000; + TFastRng<ui32> prng{42}; TVector<TString> xs{TEST_CASES_COUNT}; TString xEnc; TString xDec; TString yEnc; TString yDec; - - for (auto& x : xs) { - const size_t size = prng() % MAX_DATA_SIZE; - for (size_t j = 0; j < size; ++j) { - x += static_cast<char>(prng() % 256); - } - } - - static const auto IMPLS = NB64Etalon::GetImpls(); - for (size_t i = 0; i < static_cast<size_t>(NB64Etalon::TImpls::MAX_IMPL); ++i) { - for (size_t j = 0; j < static_cast<size_t>(NB64Etalon::TImpls::MAX_IMPL); ++j) { - const auto ei = static_cast<NB64Etalon::TImpls::EImpl>(i); - const auto ej = static_cast<NB64Etalon::TImpls::EImpl>(j); - const auto impl = IMPLS.Impl[i]; - const auto otherImpl = IMPLS.Impl[j]; - if (!impl.Encode && !impl.Decode || !otherImpl.Encode && !otherImpl.Decode) { - continue; - } - - for (const auto& x : xs) { - impl.Encode(x, xEnc); - impl.Decode(xEnc, xDec); - Y_ENSURE(x == xDec, "something is wrong with " << ei << " implementation"); - - otherImpl.Encode(x, yEnc); - otherImpl.Decode(xEnc, yDec); - Y_ENSURE(x == yDec, "something is wrong with " << ej << " implementation"); - - UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); - UNIT_ASSERT_VALUES_EQUAL(xDec, yDec); - } - } - } - } - - Y_UNIT_TEST(TestIfEncodedDataIsZeroTerminatedOnRandomData) { - constexpr size_t TEST_CASES_COUNT = 1000; - constexpr size_t MAX_DATA_SIZE = 1000; - TFastRng<ui32> prng{42}; + + for (auto& x : xs) { + const size_t size = prng() % MAX_DATA_SIZE; + for (size_t j = 0; j < size; ++j) { + x += static_cast<char>(prng() % 256); + } + } + + static const auto IMPLS = NB64Etalon::GetImpls(); + for (size_t i = 0; i < static_cast<size_t>(NB64Etalon::TImpls::MAX_IMPL); ++i) { + for (size_t j = 0; j < static_cast<size_t>(NB64Etalon::TImpls::MAX_IMPL); ++j) { + const auto ei = static_cast<NB64Etalon::TImpls::EImpl>(i); + const auto ej = static_cast<NB64Etalon::TImpls::EImpl>(j); + const auto impl = IMPLS.Impl[i]; + const auto otherImpl = IMPLS.Impl[j]; + if (!impl.Encode && !impl.Decode || !otherImpl.Encode && !otherImpl.Decode) { + continue; + } + + for (const auto& x : xs) { + impl.Encode(x, xEnc); + impl.Decode(xEnc, xDec); + Y_ENSURE(x == xDec, "something is wrong with " << ei << " implementation"); + + otherImpl.Encode(x, yEnc); + otherImpl.Decode(xEnc, yDec); + Y_ENSURE(x == yDec, "something is wrong with " << ej << " implementation"); + + UNIT_ASSERT_VALUES_EQUAL(xEnc, yEnc); + UNIT_ASSERT_VALUES_EQUAL(xDec, yDec); + } + } + } + } + + Y_UNIT_TEST(TestIfEncodedDataIsZeroTerminatedOnRandomData) { + constexpr size_t TEST_CASES_COUNT = 1000; + constexpr size_t MAX_DATA_SIZE = 1000; + TFastRng<ui32> prng{42}; TString x; TVector<char> buf; - for (size_t i = 0; i < TEST_CASES_COUNT; ++i) { - const size_t size = prng() % MAX_DATA_SIZE; - x.clear(); - for (size_t j = 0; j < size; ++j) { - x += static_cast<char>(prng() % 256); - } - - buf.assign(Base64EncodeBufSize(x.size()), Max<char>()); + for (size_t i = 0; i < TEST_CASES_COUNT; ++i) { + const size_t size = prng() % MAX_DATA_SIZE; + x.clear(); + for (size_t j = 0; j < size; ++j) { + x += static_cast<char>(prng() % 256); + } + + buf.assign(Base64EncodeBufSize(x.size()), Max<char>()); const auto* const xEncEnd = Base64Encode(buf.data(), (const unsigned char*)x.data(), x.size()); - UNIT_ASSERT_VALUES_EQUAL(*xEncEnd, '\0'); - } - } - - Y_UNIT_TEST(TestDecodeURLEncodedNoPadding) { - const auto x = "123"; - const auto xDec = Base64Decode("MTIz"); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeURLEncodedOnePadding) { - const auto x = "12"; - const auto xDec = Base64Decode("MTI,"); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeURLEncodedTwoPadding) { - const auto x = "1"; - const auto xDec = Base64Decode("MQ,,"); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeNoPaddingLongString) { - const auto x = "How do I convert between big-endian and little-endian values in C++?a"; - const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9h"); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeOnePaddingLongString) { - const auto x = "How do I convert between big-endian and little-endian values in C++?"; - const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz8="); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeTwoPaddingLongString) { - const auto x = "How do I convert between big-endian and little-endian values in C++?aa"; - const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9hYQ=="); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeURLEncodedNoPaddingLongString) { - const auto x = "How do I convert between big-endian and little-endian values in C++?a"; - const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9h"); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeURLEncodedOnePaddingLongString) { - const auto x = "How do I convert between big-endian and little-endian values in C++?"; - const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz8,"); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } - - Y_UNIT_TEST(TestDecodeURLEncodedTwoPaddingLongString) { - const auto x = "How do I convert between big-endian and little-endian values in C++?aa"; - const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9hYQ,,"); - UNIT_ASSERT_VALUES_EQUAL(x, xDec); - } + UNIT_ASSERT_VALUES_EQUAL(*xEncEnd, '\0'); + } + } + + Y_UNIT_TEST(TestDecodeURLEncodedNoPadding) { + const auto x = "123"; + const auto xDec = Base64Decode("MTIz"); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeURLEncodedOnePadding) { + const auto x = "12"; + const auto xDec = Base64Decode("MTI,"); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeURLEncodedTwoPadding) { + const auto x = "1"; + const auto xDec = Base64Decode("MQ,,"); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeNoPaddingLongString) { + const auto x = "How do I convert between big-endian and little-endian values in C++?a"; + const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9h"); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeOnePaddingLongString) { + const auto x = "How do I convert between big-endian and little-endian values in C++?"; + const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz8="); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeTwoPaddingLongString) { + const auto x = "How do I convert between big-endian and little-endian values in C++?aa"; + const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9hYQ=="); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeURLEncodedNoPaddingLongString) { + const auto x = "How do I convert between big-endian and little-endian values in C++?a"; + const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9h"); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeURLEncodedOnePaddingLongString) { + const auto x = "How do I convert between big-endian and little-endian values in C++?"; + const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz8,"); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } + + Y_UNIT_TEST(TestDecodeURLEncodedTwoPaddingLongString) { + const auto x = "How do I convert between big-endian and little-endian values in C++?aa"; + const auto xDec = Base64Decode("SG93IGRvIEkgY29udmVydCBiZXR3ZWVuIGJpZy1lbmRpYW4gYW5kIGxpdHRsZS1lbmRpYW4gdmFsdWVzIGluIEMrKz9hYQ,,"); + UNIT_ASSERT_VALUES_EQUAL(x, xDec); + } } diff --git a/library/cpp/string_utils/base64/bench/main.cpp b/library/cpp/string_utils/base64/bench/main.cpp index f3f8280136..10e09bc1c7 100644 --- a/library/cpp/string_utils/base64/bench/main.cpp +++ b/library/cpp/string_utils/base64/bench/main.cpp @@ -1,110 +1,110 @@ #include <library/cpp/string_utils/base64/base64.h> - + #include <library/cpp/testing/benchmark/bench.h> - -#include <util/generic/buffer.h> -#include <util/generic/singleton.h> + +#include <util/generic/buffer.h> +#include <util/generic/singleton.h> #include <util/generic/string.h> -#include <util/generic/vector.h> -#include <util/generic/xrange.h> -#include <util/generic/yexception.h> -#include <util/random/random.h> - -#include <array> - +#include <util/generic/vector.h> +#include <util/generic/xrange.h> +#include <util/generic/yexception.h> +#include <util/random/random.h> + +#include <array> + static TString GenerateRandomData(const size_t minSize, const size_t maxSize) { - Y_ENSURE(minSize <= maxSize, "wow"); + Y_ENSURE(minSize <= maxSize, "wow"); TString r; - for (size_t i = 0; i < minSize; ++i) { - r.push_back(RandomNumber<char>()); - } - - if (minSize == maxSize) { - return r; - } - - const size_t size = RandomNumber<size_t>() % (maxSize - minSize + 1); - for (size_t i = 0; i < size; ++i) { - r.push_back(RandomNumber<char>()); - } - - return r; -} - -template <size_t N> + for (size_t i = 0; i < minSize; ++i) { + r.push_back(RandomNumber<char>()); + } + + if (minSize == maxSize) { + return r; + } + + const size_t size = RandomNumber<size_t>() % (maxSize - minSize + 1); + for (size_t i = 0; i < size; ++i) { + r.push_back(RandomNumber<char>()); + } + + return r; +} + +template <size_t N> static std::array<TString, N> GenerateRandomDataVector(const size_t minSize, const size_t maxSize) { std::array<TString, N> r; - for (size_t i = 0; i < N; ++i) { - r[i] = GenerateRandomData(minSize, maxSize); - } - - return r; -} - -template <size_t N> + for (size_t i = 0; i < N; ++i) { + r[i] = GenerateRandomData(minSize, maxSize); + } + + return r; +} + +template <size_t N> static std::array<TString, N> Encode(const std::array<TString, N>& d) { std::array<TString, N> r; - for (size_t i = 0, iEnd = d.size(); i < iEnd; ++i) { - r[i] = Base64Encode(d[i]); - } - - return r; -} - -namespace { - template <size_t N, size_t MinSize, size_t MaxSize> - struct TRandomDataHolder { - TRandomDataHolder() - : Data(GenerateRandomDataVector<N>(MinSize, MaxSize)) - , DataEncoded(Encode<N>(Data)) - { - for (size_t i = 0; i < N; ++i) { - const size_t size = Data[i].size(); - const size_t sizeEnc = DataEncoded[i].size(); - PlaceToEncode[i].Resize(Base64EncodeBufSize(size)); - PlaceToDecode[i].Resize(Base64DecodeBufSize(sizeEnc)); - } - } - - static constexpr size_t Size = N; + for (size_t i = 0, iEnd = d.size(); i < iEnd; ++i) { + r[i] = Base64Encode(d[i]); + } + + return r; +} + +namespace { + template <size_t N, size_t MinSize, size_t MaxSize> + struct TRandomDataHolder { + TRandomDataHolder() + : Data(GenerateRandomDataVector<N>(MinSize, MaxSize)) + , DataEncoded(Encode<N>(Data)) + { + for (size_t i = 0; i < N; ++i) { + const size_t size = Data[i].size(); + const size_t sizeEnc = DataEncoded[i].size(); + PlaceToEncode[i].Resize(Base64EncodeBufSize(size)); + PlaceToDecode[i].Resize(Base64DecodeBufSize(sizeEnc)); + } + } + + static constexpr size_t Size = N; const std::array<TString, N> Data; const std::array<TString, N> DataEncoded; - std::array<TBuffer, N> PlaceToEncode; - std::array<TBuffer, N> PlaceToDecode; - }; - - template <size_t N, size_t Size> - using TFixedSizeRandomDataHolder = TRandomDataHolder<N, Size, Size>; - - using FSRDH_1 = TFixedSizeRandomDataHolder<10, 1>; - using FSRDH_2 = TFixedSizeRandomDataHolder<10, 2>; - using FSRDH_4 = TFixedSizeRandomDataHolder<10, 4>; - using FSRDH_8 = TFixedSizeRandomDataHolder<10, 8>; - using FSRDH_16 = TFixedSizeRandomDataHolder<10, 16>; - using FSRDH_32 = TFixedSizeRandomDataHolder<10, 32>; - using FSRDH_64 = TFixedSizeRandomDataHolder<10, 64>; - using FSRDH_128 = TFixedSizeRandomDataHolder<10, 128>; - using FSRDH_1024 = TFixedSizeRandomDataHolder<10, 1024>; - using FSRDH_10240 = TFixedSizeRandomDataHolder<10, 10240>; - using FSRDH_102400 = TFixedSizeRandomDataHolder<10, 102400>; - using FSRDH_1048576 = TFixedSizeRandomDataHolder<10, 1048576>; - using FSRDH_10485760 = TFixedSizeRandomDataHolder<10, 10485760>; -} - -template <typename T> -static inline void BenchEncode(T& d, const NBench::NCpu::TParams& iface) { - for (const auto it : xrange(iface.Iterations())) { - Y_UNUSED(it); - for (size_t i = 0; i < d.Size; ++i) { + std::array<TBuffer, N> PlaceToEncode; + std::array<TBuffer, N> PlaceToDecode; + }; + + template <size_t N, size_t Size> + using TFixedSizeRandomDataHolder = TRandomDataHolder<N, Size, Size>; + + using FSRDH_1 = TFixedSizeRandomDataHolder<10, 1>; + using FSRDH_2 = TFixedSizeRandomDataHolder<10, 2>; + using FSRDH_4 = TFixedSizeRandomDataHolder<10, 4>; + using FSRDH_8 = TFixedSizeRandomDataHolder<10, 8>; + using FSRDH_16 = TFixedSizeRandomDataHolder<10, 16>; + using FSRDH_32 = TFixedSizeRandomDataHolder<10, 32>; + using FSRDH_64 = TFixedSizeRandomDataHolder<10, 64>; + using FSRDH_128 = TFixedSizeRandomDataHolder<10, 128>; + using FSRDH_1024 = TFixedSizeRandomDataHolder<10, 1024>; + using FSRDH_10240 = TFixedSizeRandomDataHolder<10, 10240>; + using FSRDH_102400 = TFixedSizeRandomDataHolder<10, 102400>; + using FSRDH_1048576 = TFixedSizeRandomDataHolder<10, 1048576>; + using FSRDH_10485760 = TFixedSizeRandomDataHolder<10, 10485760>; +} + +template <typename T> +static inline void BenchEncode(T& d, const NBench::NCpu::TParams& iface) { + for (const auto it : xrange(iface.Iterations())) { + Y_UNUSED(it); + for (size_t i = 0; i < d.Size; ++i) { NBench::Escape(d.PlaceToEncode[i].data()); - Y_DO_NOT_OPTIMIZE_AWAY( + Y_DO_NOT_OPTIMIZE_AWAY( Base64Encode(d.PlaceToEncode[i].data(), (const unsigned char*)d.Data[i].data(), d.Data[i].size())); - NBench::Clobber(); - } - } -} - -template <typename T> + NBench::Clobber(); + } + } +} + +template <typename T> static inline void BenchEncodeUrl(T& d, const NBench::NCpu::TParams& iface) { for (const auto it : xrange(iface.Iterations())) { Y_UNUSED(it); @@ -118,147 +118,147 @@ static inline void BenchEncodeUrl(T& d, const NBench::NCpu::TParams& iface) { } template <typename T> -static inline void BenchDecode(T& d, const NBench::NCpu::TParams& iface) { - for (const auto it : xrange(iface.Iterations())) { - Y_UNUSED(it); - for (size_t i = 0; i < d.Size; ++i) { +static inline void BenchDecode(T& d, const NBench::NCpu::TParams& iface) { + for (const auto it : xrange(iface.Iterations())) { + Y_UNUSED(it); + for (size_t i = 0; i < d.Size; ++i) { NBench::Escape(d.PlaceToDecode[i].data()); - Y_DO_NOT_OPTIMIZE_AWAY( + Y_DO_NOT_OPTIMIZE_AWAY( Base64Decode(d.PlaceToDecode[i].data(), (const char*)d.DataEncoded[i].data(), (const char*)(d.DataEncoded[i].data() + d.DataEncoded[i].size()))); - NBench::Clobber(); - } - } -} - -Y_CPU_BENCHMARK(EncodeF1, iface) { - auto& d = *Singleton<FSRDH_1>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF1, iface) { - auto& d = *Singleton<FSRDH_1>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF2, iface) { - auto& d = *Singleton<FSRDH_2>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF2, iface) { - auto& d = *Singleton<FSRDH_2>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF4, iface) { - auto& d = *Singleton<FSRDH_4>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF4, iface) { - auto& d = *Singleton<FSRDH_4>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF8, iface) { - auto& d = *Singleton<FSRDH_8>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF8, iface) { - auto& d = *Singleton<FSRDH_8>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF16, iface) { - auto& d = *Singleton<FSRDH_16>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF16, iface) { - auto& d = *Singleton<FSRDH_16>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF32, iface) { - auto& d = *Singleton<FSRDH_32>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF32, iface) { - auto& d = *Singleton<FSRDH_32>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF64, iface) { - auto& d = *Singleton<FSRDH_64>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF64, iface) { - auto& d = *Singleton<FSRDH_64>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF128, iface) { - auto& d = *Singleton<FSRDH_128>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF128, iface) { - auto& d = *Singleton<FSRDH_128>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF1024, iface) { - auto& d = *Singleton<FSRDH_1024>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF1024, iface) { - auto& d = *Singleton<FSRDH_1024>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF10240, iface) { - auto& d = *Singleton<FSRDH_10240>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF10240, iface) { - auto& d = *Singleton<FSRDH_10240>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF102400, iface) { - auto& d = *Singleton<FSRDH_102400>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF102400, iface) { - auto& d = *Singleton<FSRDH_102400>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF1048576, iface) { - auto& d = *Singleton<FSRDH_1048576>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF1048576, iface) { - auto& d = *Singleton<FSRDH_1048576>(); - BenchDecode(d, iface); -} - -Y_CPU_BENCHMARK(EncodeF10485760, iface) { - auto& d = *Singleton<FSRDH_10485760>(); - BenchEncode(d, iface); -} - -Y_CPU_BENCHMARK(DecodeF10485760, iface) { - auto& d = *Singleton<FSRDH_10485760>(); - BenchDecode(d, iface); -} + NBench::Clobber(); + } + } +} + +Y_CPU_BENCHMARK(EncodeF1, iface) { + auto& d = *Singleton<FSRDH_1>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF1, iface) { + auto& d = *Singleton<FSRDH_1>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF2, iface) { + auto& d = *Singleton<FSRDH_2>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF2, iface) { + auto& d = *Singleton<FSRDH_2>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF4, iface) { + auto& d = *Singleton<FSRDH_4>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF4, iface) { + auto& d = *Singleton<FSRDH_4>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF8, iface) { + auto& d = *Singleton<FSRDH_8>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF8, iface) { + auto& d = *Singleton<FSRDH_8>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF16, iface) { + auto& d = *Singleton<FSRDH_16>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF16, iface) { + auto& d = *Singleton<FSRDH_16>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF32, iface) { + auto& d = *Singleton<FSRDH_32>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF32, iface) { + auto& d = *Singleton<FSRDH_32>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF64, iface) { + auto& d = *Singleton<FSRDH_64>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF64, iface) { + auto& d = *Singleton<FSRDH_64>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF128, iface) { + auto& d = *Singleton<FSRDH_128>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF128, iface) { + auto& d = *Singleton<FSRDH_128>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF1024, iface) { + auto& d = *Singleton<FSRDH_1024>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF1024, iface) { + auto& d = *Singleton<FSRDH_1024>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF10240, iface) { + auto& d = *Singleton<FSRDH_10240>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF10240, iface) { + auto& d = *Singleton<FSRDH_10240>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF102400, iface) { + auto& d = *Singleton<FSRDH_102400>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF102400, iface) { + auto& d = *Singleton<FSRDH_102400>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF1048576, iface) { + auto& d = *Singleton<FSRDH_1048576>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF1048576, iface) { + auto& d = *Singleton<FSRDH_1048576>(); + BenchDecode(d, iface); +} + +Y_CPU_BENCHMARK(EncodeF10485760, iface) { + auto& d = *Singleton<FSRDH_10485760>(); + BenchEncode(d, iface); +} + +Y_CPU_BENCHMARK(DecodeF10485760, iface) { + auto& d = *Singleton<FSRDH_10485760>(); + BenchDecode(d, iface); +} Y_CPU_BENCHMARK(EncodeUrlF1, iface) { auto& d = *Singleton<FSRDH_1>(); diff --git a/library/cpp/string_utils/base64/bench/metrics/main.py b/library/cpp/string_utils/base64/bench/metrics/main.py index 79577bf4d4..c35fd6d8cd 100644 --- a/library/cpp/string_utils/base64/bench/metrics/main.py +++ b/library/cpp/string_utils/base64/bench/metrics/main.py @@ -1,5 +1,5 @@ -import yatest.common as yc - - -def test_export_metrics(metrics): +import yatest.common as yc + + +def test_export_metrics(metrics): metrics.set_benchmark(yc.execute_benchmark('library/cpp/string_utils/base64/bench/bench')) diff --git a/library/cpp/string_utils/base64/bench/metrics/ya.make b/library/cpp/string_utils/base64/bench/metrics/ya.make index 14b57dae22..b0406516c3 100644 --- a/library/cpp/string_utils/base64/bench/metrics/ya.make +++ b/library/cpp/string_utils/base64/bench/metrics/ya.make @@ -1,20 +1,20 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) - +) + PY2TEST() - + SIZE(LARGE) - -TAG( + +TAG( ya:force_sandbox - sb:intel_e5_2660v1 + sb:intel_e5_2660v1 ya:fat -) - +) + TEST_SRCS(main.py) - + DEPENDS(library/cpp/string_utils/base64/bench) - -END() + +END() diff --git a/library/cpp/string_utils/base64/bench/ya.make b/library/cpp/string_utils/base64/bench/ya.make index 30a13c6509..5ac5f3d6ce 100644 --- a/library/cpp/string_utils/base64/bench/ya.make +++ b/library/cpp/string_utils/base64/bench/ya.make @@ -1,16 +1,16 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) - +) + Y_BENCHMARK() - -SRCS( - main.cpp -) - -PEERDIR( + +SRCS( + main.cpp +) + +PEERDIR( library/cpp/string_utils/base64 -) - -END() +) + +END() diff --git a/library/cpp/string_utils/base64/fuzz/generic/ya.make b/library/cpp/string_utils/base64/fuzz/generic/ya.make index 608c12a09e..d155e2b0a0 100644 --- a/library/cpp/string_utils/base64/fuzz/generic/ya.make +++ b/library/cpp/string_utils/base64/fuzz/generic/ya.make @@ -1,12 +1,12 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) - -FUZZ() - -PEERDIR( +) + +FUZZ() + +PEERDIR( library/cpp/string_utils/base64/fuzz/lib -) - -END() +) + +END() diff --git a/library/cpp/string_utils/base64/fuzz/lib/main.cpp b/library/cpp/string_utils/base64/fuzz/lib/main.cpp index aec5655eec..28547ae7a5 100644 --- a/library/cpp/string_utils/base64/fuzz/lib/main.cpp +++ b/library/cpp/string_utils/base64/fuzz/lib/main.cpp @@ -1,13 +1,13 @@ #include <library/cpp/string_utils/base64/base64.h> - -#include <util/system/types.h> -#include <util/system/yassert.h> - -extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { - const TStringBuf example{reinterpret_cast<const char*>(data), size}; - const auto converted = Base64Decode(Base64Encode(example)); - - Y_VERIFY(example == converted); - - return 0; -} + +#include <util/system/types.h> +#include <util/system/yassert.h> + +extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { + const TStringBuf example{reinterpret_cast<const char*>(data), size}; + const auto converted = Base64Decode(Base64Encode(example)); + + Y_VERIFY(example == converted); + + return 0; +} diff --git a/library/cpp/string_utils/base64/fuzz/lib/ya.make b/library/cpp/string_utils/base64/fuzz/lib/ya.make index 6fee5c9f99..7b981b86a3 100644 --- a/library/cpp/string_utils/base64/fuzz/lib/ya.make +++ b/library/cpp/string_utils/base64/fuzz/lib/ya.make @@ -1,16 +1,16 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) - -LIBRARY() - -SRCS( - main.cpp -) - -PEERDIR( +) + +LIBRARY() + +SRCS( + main.cpp +) + +PEERDIR( library/cpp/string_utils/base64 -) - -END() +) + +END() diff --git a/library/cpp/string_utils/base64/fuzz/ya.make b/library/cpp/string_utils/base64/fuzz/ya.make index a0ed64f273..bef82061c4 100644 --- a/library/cpp/string_utils/base64/fuzz/ya.make +++ b/library/cpp/string_utils/base64/fuzz/ya.make @@ -1,10 +1,10 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) - -RECURSE( - generic - lib +) + +RECURSE( + generic + lib uneven -) +) diff --git a/library/cpp/string_utils/base64/ut/ya.make b/library/cpp/string_utils/base64/ut/ya.make index 560d96423f..9b61241f0e 100644 --- a/library/cpp/string_utils/base64/ut/ya.make +++ b/library/cpp/string_utils/base64/ut/ya.make @@ -1,22 +1,22 @@ -OWNER( +OWNER( g:util - yazevnul -) - + yazevnul +) + UNITTEST_FOR(library/cpp/string_utils/base64) - -SRCS( - base64_ut.cpp + +SRCS( + base64_ut.cpp base64_decode_uneven_ut.cpp -) - -PEERDIR( - contrib/libs/base64/avx2 - contrib/libs/base64/ssse3 - contrib/libs/base64/neon32 - contrib/libs/base64/neon64 - contrib/libs/base64/plain32 - contrib/libs/base64/plain64 -) - -END() +) + +PEERDIR( + contrib/libs/base64/avx2 + contrib/libs/base64/ssse3 + contrib/libs/base64/neon32 + contrib/libs/base64/neon64 + contrib/libs/base64/plain32 + contrib/libs/base64/plain64 +) + +END() diff --git a/library/cpp/string_utils/base64/ya.make b/library/cpp/string_utils/base64/ya.make index ee1ec0e023..f5258c446c 100644 --- a/library/cpp/string_utils/base64/ya.make +++ b/library/cpp/string_utils/base64/ya.make @@ -1,23 +1,23 @@ -OWNER( +OWNER( g:util - yazevnul -) - -LIBRARY() - -SRCS( - base64.cpp -) - -PEERDIR( - contrib/libs/base64/avx2 - contrib/libs/base64/ssse3 - contrib/libs/base64/neon32 - contrib/libs/base64/neon64 - contrib/libs/base64/plain32 - contrib/libs/base64/plain64 -) - -END() + yazevnul +) + +LIBRARY() + +SRCS( + base64.cpp +) + +PEERDIR( + contrib/libs/base64/avx2 + contrib/libs/base64/ssse3 + contrib/libs/base64/neon32 + contrib/libs/base64/neon64 + contrib/libs/base64/plain32 + contrib/libs/base64/plain64 +) + +END() RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h index ac33cd87d2..8a240bfed8 100644 --- a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h +++ b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h @@ -112,7 +112,7 @@ namespace NLevenshtein { } // Tracing the path from final point res.clear(); - res.reserve(Max<size_t>(l1, l2)); + res.reserve(Max<size_t>(l1, l2)); for (int i = l1, j = l2; ma[i][j].second != EMT_SPECIAL;) { res.push_back(ma[i][j].second); switch (ma[i][j].second) { diff --git a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp index f8bdc941c8..cf0f78637f 100644 --- a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp +++ b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp @@ -24,8 +24,8 @@ namespace { } -Y_UNIT_TEST_SUITE(Levenstein) { - Y_UNIT_TEST(Distance) { +Y_UNIT_TEST_SUITE(Levenstein) { + Y_UNIT_TEST(Distance) { UNIT_ASSERT_VALUES_EQUAL(NLevenshtein::Distance(TStringBuf("hello"), TStringBuf("hulloah")), 3); UNIT_ASSERT_VALUES_EQUAL(NLevenshtein::Distance(TStringBuf("yeoman"), TStringBuf("yo man")), 2); } diff --git a/library/cpp/string_utils/parse_size/parse_size.cpp b/library/cpp/string_utils/parse_size/parse_size.cpp index 8c521b1e0c..39188d560b 100644 --- a/library/cpp/string_utils/parse_size/parse_size.cpp +++ b/library/cpp/string_utils/parse_size/parse_size.cpp @@ -90,6 +90,6 @@ NSize::TSize FromStringImpl<NSize::TSize>(const char* data, size_t len) { } template <> -void Out<NSize::TSize>(IOutputStream& os, const NSize::TSize& size) { +void Out<NSize::TSize>(IOutputStream& os, const NSize::TSize& size) { os << size.GetValue(); } diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index e7ce5667db..e523350b80 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -166,7 +166,7 @@ TString CGIEscapeRet(const TStringBuf url) { TString to; to.ReserveAndResize(CgiEscapeBufLen(url.size())); to.resize(CGIEscape(to.begin(), url.data(), url.size()) - to.data()); - return to; + return to; } TString& AppendCgiEscaped(const TStringBuf value, TString& to) { @@ -203,7 +203,7 @@ char* Quote(char* to, const char* from, const char* safe) { return Quote(to, FixZero(from), TCStringEndIterator(), safe); } -char* Quote(char* to, const TStringBuf s, const char* safe) { +char* Quote(char* to, const TStringBuf s, const char* safe) { return Quote(to, s.data(), s.data() + s.size(), safe); } @@ -239,7 +239,7 @@ TString CGIUnescapeRet(const TStringBuf from) { TString to; to.ReserveAndResize(CgiUnescapeBufLen(from.size())); to.resize(CGIUnescape(to.begin(), from.data(), from.size()) - to.data()); - return to; + return to; } char* UrlUnescape(char* to, TStringBuf from) { diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h index 3cea6feba1..3b7221154e 100644 --- a/library/cpp/string_utils/quote/quote.h +++ b/library/cpp/string_utils/quote/quote.h @@ -10,17 +10,17 @@ // Returns pointer to the end of the result string char* CGIEscape(char* to, const char* from); char* CGIEscape(char* to, const char* from, size_t len); -inline char* CGIEscape(char* to, const TStringBuf from) { +inline char* CGIEscape(char* to, const TStringBuf from) { return CGIEscape(to, from.data(), from.size()); } void CGIEscape(TString& url); TString CGIEscapeRet(const TStringBuf url); TString& AppendCgiEscaped(const TStringBuf value, TString& to); -inline TStringBuf CgiEscapeBuf(char* to, const TStringBuf from) { +inline TStringBuf CgiEscapeBuf(char* to, const TStringBuf from) { return TStringBuf(to, CGIEscape(to, from.data(), from.size())); } -inline TStringBuf CgiEscape(void* tmp, const TStringBuf s) { +inline TStringBuf CgiEscape(void* tmp, const TStringBuf s) { return CgiEscapeBuf(static_cast<char*>(tmp), s); } @@ -33,17 +33,17 @@ char* CGIUnescape(char* to, const char* from, size_t len); void CGIUnescape(TString& url); TString CGIUnescapeRet(const TStringBuf from); -inline TStringBuf CgiUnescapeBuf(char* to, const TStringBuf from) { +inline TStringBuf CgiUnescapeBuf(char* to, const TStringBuf from) { return TStringBuf(to, CGIUnescape(to, from.data(), from.size())); } -inline TStringBuf CgiUnescape(void* tmp, const TStringBuf s) { +inline TStringBuf CgiUnescape(void* tmp, const TStringBuf s) { return CgiUnescapeBuf(static_cast<char*>(tmp), s); } //Quote: // Is like CGIEscape, also skips encoding of user-supplied 'safe' characters. char* Quote(char* to, const char* from, const char* safe = "/"); -char* Quote(char* to, const TStringBuf s, const char* safe = "/"); +char* Quote(char* to, const TStringBuf s, const char* safe = "/"); void Quote(TString& url, const char* safe = "/"); //UrlEscape: @@ -63,10 +63,10 @@ void UrlUnescape(TString& url); TString UrlUnescapeRet(const TStringBuf from); //*BufLen: how much characters you should allocate for 'char* to' buffers. -constexpr size_t CgiEscapeBufLen(const size_t len) noexcept { +constexpr size_t CgiEscapeBufLen(const size_t len) noexcept { return 3 * len + 1; } -constexpr size_t CgiUnescapeBufLen(const size_t len) noexcept { +constexpr size_t CgiUnescapeBufLen(const size_t len) noexcept { return len + 1; } diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp index f505cf669a..6c552b279e 100644 --- a/library/cpp/string_utils/quote/quote_ut.cpp +++ b/library/cpp/string_utils/quote/quote_ut.cpp @@ -2,15 +2,15 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TCGIEscapeTest) { - Y_UNIT_TEST(ReturnsEndOfTo) { +Y_UNIT_TEST_SUITE(TCGIEscapeTest) { + Y_UNIT_TEST(ReturnsEndOfTo) { char r[10]; const char* returned = CGIEscape(r, "123"); UNIT_ASSERT_VALUES_EQUAL(r + strlen("123"), returned); UNIT_ASSERT_VALUES_EQUAL('\0', *returned); } - Y_UNIT_TEST(NotZeroTerminated) { + Y_UNIT_TEST(NotZeroTerminated) { char r[] = {'1', '2', '3', '4'}; char buf[sizeof(r) * 3 + 2]; @@ -19,13 +19,13 @@ Y_UNIT_TEST_SUITE(TCGIEscapeTest) { UNIT_ASSERT_EQUAL(ret, "1234"); } - Y_UNIT_TEST(StringBuf) { + Y_UNIT_TEST(StringBuf) { char tmp[100]; UNIT_ASSERT_VALUES_EQUAL(CgiEscape(tmp, "!@#$%^&*(){}[]\" "), TStringBuf("!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+")); } - Y_UNIT_TEST(StrokaRet) { + Y_UNIT_TEST(StrokaRet) { UNIT_ASSERT_VALUES_EQUAL(CGIEscapeRet("!@#$%^&*(){}[]\" "), TString("!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+")); } @@ -47,14 +47,14 @@ Y_UNIT_TEST_SUITE(TCGIEscapeTest) { } -Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { - Y_UNIT_TEST(StringBuf) { +Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { + Y_UNIT_TEST(StringBuf) { char tmp[100]; UNIT_ASSERT_VALUES_EQUAL(CgiUnescape(tmp, "!@%23$%25^%26*%28%29"), TStringBuf("!@#$%^&*()")); } - Y_UNIT_TEST(TestValidZeroTerm) { + Y_UNIT_TEST(TestValidZeroTerm) { char r[10]; CGIUnescape(r, "1234"); @@ -67,7 +67,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { UNIT_ASSERT_VALUES_EQUAL(r, "12=34"); } - Y_UNIT_TEST(TestInvalidZeroTerm) { + Y_UNIT_TEST(TestInvalidZeroTerm) { char r[10]; CGIUnescape(r, "%"); @@ -86,7 +86,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { UNIT_ASSERT_VALUES_EQUAL(r, "%3u123"); } - Y_UNIT_TEST(TestValidNotZeroTerm) { + Y_UNIT_TEST(TestValidNotZeroTerm) { char r[10]; CGIUnescape(r, "123456789", 4); @@ -99,7 +99,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { UNIT_ASSERT_VALUES_EQUAL(r, "12=34"); } - Y_UNIT_TEST(TestInvalidNotZeroTerm) { + Y_UNIT_TEST(TestInvalidNotZeroTerm) { char r[10]; CGIUnescape(r, "%3d", 1); @@ -124,7 +124,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { UNIT_ASSERT_VALUES_EQUAL(r, "%3u1"); } - Y_UNIT_TEST(StrokaOutParameterInplace) { + Y_UNIT_TEST(StrokaOutParameterInplace) { TString s; s = "hello%3dworld"; @@ -148,7 +148,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { UNIT_ASSERT_VALUES_EQUAL(s, ""); } - Y_UNIT_TEST(StrokaOutParameterNotInplace) { + Y_UNIT_TEST(StrokaOutParameterNotInplace) { TString s, sCopy; s = "hello%3dworld"; @@ -230,8 +230,8 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { } } -Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { - Y_UNIT_TEST(StrokaOutParameterInplace) { +Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { + Y_UNIT_TEST(StrokaOutParameterInplace) { TString s; s = "hello%3dworld"; @@ -255,7 +255,7 @@ Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { UNIT_ASSERT_VALUES_EQUAL(s, ""); } - Y_UNIT_TEST(StrokaOutParameterNotInplace) { + Y_UNIT_TEST(StrokaOutParameterNotInplace) { TString s, sCopy; s = "hello%3dworld"; @@ -285,15 +285,15 @@ Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { } } -Y_UNIT_TEST_SUITE(TQuoteTest) { - Y_UNIT_TEST(ReturnsEndOfTo) { +Y_UNIT_TEST_SUITE(TQuoteTest) { + Y_UNIT_TEST(ReturnsEndOfTo) { char r[10]; const char* returned = Quote(r, "123"); UNIT_ASSERT_VALUES_EQUAL(r + strlen("123"), returned); UNIT_ASSERT_VALUES_EQUAL('\0', *returned); } - Y_UNIT_TEST(SlashIsSafeByDefault) { + Y_UNIT_TEST(SlashIsSafeByDefault) { char r[100]; Quote(r, "/path;tail/path,tail/"); UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", r); @@ -302,7 +302,7 @@ Y_UNIT_TEST_SUITE(TQuoteTest) { UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", s.c_str()); } - Y_UNIT_TEST(SafeColons) { + Y_UNIT_TEST(SafeColons) { char r[100]; Quote(r, "/path;tail/path,tail/", ";,"); UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", r); @@ -311,7 +311,7 @@ Y_UNIT_TEST_SUITE(TQuoteTest) { UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", s.c_str()); } - Y_UNIT_TEST(StringBuf) { + Y_UNIT_TEST(StringBuf) { char r[100]; char* end = Quote(r, "abc\0/path", ""); UNIT_ASSERT_VALUES_EQUAL("abc\0%2Fpath", TStringBuf(r, end)); diff --git a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h index 8620c7517b..d7ea7c1259 100644 --- a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h +++ b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h @@ -150,7 +150,7 @@ namespace NEscJ { } template <bool quote, bool tounicode> - inline void EscapeJ(TStringBuf in, IOutputStream& out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) { + inline void EscapeJ(TStringBuf in, IOutputStream& out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) { TTempBuf b(SuggestBuffer(in.size()) + 2); if (quote) @@ -192,7 +192,7 @@ namespace NEscJ { } template <bool quote> - inline void EscapeJ(TStringBuf in, IOutputStream& out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) { + inline void EscapeJ(TStringBuf in, IOutputStream& out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) { EscapeJ<quote, false>(in, out, safe, unsafe); } diff --git a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp index 3cc25dc887..768555ea3a 100644 --- a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp +++ b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp @@ -25,10 +25,10 @@ static const TStringBuf CommonTestData[] = { RESC_FIXED_STR("There\\tare\\ttabs."), RESC_FIXED_STR("There\tare\ttabs.")}; #undef RESC_FIXED_STR -Y_UNIT_TEST_SUITE(TRelaxedEscaperTest) { - Y_UNIT_TEST(TestEscaper) { +Y_UNIT_TEST_SUITE(TRelaxedEscaperTest) { + Y_UNIT_TEST(TestEscaper) { using namespace NEscJ; - for (size_t i = 0; i < Y_ARRAY_SIZE(CommonTestData); i += 2) { + for (size_t i = 0; i < Y_ARRAY_SIZE(CommonTestData); i += 2) { TString expected(CommonTestData[i].data(), CommonTestData[i].size()); TString source(CommonTestData[i + 1].data(), CommonTestData[i + 1].size()); TString actual(EscapeJ<false>(source)); diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 284842f831..85f4ac5d69 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -124,7 +124,7 @@ TStringBuf CutSchemePrefix(const TStringBuf url) noexcept { } template <bool KeepPort> -static inline TStringBuf GetHostAndPortImpl(const TStringBuf url) { +static inline TStringBuf GetHostAndPortImpl(const TStringBuf url) { TStringBuf urlNoScheme = url; urlNoScheme.Skip(GetHttpPrefixSize(url)); @@ -324,8 +324,8 @@ static bool HasPrefix(const TStringBuf url) noexcept { TString AddSchemePrefix(const TString& url) { return AddSchemePrefix(url, TStringBuf("http")); -} - +} + TString AddSchemePrefix(const TString& url, TStringBuf scheme) { if (HasPrefix(url)) { return url; @@ -347,7 +347,7 @@ static inline int x2c(unsigned char* x) { static inline int Unescape(char* str) { char *to, *from; int dlen = 0; - if ((str = strchr(str, '%')) == nullptr) + if ((str = strchr(str, '%')) == nullptr) return dlen; for (to = str, from = str; *from; from++, to++) { if ((*to = *from) == '%') { @@ -361,7 +361,7 @@ static inline int Unescape(char* str) { return dlen; } -size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size) { +size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size) { if (source.empty() || source[0] == '?') return strlcpy(dest, "/", dest_size); size_t len = Min(dest_size - 1, source.length()); @@ -372,7 +372,7 @@ size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size) { return len; } -size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport) { +size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport) { size_t len = Min(dest_size - 1, source.length()); memcpy(dest, source.data(), len); dest[len] = 0; diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h index 287b42d3e3..84137ccc57 100644 --- a/library/cpp/string_utils/url/url.h +++ b/library/cpp/string_utils/url/url.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/fwd.h> +#include <util/generic/fwd.h> #include <util/generic/strbuf.h> namespace NUrl { @@ -60,9 +60,9 @@ TStringBuf CutSchemePrefix(const TStringBuf url) noexcept; //! @note if URL has scheme prefix already the function returns unchanged URL TString AddSchemePrefix(const TString& url, const TStringBuf scheme); -//! Same as `AddSchemePrefix(url, "http")`. +//! Same as `AddSchemePrefix(url, "http")`. TString AddSchemePrefix(const TString& url); - + Y_PURE_FUNCTION TStringBuf GetHost(const TStringBuf url) noexcept; @@ -159,8 +159,8 @@ TStringBuf CutMPrefix(const TStringBuf url) noexcept; Y_PURE_FUNCTION TStringBuf GetDomain(const TStringBuf host) noexcept; // should not be used -size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size); -size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport = 80); +size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size); +size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport = 80); Y_PURE_FUNCTION TStringBuf RemoveFinalSlash(TStringBuf str) noexcept; diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp index 2c2f5948a0..1588013893 100644 --- a/library/cpp/string_utils/url/url_ut.cpp +++ b/library/cpp/string_utils/url/url_ut.cpp @@ -4,8 +4,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TUtilUrlTest) { - Y_UNIT_TEST(TestGetHostAndGetHostAndPort) { +Y_UNIT_TEST_SUITE(TUtilUrlTest) { + Y_UNIT_TEST(TestGetHostAndGetHostAndPort) { UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetHost("ya.ru/bebe")); UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetHostAndPort("ya.ru/bebe")); UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetHost("ya.ru")); @@ -27,7 +27,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("", GetHost("")); } - Y_UNIT_TEST(TestGetPathAndQuery) { + Y_UNIT_TEST(TestGetPathAndQuery) { UNIT_ASSERT_VALUES_EQUAL("/", GetPathAndQuery("ru.wikipedia.org")); UNIT_ASSERT_VALUES_EQUAL("/", GetPathAndQuery("ru.wikipedia.org/")); UNIT_ASSERT_VALUES_EQUAL("/", GetPathAndQuery("ru.wikipedia.org:8080")); @@ -39,7 +39,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("/?1#comment", GetPathAndQuery("ru.wikipedia.org/?1#comment", false)); } - Y_UNIT_TEST(TestGetDomain) { + Y_UNIT_TEST(TestGetDomain) { UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetDomain("www.ya.ru")); UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetDomain("ya.ru")); UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetDomain("a.b.ya.ru")); @@ -48,7 +48,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("", GetDomain("")); } - Y_UNIT_TEST(TestGetParentDomain) { + Y_UNIT_TEST(TestGetParentDomain) { UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("www.ya.ru", 0)); UNIT_ASSERT_VALUES_EQUAL("ru", GetParentDomain("www.ya.ru", 1)); UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetParentDomain("www.ya.ru", 2)); @@ -62,7 +62,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("", 1)); } - Y_UNIT_TEST(TestGetZone) { + Y_UNIT_TEST(TestGetZone) { UNIT_ASSERT_VALUES_EQUAL("ru", GetZone("www.ya.ru")); UNIT_ASSERT_VALUES_EQUAL("com", GetZone("ya.com")); UNIT_ASSERT_VALUES_EQUAL("RU", GetZone("RU")); @@ -70,7 +70,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("", GetZone("")); } - Y_UNIT_TEST(TestAddSchemePrefix) { + Y_UNIT_TEST(TestAddSchemePrefix) { UNIT_ASSERT_VALUES_EQUAL("http://yandex.ru", AddSchemePrefix("yandex.ru")); UNIT_ASSERT_VALUES_EQUAL("http://yandex.ru", AddSchemePrefix("http://yandex.ru")); UNIT_ASSERT_VALUES_EQUAL("https://yandex.ru", AddSchemePrefix("https://yandex.ru")); @@ -78,7 +78,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("ftp://ya.ru", AddSchemePrefix("ya.ru", "ftp")); } - Y_UNIT_TEST(TestSchemeGet) { + Y_UNIT_TEST(TestSchemeGet) { UNIT_ASSERT_VALUES_EQUAL("http://", GetSchemePrefix("http://ya.ru/bebe")); UNIT_ASSERT_VALUES_EQUAL("", GetSchemePrefix("yaru")); UNIT_ASSERT_VALUES_EQUAL("yaru://", GetSchemePrefix("yaru://ya.ru://zzz")); @@ -87,7 +87,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("https://", GetSchemePrefix("https://")); // is that right? } - Y_UNIT_TEST(TestSchemeCut) { + Y_UNIT_TEST(TestSchemeCut) { UNIT_ASSERT_VALUES_EQUAL("ya.ru/bebe", CutSchemePrefix("http://ya.ru/bebe")); UNIT_ASSERT_VALUES_EQUAL("yaru", CutSchemePrefix("yaru")); UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutSchemePrefix("yaru://ya.ru://zzz")); @@ -104,7 +104,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("https://", CutHttpPrefix("https://", true)); // is that right? } - Y_UNIT_TEST(TestMisc) { + Y_UNIT_TEST(TestMisc) { UNIT_ASSERT_VALUES_EQUAL("", CutWWWPrefix("www.")); UNIT_ASSERT_VALUES_EQUAL("", CutWWWPrefix("WwW.")); UNIT_ASSERT_VALUES_EQUAL("www", CutWWWPrefix("www")); @@ -127,7 +127,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("ya.ru", CutMPrefix("m.ya.ru")); } - Y_UNIT_TEST(TestSplitUrlToHostAndPath) { + Y_UNIT_TEST(TestSplitUrlToHostAndPath) { TStringBuf host, path; SplitUrlToHostAndPath("https://yandex.ru/yandsearch", host, path); @@ -175,7 +175,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_STRINGS_EQUAL(fragment, "fragment"); } - Y_UNIT_TEST(TestGetSchemeHostAndPort) { + Y_UNIT_TEST(TestGetSchemeHostAndPort) { { // all components are present TStringBuf scheme("unknown"), host("unknown"); ui16 port = 0; |