tdlight/test/link.cpp

48 lines
1.8 KiB
C++
Raw Normal View History

2021-05-26 00:21:52 +02:00
//
// 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/telegram/LinkManager.h"
#include "td/utils/tests.h"
static void check_link(td::string url, td::string expected) {
auto result = td::LinkManager::check_link(url);
if (result.is_ok()) {
ASSERT_STREQ(expected, result.ok());
} else {
ASSERT_TRUE(expected.empty());
}
}
TEST(Link, check_link) {
check_link("sftp://google.com", "");
check_link("tg://google.com", "tg://google.com/");
check_link("tOn://google", "ton://google/");
check_link("httP://google.com?1#tes", "http://google.com/?1#tes");
check_link("httPs://google.com/?1#tes", "https://google.com/?1#tes");
check_link("tg://google?1#tes", "tg://google?1#tes");
check_link("tg://google/?1#tes", "tg://google?1#tes");
check_link("TG:_", "tg://_/");
check_link("sftp://google.com", "");
check_link("sftp://google.com", "");
check_link("http:google.com", "");
check_link("tg://http://google.com", "");
check_link("tg:http://google.com", "");
check_link("tg:https://google.com", "");
check_link("tg:test@google.com", "");
check_link("tg:google.com:80", "");
check_link("tg:google.com", "tg://google.com/");
check_link("tg:google.com:0", "");
check_link("tg:google.com:a", "");
check_link("tg:[2001:db8:0:0:0:ff00:42:8329]", "");
check_link("tg:127.0.0.1", "tg://127.0.0.1/");
check_link("http://[2001:db8:0:0:0:ff00:42:8329]", "http://[2001:db8:0:0:0:ff00:42:8329]/");
check_link("http://localhost", "");
check_link("http://..", "http://../");
check_link("..", "http://../");
check_link("https://.", "");
}