From: JINMEI Tatuya Date: Thu, 5 Apr 2012 23:33:46 +0000 (-0700) Subject: [1791] added a new file, which was just forgotten. X-Git-Tag: trac2351_base~226^2~116^2~33^2~7^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dcdd4e10f22f795754f91805b741988ef8a389c2;p=thirdparty%2Fkea.git [1791] added a new file, which was just forgotten. consider this as part of cf16578. --- diff --git a/src/lib/datasrc/tests/test_client.cc b/src/lib/datasrc/tests/test_client.cc new file mode 100644 index 0000000000..7709a3bc59 --- /dev/null +++ b/src/lib/datasrc/tests/test_client.cc @@ -0,0 +1,91 @@ +// 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. + +#include + +#include +#include +#include + +#include +#include +#include + +#include "test_client.h" + +#include +#include + +#include +#include + +using namespace std; +using boost::shared_ptr; + +using namespace isc::dns; + +namespace isc { +namespace datasrc { +namespace unittest { + +namespace { +// A helper subroutine for the SQLite3Client creator. +void +addRRset(ZoneUpdaterPtr updater, ConstRRsetPtr rrset) { + updater->addRRset(*rrset); +} +} + +shared_ptr +createSQLite3Client(RRClass zclass, const Name& zname, + const char* const db_file, const char* const zone_file) +{ + ifstream ifs(zone_file, ios_base::in); + if (ifs.fail()) { + isc_throw(isc::Unexpected, "Failed to open test zone file: " + << zone_file); + } + return (createSQLite3Client(zclass, zname, db_file, ifs)); +} + +shared_ptr +createSQLite3Client(RRClass zclass, const Name& zname, + const char* const db_file, istream& rr_stream) +{ + // 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. + const char* const install_cmd_prefix = INSTALL_PROG " " TEST_DATA_DIR + "/rwtest.sqlite3 "; + const string install_cmd = string(install_cmd_prefix) + db_file; + if (system(install_cmd.c_str()) != 0) { + isc_throw(isc::Unexpected, + "Error setting up; command failed: " << install_cmd); + } + + shared_ptr accessor( + new SQLite3Accessor(db_file, zclass.toText())); + shared_ptr client(new DatabaseClient(zclass, accessor)); + + ZoneUpdaterPtr updater = client->getUpdater(zname, true); + masterLoad(rr_stream, zname, zclass, boost::bind(addRRset, updater, _1)); + + updater->commit(); + + return (client); +} + +} +} +}