From e78a5fbecf6e561a99589ec5cec16bb2c486524c Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 14 Oct 2021 15:08:35 +0300 Subject: [PATCH] Explicitly specify namespace td in tdutils tests. --- tdutils/test/buffer.cpp | 28 +++++++++++------------ tdutils/test/json.cpp | 21 +++++++++-------- tdutils/test/pq.cpp | 50 ++++++++++++++++++++--------------------- 3 files changed, 48 insertions(+), 51 deletions(-) diff --git a/tdutils/test/buffer.cpp b/tdutils/test/buffer.cpp index 403af89b8..8c5d7eb02 100644 --- a/tdutils/test/buffer.cpp +++ b/tdutils/test/buffer.cpp @@ -9,47 +9,45 @@ #include "td/utils/buffer.h" #include "td/utils/Random.h" -using namespace td; - TEST(Buffer, buffer_builder) { { - BufferBuilder builder; + td::BufferBuilder builder; builder.append("b"); builder.prepend("a"); builder.append("c"); ASSERT_EQ(builder.extract().as_slice(), "abc"); } { - BufferBuilder builder{"hello", 0, 0}; + td::BufferBuilder builder{"hello", 0, 0}; ASSERT_EQ(builder.extract().as_slice(), "hello"); } { - BufferBuilder builder{"hello", 1, 1}; + td::BufferBuilder builder{"hello", 1, 1}; builder.prepend("A "); builder.append(" B"); ASSERT_EQ(builder.extract().as_slice(), "A hello B"); } { - std::string str = rand_string('a', 'z', 10000); - auto splitted_str = rand_split(str); + auto str = td::rand_string('a', 'z', 10000); + auto splitted_str = td::rand_split(str); - int l = Random::fast(0, static_cast(splitted_str.size() - 1)); + int l = td::Random::fast(0, static_cast(splitted_str.size() - 1)); int r = l; - BufferBuilder builder(splitted_str[l], 123, 1000); - while (l != 0 || r != static_cast(splitted_str.size()) - 1) { - if (l == 0 || (Random::fast_bool() && r != static_cast(splitted_str.size() - 1))) { + td::BufferBuilder builder(splitted_str[l], 123, 1000); + while (l != 0 || r != static_cast(splitted_str.size()) - 1) { + if (l == 0 || (td::Random::fast_bool() && r != static_cast(splitted_str.size() - 1))) { r++; - if (Random::fast_bool()) { + if (td::Random::fast_bool()) { builder.append(splitted_str[r]); } else { - builder.append(BufferSlice(splitted_str[r])); + builder.append(td::BufferSlice(splitted_str[r])); } } else { l--; - if (Random::fast_bool()) { + if (td::Random::fast_bool()) { builder.prepend(splitted_str[l]); } else { - builder.prepend(BufferSlice(splitted_str[l])); + builder.prepend(td::BufferSlice(splitted_str[l])); } } } diff --git a/tdutils/test/json.cpp b/tdutils/test/json.cpp index e7e986a4e..f374a233d 100644 --- a/tdutils/test/json.cpp +++ b/tdutils/test/json.cpp @@ -12,17 +12,15 @@ #include -using namespace td; - -static void decode_encode(string str, string result = "") { +static void decode_encode(td::string str, td::string result = "") { 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(r_value.ok()); + auto new_str = td::json_encode(r_value.ok()); if (result.empty()) { result = str; } @@ -31,18 +29,19 @@ static void decode_encode(string str, string result = "") { TEST(JSON, array) { char tmp[1000]; - StringBuilder sb(MutableSlice{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(MutableSlice{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("key", "value"); c("1", 2); @@ -55,8 +54,8 @@ TEST(JSON, object) { TEST(JSON, nested) { char tmp[1000]; - StringBuilder sb(MutableSlice{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; diff --git a/tdutils/test/pq.cpp b/tdutils/test/pq.cpp index a59134a0b..9c0d18555 100644 --- a/tdutils/test/pq.cpp +++ b/tdutils/test/pq.cpp @@ -18,11 +18,9 @@ #include #include -using namespace td; - #if TD_HAVE_OPENSSL -static bool is_prime(uint64 x) { - for (uint64 d = 2; d < x && d * d <= x; d++) { +static bool is_prime(td::uint64 x) { + for (td::uint64 d = 2; d < x && d * d <= x; d++) { if (x % d == 0) { return false; } @@ -30,8 +28,8 @@ static bool is_prime(uint64 x) { return true; } -static std::vector gen_primes(uint64 L, uint64 R, int limit = 0) { - std::vector res; +static td::vector gen_primes(td::uint64 L, td::uint64 R, int limit = 0) { + td::vector res; for (auto x = L; x <= R && (limit <= 0 || res.size() < static_cast(limit)); x++) { if (is_prime(x)) { res.push_back(x); @@ -40,21 +38,23 @@ static std::vector gen_primes(uint64 L, uint64 R, int limit = 0) { return res; } -static std::vector gen_primes() { - std::vector result; - append(result, gen_primes(1, 100)); - append(result, gen_primes((1ull << 31) - 500000, std::numeric_limits::max(), 5)); - append(result, gen_primes((1ull << 32) - 500000, std::numeric_limits::max(), 5)); - append(result, gen_primes((1ull << 39) - 500000, std::numeric_limits::max(), 1)); +static td::vector gen_primes() { + td::vector result; + td::append(result, gen_primes(1, 100)); + td::append(result, gen_primes((1ull << 31) - 500000, std::numeric_limits::max(), 5)); + td::append(result, gen_primes((1ull << 32) - 500000, std::numeric_limits::max(), 5)); + td::append(result, gen_primes((1ull << 39) - 500000, std::numeric_limits::max(), 1)); return result; } -using PqQuery = std::pair; +using PqQuery = std::pair; + static bool cmp(const PqQuery &a, const PqQuery &b) { return a.first * a.second < b.first * b.second; } -static std::vector gen_pq_queries() { - std::vector res; + +static td::vector gen_pq_queries() { + td::vector res; auto primes = gen_primes(); for (auto q : primes) { for (auto p : primes) { @@ -68,21 +68,21 @@ static std::vector gen_pq_queries() { return res; } -static void test_pq(uint64 first, uint64 second) { - BigNum p = BigNum::from_decimal(PSLICE() << first).move_as_ok(); - BigNum q = BigNum::from_decimal(PSLICE() << second).move_as_ok(); +static void test_pq(td::uint64 first, td::uint64 second) { + td::BigNum p = td::BigNum::from_decimal(PSLICE() << first).move_as_ok(); + td::BigNum q = td::BigNum::from_decimal(PSLICE() << second).move_as_ok(); - BigNum pq; - BigNumContext context; - BigNum::mul(pq, p, q, context); - std::string pq_str = pq.to_binary(); + td::BigNum pq; + td::BigNumContext context; + td::BigNum::mul(pq, p, q, context); + td::string pq_str = pq.to_binary(); - std::string p_str, q_str; + td::string p_str, q_str; int err = td::pq_factorize(pq_str, &p_str, &q_str); LOG_CHECK(err == 0) << first << " * " << second; - BigNum p_res = BigNum::from_binary(p_str); - BigNum q_res = BigNum::from_binary(q_str); + td::BigNum p_res = td::BigNum::from_binary(p_str); + td::BigNum q_res = td::BigNum::from_binary(q_str); LOG_CHECK(p_str == p.to_binary()) << td::tag("got", p_res.to_decimal()) << td::tag("expected", first); LOG_CHECK(q_str == q.to_binary()) << td::tag("got", q_res.to_decimal()) << td::tag("expected", second);