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>
19 config.
overwrite(
"sqdb",
"backend",
"sqlite");
20 auto value = dbPath.string();
22 config.
legacy(
"database_path", value);
28 using namespace boost::filesystem;
29 if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
37 using namespace boost::filesystem;
40 create_directory(dbPath);
44 if (!is_directory(dbPath))
47 Throw<std::runtime_error>(
"Cannot create directory: " + dbPath.string());
50 static boost::filesystem::path
53 return boost::filesystem::current_path() /
"socidb_test_databases";
85 {{
"peerfinder",
".sqlite"},
88 {
"validators",
".sqlite"}});
90 for (
auto const& i : d)
105 auto checkValues = [
this, &stringData, &intData](soci::session& s) {
109 s <<
"SELECT StringData, IntData FROM SociTestTable;", soci::into(stringResult),
110 soci::into(intResult);
112 stringResult.
size() == stringData.size() && intResult.
size() == intData.size());
113 for (
int i = 0; i < stringResult.
size(); ++i)
117 std::find(stringData.begin(), stringData.end(), stringResult[i]));
119 intData.begin(),
std::find(intData.begin(), intData.end(), intResult[i]));
120 BEAST_EXPECT(si == ii && si < stringResult.
size());
127 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
128 " Key INTEGER PRIMARY KEY,"
133 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
134 "(:stringData, :intData);",
135 soci::use(stringData), soci::use(intData);
145 namespace bfs = boost::filesystem;
148 if (bfs::is_regular_file(dbPath))
170 s <<
"DROP TABLE IF EXISTS STT;";
172 s <<
"CREATE TABLE STT ("
174 " UI INTEGER UNSIGNED,"
176 " UBI BIGINT UNSIGNED"
179 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
180 "(:id, :idu, :bid, :bidu);",
181 soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
189 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig),
190 soci::into(big), soci::into(ubig);
191 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] && ubig == ubid[0]);
201 boost::optional<std::int32_t> ig;
205 boost::optional<std::int64_t> big;
206 boost::optional<std::uint64_t> ubig;
207 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig), soci::into(uig),
208 soci::into(big), soci::into(ubig);
209 BEAST_EXPECT(*ig ==
id[0] && uig == uid[0] && *big == bid[0] && *ubig == ubid[0]);
227 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
232 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
246 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
251 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
264 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
265 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
266 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
275 namespace bfs = boost::filesystem;
278 if (bfs::is_regular_file(dbPath))
294 "BEGIN TRANSACTION;",
295 "CREATE TABLE Ledgers ( \
296 LedgerHash CHARACTER(64) PRIMARY KEY, \
297 LedgerSeq BIGINT UNSIGNED \
299 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
300 for (
auto const c : dbInit)
306 int const numRows = 16;
310 ledgerIndexes.
reserve(numRows);
311 for (
int i = 0; i < numRows; ++i)
314 if (lh[toIncIndex] ==
'z')
319 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
321 soci::use(ledgerHashes), soci::use(ledgerIndexes);
324 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
325 BEAST_EXPECT(ledgersLS.
size() == numRows);
327 namespace bfs = boost::filesystem;
330 if (bfs::is_regular_file(dbPath))
343BEAST_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.