--- /dev/null
+// 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:
// 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>
#include <datasrc/database.h>
#include <datasrc/sqlite3_accessor.h>
+#include "test_client.h"
#include <testutils/dnsmessage_test.h>
#include <gtest/gtest.h>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
+#include <fstream>
+#include <sstream>
#include <cstdlib>
#include <vector>
return (client);
}
-// Creator for the SQLite3 client to be tested. addRRset() is a helper
-// subroutine.
void
addRRset(ZoneUpdaterPtr updater, ConstRRsetPtr rrset) {
updater->addRRset(*rrset);
// 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));