1#include <test/jtx/TestSuite.h>
3#include <xrpld/core/SociDB.h>
5#include <xrpl/basics/BasicConfig.h>
6#include <xrpl/basics/contract.h>
8#include <boost/algorithm/string.hpp>
9#include <boost/filesystem.hpp>
18 config.
overwrite(
"sqdb",
"backend",
"sqlite");
19 auto value = dbPath.string();
21 config.
legacy(
"database_path", value);
27 using namespace boost::filesystem;
28 if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
36 using namespace boost::filesystem;
39 create_directory(dbPath);
43 if (!is_directory(dbPath))
46 Throw<std::runtime_error>(
"Cannot create directory: " + dbPath.string());
49 static boost::filesystem::path
52 return boost::filesystem::current_path() /
"socidb_test_databases";
84 {{
"peerfinder",
".sqlite"}, {
"state",
".db"}, {
"random",
".db"}, {
"validators",
".sqlite"}});
86 for (
auto const& i : d)
101 auto checkValues = [
this, &stringData, &intData](soci::session& s) {
105 s <<
"SELECT StringData, IntData FROM SociTestTable;", soci::into(stringResult), soci::into(intResult);
106 BEAST_EXPECT(stringResult.
size() == stringData.size() && intResult.
size() == intData.size());
107 for (
int i = 0; i < stringResult.
size(); ++i)
112 BEAST_EXPECT(si == ii && si < stringResult.
size());
119 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
120 " Key INTEGER PRIMARY KEY,"
125 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
126 "(:stringData, :intData);",
127 soci::use(stringData), soci::use(intData);
137 namespace bfs = boost::filesystem;
140 if (bfs::is_regular_file(dbPath))
161 s <<
"DROP TABLE IF EXISTS STT;";
163 s <<
"CREATE TABLE STT ("
165 " UI INTEGER UNSIGNED,"
167 " UBI BIGINT UNSIGNED"
170 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
171 "(:id, :idu, :bid, :bidu);",
172 soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
180 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig), soci::into(big),
182 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] && ubig == ubid[0]);
192 boost::optional<std::int32_t> ig;
196 boost::optional<std::int64_t> big;
197 boost::optional<std::uint64_t> ubig;
198 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig), soci::into(big),
200 BEAST_EXPECT(*ig ==
id[0] && uig == uid[0] && *big == bid[0] && *ubig == ubid[0]);
218 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
223 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
237 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
242 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
255 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
256 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
257 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
266 namespace bfs = boost::filesystem;
269 if (bfs::is_regular_file(dbPath))
283 char const* dbInit[] = {
284 "BEGIN TRANSACTION;",
285 "CREATE TABLE Ledgers ( \
286 LedgerHash CHARACTER(64) PRIMARY KEY, \
287 LedgerSeq BIGINT UNSIGNED \
289 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
290 for (
auto const c : dbInit)
296 int const numRows = 16;
300 ledgerIndexes.
reserve(numRows);
301 for (
int i = 0; i < numRows; ++i)
304 if (lh[toIncIndex] ==
'z')
309 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
311 soci::use(ledgerHashes), soci::use(ledgerIndexes);
314 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
315 BEAST_EXPECT(ledgersLS.
size() == numRows);
317 namespace bfs = boost::filesystem;
320 if (bfs::is_regular_file(dbPath))
333BEAST_DEFINE_TESTSUITE(SociDB, core,
xrpl);
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)
void testSQLiteFileNames()
static boost::filesystem::path getDatabasePath()
static void setupSQLiteConfig(BasicConfig &config, boost::filesystem::path const &dbPath)
void testSQLiteDeleteWithSubselect()
void run() override
Runs the suite.
static void cleanupDatabaseDir(boost::filesystem::path const &dbPath)
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.