|
@@ -33,25 +33,25 @@ const uint16_t TEST_PORT(5301);
|
|
|
// FIXME Shouldn't we send something that is real message?
|
|
|
const char TEST_DATA[] = "TEST DATA";
|
|
|
|
|
|
-// Test fixture for the asiolink::UDPQuery.
|
|
|
-class UDPQueryTest : public ::testing::Test,
|
|
|
- public asiolink::UDPQuery::Callback
|
|
|
+// Test fixture for the asiolink::IOFetch.
|
|
|
+class IOFetchTest : public ::testing::Test,
|
|
|
+ public asiolink::IOFetch::Callback
|
|
|
{
|
|
|
public:
|
|
|
// Expected result of the callback
|
|
|
- asiolink::UDPQuery::Result expected_;
|
|
|
+ asiolink::IOFetch::Result expected_;
|
|
|
// Did the callback run already?
|
|
|
bool run_;
|
|
|
// We use an io_service to run the query
|
|
|
io_service service_;
|
|
|
// Something to ask
|
|
|
Question question_;
|
|
|
- // Buffer where the UDPQuery will store response
|
|
|
+ // Buffer where the IOFetch will store response
|
|
|
OutputBufferPtr buffer_;
|
|
|
// The query we are testing
|
|
|
- asiolink::UDPQuery query_;
|
|
|
+ asiolink::IOFetch query_;
|
|
|
|
|
|
- UDPQueryTest() :
|
|
|
+ IOFetchTest() :
|
|
|
run_(false),
|
|
|
question_(Name("example.net"), RRClass::IN(), RRType::A()),
|
|
|
buffer_(new OutputBuffer(512)),
|
|
@@ -60,7 +60,7 @@ class UDPQueryTest : public ::testing::Test,
|
|
|
{ }
|
|
|
|
|
|
// This is the callback's (), so it can be called.
|
|
|
- void operator()(asiolink::UDPQuery::Result result) {
|
|
|
+ void operator()(asiolink::IOFetch::Result result) {
|
|
|
// We check the query returns the correct result
|
|
|
EXPECT_EQ(expected_, result);
|
|
|
// Check it is called only once
|
|
@@ -84,14 +84,14 @@ class UDPQueryTest : public ::testing::Test,
|
|
|
* That is why stop() is posted to the service_ as well instead
|
|
|
* of calling it.
|
|
|
*/
|
|
|
-TEST_F(UDPQueryTest, stop) {
|
|
|
- expected_ = asiolink::UDPQuery::STOPPED;
|
|
|
+TEST_F(IOFetchTest, stop) {
|
|
|
+ expected_ = asiolink::IOFetch::STOPPED;
|
|
|
// Post the query
|
|
|
service_.post(query_);
|
|
|
// Post query_.stop() (yes, the boost::bind thing is just
|
|
|
// query_.stop()).
|
|
|
- service_.post(boost::bind(&asiolink::UDPQuery::stop, query_,
|
|
|
- asiolink::UDPQuery::STOPPED));
|
|
|
+ service_.post(boost::bind(&asiolink::IOFetch::stop, query_,
|
|
|
+ asiolink::IOFetch::STOPPED));
|
|
|
// Run both of them
|
|
|
service_.run();
|
|
|
EXPECT_TRUE(run_);
|
|
@@ -102,8 +102,8 @@ TEST_F(UDPQueryTest, stop) {
|
|
|
* before it gets executed, it acts sanely as well (eg. has the
|
|
|
* same result as running stop() after - calls the callback).
|
|
|
*/
|
|
|
-TEST_F(UDPQueryTest, prematureStop) {
|
|
|
- expected_ = asiolink::UDPQuery::STOPPED;
|
|
|
+TEST_F(IOFetchTest, prematureStop) {
|
|
|
+ expected_ = asiolink::IOFetch::STOPPED;
|
|
|
// Stop before it is started
|
|
|
query_.stop();
|
|
|
service_.post(query_);
|
|
@@ -114,8 +114,8 @@ TEST_F(UDPQueryTest, prematureStop) {
|
|
|
/*
|
|
|
* Test that it will timeout when no answer will arrive.
|
|
|
*/
|
|
|
-TEST_F(UDPQueryTest, timeout) {
|
|
|
- expected_ = asiolink::UDPQuery::TIME_OUT;
|
|
|
+TEST_F(IOFetchTest, timeout) {
|
|
|
+ expected_ = asiolink::IOFetch::TIME_OUT;
|
|
|
service_.post(query_);
|
|
|
service_.run();
|
|
|
EXPECT_TRUE(run_);
|
|
@@ -127,15 +127,15 @@ TEST_F(UDPQueryTest, timeout) {
|
|
|
*
|
|
|
* This is done through a real socket on loopback address.
|
|
|
*/
|
|
|
-TEST_F(UDPQueryTest, receive) {
|
|
|
- expected_ = asiolink::UDPQuery::SUCCESS;
|
|
|
+TEST_F(IOFetchTest, receive) {
|
|
|
+ expected_ = asiolink::IOFetch::SUCCESS;
|
|
|
udp::socket socket(service_, udp::v4());
|
|
|
socket.set_option(socket_base::reuse_address(true));
|
|
|
socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
|
|
|
char inbuff[512];
|
|
|
udp::endpoint remote;
|
|
|
socket.async_receive_from(asio::buffer(inbuff, 512), remote, boost::bind(
|
|
|
- &UDPQueryTest::respond, this, &remote, &socket));
|
|
|
+ &IOFetchTest::respond, this, &remote, &socket));
|
|
|
service_.post(query_);
|
|
|
service_.run();
|
|
|
EXPECT_TRUE(run_);
|