2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[1791] initial refactoring: extracted createSQLite3Client so it can be shared.

the plan is to use it in in-memory tests for this branch.  No functional change
or add/delete test cases yet.
This commit is contained in:
JINMEI Tatuya
2012-04-04 21:40:25 -07:00
parent 635e3dae01
commit cf16578b3e
3 changed files with 81 additions and 17 deletions

View File

@@ -48,6 +48,7 @@ run_unittests_SOURCES += datasrc_unittest.cc
run_unittests_SOURCES += static_unittest.cc
run_unittests_SOURCES += query_unittest.cc
run_unittests_SOURCES += cache_unittest.cc
run_unittests_SOURCES += test_client.h test_client.cc
run_unittests_SOURCES += test_datasrc.h test_datasrc.cc
run_unittests_SOURCES += rbtree_unittest.cc
run_unittests_SOURCES += logger_unittest.cc

View File

@@ -0,0 +1,71 @@
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __TEST_DATA_SOURCE_CLIENT_H
#define __TEST_DATA_SOURCE_CLIENT_H 1
#include <dns/name.h>
#include <dns/rrclass.h>
#include <boost/shared_ptr.hpp>
#include <istream>
namespace isc {
namespace datasrc {
namespace unittest {
// Here we define utility modules for the convenience of tests that create
// a data source client according to the specified conditions.
/// \brief Create an SQLite3 data source client from a zone file.
///
/// This function creates an SQLite3 client for the specified zone containing
/// RRs in the specified zone file. The zone will be created in the given
/// SQLite3 database file. The database file does not have to exist; this
/// function will automatically create a new file for the test; if the given
/// file already exists this function overrides the content (so basically the
/// file must be an ephemeral one only for that test case).
///
/// The zone file must be formatted so it's accepted by the dns::masterLoad()
/// function.
///
/// \param zclass The RR class of the zone
/// \param zname The origin name of the zone
/// \param db_file The SQLite3 data base file in which the zone data should be
/// installed.
/// \param zone_file The filename of the zone data in the textual format.
/// \return Newly created \c DataSourceClient using the SQLite3 data source
boost::shared_ptr<DataSourceClient>
createSQLite3Client(dns::RRClass zclass, const dns::Name& zname,
const char* const db_file, const char* const zone_file);
/// \brief Create an SQLite3 data source client from a stream.
///
/// This is similar to the other version of the function, but takes an input
/// stream for the zone data. The stream produces strings as the corresponding
/// dns::masterLoad() function expects.
boost::shared_ptr<DataSourceClient>
createSQLite3Client(dns::RRClass zclass, const dns::Name& zname,
const char* const db_file, std::istream& rr_stream);
} // end of unittest
} // end of datasrc
} // end of isc
#endif // __TEST_DATA_SOURCE_CLIENT_H
// Local Variables:
// mode: c++
// End:

View File

@@ -12,6 +12,8 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <exceptions/exceptions.h>
#include <dns/masterload.h>
#include <dns/name.h>
#include <dns/rrclass.h>
@@ -21,6 +23,7 @@
#include <datasrc/database.h>
#include <datasrc/sqlite3_accessor.h>
#include "test_client.h"
#include <testutils/dnsmessage_test.h>
#include <gtest/gtest.h>
@@ -29,6 +32,8 @@
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <vector>
@@ -66,8 +71,6 @@ createInMemoryClient(RRClass zclass, const Name& zname) {
return (client);
}
// Creator for the SQLite3 client to be tested. addRRset() is a helper
// subroutine.
void
addRRset(ZoneUpdaterPtr updater, ConstRRsetPtr rrset) {
updater->addRRset(*rrset);
@@ -78,25 +81,14 @@ createSQLite3Client(RRClass zclass, const Name& zname) {
// We always begin with an empty template SQLite3 DB file and install
// the zone data from the zone file to ensure both cases have the
// same test data.
DataSourceClientPtr client = unittest::createSQLite3Client(
zclass, zname, TEST_DATA_BUILDDIR "/contexttest.sqlite3.copied",
TEST_ZONE_FILE);
const char* const install_cmd = INSTALL_PROG " " TEST_DATA_DIR
"/rwtest.sqlite3 " TEST_DATA_BUILDDIR "/contexttest.sqlite3.copied";
if (system(install_cmd) != 0) {
isc_throw(isc::Unexpected,
"Error setting up; command failed: " << install_cmd);
}
shared_ptr<SQLite3Accessor> accessor(
new SQLite3Accessor(TEST_DATA_BUILDDIR "/contexttest.sqlite3.copied",
zclass.toText()));
shared_ptr<DatabaseClient> client(new DatabaseClient(zclass, accessor));
ZoneUpdaterPtr updater = client->getUpdater(zname, true);
masterLoad(TEST_ZONE_FILE, zname, zclass, boost::bind(addRRset, updater,
_1));
// Insert an out-of-zone name to test if it's incorrectly returned.
// Note that neither updater nor SQLite3 accessor checks this condition,
// so this should succeed.
ZoneUpdaterPtr updater = client->getUpdater(zname, false);
stringstream ss("ns.example.com. 3600 IN A 192.0.2.7");
masterLoad(ss, Name::ROOT_NAME(), zclass,
boost::bind(addRRset, updater, _1));