55#include < dbwrapper.h>
66#include < test/util/setup_common.h>
77#include < uint256.h>
8+ #include < util/string.h>
89
910#include < memory>
1011
@@ -324,12 +325,6 @@ struct StringContentsSerializer {
324325 StringContentsSerializer () = default ;
325326 explicit StringContentsSerializer (const std::string& inp) : str(inp) {}
326327
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-
333328 template <typename Stream>
334329 void Serialize (Stream& s) const
335330 {
@@ -343,44 +338,34 @@ struct StringContentsSerializer {
343338 {
344339 str.clear ();
345340 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);
353344 }
354345 }
355346};
356347
357348BOOST_AUTO_TEST_CASE (iterator_string_ordering)
358349{
359- char buf[10 ];
360-
361350 fs::path ph = m_args.GetDataDirBase () / " iterator_string_ordering" ;
362351 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)
368356 key += key;
369357 uint32_t value = x*x;
370- BOOST_CHECK (dbw.Write (key, value));
358+ BOOST_CHECK (dbw.Write (StringContentsSerializer{ key} , value));
371359 }
372360 }
373361
374362 std::unique_ptr<CDBIterator> it (const_cast <CDBWrapper&>(dbw).NewIterator ());
375363 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)
384369 exp_key += exp_key;
385370 StringContentsSerializer key;
386371 uint32_t value;
0 commit comments