Browse Source

fixed boost % bug

cl-refactor
debris 9 years ago
parent
commit
570bfbb327
  1. 5
      libdevcore/Base64.h
  2. 37
      test/libdevcore/Base36.cpp
  3. 8
      test/libethcore/icap.cpp

5
libdevcore/Base64.h

@ -44,7 +44,10 @@ template <size_t N> inline std::string toBase36(FixedHash<N> const& _h)
typename FixedHash<N>::Arith a = _h; typename FixedHash<N>::Arith a = _h;
std::string ret; std::string ret;
for (; a > 0; a /= 36) for (; a > 0; a /= 36)
ret = c_alphabet[(unsigned)a % 36] + ret; {
unsigned r = (unsigned)(a - a / 36 * 36); // boost's % is broken
ret = c_alphabet[r] + ret;
}
return ret; return ret;
} }

37
test/libdevcore/Base36.cpp

@ -0,0 +1,37 @@
//
// Created by Marek Kotewicz on 10/08/15.
//
#include <boost/test/unit_test.hpp>
#include <libdevcore/Base64.h>
#include <libethcore/ICAP.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
BOOST_AUTO_TEST_SUITE(Base36Tests)
BOOST_AUTO_TEST_CASE(basicEncoding)
{
FixedHash<2> value("0x0048");
string encoded = toBase36<2>(value);
BOOST_CHECK_EQUAL(encoded, "20");
}
BOOST_AUTO_TEST_CASE(basicEncoding2)
{
FixedHash<2> value("0x0072");
string encoded = toBase36<2>(value);
BOOST_CHECK_EQUAL(encoded, "36");
}
BOOST_AUTO_TEST_CASE(basicEncoding3)
{
FixedHash<2> value("0xffff");
string encoded = toBase36<2>(value);
BOOST_CHECK_EQUAL(encoded, "1EKF");
}
BOOST_AUTO_TEST_SUITE_END()

8
test/libethcore/icap.cpp

@ -5,6 +5,7 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libethcore/ICAP.h> #include <libethcore/ICAP.h>
using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;
@ -52,4 +53,11 @@ BOOST_AUTO_TEST_CASE(addressDecodingWithZeroPrefix)
BOOST_CHECK_EQUAL(icap.direct(), address); BOOST_CHECK_EQUAL(icap.direct(), address);
} }
BOOST_AUTO_TEST_CASE(addressDecodingAndEncoding)
{
std::string encoded = "XE499OG1EH8ZZI0KXC6N83EKGT1BM97P2O7";
ICAP icap = ICAP::decoded(encoded);
BOOST_CHECK_EQUAL(icap.encoded(), encoded);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
Loading…
Cancel
Save