mirror of
https://github.com/monero-project/monero.git
synced 2025-04-26 12:29:09 -04:00
Convert expect<T> to boost::system::error_code
This commit is contained in:
parent
2d3ce2d64a
commit
486c3db0a2
@ -30,8 +30,12 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct category final : std::error_category
|
struct category final : monero::error_category
|
||||||
{
|
{
|
||||||
|
category() noexcept
|
||||||
|
: monero::error_category()
|
||||||
|
{}
|
||||||
|
|
||||||
virtual const char* name() const noexcept override final
|
virtual const char* name() const noexcept override final
|
||||||
{
|
{
|
||||||
return "common_category()";
|
return "common_category()";
|
||||||
@ -39,11 +43,13 @@ namespace
|
|||||||
|
|
||||||
virtual std::string message(int value) const override final
|
virtual std::string message(int value) const override final
|
||||||
{
|
{
|
||||||
switch (common_error(value))
|
switch (monero::error(value))
|
||||||
{
|
{
|
||||||
case common_error::kInvalidArgument:
|
case monero::error::none:
|
||||||
return make_error_code(std::errc::invalid_argument).message();
|
return "No error (success)";
|
||||||
case common_error::kInvalidErrorCode:
|
case monero::error::invalid_argument:
|
||||||
|
return make_error_code(monero::errc::invalid_argument).message();
|
||||||
|
case monero::error::invalid_error_code:
|
||||||
return "expect<T> was given an error value of zero";
|
return "expect<T> was given an error value of zero";
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -51,25 +57,38 @@ namespace
|
|||||||
return "Unknown basic_category() value";
|
return "Unknown basic_category() value";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::error_condition default_error_condition(int value) const noexcept override final
|
virtual monero::error_condition default_error_condition(int value) const noexcept override final
|
||||||
{
|
{
|
||||||
// maps specific errors to generic `std::errc` cases.
|
// maps specific errors to generic `std::errc` cases.
|
||||||
switch (common_error(value))
|
switch (monero::error(value))
|
||||||
{
|
{
|
||||||
case common_error::kInvalidArgument:
|
case monero::error::none:
|
||||||
case common_error::kInvalidErrorCode:
|
return monero::errc::success;
|
||||||
return std::errc::invalid_argument;
|
case monero::error::invalid_argument:
|
||||||
|
case monero::error::invalid_error_code:
|
||||||
|
return monero::errc::invalid_argument;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return std::error_condition{value, *this};
|
return monero::error_condition{value, *this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
|
||||||
|
category const& category_instance() noexcept
|
||||||
|
{
|
||||||
|
static const category instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_category const& common_category() noexcept
|
namespace monero
|
||||||
{
|
{
|
||||||
static const category instance{};
|
error_category const& default_category() noexcept
|
||||||
return instance;
|
{
|
||||||
|
return category_instance();
|
||||||
|
}
|
||||||
|
error_code make_error_code(monero::error value) noexcept
|
||||||
|
{
|
||||||
|
return {int(value), category_instance()};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,27 +26,37 @@
|
|||||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <system_error>
|
#include <boost/system/error_code.hpp>
|
||||||
|
#include <boost/system/system_error.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
enum class common_error : int
|
#define MONERO_DECLARE_ERROR_ENUM(name) \
|
||||||
{
|
namespace boost { \
|
||||||
// 0 is reserved for no error, as per expect<T>
|
namespace system { \
|
||||||
kInvalidArgument = 1, //!< A function argument is invalid
|
template<> \
|
||||||
kInvalidErrorCode //!< Default `std::error_code` given to `expect<T>`
|
struct is_error_code_enum< name > \
|
||||||
};
|
: std::true_type \
|
||||||
|
{}; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
std::error_category const& common_category() noexcept;
|
namespace monero
|
||||||
|
|
||||||
inline std::error_code make_error_code(::common_error value) noexcept
|
|
||||||
{
|
{
|
||||||
return std::error_code{int(value), common_category()};
|
namespace errc = boost::system::errc;
|
||||||
|
using error_category = boost::system::error_category;
|
||||||
|
using error_code = boost::system::error_code;
|
||||||
|
using error_condition = boost::system::error_condition;
|
||||||
|
using system_error = boost::system::system_error;
|
||||||
|
|
||||||
|
enum class error : int
|
||||||
|
{
|
||||||
|
none = 0,
|
||||||
|
invalid_argument, //!< A function argument is invalid
|
||||||
|
invalid_error_code //!< Default `monero::error_code` given to `expect<T>`
|
||||||
|
};
|
||||||
|
|
||||||
|
error_category const& default_category() noexcept;
|
||||||
|
error_code make_error_code(monero::error value) noexcept;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std
|
MONERO_DECLARE_ERROR_ENUM(monero::error)
|
||||||
{
|
|
||||||
template<>
|
|
||||||
struct is_error_code_enum<::common_error>
|
|
||||||
: true_type
|
|
||||||
{};
|
|
||||||
}
|
|
||||||
|
@ -61,10 +61,10 @@ namespace detail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void expect::throw_(std::error_code ec, const char* msg, const char* file, unsigned line)
|
void expect::throw_(monero::error_code ec, const char* msg, const char* file, unsigned line)
|
||||||
{
|
{
|
||||||
if (msg || file)
|
if (msg || file)
|
||||||
throw std::system_error{ec, generate_error(msg, file, line)};
|
throw monero::system_error{ec, generate_error(msg, file, line)};
|
||||||
throw std::system_error{ec};
|
throw monero::system_error{ec};
|
||||||
}
|
}
|
||||||
} // detail
|
} // detail
|
||||||
|
@ -35,12 +35,12 @@
|
|||||||
|
|
||||||
#include "common/error.h"
|
#include "common/error.h"
|
||||||
|
|
||||||
//! If precondition fails, return `::error::kInvalidArgument` in current scope.
|
//! If precondition fails, return `monero::error::invalid_argument` in current scope.
|
||||||
#define MONERO_PRECOND(...) \
|
#define MONERO_PRECOND(...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if (!( __VA_ARGS__ )) \
|
if (!( __VA_ARGS__ )) \
|
||||||
return {::common_error::kInvalidArgument}; \
|
return {::monero::error::invalid_argument}; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
//! Check `expect<void>` and return errors in current scope.
|
//! Check `expect<void>` and return errors in current scope.
|
||||||
@ -55,14 +55,14 @@
|
|||||||
/*! Get `T` from `expect<T>` by `std::move` as-if by function call.
|
/*! Get `T` from `expect<T>` by `std::move` as-if by function call.
|
||||||
`expect<void>` returns nothing.
|
`expect<void>` returns nothing.
|
||||||
|
|
||||||
\throw std::system_error with `expect<T>::error()`, filename and line
|
\throw monero::system_error with `expect<T>::error()`, filename and line
|
||||||
number when `expect<T>::has_error() == true`.*/
|
number when `expect<T>::has_error() == true`.*/
|
||||||
#define MONERO_UNWRAP(...) \
|
#define MONERO_UNWRAP(...) \
|
||||||
::detail::expect::unwrap( __VA_ARGS__ , nullptr, __FILE__ , __LINE__ )
|
::detail::expect::unwrap( __VA_ARGS__ , nullptr, __FILE__ , __LINE__ )
|
||||||
|
|
||||||
/* \throw std::system_error with `code` and `msg` as part of the details. The
|
/* \throw monero::system_error with `code` and `msg` as part of the details. The
|
||||||
filename and line number will automatically be injected into the explanation
|
filename and line number will automatically be injected into the explanation
|
||||||
string. `code` can be any enum convertible to `std::error_code`. */
|
string. `code` can be any enum convertible to `monero::error_code`. */
|
||||||
#define MONERO_THROW(code, msg) \
|
#define MONERO_THROW(code, msg) \
|
||||||
::detail::expect::throw_( code , msg , __FILE__ , __LINE__ )
|
::detail::expect::throw_( code , msg , __FILE__ , __LINE__ )
|
||||||
|
|
||||||
@ -77,8 +77,8 @@ namespace detail
|
|||||||
|
|
||||||
struct expect
|
struct expect
|
||||||
{
|
{
|
||||||
//! \throw std::system_error with `ec`, optional `msg` and/or optional `file` + `line`.
|
//! \throw monero::system_error with `ec`, optional `msg` and/or optional `file` + `line`.
|
||||||
static void throw_(std::error_code ec, const char* msg, const char* file, unsigned line);
|
static void throw_(monero::error_code ec, const char* msg, const char* file, unsigned line);
|
||||||
|
|
||||||
//! If `result.has_error()` call `throw_`. Otherwise, \return `*result` by move.
|
//! If `result.has_error()` call `throw_`. Otherwise, \return `*result` by move.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -97,9 +97,9 @@ namespace detail
|
|||||||
/*!
|
/*!
|
||||||
`expect<T>` is a value or error implementation, similar to Rust std::result
|
`expect<T>` is a value or error implementation, similar to Rust std::result
|
||||||
or various C++ proposals (boost::expected, boost::outcome). This
|
or various C++ proposals (boost::expected, boost::outcome). This
|
||||||
implementation currently has a strict error type, `std::error_code`, and a
|
implementation currently has a strict error type, `monero::error_code`, and
|
||||||
templated value type `T`. `expect<T>` is implicitly convertible from `T`
|
a templated value type `T`. `expect<T>` is implicitly convertible from `T`
|
||||||
or `std::error_code`, and one `expect<T>` object type is implicitly
|
or `monero::error_code`, and one `expect<T>` object type is implicitly
|
||||||
convertible to another `expect<U>` object iff the destination value type
|
convertible to another `expect<U>` object iff the destination value type
|
||||||
can be implicitly constructed from the source value type (i.e.
|
can be implicitly constructed from the source value type (i.e.
|
||||||
`struct U { ... U(T src) { ...} ... };`).
|
`struct U { ... U(T src) { ...} ... };`).
|
||||||
@ -108,14 +108,14 @@ namespace detail
|
|||||||
comparison between different value types is allowed provided the two values
|
comparison between different value types is allowed provided the two values
|
||||||
types have a `operator==` defined between them (i.e.
|
types have a `operator==` defined between them (i.e.
|
||||||
`assert(expect<int>{100} == expect<short>{100});`). Comparisons can also be
|
`assert(expect<int>{100} == expect<short>{100});`). Comparisons can also be
|
||||||
done against `std::error_code` objects or error code enums directly (i.e.
|
done against `monero::error_code` objects or error code enums directly (i.e.
|
||||||
`assert(expect<int>{make_error_code(common_error::kInvalidArgument)} == error::kInvalidArgument)`).
|
`assert(expect<int>{make_error_code(monero::error::invalid_argument)} == error::invalid_argument)`).
|
||||||
Comparison of default constructed `std::error_code` will always fail.
|
Comparison of default constructed `monero::error_code` will always fail.
|
||||||
"Generic" comparisons can be done with `std::error_condition` via the `matches`
|
"Generic" comparisons can be done with `monero::error_condition` via the
|
||||||
method only (i.e.
|
`matches` method only (i.e.
|
||||||
`assert(expect<int>{make_error_code{common_error::kInvalidErrorCode}.matches(std::errc::invalid_argument))`),
|
`assert(expect<int>{make_error_code{monero::error::invalid_error_code}.matches(monero::errc::invalid_argument))`),
|
||||||
`operator==` and `operator!=` will not work with `std::errc` or
|
`operator==` and `operator!=` will not work with `monero::errc` or
|
||||||
`std::error_condition`. A comparison with `matches` is more expensive
|
`monero::error_condition`. A comparison with `matches` is more expensive
|
||||||
because an equivalency between error categories is computed, but is
|
because an equivalency between error categories is computed, but is
|
||||||
recommended when an error can be one of several categories (this is going
|
recommended when an error can be one of several categories (this is going
|
||||||
to be the case in nearly every situation when calling a function from
|
to be the case in nearly every situation when calling a function from
|
||||||
@ -141,7 +141,7 @@ class expect
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MEMBERS
|
// MEMBERS
|
||||||
std::error_code code_;
|
monero::error_code code_;
|
||||||
typename std::aligned_storage<sizeof(T), alignof(T)>::type storage_;
|
typename std::aligned_storage<sizeof(T), alignof(T)>::type storage_;
|
||||||
// MEMBERS
|
// MEMBERS
|
||||||
|
|
||||||
@ -161,7 +161,6 @@ class expect
|
|||||||
void store(U&& value) noexcept(std::is_nothrow_constructible<T, U>())
|
void store(U&& value) noexcept(std::is_nothrow_constructible<T, U>())
|
||||||
{
|
{
|
||||||
new (std::addressof(storage_)) T{std::forward<U>(value)};
|
new (std::addressof(storage_)) T{std::forward<U>(value)};
|
||||||
code_ = std::error_code{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void maybe_throw() const
|
void maybe_throw() const
|
||||||
@ -172,24 +171,27 @@ class expect
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
using error_type = std::error_code;
|
using error_type = monero::error_code;
|
||||||
|
|
||||||
expect() = delete;
|
expect() = delete;
|
||||||
|
|
||||||
/*! Store an error, `code`, in the `expect` object. If `code` creates a
|
/*! Store an error, `code`, in the `expect` object. If `code` creates a
|
||||||
`std::error_code` object whose `.value() == 0`, then `error()` will be set
|
`monero::error_code` object whose `.value() == 0`, then `error()` will be
|
||||||
to `::common_error::kInvalidErrorCode`. */
|
set to `::monero::error::invalid_error_code`. */
|
||||||
expect(std::error_code const& code) noexcept
|
expect(error_type const& code) noexcept
|
||||||
: code_(code), storage_()
|
: code_(code), storage_()
|
||||||
{
|
{
|
||||||
if (!has_error())
|
if (!has_error())
|
||||||
code_ = ::common_error::kInvalidErrorCode;
|
code_ = ::monero::error::invalid_error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Store a value, `val`, in the `expect` object.
|
//! Store a value, `val`, in the `expect` object.
|
||||||
expect(T val) noexcept(std::is_nothrow_move_constructible<T>())
|
expect(T val) noexcept(std::is_nothrow_move_constructible<T>())
|
||||||
: code_(), storage_()
|
: code_(monero::error::none), storage_()
|
||||||
{
|
{
|
||||||
|
/* `monero::error::none` is used instead of default constructor because
|
||||||
|
Boost error_code in 1.68+ is header based and drags many instructions
|
||||||
|
into other functions unless compiling in C++14+. */
|
||||||
store(std::move(val));
|
store(std::move(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,16 +275,16 @@ public:
|
|||||||
bool has_value() const noexcept { return !has_error(); }
|
bool has_value() const noexcept { return !has_error(); }
|
||||||
|
|
||||||
//! \return Error - always safe to call. Empty when `!has_error()`.
|
//! \return Error - always safe to call. Empty when `!has_error()`.
|
||||||
std::error_code error() const noexcept { return code_; }
|
error_type error() const noexcept { return code_; }
|
||||||
|
|
||||||
//! \return Value if `has_value()` otherwise \throw `std::system_error{error()}`.
|
//! \return Value if `has_value()` otherwise \throw `monero::system_error{error()}`.
|
||||||
T& value() &
|
T& value() &
|
||||||
{
|
{
|
||||||
maybe_throw();
|
maybe_throw();
|
||||||
return get();
|
return get();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \return Value if `has_value()` otherwise \throw `std::system_error{error()}`.
|
//! \return Value if `has_value()` otherwise \throw `monero::system_error{error()}`.
|
||||||
T const& value() const &
|
T const& value() const &
|
||||||
{
|
{
|
||||||
maybe_throw();
|
maybe_throw();
|
||||||
@ -318,7 +320,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \return False if `has_value()`, otherwise `error() == rhs`.
|
//! \return False if `has_value()`, otherwise `error() == rhs`.
|
||||||
bool equal(std::error_code const& rhs) const noexcept
|
bool equal(error_type const& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return has_error() && error() == rhs;
|
return has_error() && error() == rhs;
|
||||||
}
|
}
|
||||||
@ -327,14 +329,14 @@ public:
|
|||||||
\note This function is `noexcept` when `U == T` is `noexcept`.
|
\note This function is `noexcept` when `U == T` is `noexcept`.
|
||||||
\return False if `has_error()`, otherwise `value() == rhs`.
|
\return False if `has_error()`, otherwise `value() == rhs`.
|
||||||
*/
|
*/
|
||||||
template<typename U, typename = detail::enable_if<!std::is_constructible<std::error_code, U>::value>>
|
template<typename U, typename = detail::enable_if<!std::is_constructible<error_type, U>::value>>
|
||||||
bool equal(U const& rhs) const noexcept(noexcept(*std::declval<expect<T>>() == rhs))
|
bool equal(U const& rhs) const noexcept(noexcept(*std::declval<expect<T>>() == rhs))
|
||||||
{
|
{
|
||||||
return has_value() && get() == rhs;
|
return has_value() && get() == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \return False if `has_value()`, otherwise `error() == rhs`.
|
//! \return False if `has_value()`, otherwise `error() == rhs`.
|
||||||
bool matches(std::error_condition const& rhs) const noexcept
|
bool matches(monero::error_condition const& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return has_error() && error() == rhs;
|
return has_error() && error() == rhs;
|
||||||
}
|
}
|
||||||
@ -343,22 +345,26 @@ public:
|
|||||||
template<>
|
template<>
|
||||||
class expect<void>
|
class expect<void>
|
||||||
{
|
{
|
||||||
std::error_code code_;
|
monero::error_code code_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using value_type = void;
|
using value_type = void;
|
||||||
using error_type = std::error_code;
|
using error_type = monero::error_code;
|
||||||
|
|
||||||
//! Create a successful object.
|
//! Create a successful object.
|
||||||
expect() noexcept
|
expect() noexcept
|
||||||
: code_()
|
: code_(monero::error::none)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
expect(std::error_code const& code) noexcept
|
/* `monero::error::none` is used instead of default constructor because
|
||||||
|
Boost error_code in 1.68+ is header based and drags many instructions
|
||||||
|
into other functions unless compiling in C++14+. */
|
||||||
|
|
||||||
|
expect(error_type const& code) noexcept
|
||||||
: code_(code)
|
: code_(code)
|
||||||
{
|
{
|
||||||
if (!has_error())
|
if (!has_error())
|
||||||
code_ = ::common_error::kInvalidErrorCode;
|
code_ = ::monero::error::invalid_error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(expect const&) = default;
|
expect(expect const&) = default;
|
||||||
@ -372,7 +378,7 @@ public:
|
|||||||
bool has_error() const noexcept { return bool(code_); }
|
bool has_error() const noexcept { return bool(code_); }
|
||||||
|
|
||||||
//! \return Error - alway
|
//! \return Error - alway
|
||||||
std::error_code error() const noexcept { return code_; }
|
error_type error() const noexcept { return code_; }
|
||||||
|
|
||||||
//! \return `error() == rhs.error()`.
|
//! \return `error() == rhs.error()`.
|
||||||
bool equal(expect const& rhs) const noexcept
|
bool equal(expect const& rhs) const noexcept
|
||||||
@ -381,13 +387,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \return `has_error() && error() == rhs`.
|
//! \return `has_error() && error() == rhs`.
|
||||||
bool equal(std::error_code const& rhs) const noexcept
|
bool equal(error_type const& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return has_error() && error() == rhs;
|
return has_error() && error() == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \return False if `has_value()`, otherwise `error() == rhs`.
|
//! \return False if `has_value()`, otherwise `error() == rhs`.
|
||||||
bool matches(std::error_condition const& rhs) const noexcept
|
bool matches(monero::error_condition const& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return has_error() && error() == rhs;
|
return has_error() && error() == rhs;
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct category final : std::error_category
|
struct category final : monero::error_category
|
||||||
{
|
{
|
||||||
|
category() noexcept
|
||||||
|
: monero::error_category()
|
||||||
|
{}
|
||||||
|
|
||||||
virtual const char* name() const noexcept override final
|
virtual const char* name() const noexcept override final
|
||||||
{
|
{
|
||||||
return "lmdb::error_category()";
|
return "lmdb::error_category()";
|
||||||
@ -46,7 +50,7 @@ namespace {
|
|||||||
return "Unknown lmdb::error_category() value";
|
return "Unknown lmdb::error_category() value";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::error_condition default_error_condition(int value) const noexcept override final
|
virtual monero::error_condition default_error_condition(int value) const noexcept override final
|
||||||
{
|
{
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
@ -55,44 +59,53 @@ namespace {
|
|||||||
break; // map to nothing generic
|
break; // map to nothing generic
|
||||||
case MDB_PAGE_NOTFOUND:
|
case MDB_PAGE_NOTFOUND:
|
||||||
case MDB_CORRUPTED:
|
case MDB_CORRUPTED:
|
||||||
return std::errc::bad_address;
|
return monero::errc::bad_address;
|
||||||
case MDB_PANIC:
|
case MDB_PANIC:
|
||||||
case MDB_VERSION_MISMATCH:
|
case MDB_VERSION_MISMATCH:
|
||||||
case MDB_INVALID:
|
case MDB_INVALID:
|
||||||
break; // map to nothing generic
|
break; // map to nothing generic
|
||||||
case MDB_MAP_FULL:
|
case MDB_MAP_FULL:
|
||||||
return std::errc::no_buffer_space;
|
return monero::errc::no_buffer_space;
|
||||||
case MDB_DBS_FULL:
|
case MDB_DBS_FULL:
|
||||||
break; // map to nothing generic
|
break; // map to nothing generic
|
||||||
case MDB_READERS_FULL:
|
case MDB_READERS_FULL:
|
||||||
case MDB_TLS_FULL:
|
case MDB_TLS_FULL:
|
||||||
return std::errc::no_lock_available;
|
return monero::errc::no_lock_available;
|
||||||
case MDB_TXN_FULL:
|
case MDB_TXN_FULL:
|
||||||
case MDB_CURSOR_FULL:
|
case MDB_CURSOR_FULL:
|
||||||
case MDB_PAGE_FULL:
|
case MDB_PAGE_FULL:
|
||||||
case MDB_MAP_RESIZED:
|
case MDB_MAP_RESIZED:
|
||||||
break; // map to nothing generic
|
break; // map to nothing generic
|
||||||
case MDB_INCOMPATIBLE:
|
case MDB_INCOMPATIBLE:
|
||||||
return std::errc::invalid_argument;
|
return monero::errc::invalid_argument;
|
||||||
case MDB_BAD_RSLOT:
|
case MDB_BAD_RSLOT:
|
||||||
case MDB_BAD_TXN:
|
case MDB_BAD_TXN:
|
||||||
case MDB_BAD_VALSIZE:
|
case MDB_BAD_VALSIZE:
|
||||||
case MDB_BAD_DBI:
|
case MDB_BAD_DBI:
|
||||||
return std::errc::invalid_argument;
|
return monero::errc::invalid_argument;
|
||||||
default:
|
default:
|
||||||
return std::error_condition{value, std::generic_category()};
|
return monero::errc::errc_t(value);
|
||||||
}
|
}
|
||||||
return std::error_condition{value, *this};
|
return monero::error_condition{value, *this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
|
||||||
|
category const& category_instance() noexcept
|
||||||
namespace lmdb
|
|
||||||
{
|
|
||||||
std::error_category const& error_category() noexcept
|
|
||||||
{
|
{
|
||||||
static const category instance{};
|
static const category instance{};
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace lmdb
|
||||||
|
{
|
||||||
|
monero::error_category const& error_category() noexcept
|
||||||
|
{
|
||||||
|
return category_instance();
|
||||||
|
}
|
||||||
|
monero::error_code make_error_code(const error value) noexcept
|
||||||
|
{
|
||||||
|
return {int(value), category_instance()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <system_error>
|
#include "common/error.h"
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
//! Executes a LMDB command, and returns errors via `lmdb::error` enum.
|
//! Executes a LMDB command, and returns errors via `lmdb::error` enum.
|
||||||
#define MONERO_LMDB_CHECK(...) \
|
#define MONERO_LMDB_CHECK(...) \
|
||||||
@ -47,18 +46,8 @@ namespace lmdb
|
|||||||
// All other errors are the values reported by LMDB
|
// All other errors are the values reported by LMDB
|
||||||
};
|
};
|
||||||
|
|
||||||
std::error_category const& error_category() noexcept;
|
monero::error_category const& error_category() noexcept;
|
||||||
|
monero::error_code make_error_code(error value) noexcept;
|
||||||
inline std::error_code make_error_code(error value) noexcept
|
|
||||||
{
|
|
||||||
return std::error_code{int(value), error_category()};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std
|
MONERO_DECLARE_ERROR_ENUM(lmdb::error)
|
||||||
{
|
|
||||||
template<>
|
|
||||||
struct is_error_code_enum<::lmdb::error>
|
|
||||||
: true_type
|
|
||||||
{};
|
|
||||||
}
|
|
||||||
|
@ -80,7 +80,7 @@ namespace lmdb
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\param cur Iterate over keys starting at this cursor position.
|
\param cur Iterate over keys starting at this cursor position.
|
||||||
\throw std::system_error if unexpected LMDB error. This can happen
|
\throw monero::system_error if unexpected LMDB error. This can happen
|
||||||
if `cur` is invalid.
|
if `cur` is invalid.
|
||||||
*/
|
*/
|
||||||
key_iterator(MDB_cursor* cur)
|
key_iterator(MDB_cursor* cur)
|
||||||
@ -148,7 +148,7 @@ namespace lmdb
|
|||||||
object - the other fields in the struct `account` are never copied
|
object - the other fields in the struct `account` are never copied
|
||||||
from the database.
|
from the database.
|
||||||
|
|
||||||
\throw std::system_error if LMDB has unexpected errors.
|
\throw monero::system_error if LMDB has unexpected errors.
|
||||||
\return C++ iterator starting at current cursor position.
|
\return C++ iterator starting at current cursor position.
|
||||||
*/
|
*/
|
||||||
template<typename T = V, typename F = T, std::size_t offset = 0>
|
template<typename T = V, typename F = T, std::size_t offset = 0>
|
||||||
@ -166,7 +166,7 @@ namespace lmdb
|
|||||||
will return a range of `decltype(account.id)` objects - the other
|
will return a range of `decltype(account.id)` objects - the other
|
||||||
fields in the struct `account` are never copied from the database.
|
fields in the struct `account` are never copied from the database.
|
||||||
|
|
||||||
\throw std::system_error if LMDB has unexpected errors.
|
\throw monero::system_error if LMDB has unexpected errors.
|
||||||
\return An InputIterator range over values at cursor position.
|
\return An InputIterator range over values at cursor position.
|
||||||
*/
|
*/
|
||||||
template<typename T = V, typename F = T, std::size_t offset = 0>
|
template<typename T = V, typename F = T, std::size_t offset = 0>
|
||||||
@ -227,7 +227,7 @@ namespace lmdb
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\throw std::system_error if LMDB has unexpected errors.
|
\throw monero::system_error if LMDB has unexpected errors.
|
||||||
\return C++ iterator over database keys from current cursor
|
\return C++ iterator over database keys from current cursor
|
||||||
position that will reach `.is_end()` after the last key.
|
position that will reach `.is_end()` after the last key.
|
||||||
*/
|
*/
|
||||||
@ -237,7 +237,7 @@ namespace lmdb
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\throw std::system_error if LMDB has unexpected errors.
|
\throw monero::system_error if LMDB has unexpected errors.
|
||||||
\return Range from current cursor position until last key record.
|
\return Range from current cursor position until last key record.
|
||||||
Useful in for-each range loops or in templated code
|
Useful in for-each range loops or in templated code
|
||||||
*/
|
*/
|
||||||
|
@ -40,7 +40,7 @@ namespace lmdb
|
|||||||
namespace stream
|
namespace stream
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
\throw std::system_error if unexpected LMDB error.
|
\throw monero::system_error if unexpected LMDB error.
|
||||||
\return 0 if `cur == nullptr`, otherwise count of values at current key.
|
\return 0 if `cur == nullptr`, otherwise count of values at current key.
|
||||||
*/
|
*/
|
||||||
mdb_size_t count(MDB_cursor* cur);
|
mdb_size_t count(MDB_cursor* cur);
|
||||||
@ -53,9 +53,9 @@ namespace lmdb
|
|||||||
\param key expected key size or 0 to skip key size check.
|
\param key expected key size or 0 to skip key size check.
|
||||||
\param value expected value size or 0 to skip value size check.
|
\param value expected value size or 0 to skip value size check.
|
||||||
|
|
||||||
\throw std::system_error if `key != 0` and `key_.mv_size != key`.
|
\throw monero::system_error if `key != 0` and `key_.mv_size != key`.
|
||||||
\throw std::system_error if `value != 0` and `value_.mv_size != value`.
|
\throw monero::system_error if `value != 0` and `value_.mv_size != value`.
|
||||||
\throw std::system_error if `mdb_cursor_get` returns any error
|
\throw monero::system_error if `mdb_cursor_get` returns any error
|
||||||
other than `MDB_NOTFOUND`.
|
other than `MDB_NOTFOUND`.
|
||||||
|
|
||||||
\return {key bytes, value bytes} or two empty spans if `MDB_NOTFOUND`.
|
\return {key bytes, value bytes} or two empty spans if `MDB_NOTFOUND`.
|
||||||
@ -105,7 +105,7 @@ namespace lmdb
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\param cur Iterate over values starting at this cursor position.
|
\param cur Iterate over values starting at this cursor position.
|
||||||
\throw std::system_error if unexpected LMDB error. This can happen
|
\throw monero::system_error if unexpected LMDB error. This can happen
|
||||||
if `cur` is invalid.
|
if `cur` is invalid.
|
||||||
*/
|
*/
|
||||||
value_iterator(MDB_cursor* cur)
|
value_iterator(MDB_cursor* cur)
|
||||||
@ -224,7 +224,7 @@ namespace lmdb
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\throw std::system_error if LMDB has unexpected errors.
|
\throw monero::system_error if LMDB has unexpected errors.
|
||||||
\return Number of values at this key.
|
\return Number of values at this key.
|
||||||
*/
|
*/
|
||||||
std::size_t count() const
|
std::size_t count() const
|
||||||
@ -242,7 +242,7 @@ namespace lmdb
|
|||||||
object - the other fields in the struct `account` are never copied
|
object - the other fields in the struct `account` are never copied
|
||||||
from the database.
|
from the database.
|
||||||
|
|
||||||
\throw std::system_error if LMDB has unexpected errors.
|
\throw monero::system_error if LMDB has unexpected errors.
|
||||||
\return C++ iterator starting at current cursor position.
|
\return C++ iterator starting at current cursor position.
|
||||||
*/
|
*/
|
||||||
template<typename U = T, typename F = U, std::size_t offset = 0>
|
template<typename U = T, typename F = U, std::size_t offset = 0>
|
||||||
@ -260,7 +260,7 @@ namespace lmdb
|
|||||||
will return a range of `decltype(account.id)` objects - the other
|
will return a range of `decltype(account.id)` objects - the other
|
||||||
fields in the struct `account` are never copied from the database.
|
fields in the struct `account` are never copied from the database.
|
||||||
|
|
||||||
\throw std::system_error if LMDB has unexpected errors.
|
\throw monero::system_error if LMDB has unexpected errors.
|
||||||
\return An InputIterator range over values at cursor position.
|
\return An InputIterator range over values at cursor position.
|
||||||
*/
|
*/
|
||||||
template<typename U = T, typename F = U, std::size_t offset = 0>
|
template<typename U = T, typename F = U, std::size_t offset = 0>
|
||||||
|
@ -107,7 +107,7 @@ namespace dandelionpp
|
|||||||
{
|
{
|
||||||
// max value is used by `select_stem` as error case
|
// max value is used by `select_stem` as error case
|
||||||
if (stems == std::numeric_limits<std::size_t>::max())
|
if (stems == std::numeric_limits<std::size_t>::max())
|
||||||
MONERO_THROW(common_error::kInvalidArgument, "stems value cannot be max size_t");
|
MONERO_THROW(monero::error::invalid_argument, "stems value cannot be max size_t");
|
||||||
|
|
||||||
usage_count_.resize(stems);
|
usage_count_.resize(stems);
|
||||||
if (stems < out_mapping_.size())
|
if (stems < out_mapping_.size())
|
||||||
|
@ -32,18 +32,18 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct net_category : std::error_category
|
struct net_category final : monero::error_category
|
||||||
{
|
{
|
||||||
net_category() noexcept
|
net_category() noexcept
|
||||||
: std::error_category()
|
: monero::error_category()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const char* name() const noexcept override
|
const char* name() const noexcept override final
|
||||||
{
|
{
|
||||||
return "net::error_category";
|
return "net::error_category";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string message(int value) const override
|
std::string message(int value) const override final
|
||||||
{
|
{
|
||||||
switch (net::error(value))
|
switch (net::error(value))
|
||||||
{
|
{
|
||||||
@ -72,28 +72,38 @@ namespace
|
|||||||
return "Unknown net::error";
|
return "Unknown net::error";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_condition default_error_condition(int value) const noexcept override
|
monero::error_condition default_error_condition(int value) const noexcept override final
|
||||||
{
|
{
|
||||||
switch (net::error(value))
|
switch (net::error(value))
|
||||||
{
|
{
|
||||||
case net::error::invalid_port:
|
case net::error::invalid_port:
|
||||||
case net::error::invalid_mask:
|
case net::error::invalid_mask:
|
||||||
return std::errc::result_out_of_range;
|
return monero::errc::result_out_of_range;
|
||||||
case net::error::expected_tld:
|
case net::error::expected_tld:
|
||||||
case net::error::invalid_tor_address:
|
case net::error::invalid_tor_address:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return std::error_condition{value, *this};
|
return monero::error_condition{value, *this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
|
||||||
|
net_category const& category_instance() noexcept
|
||||||
|
{
|
||||||
|
static const net_category category;
|
||||||
|
return category;
|
||||||
|
}
|
||||||
} // anonymous
|
} // anonymous
|
||||||
|
|
||||||
namespace net
|
namespace net
|
||||||
{
|
{
|
||||||
std::error_category const& error_category() noexcept
|
monero::error_category const& error_category() noexcept
|
||||||
{
|
{
|
||||||
static const net_category instance{};
|
return category_instance();
|
||||||
return instance;
|
}
|
||||||
|
|
||||||
|
monero::error_code make_error_code(error value) noexcept
|
||||||
|
{
|
||||||
|
return {int(value), category_instance()};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <system_error>
|
#include "common/error.h"
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
namespace net
|
namespace net
|
||||||
{
|
{
|
||||||
@ -49,20 +48,11 @@ namespace net
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \return `std::error_category` for `net` namespace.
|
//! \return `monero::error_category` for `net` namespace.
|
||||||
std::error_category const& error_category() noexcept;
|
monero::error_category const& error_category() noexcept;
|
||||||
|
|
||||||
//! \return `net::error` as a `std::error_code` value.
|
//! \return `net::error` as a `std::error_code` value.
|
||||||
inline std::error_code make_error_code(error value) noexcept
|
monero::error_code make_error_code(error value) noexcept;
|
||||||
{
|
|
||||||
return std::error_code{int(value), error_category()};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std
|
MONERO_DECLARE_ERROR_ENUM(net::error)
|
||||||
{
|
|
||||||
template<>
|
|
||||||
struct is_error_code_enum<::net::error>
|
|
||||||
: true_type
|
|
||||||
{};
|
|
||||||
}
|
|
||||||
|
@ -137,12 +137,22 @@ namespace socks
|
|||||||
return boost::system::error_condition{value, *this};
|
return boost::system::error_condition{value, *this};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
|
||||||
|
const socks_category& category_instance() noexcept
|
||||||
|
{
|
||||||
|
static const socks_category instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::system::error_category& error_category() noexcept
|
const boost::system::error_category& error_category() noexcept
|
||||||
{
|
{
|
||||||
static const socks_category instance{};
|
return category_instance();
|
||||||
return instance;
|
}
|
||||||
|
|
||||||
|
boost::system::error_code make_error_code(error value) noexcept
|
||||||
|
{
|
||||||
|
return {int(value), category_instance()};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct client::completed
|
struct client::completed
|
||||||
|
@ -76,18 +76,15 @@ namespace socks
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* boost::system::error_code is extended for easier compatibility with
|
/* boost::system::error_code is extended for easier compatibility with
|
||||||
boost::asio errors. If std::error_code is needed (with expect<T> for
|
boost::asio errors. If std::error_code is needed, then upgrade to boost
|
||||||
instance), then upgrade to boost 1.65+ or use conversion code in
|
1.65+ or use conversion code in develop branch at
|
||||||
develop branch at boost/system/detail/std_interoperability.hpp */
|
boost/system/detail/std_interoperability.hpp */
|
||||||
|
|
||||||
//! \return boost::system::error_category for net::socks namespace
|
//! \return boost::system::error_category for net::socks namespace
|
||||||
const boost::system::error_category& error_category() noexcept;
|
const boost::system::error_category& error_category() noexcept;
|
||||||
|
|
||||||
//! \return net::socks::error as a boost::system::error_code.
|
//! \return net::socks::error as a boost::system::error_code.
|
||||||
inline boost::system::error_code make_error_code(error value) noexcept
|
boost::system::error_code make_error_code(error value) noexcept;
|
||||||
{
|
|
||||||
return boost::system::error_code{int(value), socks::error_category()};
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Client support for socks connect and resolve commands.
|
//! Client support for socks connect and resolve commands.
|
||||||
class client
|
class client
|
||||||
|
@ -64,7 +64,7 @@ namespace socks
|
|||||||
{
|
{
|
||||||
std::uint16_t port = 0;
|
std::uint16_t port = 0;
|
||||||
if (!epee::string_tools::get_xtype_from_string(port, remote_port))
|
if (!epee::string_tools::get_xtype_from_string(port, remote_port))
|
||||||
throw std::system_error{net::error::invalid_port, "Remote port for socks proxy"};
|
throw monero::system_error{net::error::invalid_port, "Remote port for socks proxy"};
|
||||||
|
|
||||||
bool is_set = false;
|
bool is_set = false;
|
||||||
std::uint32_t ip_address = 0;
|
std::uint32_t ip_address = 0;
|
||||||
@ -80,7 +80,7 @@ namespace socks
|
|||||||
is_set = proxy->set_connect_command(remote_host, port);
|
is_set = proxy->set_connect_command(remote_host, port);
|
||||||
|
|
||||||
if (!is_set || !net::socks::client::connect_and_send(proxy, proxy_address))
|
if (!is_set || !net::socks::client::connect_and_send(proxy, proxy_address))
|
||||||
throw std::system_error{net::error::invalid_host, "Address for socks proxy"};
|
throw monero::system_error{net::error::invalid_host, "Address for socks proxy"};
|
||||||
|
|
||||||
timeout.async_wait(net::socks::client::async_close{std::move(proxy)});
|
timeout.async_wait(net::socks::client::async_close{std::move(proxy)});
|
||||||
}
|
}
|
||||||
|
@ -35,49 +35,66 @@
|
|||||||
|
|
||||||
#include "byte_slice.h"
|
#include "byte_slice.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct category final : monero::error_category
|
||||||
|
{
|
||||||
|
category() noexcept
|
||||||
|
: monero::error_category()
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual const char* name() const noexcept override final
|
||||||
|
{
|
||||||
|
return "net::zmq::error_category()";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string message(int value) const override final
|
||||||
|
{
|
||||||
|
char const* const msg = zmq_strerror(value);
|
||||||
|
if (msg)
|
||||||
|
return msg;
|
||||||
|
return "zmq_strerror failure";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual monero::error_condition default_error_condition(int value) const noexcept override final
|
||||||
|
{
|
||||||
|
// maps specific errors to generic `std::errc` cases.
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case EFSM:
|
||||||
|
case ETERM:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* zmq is using cerrno errors. C++ spec indicates that
|
||||||
|
`std::errc` values must be identical to the cerrno value. So
|
||||||
|
just map every zmq specific error to the generic errc
|
||||||
|
equivalent. zmq extensions must be in the switch or they map
|
||||||
|
to a non-existent errc enum value. */
|
||||||
|
return monero::errc::errc_t(value);
|
||||||
|
}
|
||||||
|
return monero::error_condition{value, *this};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
|
||||||
|
const category& category_instance() noexcept
|
||||||
|
{
|
||||||
|
static const category instance{};
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace net
|
namespace net
|
||||||
{
|
{
|
||||||
namespace zmq
|
namespace zmq
|
||||||
{
|
{
|
||||||
const std::error_category& error_category() noexcept
|
const monero::error_category& error_category() noexcept
|
||||||
{
|
{
|
||||||
struct category final : std::error_category
|
return category_instance();
|
||||||
{
|
}
|
||||||
virtual const char* name() const noexcept override final
|
|
||||||
{
|
|
||||||
return "error::error_category()";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::string message(int value) const override final
|
monero::error_code make_error_code(int code) noexcept
|
||||||
{
|
{
|
||||||
char const* const msg = zmq_strerror(value);
|
return {code, category_instance()};
|
||||||
if (msg)
|
|
||||||
return msg;
|
|
||||||
return "zmq_strerror failure";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::error_condition default_error_condition(int value) const noexcept override final
|
|
||||||
{
|
|
||||||
// maps specific errors to generic `std::errc` cases.
|
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case EFSM:
|
|
||||||
case ETERM:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* zmq is using cerrno errors. C++ spec indicates that
|
|
||||||
`std::errc` values must be identical to the cerrno value.
|
|
||||||
So just map every zmq specific error to the generic errc
|
|
||||||
equivalent. zmq extensions must be in the switch or they
|
|
||||||
map to a non-existent errc enum value. */
|
|
||||||
return std::errc(value);
|
|
||||||
}
|
|
||||||
return std::error_condition{value, *this};
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
static const category instance{};
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminate::call(void* ptr) noexcept
|
void terminate::call(void* ptr) noexcept
|
||||||
|
@ -65,16 +65,13 @@ namespace net
|
|||||||
namespace zmq
|
namespace zmq
|
||||||
{
|
{
|
||||||
//! \return Category for ZMQ errors.
|
//! \return Category for ZMQ errors.
|
||||||
const std::error_category& error_category() noexcept;
|
const monero::error_category& error_category() noexcept;
|
||||||
|
|
||||||
//! \return `code` (usally from zmq_errno()`) using `net::zmq::error_category()`.
|
//! \return `code` (usally from zmq_errno()`) using `net::zmq::error_category()`.
|
||||||
inline std::error_code make_error_code(int code) noexcept
|
monero::error_code make_error_code(int code) noexcept;
|
||||||
{
|
|
||||||
return std::error_code{code, error_category()};
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \return Error from `zmq_errno()` using `net::zmq::error_category()`.
|
//! \return Error from `zmq_errno()` using `net::zmq::error_category()`.
|
||||||
inline std::error_code get_error_code() noexcept
|
inline monero::error_code get_error_code() noexcept
|
||||||
{
|
{
|
||||||
return make_error_code(zmq_errno());
|
return make_error_code(zmq_errno());
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ void ZmqServer::serve()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::system_error& e)
|
catch (const boost::system::system_error& e)
|
||||||
{
|
{
|
||||||
if (e.code() != net::zmq::make_error_code(ETERM))
|
if (e.code() != net::zmq::make_error_code(ETERM))
|
||||||
MERROR("ZMQ RPC Server Error: " << e.what());
|
MERROR("ZMQ RPC Server Error: " << e.what());
|
||||||
|
@ -118,15 +118,15 @@ namespace
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void conversion_bench()
|
void conversion_bench()
|
||||||
{
|
{
|
||||||
EXPECT_TRUE((std::is_convertible<std::error_code, expect<T>>()));
|
EXPECT_TRUE((std::is_convertible<monero::error_code, expect<T>>()));
|
||||||
EXPECT_TRUE((std::is_convertible<std::error_code&&, expect<T>>()));
|
EXPECT_TRUE((std::is_convertible<monero::error_code&&, expect<T>>()));
|
||||||
EXPECT_TRUE((std::is_convertible<std::error_code&, expect<T>>()));
|
EXPECT_TRUE((std::is_convertible<monero::error_code&, expect<T>>()));
|
||||||
EXPECT_TRUE((std::is_convertible<std::error_code const&, expect<T>>()));
|
EXPECT_TRUE((std::is_convertible<monero::error_code const&, expect<T>>()));
|
||||||
|
|
||||||
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code>()));
|
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code>()));
|
||||||
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code&&>()));
|
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code&&>()));
|
||||||
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code&>()));
|
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code&>()));
|
||||||
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code const&>()));
|
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code const&>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,10 +236,10 @@ TEST(Expect, NoExcept)
|
|||||||
EXPECT_TRUE(noexcept(std::declval<expect<int>>() != 0));
|
EXPECT_TRUE(noexcept(std::declval<expect<int>>() != 0));
|
||||||
EXPECT_TRUE(noexcept(0 != std::declval<expect<int>>()));
|
EXPECT_TRUE(noexcept(0 != std::declval<expect<int>>()));
|
||||||
|
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code&&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code&&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code const&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code const&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct&&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct&&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct&>()));
|
||||||
@ -254,10 +254,10 @@ TEST(Expect, NoExcept)
|
|||||||
EXPECT_TRUE(std::is_nothrow_move_assignable<expect<throw_construct>>());
|
EXPECT_TRUE(std::is_nothrow_move_assignable<expect<throw_construct>>());
|
||||||
EXPECT_TRUE(std::is_nothrow_destructible<expect<throw_construct>>());
|
EXPECT_TRUE(std::is_nothrow_destructible<expect<throw_construct>>());
|
||||||
|
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code&&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code&&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code const&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code const&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, throw_copies>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, throw_copies>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, throw_copies&&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, throw_copies&&>()));
|
||||||
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_copies>, throw_copies&>()));
|
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_copies>, throw_copies&>()));
|
||||||
@ -284,10 +284,10 @@ TEST(Expect, NoExcept)
|
|||||||
EXPECT_TRUE(noexcept(std::declval<expect<throw_copies>>() != std::declval<throw_moves>()));
|
EXPECT_TRUE(noexcept(std::declval<expect<throw_copies>>() != std::declval<throw_moves>()));
|
||||||
EXPECT_TRUE(noexcept(std::declval<throw_moves>() != std::declval<expect<throw_copies>>()));
|
EXPECT_TRUE(noexcept(std::declval<throw_moves>() != std::declval<expect<throw_copies>>()));
|
||||||
|
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code&&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code&&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code&>()));
|
||||||
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code const&>()));
|
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code const&>()));
|
||||||
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves>()));
|
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves>()));
|
||||||
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves&&>()));
|
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves&&>()));
|
||||||
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves&>()));
|
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves&>()));
|
||||||
@ -339,20 +339,20 @@ TEST(Expect, Assignment)
|
|||||||
EXPECT_TRUE(val2.value() == "foobar");
|
EXPECT_TRUE(val2.value() == "foobar");
|
||||||
EXPECT_TRUE(*val2 == "foobar");
|
EXPECT_TRUE(*val2 == "foobar");
|
||||||
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
|
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
|
||||||
EXPECT_EQ(val1.error(), std::error_code{});
|
EXPECT_EQ(val1.error(), monero::error::none);
|
||||||
EXPECT_EQ(val2.error(), std::error_code{});
|
EXPECT_EQ(val2.error(), monero::error::none);
|
||||||
EXPECT_TRUE(!val1.equal(std::error_code{}));
|
EXPECT_TRUE(!val1.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error::none == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error::none == val2));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error::none != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error::none != val2);
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val1 = std::move(val2);
|
val1 = std::move(val2);
|
||||||
|
|
||||||
@ -368,20 +368,20 @@ TEST(Expect, Assignment)
|
|||||||
EXPECT_EQ(val2.value(), std::string{});
|
EXPECT_EQ(val2.value(), std::string{});
|
||||||
EXPECT_TRUE(*val2 == std::string{});
|
EXPECT_TRUE(*val2 == std::string{});
|
||||||
EXPECT_TRUE(boost::equals(val2->c_str(), ""));
|
EXPECT_TRUE(boost::equals(val2->c_str(), ""));
|
||||||
EXPECT_EQ(val1.error(), std::error_code{});
|
EXPECT_EQ(val1.error(), monero::error::none);
|
||||||
EXPECT_EQ(val2.error(), std::error_code{});
|
EXPECT_EQ(val2.error(), monero::error::none);
|
||||||
EXPECT_TRUE(!val1.equal(std::error_code{}));
|
EXPECT_TRUE(!val1.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error::none == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error::none == val2));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error::none != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error::none != val2);
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val2 = val1;
|
val2 = val1;
|
||||||
|
|
||||||
@ -397,22 +397,22 @@ TEST(Expect, Assignment)
|
|||||||
EXPECT_EQ(val2.value(), "foobar");
|
EXPECT_EQ(val2.value(), "foobar");
|
||||||
EXPECT_TRUE(*val2 == "foobar");
|
EXPECT_TRUE(*val2 == "foobar");
|
||||||
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
|
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
|
||||||
EXPECT_EQ(val1.error(), std::error_code{});
|
EXPECT_EQ(val1.error(), monero::error::none);
|
||||||
EXPECT_EQ(val2.error(), std::error_code{});
|
EXPECT_EQ(val2.error(), monero::error::none);
|
||||||
EXPECT_TRUE(!val1.equal(std::error_code{}));
|
EXPECT_TRUE(!val1.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error::none == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error::none == val2));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error::none != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error::none != val2);
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val1 = make_error_code(common_error::kInvalidArgument);
|
val1 = make_error_code(monero::error::invalid_argument);
|
||||||
|
|
||||||
ASSERT_TRUE(val1.has_error());
|
ASSERT_TRUE(val1.has_error());
|
||||||
ASSERT_TRUE(val2.has_value());
|
ASSERT_TRUE(val2.has_value());
|
||||||
@ -420,27 +420,27 @@ TEST(Expect, Assignment)
|
|||||||
EXPECT_TRUE(bool(val2));
|
EXPECT_TRUE(bool(val2));
|
||||||
EXPECT_TRUE(!val1.has_value());
|
EXPECT_TRUE(!val1.has_value());
|
||||||
EXPECT_TRUE(!val2.has_error());
|
EXPECT_TRUE(!val2.has_error());
|
||||||
EXPECT_EQ(val1.error(), common_error::kInvalidArgument);
|
EXPECT_EQ(val1.error(), monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(val1 == common_error::kInvalidArgument);
|
EXPECT_TRUE(val1 == monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(common_error::kInvalidArgument == val1);
|
EXPECT_TRUE(monero::error::invalid_argument == val1);
|
||||||
EXPECT_STREQ(val2.value().c_str(), "foobar");
|
EXPECT_STREQ(val2.value().c_str(), "foobar");
|
||||||
EXPECT_TRUE(*val2 == "foobar");
|
EXPECT_TRUE(*val2 == "foobar");
|
||||||
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
|
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
|
||||||
EXPECT_NE(val1.error(), std::error_code{});
|
EXPECT_NE(val1.error(), monero::error::none);
|
||||||
EXPECT_EQ(val2.error(), std::error_code{});
|
EXPECT_EQ(val2.error(), monero::error::none);
|
||||||
EXPECT_TRUE(val1.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(val1.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error::none == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error::none == val2));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error::none != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error::none != val2);
|
||||||
EXPECT_TRUE(val1.matches(std::errc::invalid_argument));
|
EXPECT_TRUE(val1.matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val2 = val1;
|
val2 = val1;
|
||||||
|
|
||||||
@ -450,28 +450,28 @@ TEST(Expect, Assignment)
|
|||||||
EXPECT_TRUE(!val2);
|
EXPECT_TRUE(!val2);
|
||||||
EXPECT_TRUE(!val1.has_value());
|
EXPECT_TRUE(!val1.has_value());
|
||||||
EXPECT_TRUE(!val2.has_value());
|
EXPECT_TRUE(!val2.has_value());
|
||||||
EXPECT_EQ(val1.error(), common_error::kInvalidArgument);
|
EXPECT_EQ(val1.error(), monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(val1 == common_error::kInvalidArgument);
|
EXPECT_TRUE(val1 == monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(common_error::kInvalidArgument == val1);
|
EXPECT_TRUE(monero::error::invalid_argument == val1);
|
||||||
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
|
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
|
EXPECT_TRUE(val2 == monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(common_error::kInvalidArgument == val2);
|
EXPECT_TRUE(monero::error::invalid_argument == val2);
|
||||||
EXPECT_NE(val1.error(), std::error_code{});
|
EXPECT_NE(val1.error(), monero::error::none);
|
||||||
EXPECT_NE(val2.error(), std::error_code{});
|
EXPECT_NE(val2.error(), monero::error::none);
|
||||||
EXPECT_TRUE(val1.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(val1.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error::none == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error::none == val2));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error::none != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error::none != val2);
|
||||||
EXPECT_TRUE(val1.matches(std::errc::invalid_argument));
|
EXPECT_TRUE(val1.matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
|
EXPECT_TRUE(val2.matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val1 = std::string{"barfoo"};
|
val1 = std::string{"barfoo"};
|
||||||
|
|
||||||
@ -484,24 +484,24 @@ TEST(Expect, Assignment)
|
|||||||
EXPECT_STREQ(val1.value().c_str(), "barfoo");
|
EXPECT_STREQ(val1.value().c_str(), "barfoo");
|
||||||
EXPECT_TRUE(*val1 == "barfoo");
|
EXPECT_TRUE(*val1 == "barfoo");
|
||||||
EXPECT_TRUE(boost::equals(val1->c_str(), "barfoo"));
|
EXPECT_TRUE(boost::equals(val1->c_str(), "barfoo"));
|
||||||
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
|
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
|
EXPECT_TRUE(val2 == monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(common_error::kInvalidArgument == val2);
|
EXPECT_TRUE(monero::error::invalid_argument == val2);
|
||||||
EXPECT_EQ(val1.error(), std::error_code{});
|
EXPECT_EQ(val1.error(), monero::error::none);
|
||||||
EXPECT_NE(val2.error(), std::error_code{});
|
EXPECT_NE(val2.error(), monero::error::none);
|
||||||
EXPECT_TRUE(!val1.equal(std::error_code{}));
|
EXPECT_TRUE(!val1.equal(monero::error::none));
|
||||||
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error::none == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error::none == val2));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error::none != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error::none != val2);
|
||||||
EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
|
EXPECT_TRUE(val2.matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val2 = val1;
|
val2 = val1;
|
||||||
|
|
||||||
@ -517,20 +517,20 @@ TEST(Expect, Assignment)
|
|||||||
EXPECT_EQ(val2.value(), "barfoo");
|
EXPECT_EQ(val2.value(), "barfoo");
|
||||||
EXPECT_TRUE(*val2 == "barfoo");
|
EXPECT_TRUE(*val2 == "barfoo");
|
||||||
EXPECT_TRUE(boost::equals(val2->c_str(), "barfoo"));
|
EXPECT_TRUE(boost::equals(val2->c_str(), "barfoo"));
|
||||||
EXPECT_EQ(val1.error(), std::error_code{});
|
EXPECT_EQ(val1.error(), monero::error::none);
|
||||||
EXPECT_EQ(val2.error(), std::error_code{});
|
EXPECT_EQ(val2.error(), monero::error::none);
|
||||||
EXPECT_TRUE(!val1.equal(std::error_code{}));
|
EXPECT_TRUE(!val1.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error::none));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error::none == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error::none));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error::none == val2));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error::none != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error::none);
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error::none != val2);
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Expect, AssignmentThrowsOnMove)
|
TEST(Expect, AssignmentThrowsOnMove)
|
||||||
@ -554,14 +554,14 @@ TEST(Expect, AssignmentThrowsOnMove)
|
|||||||
};
|
};
|
||||||
|
|
||||||
expect<throw_on_move> val1{expect<const char*>{"foobar"}};
|
expect<throw_on_move> val1{expect<const char*>{"foobar"}};
|
||||||
expect<throw_on_move> val2{common_error::kInvalidArgument};
|
expect<throw_on_move> val2{monero::error::invalid_argument};
|
||||||
|
|
||||||
ASSERT_TRUE(val1.has_value());
|
ASSERT_TRUE(val1.has_value());
|
||||||
ASSERT_TRUE(val2.has_error());
|
ASSERT_TRUE(val2.has_error());
|
||||||
EXPECT_TRUE(!val1.has_error());
|
EXPECT_TRUE(!val1.has_error());
|
||||||
EXPECT_TRUE(!val2.has_value());
|
EXPECT_TRUE(!val2.has_value());
|
||||||
EXPECT_STREQ(val1->msg.c_str(), "foobar");
|
EXPECT_STREQ(val1->msg.c_str(), "foobar");
|
||||||
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
|
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
|
||||||
|
|
||||||
EXPECT_THROW(val2 = std::move(val1), construct_error);
|
EXPECT_THROW(val2 = std::move(val1), construct_error);
|
||||||
|
|
||||||
@ -570,7 +570,7 @@ TEST(Expect, AssignmentThrowsOnMove)
|
|||||||
EXPECT_TRUE(!val1.has_error());
|
EXPECT_TRUE(!val1.has_error());
|
||||||
EXPECT_TRUE(!val2.has_value());
|
EXPECT_TRUE(!val2.has_value());
|
||||||
EXPECT_STREQ(val1->msg.c_str(), "foobar");
|
EXPECT_STREQ(val1->msg.c_str(), "foobar");
|
||||||
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
|
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
|
||||||
|
|
||||||
EXPECT_THROW(val1 = expect<const char*>{"barfoo"}, assignment_error);
|
EXPECT_THROW(val1 = expect<const char*>{"barfoo"}, assignment_error);
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ TEST(Expect, AssignmentThrowsOnMove)
|
|||||||
EXPECT_TRUE(!val1.has_error());
|
EXPECT_TRUE(!val1.has_error());
|
||||||
EXPECT_TRUE(!val2.has_value());
|
EXPECT_TRUE(!val2.has_value());
|
||||||
EXPECT_STREQ(val1->msg.c_str(), "foobar");
|
EXPECT_STREQ(val1->msg.c_str(), "foobar");
|
||||||
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
|
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
|
||||||
|
|
||||||
EXPECT_NO_THROW(val2 = val1);
|
EXPECT_NO_THROW(val2 = val1);
|
||||||
|
|
||||||
@ -619,9 +619,9 @@ TEST(Expect, EqualWithStrings)
|
|||||||
EXPECT_TRUE(val1.equal(""));
|
EXPECT_TRUE(val1.equal(""));
|
||||||
EXPECT_TRUE(val2.equal("barfoo"));
|
EXPECT_TRUE(val2.equal("barfoo"));
|
||||||
EXPECT_TRUE(val3.equal(""));
|
EXPECT_TRUE(val3.equal(""));
|
||||||
EXPECT_TRUE(!val1.equal(std::error_code{}));
|
EXPECT_TRUE(!val1.equal(monero::error_code{}));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error_code{}));
|
||||||
EXPECT_TRUE(!val3.equal(std::error_code{}));
|
EXPECT_TRUE(!val3.equal(monero::error_code{}));
|
||||||
EXPECT_TRUE(val1 == "");
|
EXPECT_TRUE(val1 == "");
|
||||||
EXPECT_TRUE("" == val1);
|
EXPECT_TRUE("" == val1);
|
||||||
EXPECT_TRUE(val2 == "barfoo");
|
EXPECT_TRUE(val2 == "barfoo");
|
||||||
@ -634,23 +634,23 @@ TEST(Expect, EqualWithStrings)
|
|||||||
EXPECT_TRUE(!("barfoo" != val2));
|
EXPECT_TRUE(!("barfoo" != val2));
|
||||||
EXPECT_TRUE(!(val3 != ""));
|
EXPECT_TRUE(!(val3 != ""));
|
||||||
EXPECT_TRUE(!("" != val3));
|
EXPECT_TRUE(!("" != val3));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error_code{} == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error_code{} == val2));
|
||||||
EXPECT_TRUE(!(val3 == std::error_code{}));
|
EXPECT_TRUE(!(val3 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val3));
|
EXPECT_TRUE(!(monero::error_code{} == val3));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error_code{});
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error_code{} != val1);
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error_code{});
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error_code{} != val2);
|
||||||
EXPECT_TRUE(val3 != std::error_code{});
|
EXPECT_TRUE(val3 != monero::error_code{});
|
||||||
EXPECT_TRUE(std::error_code{} != val3);
|
EXPECT_TRUE(monero::error_code{} != val3);
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val3.matches(std::error_condition{}));
|
EXPECT_TRUE(!val3.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val2 = make_error_code(common_error::kInvalidArgument);
|
val2 = make_error_code(monero::error::invalid_argument);
|
||||||
|
|
||||||
EXPECT_TRUE(!val1.equal(val2));
|
EXPECT_TRUE(!val1.equal(val2));
|
||||||
EXPECT_TRUE(val1.equal(val3));
|
EXPECT_TRUE(val1.equal(val3));
|
||||||
@ -671,15 +671,15 @@ TEST(Expect, EqualWithStrings)
|
|||||||
EXPECT_TRUE(val2 != val3);
|
EXPECT_TRUE(val2 != val3);
|
||||||
EXPECT_TRUE(val3 != val2);
|
EXPECT_TRUE(val3 != val2);
|
||||||
|
|
||||||
EXPECT_TRUE(!val1.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(!val1.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!val3.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(!val3.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
|
EXPECT_TRUE(val2 == monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(common_error::kInvalidArgument == val2);
|
EXPECT_TRUE(monero::error::invalid_argument == val2);
|
||||||
EXPECT_TRUE(!(val2 != common_error::kInvalidArgument));
|
EXPECT_TRUE(!(val2 != monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!(common_error::kInvalidArgument != val2));
|
EXPECT_TRUE(!(monero::error::invalid_argument != val2));
|
||||||
EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
|
EXPECT_TRUE(val2.matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(!val2.matches(std::error_condition{}));
|
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
|
||||||
|
|
||||||
val1 = expect<std::string>{"barfoo"};
|
val1 = expect<std::string>{"barfoo"};
|
||||||
|
|
||||||
@ -707,13 +707,13 @@ TEST(Expect, EqualWithStrings)
|
|||||||
EXPECT_TRUE("barfoo" == val1);
|
EXPECT_TRUE("barfoo" == val1);
|
||||||
EXPECT_TRUE(!(val1 != "barfoo"));
|
EXPECT_TRUE(!(val1 != "barfoo"));
|
||||||
EXPECT_TRUE(!("barfoo" != val1));
|
EXPECT_TRUE(!("barfoo" != val1));
|
||||||
EXPECT_TRUE(!val1.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(!val1.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!(val1 == common_error::kInvalidArgument));
|
EXPECT_TRUE(!(val1 == monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!(common_error::kInvalidArgument == val1));
|
EXPECT_TRUE(!(monero::error::invalid_argument == val1));
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error_code{} == val1));
|
||||||
EXPECT_TRUE(!val1.matches(std::error_condition{}));
|
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
|
||||||
EXPECT_TRUE(!val1.matches(std::errc::invalid_argument));
|
EXPECT_TRUE(!val1.matches(monero::errc::invalid_argument));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Expect, EqualWithVoid)
|
TEST(Expect, EqualWithVoid)
|
||||||
@ -723,40 +723,40 @@ TEST(Expect, EqualWithVoid)
|
|||||||
|
|
||||||
EXPECT_TRUE(val1.equal(val2));
|
EXPECT_TRUE(val1.equal(val2));
|
||||||
EXPECT_TRUE(val2.equal(val1));
|
EXPECT_TRUE(val2.equal(val1));
|
||||||
EXPECT_TRUE(!val1.equal(std::error_code{}));
|
EXPECT_TRUE(!val1.equal(monero::error_code{}));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error_code{}));
|
||||||
EXPECT_TRUE(val1 == val2);
|
EXPECT_TRUE(val1 == val2);
|
||||||
EXPECT_TRUE(val2 == val1);
|
EXPECT_TRUE(val2 == val1);
|
||||||
EXPECT_TRUE(!(val1 == std::error_code{}));
|
EXPECT_TRUE(!(val1 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val1));
|
EXPECT_TRUE(!(monero::error_code{} == val1));
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error_code{} == val2));
|
||||||
EXPECT_TRUE(!(val1 != val2));
|
EXPECT_TRUE(!(val1 != val2));
|
||||||
EXPECT_TRUE(!(val2 != val1));
|
EXPECT_TRUE(!(val2 != val1));
|
||||||
EXPECT_TRUE(val1 != std::error_code{});
|
EXPECT_TRUE(val1 != monero::error_code{});
|
||||||
EXPECT_TRUE(std::error_code{} != val1);
|
EXPECT_TRUE(monero::error_code{} != val1);
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error_code{} == val2));
|
||||||
|
|
||||||
val2 = make_error_code(common_error::kInvalidArgument);
|
val2 = make_error_code(monero::error::invalid_argument);
|
||||||
|
|
||||||
EXPECT_TRUE(!val1.equal(val2));
|
EXPECT_TRUE(!val1.equal(val2));
|
||||||
EXPECT_TRUE(!val2.equal(val1));
|
EXPECT_TRUE(!val2.equal(val1));
|
||||||
EXPECT_TRUE(!val1.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(!val1.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
|
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!val2.equal(std::error_code{}));
|
EXPECT_TRUE(!val2.equal(monero::error_code{}));
|
||||||
EXPECT_TRUE(!(val1 == val2));
|
EXPECT_TRUE(!(val1 == val2));
|
||||||
EXPECT_TRUE(!(val2 == val1));
|
EXPECT_TRUE(!(val2 == val1));
|
||||||
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
|
EXPECT_TRUE(val2 == monero::error::invalid_argument);
|
||||||
EXPECT_TRUE(common_error::kInvalidArgument == val2);
|
EXPECT_TRUE(monero::error::invalid_argument == val2);
|
||||||
EXPECT_TRUE(!(val2 == std::error_code{}));
|
EXPECT_TRUE(!(val2 == monero::error_code{}));
|
||||||
EXPECT_TRUE(!(std::error_code{} == val2));
|
EXPECT_TRUE(!(monero::error_code{} == val2));
|
||||||
EXPECT_TRUE(val1 != val2);
|
EXPECT_TRUE(val1 != val2);
|
||||||
EXPECT_TRUE(val2 != val1);
|
EXPECT_TRUE(val2 != val1);
|
||||||
EXPECT_TRUE(!(val2 != common_error::kInvalidArgument));
|
EXPECT_TRUE(!(val2 != monero::error::invalid_argument));
|
||||||
EXPECT_TRUE(!(common_error::kInvalidArgument != val2));
|
EXPECT_TRUE(!(monero::error::invalid_argument != val2));
|
||||||
EXPECT_TRUE(val2 != std::error_code{});
|
EXPECT_TRUE(val2 != monero::error_code{});
|
||||||
EXPECT_TRUE(std::error_code{} != val2);
|
EXPECT_TRUE(monero::error_code{} != val2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Expect, EqualNoCopies)
|
TEST(Expect, EqualNoCopies)
|
||||||
@ -801,7 +801,7 @@ TEST(Expect, EqualNoCopies)
|
|||||||
EXPECT_TRUE(!(val1 != val3));
|
EXPECT_TRUE(!(val1 != val3));
|
||||||
EXPECT_TRUE(!(val3 != val1));
|
EXPECT_TRUE(!(val3 != val1));
|
||||||
|
|
||||||
expect<throw_on_copy> val4{common_error::kInvalidArgument};
|
expect<throw_on_copy> val4{monero::error::invalid_argument};
|
||||||
|
|
||||||
EXPECT_TRUE(!val4.equal(throw_on_copy{}));
|
EXPECT_TRUE(!val4.equal(throw_on_copy{}));
|
||||||
EXPECT_TRUE(!(val4 == throw_on_copy{}));
|
EXPECT_TRUE(!(val4 == throw_on_copy{}));
|
||||||
@ -817,99 +817,99 @@ TEST(Expect, EqualNoCopies)
|
|||||||
|
|
||||||
TEST(Expect, Macros) {
|
TEST(Expect, Macros) {
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> ::common_error {
|
[] () -> ::monero::error {
|
||||||
MONERO_PRECOND(true);
|
MONERO_PRECOND(true);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidErrorCode
|
} () == monero::error::invalid_error_code
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> ::common_error {
|
[] () -> ::monero::error {
|
||||||
MONERO_PRECOND(false);
|
MONERO_PRECOND(false);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidArgument
|
} () == monero::error::invalid_argument
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> std::error_code {
|
[] () -> monero::error_code {
|
||||||
MONERO_PRECOND(true);
|
MONERO_PRECOND(true);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidErrorCode
|
} () == monero::error::invalid_error_code
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> std::error_code {
|
[] () -> monero::error_code {
|
||||||
MONERO_PRECOND(false);
|
MONERO_PRECOND(false);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidArgument
|
} () == monero::error::invalid_argument
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<void> {
|
[] () -> expect<void> {
|
||||||
MONERO_PRECOND(true);
|
MONERO_PRECOND(true);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidErrorCode
|
} () == monero::error::invalid_error_code
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<void> {
|
[] () -> expect<void> {
|
||||||
MONERO_PRECOND(false);
|
MONERO_PRECOND(false);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidArgument
|
} () == monero::error::invalid_argument
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<int> {
|
[] () -> expect<int> {
|
||||||
MONERO_PRECOND(true);
|
MONERO_PRECOND(true);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidErrorCode
|
} () == monero::error::invalid_error_code
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<int> {
|
[] () -> expect<int> {
|
||||||
MONERO_PRECOND(false);
|
MONERO_PRECOND(false);
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidArgument
|
} () == monero::error::invalid_argument
|
||||||
);
|
);
|
||||||
|
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> std::error_code {
|
[] () -> monero::error_code {
|
||||||
MONERO_CHECK(expect<void>{});
|
MONERO_CHECK(expect<void>{});
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidErrorCode
|
} () == monero::error::invalid_error_code
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> std::error_code {
|
[] () -> monero::error_code {
|
||||||
MONERO_CHECK(expect<void>{common_error::kInvalidArgument});
|
MONERO_CHECK(expect<void>{monero::error::invalid_argument});
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidArgument
|
} () == monero::error::invalid_argument
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<void> {
|
[] () -> expect<void> {
|
||||||
MONERO_CHECK(expect<void>{});
|
MONERO_CHECK(expect<void>{});
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidErrorCode
|
} () == monero::error::invalid_error_code
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<void> {
|
[] () -> expect<void> {
|
||||||
MONERO_CHECK(expect<void>{common_error::kInvalidArgument});
|
MONERO_CHECK(expect<void>{monero::error::invalid_argument});
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidArgument
|
} () == monero::error::invalid_argument
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<int> {
|
[] () -> expect<int> {
|
||||||
MONERO_CHECK(expect<void>{});
|
MONERO_CHECK(expect<void>{});
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidErrorCode
|
} () == monero::error::invalid_error_code
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
[] () -> expect<int> {
|
[] () -> expect<int> {
|
||||||
MONERO_CHECK(expect<void>{common_error::kInvalidArgument});
|
MONERO_CHECK(expect<void>{monero::error::invalid_argument});
|
||||||
return {common_error::kInvalidErrorCode};
|
return {monero::error::invalid_error_code};
|
||||||
} () == common_error::kInvalidArgument
|
} () == monero::error::invalid_argument
|
||||||
);
|
);
|
||||||
|
|
||||||
EXPECT_NO_THROW(MONERO_UNWRAP(success()));
|
EXPECT_NO_THROW(MONERO_UNWRAP(success()));
|
||||||
EXPECT_NO_THROW(MONERO_UNWRAP(expect<void>{}));
|
EXPECT_NO_THROW(MONERO_UNWRAP(expect<void>{}));
|
||||||
EXPECT_NO_THROW(MONERO_UNWRAP(expect<int>{0}));
|
EXPECT_NO_THROW(MONERO_UNWRAP(expect<int>{0}));
|
||||||
EXPECT_THROW(
|
EXPECT_THROW(
|
||||||
MONERO_UNWRAP(expect<void>{common_error::kInvalidArgument}), std::system_error
|
MONERO_UNWRAP(expect<void>{monero::error::invalid_argument}), monero::system_error
|
||||||
);
|
);
|
||||||
EXPECT_THROW(
|
EXPECT_THROW(
|
||||||
MONERO_UNWRAP(expect<int>{common_error::kInvalidArgument}), std::system_error
|
MONERO_UNWRAP(expect<int>{monero::error::invalid_argument}), monero::system_error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ TEST(LMDB, Table)
|
|||||||
static_assert(test.flags == 0, "bad flags");
|
static_assert(test.flags == 0, "bad flags");
|
||||||
static_assert(&lmdb::less<unsigned> == test.key_cmp, "bad key_cmp");
|
static_assert(&lmdb::less<unsigned> == test.key_cmp, "bad key_cmp");
|
||||||
static_assert(test.value_cmp == nullptr, "bad value_cmp");
|
static_assert(test.value_cmp == nullptr, "bad value_cmp");
|
||||||
EXPECT_TRUE(test.get_value<bytes>(MDB_val{}).matches(std::errc::invalid_argument));
|
EXPECT_TRUE(test.get_value<bytes>(MDB_val{}).matches(monero::errc::invalid_argument));
|
||||||
|
|
||||||
lmdb::basic_table<big_choice, one> test2{
|
lmdb::basic_table<big_choice, one> test2{
|
||||||
"foo2", MDB_DUPSORT, &lmdb::compare<one>
|
"foo2", MDB_DUPSORT, &lmdb::compare<one>
|
||||||
@ -200,7 +200,7 @@ TEST(LMDB, Table)
|
|||||||
EXPECT_EQ((MDB_DUPSORT | MDB_DUPFIXED), test2.flags);
|
EXPECT_EQ((MDB_DUPSORT | MDB_DUPFIXED), test2.flags);
|
||||||
EXPECT_EQ(&lmdb::less<unsigned long>, test2.key_cmp);
|
EXPECT_EQ(&lmdb::less<unsigned long>, test2.key_cmp);
|
||||||
EXPECT_EQ(&lmdb::compare<one>, test2.value_cmp);
|
EXPECT_EQ(&lmdb::compare<one>, test2.value_cmp);
|
||||||
EXPECT_TRUE(test2.get_value<one>(MDB_val{}).matches(std::errc::invalid_argument));
|
EXPECT_TRUE(test2.get_value<one>(MDB_val{}).matches(monero::errc::invalid_argument));
|
||||||
|
|
||||||
one record{};
|
one record{};
|
||||||
boost::iota(record.i.data, 0);
|
boost::iota(record.i.data, 0);
|
||||||
@ -216,18 +216,18 @@ TEST(LMDB, Table)
|
|||||||
EXPECT_TRUE(boost::equal(record.j.data, j_copy.data));
|
EXPECT_TRUE(boost::equal(record.j.data, j_copy.data));
|
||||||
|
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
test.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
|
test.get_key_stream(test_cursor{}).matches(monero::errc::invalid_argument)
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
test2.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
|
test2.get_key_stream(test_cursor{}).matches(monero::errc::invalid_argument)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
test.get_value_stream(choice(0), test_cursor{}).matches(std::errc::invalid_argument)
|
test.get_value_stream(choice(0), test_cursor{}).matches(monero::errc::invalid_argument)
|
||||||
);
|
);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
test2.get_value_stream(big_choice(0), test_cursor{}).matches(std::errc::invalid_argument)
|
test2.get_value_stream(big_choice(0), test_cursor{}).matches(monero::errc::invalid_argument)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,14 +235,14 @@ TEST(LMDB, InvalidDatabase)
|
|||||||
{
|
{
|
||||||
lmdb::database test{lmdb::environment{}};
|
lmdb::database test{lmdb::environment{}};
|
||||||
|
|
||||||
EXPECT_TRUE(test.resize().matches(std::errc::invalid_argument));
|
EXPECT_TRUE(test.resize().matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(test.create_read_txn().matches(std::errc::invalid_argument));
|
EXPECT_TRUE(test.create_read_txn().matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(test.reset_txn(lmdb::read_txn{}).matches(std::errc::invalid_argument));
|
EXPECT_TRUE(test.reset_txn(lmdb::read_txn{}).matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(test.create_write_txn().matches(std::errc::invalid_argument));
|
EXPECT_TRUE(test.create_write_txn().matches(monero::errc::invalid_argument));
|
||||||
EXPECT_TRUE(test.commit(lmdb::write_txn{}).matches(std::errc::invalid_argument));
|
EXPECT_TRUE(test.commit(lmdb::write_txn{}).matches(monero::errc::invalid_argument));
|
||||||
|
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
test.try_write( [](MDB_txn&) { return success(); } ).matches(std::errc::invalid_argument)
|
test.try_write( [](MDB_txn&) { return success(); } ).matches(monero::errc::invalid_argument)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1653,7 +1653,7 @@ TEST(zmq, error_codes)
|
|||||||
std::addressof(net::zmq::make_error_code(0).category())
|
std::addressof(net::zmq::make_error_code(0).category())
|
||||||
);
|
);
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
std::make_error_condition(std::errc::not_a_socket),
|
make_error_condition(monero::errc::not_a_socket),
|
||||||
net::zmq::make_error_code(ENOTSOCK)
|
net::zmq::make_error_code(ENOTSOCK)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1662,7 +1662,7 @@ TEST(zmq, error_codes)
|
|||||||
{
|
{
|
||||||
MONERO_ZMQ_CHECK(zmq_msg_send(nullptr, nullptr, 0));
|
MONERO_ZMQ_CHECK(zmq_msg_send(nullptr, nullptr, 0));
|
||||||
return success();
|
return success();
|
||||||
}().matches(std::errc::not_a_socket)
|
}().matches(monero::errc::not_a_socket)
|
||||||
);
|
);
|
||||||
|
|
||||||
bool thrown = false;
|
bool thrown = false;
|
||||||
@ -1670,10 +1670,10 @@ TEST(zmq, error_codes)
|
|||||||
{
|
{
|
||||||
MONERO_ZMQ_THROW("stuff");
|
MONERO_ZMQ_THROW("stuff");
|
||||||
}
|
}
|
||||||
catch (const std::system_error& e)
|
catch (const boost::system::system_error& e)
|
||||||
{
|
{
|
||||||
thrown = true;
|
thrown = true;
|
||||||
EXPECT_EQ(std::make_error_condition(std::errc::not_a_socket), e.code());
|
EXPECT_EQ(make_error_condition(monero::errc::not_a_socket), e.code());
|
||||||
}
|
}
|
||||||
EXPECT_TRUE(thrown);
|
EXPECT_TRUE(thrown);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user