29 #include <gtest/gtest.h> 31 #include <boost/algorithm/string/predicate.hpp> 32 #include <boost/utility/string_ref.hpp> 34 #include <system_error> 35 #include <type_traits> 42 struct throw_construct;
48 move_only() =
default;
49 move_only(move_only
const&) =
delete;
50 move_only(move_only&&) =
default;
51 ~move_only() =
default;
52 move_only&
operator=(move_only
const&) =
delete;
53 move_only&
operator=(move_only&&) =
default;
56 struct throw_construct
59 throw_construct(
int) {}
60 throw_construct(throw_construct
const&) =
default;
61 throw_construct(throw_construct&&) =
default;
62 ~throw_construct() =
default;
63 throw_construct&
operator=(throw_construct
const&) =
default;
64 throw_construct&
operator=(throw_construct&&) =
default;
69 throw_copies() noexcept {}
70 throw_copies(throw_copies
const&) {}
71 throw_copies(throw_copies&&) =
default;
72 ~throw_copies() =
default;
73 throw_copies&
operator=(throw_copies
const&) {
return *
this; }
74 throw_copies&
operator=(throw_copies&&) =
default;
75 bool operator==(throw_copies
const&) noexcept {
return true; }
76 bool operator==(throw_moves
const&) noexcept {
return true; }
81 throw_moves() noexcept {}
82 throw_moves(throw_moves
const&) =
default;
83 throw_moves(throw_moves&&) {}
84 ~throw_moves() =
default;
85 throw_moves&
operator=(throw_moves
const&) =
default;
86 throw_moves&
operator=(throw_moves&&) {
return *
this; }
87 bool operator==(throw_moves
const&) {
return true; }
88 bool operator==(throw_copies
const&) {
return true; }
92 void construction_bench()
102 void noexcept_bench()
119 void conversion_bench()
136 construction_bench<void>();
137 construction_bench<int>();
149 struct implicit { implicit(
int) {} };
150 struct explicit_only {
explicit explicit_only(
int) {} };
152 conversion_bench<void>();
153 conversion_bench<int>();
212 noexcept_bench<void>();
213 noexcept_bench<int>();
341 EXPECT_TRUE(boost::equals(val2->c_str(),
"foobar"));
342 EXPECT_EQ(val1.error(), std::error_code{});
343 EXPECT_EQ(val2.error(), std::error_code{});
354 EXPECT_TRUE(!val1.matches(std::error_condition{}));
355 EXPECT_TRUE(!val2.matches(std::error_condition{}));
367 EXPECT_TRUE(boost::equals(val1->c_str(),
"foobar"));
371 EXPECT_EQ(val1.error(), std::error_code{});
372 EXPECT_EQ(val2.error(), std::error_code{});
383 EXPECT_TRUE(!val1.matches(std::error_condition{}));
384 EXPECT_TRUE(!val2.matches(std::error_condition{}));
396 EXPECT_TRUE(boost::equals(val1->c_str(),
"foobar"));
399 EXPECT_TRUE(boost::equals(val2->c_str(),
"foobar"));
400 EXPECT_EQ(val1.error(), std::error_code{});
401 EXPECT_EQ(val2.error(), std::error_code{});
412 EXPECT_TRUE(!val1.matches(std::error_condition{}));
413 EXPECT_TRUE(!val2.matches(std::error_condition{}));
428 EXPECT_TRUE(boost::equals(val2->c_str(),
"foobar"));
429 EXPECT_NE(val1.error(), std::error_code{});
430 EXPECT_EQ(val2.error(), std::error_code{});
441 EXPECT_TRUE(val1.matches(std::errc::invalid_argument));
442 EXPECT_TRUE(!val1.matches(std::error_condition{}));
443 EXPECT_TRUE(!val2.matches(std::error_condition{}));
459 EXPECT_NE(val1.error(), std::error_code{});
460 EXPECT_NE(val2.error(), std::error_code{});
471 EXPECT_TRUE(val1.matches(std::errc::invalid_argument));
472 EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
473 EXPECT_TRUE(!val1.matches(std::error_condition{}));
474 EXPECT_TRUE(!val2.matches(std::error_condition{}));
486 EXPECT_TRUE(boost::equals(val1->c_str(),
"barfoo"));
490 EXPECT_EQ(val1.error(), std::error_code{});
491 EXPECT_NE(val2.error(), std::error_code{});
502 EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
503 EXPECT_TRUE(!val1.matches(std::error_condition{}));
504 EXPECT_TRUE(!val2.matches(std::error_condition{}));
516 EXPECT_TRUE(boost::equals(val1->c_str(),
"barfoo"));
519 EXPECT_TRUE(boost::equals(val2->c_str(),
"barfoo"));
520 EXPECT_EQ(val1.error(), std::error_code{});
521 EXPECT_EQ(val2.error(), std::error_code{});
532 EXPECT_TRUE(!val1.matches(std::error_condition{}));
533 EXPECT_TRUE(!val2.matches(std::error_condition{}));
538 struct construct_error {};
539 struct assignment_error {};
541 struct throw_on_move {
544 throw_on_move(
const char* msg) : msg(msg) {}
545 throw_on_move(throw_on_move&&) {
546 throw construct_error{};
548 throw_on_move(throw_on_move
const&) =
default;
549 ~throw_on_move() =
default;
550 throw_on_move&
operator=(throw_on_move&&) {
551 throw assignment_error{};
553 throw_on_move&
operator=(throw_on_move
const&) =
default;
649 EXPECT_TRUE(!val1.matches(std::error_condition{}));
650 EXPECT_TRUE(!val2.matches(std::error_condition{}));
651 EXPECT_TRUE(!val3.matches(std::error_condition{}));
681 EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
682 EXPECT_TRUE(!val2.matches(std::error_condition{}));
715 EXPECT_TRUE(!val1.matches(std::error_condition{}));
716 EXPECT_TRUE(!val1.matches(std::errc::invalid_argument));
764 struct copy_error {};
766 struct throw_on_copy {
767 throw_on_copy() =
default;
768 throw_on_copy(
int) noexcept {}
769 throw_on_copy(throw_on_copy
const&) {
772 ~throw_on_copy() =
default;
773 throw_on_copy&
operator=(throw_on_copy
const&) {
777 bool operator==(throw_on_copy
const&)
const noexcept {
return true; }
832 [] () -> std::error_code {
838 [] () -> std::error_code {
869 [] () -> std::error_code {
875 [] () -> std::error_code {
#define EXPECT_NO_THROW(statement)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_THROW(statement, expected_exception)
std::error_code make_error_code(::common_error value) noexcept
bool operator==(const some_test_data &a, const some_test_data &b)
A function argument is invalid.
void Expect(bool condition, const char *file, int line, const string &msg)
bool equal(expect const &rhs) const noexcept
#define ELECTRONEUM_CHECK(...)
Check expect<void> and return errors in current scope.
#define EXPECT_NE(val1, val2)
expect< void > success() noexcept
#define ELECTRONEUM_UNWRAP(...)
TEST(Expect, Constructions)
const T & move(const T &t)
#define ASSERT_TRUE(condition)
#define ELECTRONEUM_PRECOND(...)
If precondition fails, return ::error::kInvalidArgument in current scope.
Default std::error_code given to expect<T>
connection< TProtocol > & operator=(const connection< TProtocol > &obj)
error
Tracks LMDB error codes.
#define EXPECT_EQ(val1, val2)