Put modules in ripple namespace

This commit is contained in:
Vinnie Falco
2013-06-27 13:41:20 -07:00
parent 8588587b71
commit 638656a597
35 changed files with 198 additions and 234 deletions

View File

@@ -7,6 +7,8 @@ BOOST_AUTO_TEST_SUITE (DeterministicKeys_test)
BOOST_AUTO_TEST_CASE (DeterminsticKeys_test1)
{
using namespace ripple;
Log (lsDEBUG) << "Beginning deterministic key test";
uint128 seed1, seed2;

View File

@@ -7,6 +7,8 @@ BOOST_AUTO_TEST_SUITE (ripple_address)
BOOST_AUTO_TEST_CASE ( check_crypto )
{
using namespace ripple;
// Construct a seed.
RippleAddress naSeed;

View File

@@ -5,6 +5,9 @@
//==============================================================================
// For unit tests:
namespace ripple
{
static STAmount serdes (const STAmount& s)
{
Serializer ser;
@@ -16,12 +19,75 @@ static STAmount serdes (const STAmount& s)
return STAmount::deserialize (sit);
}
static bool roundTest (int n, int d, int m)
{
// check STAmount rounding
STAmount num (CURRENCY_ONE, ACCOUNT_ONE, n);
STAmount den (CURRENCY_ONE, ACCOUNT_ONE, d);
STAmount mul (CURRENCY_ONE, ACCOUNT_ONE, m);
STAmount quot = STAmount::divide (n, d, CURRENCY_ONE, ACCOUNT_ONE);
STAmount res = STAmount::multiply (quot, mul, CURRENCY_ONE, ACCOUNT_ONE);
if (res.isNative ())
BOOST_FAIL ("Product is native");
res.roundSelf ();
STAmount cmp (CURRENCY_ONE, ACCOUNT_ONE, (n * m) / d);
if (cmp.isNative ())
BOOST_FAIL ("Comparison amount is native");
if (res == cmp)
return true;
cmp.throwComparable (res);
WriteLog (lsWARNING, STAmount) << "(" << num.getText () << "/" << den.getText () << ") X " << mul.getText () << " = "
<< res.getText () << " not " << cmp.getText ();
BOOST_FAIL ("Round fail");
return false;
}
static void mulTest (int a, int b)
{
STAmount aa (CURRENCY_ONE, ACCOUNT_ONE, a);
STAmount bb (CURRENCY_ONE, ACCOUNT_ONE, b);
STAmount prod1 (STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE));
if (prod1.isNative ())
BOOST_FAIL ("product is native");
STAmount prod2 (CURRENCY_ONE, ACCOUNT_ONE, static_cast<uint64> (a) * static_cast<uint64> (b));
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "nn(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
aa = a;
prod1 = STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE);
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "n(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
}
}
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_SUITE (amount)
BOOST_AUTO_TEST_CASE ( setValue_test )
{
using namespace ripple;
STAmount saTmp;
#if 0
@@ -45,6 +111,8 @@ BOOST_AUTO_TEST_CASE ( setValue_test )
BOOST_AUTO_TEST_CASE ( NativeCurrency_test )
{
using namespace ripple;
STAmount zero, one (1), hundred (100);
if (serdes (zero) != zero) BOOST_FAIL ("STAmount fail");
@@ -184,6 +252,8 @@ BOOST_AUTO_TEST_CASE ( NativeCurrency_test )
BOOST_AUTO_TEST_CASE ( CustomCurrency_test )
{
using namespace ripple;
STAmount zero (CURRENCY_ONE, ACCOUNT_ONE), one (CURRENCY_ONE, ACCOUNT_ONE, 1), hundred (CURRENCY_ONE, ACCOUNT_ONE, 100);
serdes (one).getRaw ();
@@ -364,67 +434,10 @@ BOOST_AUTO_TEST_CASE ( CustomCurrency_test )
//------------------------------------------------------------------------------
static bool roundTest (int n, int d, int m)
{
// check STAmount rounding
STAmount num (CURRENCY_ONE, ACCOUNT_ONE, n);
STAmount den (CURRENCY_ONE, ACCOUNT_ONE, d);
STAmount mul (CURRENCY_ONE, ACCOUNT_ONE, m);
STAmount quot = STAmount::divide (n, d, CURRENCY_ONE, ACCOUNT_ONE);
STAmount res = STAmount::multiply (quot, mul, CURRENCY_ONE, ACCOUNT_ONE);
if (res.isNative ())
BOOST_FAIL ("Product is native");
res.roundSelf ();
STAmount cmp (CURRENCY_ONE, ACCOUNT_ONE, (n * m) / d);
if (cmp.isNative ())
BOOST_FAIL ("Comparison amount is native");
if (res == cmp)
return true;
cmp.throwComparable (res);
WriteLog (lsWARNING, STAmount) << "(" << num.getText () << "/" << den.getText () << ") X " << mul.getText () << " = "
<< res.getText () << " not " << cmp.getText ();
BOOST_FAIL ("Round fail");
return false;
}
static void mulTest (int a, int b)
{
STAmount aa (CURRENCY_ONE, ACCOUNT_ONE, a);
STAmount bb (CURRENCY_ONE, ACCOUNT_ONE, b);
STAmount prod1 (STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE));
if (prod1.isNative ())
BOOST_FAIL ("product is native");
STAmount prod2 (CURRENCY_ONE, ACCOUNT_ONE, static_cast<uint64> (a) * static_cast<uint64> (b));
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "nn(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
aa = a;
prod1 = STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE);
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "n(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
}
BOOST_AUTO_TEST_CASE ( CurrencyMulDivTests )
{
using namespace ripple;
CBigNum b;
for (int i = 0; i < 16; ++i)
@@ -483,6 +496,8 @@ BOOST_AUTO_TEST_CASE ( CurrencyMulDivTests )
BOOST_AUTO_TEST_CASE ( UnderFlowTests )
{
using namespace ripple;
STAmount bigNative (STAmount::cMaxNative / 2);
STAmount bigValue (CURRENCY_ONE, ACCOUNT_ONE,
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMaxOffset - 1);
@@ -536,6 +551,8 @@ BOOST_AUTO_TEST_SUITE (amountRound)
BOOST_AUTO_TEST_CASE ( amountRound_test )
{
using namespace ripple;
uint64 value = 25000000000000000ull;
int offset = -14;
STAmount::canonicalizeRound (false, value, offset, true);

View File

@@ -8,6 +8,8 @@ BOOST_AUTO_TEST_SUITE (SerializedObject)
BOOST_AUTO_TEST_CASE ( FieldManipulation_test )
{
using namespace ripple;
if (sfGeneric.isUseful ())
BOOST_FAIL ("sfGeneric must not be useful");

View File

@@ -8,6 +8,8 @@ BOOST_AUTO_TEST_SUITE (Serializer_suite)
BOOST_AUTO_TEST_CASE ( Serializer_PrefixHash_test )
{
using namespace ripple;
Serializer s1;
s1.add32 (3);
s1.add256 (uint256 ());

View File

@@ -54,10 +54,8 @@
#undef min
#endif
#if RIPPLE_USE_NAMESPACE
namespace ripple
{
#endif
#include "crypto/ripple_Base58.h" // for RippleAddress
#include "crypto/ripple_CKey.h" // needs RippleAddress VFALCO TODO remove this dependency cycle
@@ -93,9 +91,7 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
#include "utility/ripple_JSONCache.cpp"
#if RIPPLE_USE_NAMESPACE
}
#endif
// These must be outside the namespace because of boost
#include "crypto/ripple_CKeyDeterministicUnitTests.cpp"

View File

@@ -52,10 +52,8 @@
// additional hierarchy via directories.
#include "ripple.pb.h"
#if RIPPLE_USE_NAMESPACE
namespace ripple
{
#endif
#include "crypto/ripple_CBigNum.h"
#include "crypto/ripple_Base58.h" // VFALCO TODO Can be moved to .cpp if we clean up setAlphabet stuff
@@ -80,11 +78,8 @@ namespace ripple
#include "utility/ripple_JSONCache.h"
#include "utility/ripple_UptimeTimerAdapter.h"
#if RIPPLE_USE_NAMESPACE
}
#endif
#if RIPPLE_USE_NAMESPACE
namespace boost
{
template <>
@@ -135,57 +130,5 @@ namespace boost
typedef ripple::STArray::const_iterator type;
};
}
#else
namespace boost
{
template <>
struct range_mutable_iterator <STPath>
{
typedef std::vector <STPathElement>::iterator type;
};
template <>
struct range_const_iterator <STPath>
{
typedef std::vector <STPathElement>::const_iterator type;
};
template <>
struct range_mutable_iterator <STPathSet>
{
typedef std::vector <STPath>::iterator type;
};
template <>
struct range_const_iterator <STPathSet>
{
typedef std::vector <STPath>::const_iterator type;
};
template <>
struct range_mutable_iterator <STObject>
{
typedef STObject::iterator type;
};
template <>
struct range_const_iterator <STObject>
{
typedef STObject::const_iterator type;
};
template <>
struct range_mutable_iterator <STArray>
{
typedef STArray::iterator type;
};
template <>
struct range_const_iterator <STArray>
{
typedef STArray::const_iterator type;
};
}
#endif
#endif