1#include <test/jtx/TestSuite.h>
3#include <xrpl/basics/BasicConfig.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/rdb/SociDB.h>
7#include <boost/algorithm/string.hpp>
8#include <boost/filesystem.hpp>
17 config.
overwrite(
"sqdb",
"backend",
"sqlite");
18 auto value = dbPath.string();
20 config.
legacy(
"database_path", value);
26 using namespace boost::filesystem;
27 if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
35 using namespace boost::filesystem;
38 create_directory(dbPath);
42 if (!is_directory(dbPath))
45 Throw<std::runtime_error>(
"Cannot create directory: " + dbPath.string());
48 static boost::filesystem::path
51 return boost::filesystem::current_path() /
"socidb_test_databases";
83 {{
"peerfinder",
".sqlite"}, {
"state",
".db"}, {
"random",
".db"}, {
"validators",
".sqlite"}});
85 for (
auto const& i : d)
100 auto checkValues = [
this, &stringData, &intData](soci::session& s) {
104 s <<
"SELECT StringData, IntData FROM SociTestTable;", soci::into(stringResult), soci::into(intResult);
105 BEAST_EXPECT(stringResult.
size() == stringData.size() && intResult.
size() == intData.size());
106 for (
int i = 0; i < stringResult.
size(); ++i)
111 BEAST_EXPECT(si == ii && si < stringResult.
size());
118 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
119 " Key INTEGER PRIMARY KEY,"
124 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
125 "(:stringData, :intData);",
126 soci::use(stringData), soci::use(intData);
136 namespace bfs = boost::filesystem;
139 if (bfs::is_regular_file(dbPath))
160 s <<
"DROP TABLE IF EXISTS STT;";
162 s <<
"CREATE TABLE STT ("
164 " UI INTEGER UNSIGNED,"
166 " UBI BIGINT UNSIGNED"
169 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
170 "(:id, :idu, :bid, :bidu);",
171 soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
179 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig), soci::into(big),
181 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] && ubig == ubid[0]);
191 boost::optional<std::int32_t> ig;
195 boost::optional<std::int64_t> big;
196 boost::optional<std::uint64_t> ubig;
197 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig), soci::into(big),
199 BEAST_EXPECT(*ig ==
id[0] && uig == uid[0] && *big == bid[0] && *ubig == ubid[0]);
217 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
222 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
236 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
241 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
254 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
255 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
256 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
265 namespace bfs = boost::filesystem;
268 if (bfs::is_regular_file(dbPath))
282 char const* dbInit[] = {
283 "BEGIN TRANSACTION;",
284 "CREATE TABLE Ledgers ( \
285 LedgerHash CHARACTER(64) PRIMARY KEY, \
286 LedgerSeq BIGINT UNSIGNED \
288 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
289 for (
auto const c : dbInit)
295 int const numRows = 16;
299 ledgerIndexes.
reserve(numRows);
300 for (
int i = 0; i < numRows; ++i)
303 if (lh[toIncIndex] ==
'z')
308 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
310 soci::use(ledgerHashes), soci::use(ledgerIndexes);
313 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
314 BEAST_EXPECT(ledgersLS.
size() == numRows);
316 namespace bfs = boost::filesystem;
319 if (bfs::is_regular_file(dbPath))
332BEAST_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.