diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (patch) | |
tree | cb7a9f4a92c0d4cc5a86eeed49ad71e810953c1f /library/cpp/binsaver/ut_util/ut_util.h | |
parent | 83a8efcf3af051e3dd59c00d1d5dafc96412ec1e (diff) | |
download | ydb-00afc96e9c0298054b7386fa7fb9e3cc3d67b974.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/binsaver/ut_util/ut_util.h')
-rw-r--r-- | library/cpp/binsaver/ut_util/ut_util.h | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/library/cpp/binsaver/ut_util/ut_util.h b/library/cpp/binsaver/ut_util/ut_util.h index 52e7bcf8e1..be8f89cc7c 100644 --- a/library/cpp/binsaver/ut_util/ut_util.h +++ b/library/cpp/binsaver/ut_util/ut_util.h @@ -1,71 +1,71 @@ -#pragma once - +#pragma once + #include <library/cpp/binsaver/bin_saver.h> #include <library/cpp/binsaver/mem_io.h> #include <library/cpp/binsaver/util_stream_io.h> - + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/vector.h> -#include <util/stream/buffer.h> - -#include <functional> - - -/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself - * comparerChecksInside == false means comparer returns if its arguments are equal - */ - -template <class T, class TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void UnitTestCheckWithComparer(const T& lhs, const T& rhs, const TComparer& comparer) { - if constexpr (comparerChecksInside) { - comparer(lhs, rhs); - } else { - UNIT_ASSERT(comparer(lhs, rhs)); - } -} - - -/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself - * comparerChecksInside == false means comparer returns true if its arguments are equal - */ - -template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void TestBinSaverSerializationToBuffer(const T& original, const TComparer& comparer = TComparer()) { - TBufferOutput out; - { - TYaStreamOutput yaOut(out); - - IBinSaver f(yaOut, false, false); - f.Add(0, const_cast<T*>(&original)); - } - TBufferInput in(out.Buffer()); - T restored; - { - TYaStreamInput yaIn(in); - IBinSaver f(yaIn, true, false); - f.Add(0, &restored); - } - UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); -} - -template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void TestBinSaverSerializationToVector(const T& original, const TComparer& comparer = TComparer()) { - TVector<char> out; - SerializeToMem(&out, *const_cast<T*>(&original)); - T restored; - SerializeFromMem(&out, restored); - UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); - - TVector<TVector<char>> out2D; - SerializeToMem(&out2D, *const_cast<T*>(&original)); - T restored2D; - SerializeFromMem(&out2D, restored2D); - UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored2D, comparer); -} - -template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> -void TestBinSaverSerialization(const T& original, const TComparer& comparer = TComparer()) { - TestBinSaverSerializationToBuffer<T, TComparer, comparerChecksInside>(original, comparer); - TestBinSaverSerializationToVector<T, TComparer, comparerChecksInside>(original, comparer); -} + +#include <util/generic/vector.h> +#include <util/stream/buffer.h> + +#include <functional> + + +/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself + * comparerChecksInside == false means comparer returns if its arguments are equal + */ + +template <class T, class TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void UnitTestCheckWithComparer(const T& lhs, const T& rhs, const TComparer& comparer) { + if constexpr (comparerChecksInside) { + comparer(lhs, rhs); + } else { + UNIT_ASSERT(comparer(lhs, rhs)); + } +} + + +/* comparerChecksInside == true means comparer uses UNIT_ASSERT... inside itself + * comparerChecksInside == false means comparer returns true if its arguments are equal + */ + +template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void TestBinSaverSerializationToBuffer(const T& original, const TComparer& comparer = TComparer()) { + TBufferOutput out; + { + TYaStreamOutput yaOut(out); + + IBinSaver f(yaOut, false, false); + f.Add(0, const_cast<T*>(&original)); + } + TBufferInput in(out.Buffer()); + T restored; + { + TYaStreamInput yaIn(in); + IBinSaver f(yaIn, true, false); + f.Add(0, &restored); + } + UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); +} + +template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void TestBinSaverSerializationToVector(const T& original, const TComparer& comparer = TComparer()) { + TVector<char> out; + SerializeToMem(&out, *const_cast<T*>(&original)); + T restored; + SerializeFromMem(&out, restored); + UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored, comparer); + + TVector<TVector<char>> out2D; + SerializeToMem(&out2D, *const_cast<T*>(&original)); + T restored2D; + SerializeFromMem(&out2D, restored2D); + UnitTestCheckWithComparer<T, TComparer, comparerChecksInside>(original, restored2D, comparer); +} + +template <typename T, typename TComparer = std::equal_to<T>, bool comparerChecksInside = false> +void TestBinSaverSerialization(const T& original, const TComparer& comparer = TComparer()) { + TestBinSaverSerializationToBuffer<T, TComparer, comparerChecksInside>(original, comparer); + TestBinSaverSerializationToVector<T, TComparer, comparerChecksInside>(original, comparer); +} |