diff options
author | George Hazan <ghazan@miranda.im> | 2022-11-30 17:48:47 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-11-30 17:48:47 +0300 |
commit | 0ece30dc7c0e34b4c5911969b8fa99c33c6d023c (patch) | |
tree | 671325d3fec09b999411e4e3ab84ef8259261818 /protocols/Telegram/tdlib/td/tdutils/test/json.cpp | |
parent | 46c53ffc6809c67e4607e99951a2846c382b63b2 (diff) |
Telegram: update for TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/tdutils/test/json.cpp')
-rw-r--r-- | protocols/Telegram/tdlib/td/tdutils/test/json.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/protocols/Telegram/tdlib/td/tdutils/test/json.cpp b/protocols/Telegram/tdlib/td/tdutils/test/json.cpp index deca81a791..4e57b2d562 100644 --- a/protocols/Telegram/tdlib/td/tdutils/test/json.cpp +++ b/protocols/Telegram/tdlib/td/tdutils/test/json.cpp @@ -1,31 +1,26 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 // // 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) // -#include "td/utils/tests.h" - #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" +#include "td/utils/Slice.h" #include "td/utils/StringBuilder.h" +#include "td/utils/tests.h" -#include <tuple> #include <utility> -REGISTER_TESTS(json) - -using namespace td; - -static void decode_encode(string str, string result = "") { +static void decode_encode(const td::string &str, td::string result = td::string()) { auto str_copy = str; - auto r_value = json_decode(str_copy); + auto r_value = td::json_decode(str_copy); ASSERT_TRUE(r_value.is_ok()); if (r_value.is_error()) { LOG(INFO) << r_value.error(); return; } - auto new_str = json_encode<string>(r_value.ok()); + auto new_str = td::json_encode<td::string>(r_value.ok()); if (result.empty()) { result = str; } @@ -34,21 +29,22 @@ static void decode_encode(string str, string result = "") { TEST(JSON, array) { char tmp[1000]; - StringBuilder sb({tmp, sizeof(tmp)}); - JsonBuilder jb(std::move(sb)); + td::StringBuilder sb(td::MutableSlice{tmp, sizeof(tmp)}); + td::JsonBuilder jb(std::move(sb)); jb.enter_value().enter_array() << "Hello" << -123; ASSERT_EQ(jb.string_builder().is_error(), false); auto encoded = jb.string_builder().as_cslice().str(); ASSERT_EQ("[\"Hello\",-123]", encoded); decode_encode(encoded); } + TEST(JSON, object) { char tmp[1000]; - StringBuilder sb({tmp, sizeof(tmp)}); - JsonBuilder jb(std::move(sb)); + td::StringBuilder sb(td::MutableSlice{tmp, sizeof(tmp)}); + td::JsonBuilder jb(std::move(sb)); auto c = jb.enter_object(); - c << std::tie("key", "value"); - c << std::make_pair("1", 2); + c("key", "value"); + c("1", 2); c.leave(); ASSERT_EQ(jb.string_builder().is_error(), false); auto encoded = jb.string_builder().as_cslice().str(); @@ -58,8 +54,8 @@ TEST(JSON, object) { TEST(JSON, nested) { char tmp[1000]; - StringBuilder sb({tmp, sizeof(tmp)}); - JsonBuilder jb(std::move(sb)); + td::StringBuilder sb(td::MutableSlice{tmp, sizeof(tmp)}); + td::JsonBuilder jb(std::move(sb)); { auto a = jb.enter_array(); a << 1; |