database_sqlite3_unittest.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <datasrc/tests/database_unittest.h>
  15. #include <datasrc/database.h>
  16. #include <datasrc/sqlite3_accessor.h>
  17. #include <exceptions/exceptions.h>
  18. #include <gtest/gtest.h>
  19. #include <boost/shared_ptr.hpp>
  20. #include <cstdlib>
  21. #include <string>
  22. using std::string;
  23. using namespace isc::datasrc;
  24. using namespace isc::datasrc::test;
  25. namespace {
  26. boost::shared_ptr<DatabaseAccessor>
  27. createSQLite3Accessor() {
  28. // To make sure we always have empty diffs table at the beginning of
  29. // each test, we re-install the writable data source here.
  30. const char* const install_cmd = INSTALL_PROG " -c " TEST_DATA_COMMONDIR
  31. "/rwtest.sqlite3 " TEST_DATA_BUILDDIR "/rwtest.sqlite3.copied";
  32. if (std::system(install_cmd) != 0) {
  33. // any exception will do, this is failure in test setup, but nice
  34. // to show the command that fails, and shouldn't be caught
  35. isc_throw(isc::Unexpected,
  36. "Error setting up; command failed: " << install_cmd);
  37. }
  38. // The SQLite accessor implements all API, so we can use the generic
  39. // loadTestDataGeneric once accessor is created.
  40. boost::shared_ptr<DatabaseAccessor> accessor(
  41. new SQLite3Accessor(TEST_DATA_BUILDDIR "/rwtest.sqlite3.copied",
  42. "IN"));
  43. loadTestDataGeneric(*accessor);
  44. return (accessor);
  45. }
  46. // The test parameter for the SQLite3 accessor. We can use enableNSEC3Generic
  47. // as this accessor fully supports NSEC3 related APIs.
  48. const DatabaseClientTestParam sqlite3_param = { createSQLite3Accessor,
  49. enableNSEC3Generic };
  50. INSTANTIATE_TEST_CASE_P(SQLite3, DatabaseClientTest,
  51. ::testing::Values(&sqlite3_param));
  52. INSTANTIATE_TEST_CASE_P(SQLite3, RRsetCollectionTest,
  53. ::testing::Values(&sqlite3_param));
  54. }