31 lines
876 B
C++
31 lines
876 B
C++
|
#include <gtest/gtest.h>
|
||
|
#include <ulib/log/log.h>
|
||
|
#include <asio.hpp>
|
||
|
|
||
|
static const char kTag[] = "asio";
|
||
|
|
||
|
TEST(asio, base)
|
||
|
{
|
||
|
asio::io_context io_context;
|
||
|
asio::post(io_context, []() {});
|
||
|
asio::ip::tcp::resolver::query query("www.baidu.com", "http");
|
||
|
asio::ip::tcp::socket::reuse_address reuse_address(true);
|
||
|
asio::ip::tcp::resolver resolver(io_context);
|
||
|
int count = 0;
|
||
|
resolver.async_resolve(
|
||
|
query,
|
||
|
[&](const asio::error_code &ec,
|
||
|
asio::ip::tcp::resolver::iterator iter) {
|
||
|
ASSERT_FALSE(ec);
|
||
|
|
||
|
if (iter == asio::ip::tcp::resolver::iterator()) { return; }
|
||
|
++count;
|
||
|
|
||
|
ULOG_ERROR(kTag, "iter-> {}:{}",
|
||
|
iter->endpoint().address().to_string(),
|
||
|
iter->endpoint().port());
|
||
|
});
|
||
|
io_context.run();
|
||
|
EXPECT_GE(count, 1);
|
||
|
}
|