summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/tdutils/test/misc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/tdutils/test/misc.cpp')
-rw-r--r--protocols/Telegram/tdlib/td/tdutils/test/misc.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/protocols/Telegram/tdlib/td/tdutils/test/misc.cpp b/protocols/Telegram/tdlib/td/tdutils/test/misc.cpp
index 7db990dad1..e1612a9924 100644
--- a/protocols/Telegram/tdlib/td/tdutils/test/misc.cpp
+++ b/protocols/Telegram/tdlib/td/tdutils/test/misc.cpp
@@ -1,5 +1,5 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -40,6 +40,7 @@
#include "td/utils/translit.h"
#include "td/utils/uint128.h"
#include "td/utils/unicode.h"
+#include "td/utils/unique_value_ptr.h"
#include "td/utils/utf8.h"
#include <algorithm>
@@ -440,7 +441,7 @@ static void test_to_double_one(td::CSlice str, td::Slice expected, int precision
auto result = PSTRING() << td::StringBuilder::FixedDouble(to_double(str), precision);
if (expected != result) {
LOG(ERROR) << "To double conversion failed: have " << str << ", expected " << expected << ", parsed "
- << to_double(str) << ", got " << result;
+ << to_double(str) << ", receive " << result;
}
}
@@ -516,7 +517,8 @@ TEST(Misc, print_uint) {
static void test_idn_to_ascii_one(const td::string &host, const td::string &result) {
if (result != td::idn_to_ascii(host).ok()) {
- LOG(ERROR) << "Failed to convert " << host << " to " << result << ", got \"" << td::idn_to_ascii(host).ok() << "\"";
+ LOG(ERROR) << "Failed to convert " << host << " to " << result << ", receive \"" << td::idn_to_ascii(host).ok()
+ << "\"";
}
}
@@ -834,9 +836,9 @@ TEST(Misc, StringBuilder) {
if (use_buf) {
ASSERT_EQ(res, sb.as_cslice());
} else {
- auto got = sb.as_cslice();
- res.resize(got.size());
- ASSERT_EQ(res, got);
+ auto sb_result = sb.as_cslice();
+ res.resize(sb_result.size());
+ ASSERT_EQ(res, sb_result);
}
}
}
@@ -1260,3 +1262,32 @@ TEST(FloodControl, Fast) {
LOG(INFO) << ++count << ": " << now;
}
}
+
+TEST(UniqueValuePtr, Basic) {
+ auto a = td::make_unique_value<int>(5);
+ td::unique_value_ptr<int> b;
+ ASSERT_TRUE(b == nullptr);
+ ASSERT_TRUE(a != nullptr);
+ ASSERT_TRUE(a != b);
+ b = a;
+ ASSERT_TRUE(a != nullptr);
+ ASSERT_TRUE(b != nullptr);
+ ASSERT_TRUE(a == b);
+ *a = 6;
+ ASSERT_TRUE(a != nullptr);
+ ASSERT_TRUE(b != nullptr);
+ ASSERT_TRUE(a != b);
+ b = std::move(a);
+ ASSERT_TRUE(a == nullptr);
+ ASSERT_TRUE(b != nullptr);
+ ASSERT_TRUE(a != b);
+ auto c = td::make_unique_value<td::unique_value_ptr<int>>(a);
+ ASSERT_TRUE(*c == a);
+ ASSERT_TRUE(*c == nullptr);
+ c = td::make_unique_value<td::unique_value_ptr<int>>(b);
+ ASSERT_TRUE(*c == b);
+ ASSERT_TRUE(**c == 6);
+ auto d = c;
+ ASSERT_TRUE(c == d);
+ ASSERT_TRUE(6 == **d);
+}