Move HttpUrl test to separate header.

This commit is contained in:
levlam 2021-05-24 23:09:41 +03:00
parent 25c2692cf1
commit 4cc60bbc25
3 changed files with 29 additions and 20 deletions

View File

@ -292,6 +292,7 @@ set(TDUTILS_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/test/gzip.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/HazardPointers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/heap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/HttpUrl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/json.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/List.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/log.cpp

28
tdutils/test/HttpUrl.cpp Normal file
View File

@ -0,0 +1,28 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// 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/common.h"
#include "td/utils/HttpUrl.h"
#include "td/utils/tests.h"
static void test_get_url_query_file_name(const char *prefix, const char *suffix, const char *file_name) {
auto path = td::string(prefix) + td::string(file_name) + td::string(suffix);
ASSERT_STREQ(file_name, td::get_url_query_file_name(path));
ASSERT_STREQ(file_name, td::get_url_file_name("http://telegram.org" + path));
ASSERT_STREQ(file_name, td::get_url_file_name("http://telegram.org:80" + path));
ASSERT_STREQ(file_name, td::get_url_file_name("telegram.org" + path));
}
TEST(HttpUrl, get_url_query_file_name) {
for (auto suffix : {"?t=1#test", "#test?t=1", "#?t=1", "?t=1#", "#test", "?t=1", "#", "?", ""}) {
test_get_url_query_file_name("", suffix, "");
test_get_url_query_file_name("/", suffix, "");
test_get_url_query_file_name("/a/adasd/", suffix, "");
test_get_url_query_file_name("/a/lklrjetn/", suffix, "adasd.asdas");
test_get_url_query_file_name("/", suffix, "a123asadas");
test_get_url_query_file_name("/", suffix, "\\a\\1\\2\\3\\a\\s\\a\\das");
}
}

View File

@ -15,7 +15,6 @@
#include "td/utils/Hash.h"
#include "td/utils/HashMap.h"
#include "td/utils/HashSet.h"
#include "td/utils/HttpUrl.h"
#include "td/utils/invoke.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
@ -516,25 +515,6 @@ TEST(Misc, print_uint) {
ASSERT_STREQ("9223372036854775807", PSLICE() << 9223372036854775807u);
}
static void test_get_url_query_file_name_one(const char *prefix, const char *suffix, const char *file_name) {
auto path = td::string(prefix) + td::string(file_name) + td::string(suffix);
ASSERT_STREQ(file_name, td::get_url_query_file_name(path));
ASSERT_STREQ(file_name, td::get_url_file_name("http://telegram.org" + path));
ASSERT_STREQ(file_name, td::get_url_file_name("http://telegram.org:80" + path));
ASSERT_STREQ(file_name, td::get_url_file_name("telegram.org" + path));
}
TEST(Misc, get_url_query_file_name) {
for (auto suffix : {"?t=1#test", "#test?t=1", "#?t=1", "?t=1#", "#test", "?t=1", "#", "?", ""}) {
test_get_url_query_file_name_one("", suffix, "");
test_get_url_query_file_name_one("/", suffix, "");
test_get_url_query_file_name_one("/a/adasd/", suffix, "");
test_get_url_query_file_name_one("/a/lklrjetn/", suffix, "adasd.asdas");
test_get_url_query_file_name_one("/", suffix, "a123asadas");
test_get_url_query_file_name_one("/", suffix, "\\a\\1\\2\\3\\a\\s\\a\\das");
}
}
static void test_idn_to_ascii_one(td::string host, 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() << "\"";