20#include <test/jtx/TestSuite.h>
21#include <xrpld/core/ConfigSections.h>
22#include <xrpld/core/SociDB.h>
23#include <xrpl/basics/BasicConfig.h>
24#include <xrpl/basics/contract.h>
25#include <boost/algorithm/string.hpp>
26#include <boost/filesystem.hpp>
35 boost::filesystem::path
const& dbPath)
37 config.
overwrite(
"sqdb",
"backend",
"sqlite");
38 auto value = dbPath.string();
40 config.
legacy(
"database_path", value);
46 using namespace boost::filesystem;
47 if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
55 using namespace boost::filesystem;
58 create_directory(dbPath);
62 if (!is_directory(dbPath))
65 Throw<std::runtime_error>(
66 "Cannot create directory: " + dbPath.string());
69 static boost::filesystem::path
72 return boost::filesystem::current_path() /
"socidb_test_databases";
104 {{
"peerfinder",
".sqlite"},
107 {
"validators",
".sqlite"}});
109 for (
auto const& i : d)
124 {
"String1",
"String2",
"String3"});
126 auto checkValues = [
this, &stringData, &intData](soci::session& s) {
130 s <<
"SELECT StringData, IntData FROM SociTestTable;",
131 soci::into(stringResult), soci::into(intResult);
133 stringResult.
size() == stringData.size() &&
134 intResult.
size() == intData.size());
135 for (
int i = 0; i < stringResult.
size(); ++i)
140 stringData.begin(), stringData.end(), stringResult[i]));
143 std::find(intData.begin(), intData.end(), intResult[i]));
144 BEAST_EXPECT(si == ii && si < stringResult.
size());
151 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
152 " Key INTEGER PRIMARY KEY,"
157 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
158 "(:stringData, :intData);",
159 soci::use(stringData), soci::use(intData);
169 namespace bfs = boost::filesystem;
172 if (bfs::is_regular_file(dbPath))
195 s <<
"DROP TABLE IF EXISTS STT;";
197 s <<
"CREATE TABLE STT ("
199 " UI INTEGER UNSIGNED,"
201 " UBI BIGINT UNSIGNED"
204 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
205 "(:id, :idu, :bid, :bidu);",
206 soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
214 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
215 soci::into(uig), soci::into(big), soci::into(ubig);
217 ig ==
id[0] && uig == uid[0] && big == bid[0] &&
228 boost::optional<std::int32_t> ig;
232 boost::optional<std::int64_t> big;
233 boost::optional<std::uint64_t> ubig;
234 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
235 soci::into(uig), soci::into(big), soci::into(ubig);
237 *ig ==
id[0] && uig == uid[0] && *big == bid[0] &&
256 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
261 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
275 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
280 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
293 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
294 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
295 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
304 namespace bfs = boost::filesystem;
307 if (bfs::is_regular_file(dbPath))
321 const char* dbInit[] = {
322 "BEGIN TRANSACTION;",
323 "CREATE TABLE Ledgers ( \
324 LedgerHash CHARACTER(64) PRIMARY KEY, \
325 LedgerSeq BIGINT UNSIGNED \
327 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
328 for (
auto const c : dbInit)
334 int const numRows = 16;
338 ledgerIndexes.
reserve(numRows);
339 for (
int i = 0; i < numRows; ++i)
342 if (lh[toIncIndex] ==
'z')
347 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
349 soci::use(ledgerHashes), soci::use(ledgerIndexes);
352 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
353 BEAST_EXPECT(ledgersLS.
size() == numRows);
355 namespace bfs = boost::filesystem;
358 if (bfs::is_regular_file(dbPath))
371BEAST_DEFINE_TESTSUITE(SociDB, core,
ripple);
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
Holds unparsed configuration information.
void overwrite(std::string const §ion, std::string const &key, std::string const &value)
Overwrite a key/value pair with a command line argument If the section does not exist it is created.
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
DBConfig is used when a client wants to delay opening a soci::session after parsing the config parame...
void open(soci::session &s) const
std::string connectionString() const
static void setupDatabaseDir(boost::filesystem::path const &dbPath)
static void setupSQLiteConfig(BasicConfig &config, boost::filesystem::path const &dbPath)
void run() override
Runs the suite.
void testSQLiteFileNames()
static boost::filesystem::path getDatabasePath()
static void cleanupDatabaseDir(boost::filesystem::path const &dbPath)
void testSQLiteDeleteWithSubselect()
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.