From 4c2859b85c8950810890a7b380dcc2ab30772238 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 26 Jul 2023 14:21:27 +0300 Subject: [PATCH] Add test for zero_encode. --- tdutils/test/misc.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tdutils/test/misc.cpp b/tdutils/test/misc.cpp index e1612a992..140223373 100644 --- a/tdutils/test/misc.cpp +++ b/tdutils/test/misc.cpp @@ -265,6 +265,45 @@ TEST(Misc, base64) { ASSERT_TRUE(td::base64url_encode("ab>(i); + } + test_zero_encode(str, str, str); + + test_zero_encode(""); + test_zero_encode(td::Slice("\0"), td::Slice("\0\1"), td::Slice("\0\1")); + test_zero_encode(td::Slice("\0\xff\0\xff\0\xff\0\xff\0\xff\0\xff\0\xff"), + td::Slice("\0\1\xff\0\1\xff\0\1\xff\0\1\xff\0\1\xff\0\1\xff\0\1\xff"), + td::Slice("\0\1\xff\1\0\1\xff\1\0\1\xff\1\0\1\xff\1\0\1\xff\1\0\1\xff\1\0\1\xff\1")); + test_zero_encode(td::Slice("\0\0\xff\xff\0\0\xff\xff\0\0\xff\xff\0\0\xff\xff\0\0\xff\xff\0\0\xff\xff"), + td::Slice("\0\2\xff\xff\0\2\xff\xff\0\2\xff\xff\0\2\xff\xff\0\2\xff\xff\0\2\xff\xff"), + td::Slice("\0\2\xff\2\0\2\xff\2\0\2\xff\2\0\2\xff\2\0\2\xff\2\0\2\xff\2")); + test_zero_encode(td::Slice("\0\0\0\0\0\xff\xff\xff\xff\xff"), td::Slice("\0\5\xff\xff\xff\xff\xff"), + td::Slice("\0\5\xff\5")); + test_zero_encode(td::Slice( + "\0\0\0\0\0\xff\xff\xff\xff\xff\0\0\0\0\0\xff\xff\xff\xff\xff\0\0\0\0\0\xff\xff\xff\xff\xff\0\0\0\0\0\xff\xff\xff" + "\xff\xff\0\0\0\0\0\xff\xff\xff\xff\xff\0\0\0\0\0\xff\xff\xff\xff\xff\0\0\0\0\0\xff\xff\xff\xff\xff")); + test_zero_encode(td::string(1000, '\0')); + test_zero_encode(str + td::string(1000, '\0') + str + td::string(1000, '\xff') + str); +} + template static void test_remove_if(td::vector v, const T &func, const td::vector &expected) { td::remove_if(v, func);