5
5
#include < dbwrapper.h>
6
6
#include < test/util/setup_common.h>
7
7
#include < uint256.h>
8
+ #include < util/string.h>
8
9
9
10
#include < memory>
10
11
@@ -324,12 +325,6 @@ struct StringContentsSerializer {
324
325
StringContentsSerializer () = default ;
325
326
explicit StringContentsSerializer (const std::string& inp) : str(inp) {}
326
327
327
- StringContentsSerializer& operator +=(const std::string& s) {
328
- str += s;
329
- return *this ;
330
- }
331
- StringContentsSerializer& operator +=(const StringContentsSerializer& s) { return *this += s.str ; }
332
-
333
328
template <typename Stream>
334
329
void Serialize (Stream& s) const
335
330
{
@@ -343,44 +338,34 @@ struct StringContentsSerializer {
343
338
{
344
339
str.clear ();
345
340
uint8_t c{0 };
346
- while (true ) {
347
- try {
348
- s >> c;
349
- str.push_back (c);
350
- } catch (const std::ios_base::failure&) {
351
- break ;
352
- }
341
+ while (!s.eof ()) {
342
+ s >> c;
343
+ str.push_back (c);
353
344
}
354
345
}
355
346
};
356
347
357
348
BOOST_AUTO_TEST_CASE (iterator_string_ordering)
358
349
{
359
- char buf[10 ];
360
-
361
350
fs::path ph = m_args.GetDataDirBase () / " iterator_string_ordering" ;
362
351
CDBWrapper dbw (ph, (1 << 20 ), true , false , false );
363
- for (int x=0x00 ; x<10 ; ++x) {
364
- for (int y = 0 ; y < 10 ; y++) {
365
- snprintf (buf, sizeof (buf), " %d" , x);
366
- StringContentsSerializer key (buf);
367
- for (int z = 0 ; z < y; z++)
352
+ for (int x = 0 ; x < 10 ; ++x) {
353
+ for (int y = 0 ; y < 10 ; ++y) {
354
+ std::string key{ToString (x)};
355
+ for (int z = 0 ; z < y; ++z)
368
356
key += key;
369
357
uint32_t value = x*x;
370
- BOOST_CHECK (dbw.Write (key, value));
358
+ BOOST_CHECK (dbw.Write (StringContentsSerializer{ key} , value));
371
359
}
372
360
}
373
361
374
362
std::unique_ptr<CDBIterator> it (const_cast <CDBWrapper&>(dbw).NewIterator ());
375
363
for (const int seek_start : {0 , 5 }) {
376
- snprintf (buf, sizeof (buf), " %d" , seek_start);
377
- StringContentsSerializer seek_key (buf);
378
- it->Seek (seek_key);
379
- for (unsigned int x=seek_start; x<10 ; ++x) {
380
- for (int y = 0 ; y < 10 ; y++) {
381
- snprintf (buf, sizeof (buf), " %d" , x);
382
- std::string exp_key (buf);
383
- for (int z = 0 ; z < y; z++)
364
+ it->Seek (StringContentsSerializer{ToString (seek_start)});
365
+ for (unsigned int x = seek_start; x < 10 ; ++x) {
366
+ for (int y = 0 ; y < 10 ; ++y) {
367
+ std::string exp_key{ToString (x)};
368
+ for (int z = 0 ; z < y; ++z)
384
369
exp_key += exp_key;
385
370
StringContentsSerializer key;
386
371
uint32_t value;
0 commit comments