Commit c54a03be authored by JINMEI Tatuya's avatar JINMEI Tatuya

exception guarantee test with a half-broken DB file. it currently fails,

so commented out.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1387 e5f2f494-b856-4b98-b285-d166d9295462
parent 630c1f48
......@@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include <sqlite3.h>
#include <gtest/gtest.h>
#include <dns/name.h>
......@@ -48,6 +49,11 @@ ElementPtr SQLITE_DBFILE_EXAMPLE2 = Element::createFromString(
"{ \"database_file\": \"testdata/test2.sqlite3\"}");
ElementPtr SQLITE_DBFILE_EXAMPLE_ROOT = Element::createFromString(
"{ \"database_file\": \"testdata/test-root.sqlite3\"}");
ElementPtr SQLITE_DBFILE_BROKENDB = Element::createFromString(
"{ \"database_file\": \"testdata/brokendb.sqlite3\"}");
ElementPtr SQLITE_DBFILE_MEMORY = Element::createFromString(
"{ \"database_file\": \":memory:\"}");
// The following file must be non existent and must be non"creatable";
// the sqlite3 library will try to create a new DB file if it doesn't exist,
// so to test a failure case the create operation should also fail.
......@@ -376,6 +382,24 @@ TEST_F(Sqlite3DataSourceTest, doubleClose) {
EXPECT_THROW(data_source.close(), DataSourceError);
}
#if 0 // currently fails
TEST_F(Sqlite3DataSourceTest, openBrokenDB) {
EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
// The database exists but is broken. An exception will be thrown
// in the middle of the initialization.
EXPECT_THROW(data_source.init(SQLITE_DBFILE_BROKENDB), Sqlite3Error);
// Confirming the strong exception guarantee: the data source must be
// in the closed state.
EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_EXAMPLE));
}
#endif
// This test only confirms that on-the-fly schema creation works.
TEST_F(Sqlite3DataSourceTest, memoryDB) {
EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_MEMORY));
}
TEST_F(Sqlite3DataSourceTest, findClosestEnclosure) {
NameMatch name_match(www_name);
data_source.findClosestEnclosure(name_match, rrclass);
......
/*
* Copyright (C) 2010 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.
*/
/* $Id$ */
/*
* This file is provided for reference purpose only. A broken DB file, named
* "brokendb.sqlite3" in this directory was created using this program.
*/
#include <stdio.h>
#include <sqlite3.h>
static const char* create_statement =
"CREATE TABLE schema_version (version INTEGER NOT NULL)";
int
main() {
sqlite3* db = NULL;
if (sqlite3_open("brokendb.sqlite3", &db) != 0) {
sqlite3_close(db);
fprintf(stderr, "failed to open sqlite3 DB");
return (-1);
}
if (sqlite3_exec(db, create_statement, NULL, NULL, NULL) != SQLITE_OK) {
fprintf(stderr, "failed to execute SQL statement: %s\n",
create_statement);
return (-1);
}
sqlite3_close(db);
return (0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment