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        boost::filesystem::path 
const& dbPath)
 
   20        config.
overwrite(
"sqdb", 
"backend", 
"sqlite");
 
   21        auto value = dbPath.string();
 
   23            config.
legacy(
"database_path", value);
 
 
   29        using namespace boost::filesystem;
 
   30        if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
 
 
   38        using namespace boost::filesystem;
 
   41            create_directory(dbPath);
 
   45        if (!is_directory(dbPath))
 
   48            Throw<std::runtime_error>(
 
   49                "Cannot create directory: " + dbPath.string());
 
 
   52    static boost::filesystem::path
 
   55        return boost::filesystem::current_path() / 
"socidb_test_databases";
 
 
   87            {{
"peerfinder", 
".sqlite"},
 
   90             {
"validators", 
".sqlite"}});
 
   92        for (
auto const& i : d)
 
 
  107            {
"String1", 
"String2", 
"String3"});
 
  109        auto checkValues = [
this, &stringData, &intData](soci::session& s) {
 
  113            s << 
"SELECT StringData, IntData FROM SociTestTable;",
 
  114                soci::into(stringResult), soci::into(intResult);
 
  116                stringResult.
size() == stringData.size() &&
 
  117                intResult.
size() == intData.size());
 
  118            for (
int i = 0; i < stringResult.
size(); ++i)
 
  123                        stringData.begin(), stringData.end(), stringResult[i]));
 
  126                    std::find(intData.begin(), intData.end(), intResult[i]));
 
  127                BEAST_EXPECT(si == ii && si < stringResult.
size());
 
  134            s << 
"CREATE TABLE IF NOT EXISTS SociTestTable (" 
  135                 "  Key                    INTEGER PRIMARY KEY," 
  140            s << 
"INSERT INTO SociTestTable (StringData, IntData) VALUES " 
  141                 "(:stringData, :intData);",
 
  142                soci::use(stringData), soci::use(intData);
 
  152            namespace bfs = boost::filesystem;
 
  155            if (bfs::is_regular_file(dbPath))
 
 
  178            s << 
"DROP TABLE IF EXISTS STT;";
 
  180            s << 
"CREATE TABLE STT (" 
  182                 "  UI             INTEGER UNSIGNED," 
  184                 "  UBI            BIGINT UNSIGNED" 
  187            s << 
"INSERT INTO STT (I, UI, BI, UBI) VALUES " 
  188                 "(:id, :idu, :bid, :bidu);",
 
  189                soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
 
  197                s << 
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
 
  198                    soci::into(uig), soci::into(big), soci::into(ubig);
 
  200                    ig == 
id[0] && uig == uid[0] && big == bid[0] &&
 
  211                boost::optional<std::int32_t> ig;
 
  215                boost::optional<std::int64_t> big;
 
  216                boost::optional<std::uint64_t> ubig;
 
  217                s << 
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
 
  218                    soci::into(uig), soci::into(big), soci::into(ubig);
 
  220                    *ig == 
id[0] && uig == uid[0] && *big == bid[0] &&
 
  239                s << 
"SELECT I, UI, BI, UBI from STT", soci::into (r);
 
  244                BEAST_EXPECT(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] &&
 
  276                s << 
"SELECT I, UI, BI, UBI from STT", soci::into (d);
 
  277                BEAST_EXPECT(get<0>(d) == 
id[0] && get<1>(d) == uid[0] &&
 
  278                        get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
 
  287            namespace bfs = boost::filesystem;
 
  290            if (bfs::is_regular_file(dbPath))
 
 
  304            char const* dbInit[] = {
 
  305                "BEGIN TRANSACTION;",
 
  306                "CREATE TABLE Ledgers (                     \ 
  307                LedgerHash      CHARACTER(64) PRIMARY KEY,  \ 
  308                LedgerSeq       BIGINT UNSIGNED             \ 
  310                "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
 
  311            for (
auto const c : dbInit)
 
  317            int const numRows = 16;
 
  321            ledgerIndexes.
reserve(numRows);
 
  322            for (
int i = 0; i < numRows; ++i)
 
  325                if (lh[toIncIndex] == 
'z')
 
  330            s << 
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES " 
  332                soci::use(ledgerHashes), soci::use(ledgerIndexes);
 
  335            s << 
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
 
  336            BEAST_EXPECT(ledgersLS.
size() == numRows);
 
  338        namespace bfs = boost::filesystem;
 
  341        if (bfs::is_regular_file(dbPath))
 
 
 
  354BEAST_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.