11 #include <boost/test/unit_test.hpp>
17 for (
unsigned int i = 0; i < key.size(); i++)
18 isnull &= (key[i] ==
'\x00');
28 fs::path ph = SetDataDir(std::string(
"dbwrapper"));
42 fs::path ph = SetDataDir(std::string(
"dbwrapper_basic_data"));
50 std::string key_block =
"b" + InsecureRand256().
ToString();
52 uint256 in_block = InsecureRand256();
58 std::string key_file =
strprintf(
"f%04x", InsecureRand32());
60 uint256 in_file_info = InsecureRand256();
66 std::string key_transaction =
"t" + InsecureRand256().ToString();
68 uint256 in_transaction = InsecureRand256();
74 std::string key_utxo =
"c" + InsecureRand256().ToString();
76 uint256 in_utxo = InsecureRand256();
82 char key_last_blockfile_number =
'l';
83 uint32_t lastblockfilenumber = InsecureRand32();
89 char key_IsReindexing =
'R';
90 bool isInReindexing = InsecureRandBool();
96 char key_lastblockhash_uxto =
'B';
97 uint256 lastblock_hash = InsecureRand256();
103 std::string file_option_tag =
"F";
104 uint8_t filename_length = InsecureRandBits(8);
105 std::string filename =
"randomfilename";
106 std::string key_file_option =
strprintf(
"%s%01x%s", file_option_tag,filename_length,filename);
108 bool in_file_bool = InsecureRandBool();
118 fs::path ph = SetDataDir(std::string(
"dbwrapper_batch"));
131 batch.
Write(key, in);
132 batch.
Write(key2, in2);
133 batch.
Write(key3, in3);
153 fs::path ph = SetDataDir(std::string(
"dbwrapper_iterator"));
164 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
173 it->GetValue(val_res);
180 it->GetValue(val_res);
191 fs::path ph = SetDataDir(std::string(
"iterator_ordering"));
193 for (
int x=0x00; x<256; ++x) {
195 uint32_t value = x*x;
200 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
202 for (
int x=0x00; x<256; ++x) {
204 uint32_t value = x*x;
208 for (
int seek_start : {0x00, 0x80}) {
209 it->Seek((uint8_t)seek_start);
210 for (
int x=seek_start; x<255; ++x) {
243 template<
typename Stream>
246 for (
size_t i = 0; i <
str.size(); i++) {
251 template<
typename Stream>
260 }
catch (
const std::ios_base::failure&) {
271 fs::path ph = SetDataDir(std::string(
"iterator_string_ordering"));
273 for (
int x=0x00; x<10; ++x) {
274 for (
int y = 0; y < 10; y++) {
275 snprintf(buf,
sizeof(buf),
"%d", x);
277 for (
int z = 0; z < y; z++)
279 uint32_t value = x*x;
284 boost::scoped_ptr<CDBIterator> it(
const_cast<CDBWrapper*
>(&dbw)->NewIterator());
285 for (
int c=0; c<2; ++c) {
291 snprintf(buf,
sizeof(buf),
"%d", seek_start);
294 for (
int x=seek_start; x<10; ++x) {
295 for (
int y = 0; y < 10; y++) {
296 snprintf(buf,
sizeof(buf),
"%d", x);
297 std::string exp_key(buf);
298 for (
int z = 0; z < y; z++)
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
bool Read(const K &key, V &value) const
bool Write(const K &key, const V &value, bool fSync=false)
std::string ToString() const
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(dbwrapper)
bool is_null_key(const std::vector< unsigned char > &key)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
uint256 GetRandHash() noexcept
void Unserialize(Stream &s)
StringContentsSerializer & operator+=(const std::string &s)
StringContentsSerializer & operator+=(const StringContentsSerializer &s)
void Serialize(Stream &s) const
StringContentsSerializer(const std::string &inp)
StringContentsSerializer()