#include <testutils/dnsmessage_test.h>
#include <testutils/srv_test.h>
#include <testutils/portconfig.h>
+#include <testutils/socket_request.h>
using namespace std;
using namespace isc::cc;
const char* const BADCONFIG_TESTDB =
"{ \"database_file\": \"" TEST_DATA_DIR "/nodir/notexist\"}";
-class AuthSrvTest : public SrvTestBase {
+class AuthSrvTest : public SrvTestBase, public TestSocketRequestor {
protected:
AuthSrvTest() :
+ TestSocketRequestor(dnss_, address_store_, 53210),
dnss_(ios_, NULL, NULL, NULL),
server(true, xfrout),
rrclass(RRClass::IN())
AuthSrv server;
const RRClass rrclass;
vector<uint8_t> response_data;
+ AddressList address_store_;
};
// A helper function that builds a response to version.bind/TXT/CH that
TEST_F(AuthSrvTest, listenAddresses) {
isc::testutils::portconfig::listenAddresses(server);
+ // Check it requests the correct addresses
+ const char* tokens[] = {
+ "TCP:127.0.0.1:53210:1",
+ "UDP:127.0.0.1:53210:2",
+ "TCP:::1:53210:3",
+ "UDP:::1:53210:4",
+ NULL
+ };
+ checkTokens(tokens, given_tokens_, "Given tokens");
+ // It returns back to empty set of addresses afterwards, so
+ // they should be released
+ checkTokens(tokens, released_tokens_, "Released tokens");
}
}
#include <testutils/mockups.h>
#include <testutils/portconfig.h>
+#include <testutils/socket_request.h>
using namespace isc::dns;
using namespace isc::data;
using namespace isc::asiolink;
namespace {
-class AuthConfigTest : public ::testing::Test {
+class AuthConfigTest : public isc::testutils::TestSocketRequestor {
protected:
AuthConfigTest() :
+ TestSocketRequestor(dnss_, address_store_, 53210),
dnss_(ios_, NULL, NULL, NULL),
rrclass(RRClass::IN()),
server(true, xfrout)
const RRClass rrclass;
MockXfroutClient xfrout;
AuthSrv server;
+ isc::server_common::portconfig::AddressList address_store_;
};
TEST_F(AuthConfigTest, datasourceConfig) {
struct InstallListenAddresses : public testutils::TestSocketRequestor {
InstallListenAddresses() :
// The members aren't initialized yet, but we need to store refs only
- TestSocketRequestor(dnss_, store_), dnss_(ios_, NULL, NULL, NULL)
+ TestSocketRequestor(dnss_, store_, 5288), dnss_(ios_, NULL, NULL, NULL)
{
valid_.push_back(AddressPair("127.0.0.1", 5288));
valid_.push_back(AddressPair("::1", 5288));
EXPECT_EQ("127.0.0.1", server.getListenAddresses()[0].first);
EXPECT_EQ(53210, server.getListenAddresses()[0].second);
- // As this is example address, the machine should not have it on
- // any interface
+ // This address is rejected by the test socket requestor
config = Element::fromJSON("{"
"\"listen_on\": ["
" {"
- " \"address\": \"192.0.2.0\","
+ " \"address\": \"192.0.2.2\","
" \"port\": 53210"
" }"
"]"
// TODO Docs
class TestSocketRequestor : public isc::server_common::SocketRequestor,
- public ::testing::Test {
+ virtual public ::testing::Test {
protected:
TestSocketRequestor(asiodns::DNSService& dnss,
- server_common::portconfig::AddressList& store) :
- last_token_(0), break_rollback_(false), dnss_(dnss), store_(store)
+ server_common::portconfig::AddressList& store,
+ uint16_t expect_port) :
+ last_token_(0), break_rollback_(false), dnss_(dnss), store_(store),
+ expect_port_(expect_port)
{}
+ virtual ~ TestSocketRequestor() {}
// Store the tokens as they go in and out
std::vector<std::string> released_tokens_;
std::vector<std::string> given_tokens_;
}
const std::string proto(protocol == TCP ? "TCP" : "UDP");
size_t number = ++ last_token_;
- EXPECT_EQ(5288, port);
+ EXPECT_EQ(expect_port_, port);
EXPECT_EQ(DONT_SHARE, mode);
EXPECT_EQ("dummy_app", name);
const std::string token(proto + ":" + address + ":" +
private:
asiodns::DNSService& dnss_;
server_common::portconfig::AddressList& store_;
+ uint16_t expect_port_;
};
}
extern const unsigned int AD_FLAG;
extern const unsigned int CD_FLAG;
-// The base class for Auth and Recurse test case
-class SrvTestBase : public ::testing::Test {
+/// \brief The base class for Auth and Recurse test case
+///
+/// The Test is inherited virtually because some tests are built of more
+/// test-base-components, all of which need to inherit Test.
+class SrvTestBase : virtual public ::testing::Test {
protected:
SrvTestBase();
virtual ~SrvTestBase();