diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index beab4783d..748d05d43 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1441,6 +1441,10 @@ + + True + True + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index d6031d540..f954ba6a4 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -1923,6 +1923,9 @@ ripple\basics + + ripple\basics\tests + ripple\basics\tests diff --git a/src/ripple/basics/tests/base_uint.test.cpp b/src/ripple/basics/tests/base_uint.test.cpp new file mode 100644 index 000000000..a55d7672f --- /dev/null +++ b/src/ripple/basics/tests/base_uint.test.cpp @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012-2016 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include +#include + +namespace ripple { +namespace test { + +struct base_uint_test : beast::unit_test::suite +{ + using test96 = base_uint<96>; + + template + void checkHash(bt const& t, std::string const& hash) + { + auto h = sha512Half(t); + expect(to_string(h) == hash); + } + + void run() + { + Blob raw{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + expect(test96::bytes == raw.size()); + + test96 u(raw); + expect(raw.size() == u.size()); + expect(to_string(u) == "0102030405060708090A0B0C"); + expect(*u.data() == 1); + expect(u.signum() == 1); + expect(!!u); + expect(!u.isZero()); + expect(u.isNonZero()); + unsigned char t = 0; + for (auto& d : u) + { + expect(d == ++t); + } + checkHash(u, "25996DBE31A04FF03E4E63C9C647AC6D459475E2845529238F3D08F4A37EBC54"); + + test96 v(~u); + expect(to_string(v) == "FEFDFCFBFAF9F8F7F6F5F4F3"); + expect(*v.data() == 0xfe); + expect(v.signum() == 1); + expect(!!v); + expect(!v.isZero()); + expect(v.isNonZero()); + t = 0xff; + for (auto& d : v) + { + expect(d == --t); + } + checkHash(v, "019A8C0B8307FD822A1346546200328DB40B4565793FD4799B83D780BDB634CE"); + + expect(compare(u, v) < 0); + expect(compare(v, u) > 0); + + v = u; + expect(v == u); + + test96 z(beast::zero); + expect(to_string(z) == "000000000000000000000000"); + expect(*z.data() == 0); + expect(*z.begin() == 0); + expect(*std::prev(z.end(), 1) == 0); + expect(z.signum() == 0); + expect(!z); + expect(z.isZero()); + expect(!z.isNonZero()); + for (auto& d : z) + { + expect(d == 0); + } + checkHash(z, "666A9A1A7542E895A9F447D1C3E0FFD679BBF6346E0C43F5C7A733C46F5E56C2"); + + test96 n(z); + n++; + expect(n == test96(1)); + n--; + expect(n == beast::zero); + expect(n == z); + n--; + expect(to_string(n) == "FFFFFFFFFFFFFFFFFFFFFFFF"); + n = beast::zero; + expect(n == z); + + auto hash = sha512Half(u, v, z, n); + expect(to_string(hash) == + "55CAB39C72F2572057114B4732210605AA22C6E89243FBB5F9943130D813F902"); + } +}; + +BEAST_DEFINE_TESTSUITE(base_uint, ripple_basics, ripple); + +} // namespace test +} // namespace ripple diff --git a/src/ripple/protocol/tests/STObject.test.cpp b/src/ripple/protocol/tests/STObject.test.cpp index 7fd8e4e1d..c29bdb838 100644 --- a/src/ripple/protocol/tests/STObject.test.cpp +++ b/src/ripple/protocol/tests/STObject.test.cpp @@ -108,6 +108,7 @@ public: SField const& sfTestVL = SField::getField (STI_VL, 255); SField const& sfTestH256 = SField::getField (STI_HASH256, 255); SField const& sfTestU32 = SField::getField (STI_UINT32, 255); + SField const& sfTestV256 = SField::getField(STI_VECTOR256, 255); SField const& sfTestObject = SField::getField (STI_OBJECT, 255); SOTemplate elements; @@ -115,6 +116,7 @@ public: elements.push_back (SOElement (sfTestVL, SOE_REQUIRED)); elements.push_back (SOElement (sfTestH256, SOE_OPTIONAL)); elements.push_back (SOElement (sfTestU32, SOE_REQUIRED)); + elements.push_back (SOElement (sfTestV256, SOE_OPTIONAL)); STObject object1 (elements, sfTestObject); STObject object2 (object1); @@ -182,6 +184,27 @@ public: unexpected (object3.getFieldVL (sfTestVL) != j, "STObject error"); } + + { + std::vector uints; + uints.reserve(5); + for (int i = 0; i < uints.capacity(); ++i) + { + uints.emplace_back(i); + } + object1.setFieldV256(sfTestV256, STVector256(uints)); + + Serializer s; + object1.add(s); + SerialIter it(s.slice()); + + STObject object3(elements, it, sfTestObject); + + auto const& uints1 = object1.getFieldV256(sfTestV256); + auto const& uints3 = object3.getFieldV256(sfTestV256); + + expect(uints1 == uints3); + } } // Exercise field accessors @@ -428,11 +451,14 @@ public: STObject st(sfGeneric); std::vector v; v.emplace_back(1); + v.emplace_back(2); st[sf] = v; st[sf] = std::move(v); auto const& cst = st; - expect(cst[sf].size() == 1); - expect(cst[~sf]->size() == 1); + expect(cst[sf].size() == 2); + expect(cst[~sf]->size() == 2); + expect(cst[sf][0] == 1); + expect(cst[sf][1] == 2); static_assert(std::is_same const&>::value, ""); } diff --git a/src/ripple/unity/basics.cpp b/src/ripple/unity/basics.cpp index 8ba351a5a..e9b5384a3 100644 --- a/src/ripple/unity/basics.cpp +++ b/src/ripple/unity/basics.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include