From 9322bf68cd3c5c5c7da238530f3722bd3459ef25 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 27 Sep 2020 20:38:23 +0300 Subject: [PATCH] Move test functions implementation to cpp. GitOrigin-RevId: eec1d208f410a3f546dfe230d1780ecdac02d3b4 --- tdutils/td/utils/tests.cpp | 26 ++++++++++++++++++++++++++ tdutils/td/utils/tests.h | 25 ++----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/tdutils/td/utils/tests.cpp b/tdutils/td/utils/tests.cpp index c36eb2379..f036918f0 100644 --- a/tdutils/td/utils/tests.cpp +++ b/tdutils/td/utils/tests.cpp @@ -12,6 +12,7 @@ #include "td/utils/PathView.h" #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" +#include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" @@ -20,10 +21,35 @@ namespace td { +string rand_string(int from, int to, size_t len) { + string res(len, '\0'); + for (auto &c : res) { + c = static_cast(Random::fast(from, to)); + } + return res; +} + +vector rand_split(Slice str) { + vector res; + size_t pos = 0; + while (pos < str.size()) { + size_t len; + if (Random::fast(0, 1) == 1) { + len = Random::fast(1, 10); + } else { + len = Random::fast(100, 200); + } + res.push_back(str.substr(pos, len).str()); + pos += len; + } + return res; +} + struct TestInfo { string name; string result_hash; // base64 }; + StringBuilder &operator<<(StringBuilder &sb, const TestInfo &info) { // should I use JSON? CHECK(!info.name.empty()); diff --git a/tdutils/td/utils/tests.h b/tdutils/td/utils/tests.h index 976d8ed00..6dbff9ded 100644 --- a/tdutils/td/utils/tests.h +++ b/tdutils/td/utils/tests.h @@ -11,7 +11,6 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/port/thread.h" -#include "td/utils/Random.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" @@ -146,29 +145,9 @@ class Stage { std::atomic value_{0}; }; -inline string rand_string(int from, int to, size_t len) { - string res(len, '\0'); - for (auto &c : res) { - c = static_cast(Random::fast(from, to)); - } - return res; -} +string rand_string(int from, int to, size_t len); -inline vector rand_split(Slice str) { - vector res; - size_t pos = 0; - while (pos < str.size()) { - size_t len; - if (Random::fast(0, 1) == 1) { - len = Random::fast(1, 10); - } else { - len = Random::fast(100, 200); - } - res.push_back(str.substr(pos, len).str()); - pos += len; - } - return res; -} +vector rand_split(Slice str); template void assert_eq_impl(const T1 &expected, const T2 &got, const char *file, int line) {