20#include <test/jtx/TestSuite.h>
22#include <xrpld/core/SociDB.h>
24#include <xrpl/basics/BasicConfig.h>
25#include <xrpl/basics/contract.h>
27#include <boost/algorithm/string.hpp>
28#include <boost/filesystem.hpp>
37 boost::filesystem::path
const& dbPath)
39 config.
overwrite(
"sqdb",
"backend",
"sqlite");
40 auto value = dbPath.string();
42 config.
legacy(
"database_path", value);
48 using namespace boost::filesystem;
49 if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
57 using namespace boost::filesystem;
60 create_directory(dbPath);
64 if (!is_directory(dbPath))
67 Throw<std::runtime_error>(
68 "Cannot create directory: " + dbPath.string());
71 static boost::filesystem::path
74 return boost::filesystem::current_path() /
"socidb_test_databases";
106 {{
"peerfinder",
".sqlite"},
109 {
"validators",
".sqlite"}});
111 for (
auto const& i : d)
126 {
"String1",
"String2",
"String3"});
128 auto checkValues = [
this, &stringData, &intData](soci::session& s) {
132 s <<
"SELECT StringData, IntData FROM SociTestTable;",
133 soci::into(stringResult), soci::into(intResult);
135 stringResult.
size() == stringData.size() &&
136 intResult.
size() == intData.size());
137 for (
int i = 0; i < stringResult.
size(); ++i)
142 stringData.begin(), stringData.end(), stringResult[i]));
145 std::find(intData.begin(), intData.end(), intResult[i]));
146 BEAST_EXPECT(si == ii && si < stringResult.
size());
153 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
154 " Key INTEGER PRIMARY KEY,"
159 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
160 "(:stringData, :intData);",
161 soci::use(stringData), soci::use(intData);
171 namespace bfs = boost::filesystem;
174 if (bfs::is_regular_file(dbPath))
197 s <<
"DROP TABLE IF EXISTS STT;";
199 s <<
"CREATE TABLE STT ("
201 " UI INTEGER UNSIGNED,"
203 " UBI BIGINT UNSIGNED"
206 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
207 "(:id, :idu, :bid, :bidu);",
208 soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
216 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
217 soci::into(uig), soci::into(big), soci::into(ubig);
219 ig ==
id[0] && uig == uid[0] && big == bid[0] &&
230 boost::optional<std::int32_t> ig;
234 boost::optional<std::int64_t> big;
235 boost::optional<std::uint64_t> ubig;
236 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
237 soci::into(uig), soci::into(big), soci::into(ubig);
239 *ig ==
id[0] && uig == uid[0] && *big == bid[0] &&
258 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
263 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
277 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
282 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
295 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
296 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
297 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
306 namespace bfs = boost::filesystem;
309 if (bfs::is_regular_file(dbPath))
323 char const* dbInit[] = {
324 "BEGIN TRANSACTION;",
325 "CREATE TABLE Ledgers ( \
326 LedgerHash CHARACTER(64) PRIMARY KEY, \
327 LedgerSeq BIGINT UNSIGNED \
329 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
330 for (
auto const c : dbInit)
336 int const numRows = 16;
340 ledgerIndexes.
reserve(numRows);
341 for (
int i = 0; i < numRows; ++i)
344 if (lh[toIncIndex] ==
'z')
349 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
351 soci::use(ledgerHashes), soci::use(ledgerIndexes);
354 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
355 BEAST_EXPECT(ledgersLS.
size() == numRows);
357 namespace bfs = boost::filesystem;
360 if (bfs::is_regular_file(dbPath))
373BEAST_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.