From 527d704d5ca2bea417e39440b08b9cb3fd916a6c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 11 Dec 2015 16:53:49 +1300 Subject: [PATCH] Add testcoverage for reading an embedded database --- xapian-core/tests/api_backend.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/xapian-core/tests/api_backend.cc b/xapian-core/tests/api_backend.cc index 5de239da1..42787ad5b 100644 --- a/xapian-core/tests/api_backend.cc +++ b/xapian-core/tests/api_backend.cc @@ -27,8 +27,10 @@ #define XAPIAN_DEPRECATED(X) X #include +#include "backendmanager.h" #include "filetests.h" #include "str.h" +#include "testrunner.h" #include "testsuite.h" #include "testutils.h" #include "unixcmds.h" @@ -44,6 +46,8 @@ # include "safesyswait.h" #endif +#include + using namespace std; /// Regression test - lockfile should honour umask, was only user-readable. @@ -1366,3 +1370,26 @@ DEFINE_TESTCASE(enquiregetquery1, backend) { TEST_EQUAL(enq.get_query().get_description(), "Query()"); return true; } + +DEFINE_TESTCASE(embedded1, singlefile) { + // In reality you should align the embedded database to a multiple of + // database block size, but any offset is meant to work. + off_t offset = 1234; + + Xapian::Database db = get_database("apitest_simpledata"); + const string & db_path = get_database_path("apitest_simpledata"); + const string & tmp_path = db_path + "-embedded"; + ofstream out(tmp_path, fstream::trunc|fstream::binary); + out.seekp(offset); + out << ifstream(db_path, fstream::binary).rdbuf(); + out.close(); + + { + int fd = open(tmp_path.c_str(), O_RDONLY|O_BINARY); + lseek(fd, offset, SEEK_SET); + Xapian::Database db_embedded(fd); + TEST_EQUAL(db.get_doccount(), db_embedded.get_doccount()); + } + + return true; +} -- 2.11.4.GIT