Commit ea9ffd8f authored by Dominik Charousset's avatar Dominik Charousset Committed by Dominik Charousset

Make .with optional in expected() clauses

parent cbd91767
...@@ -174,6 +174,12 @@ public: ...@@ -174,6 +174,12 @@ public:
// nop // nop
} }
virtual ~expect_clause_base() {
CAF_ASSERT(peek_ != nullptr);
peek_();
run_once();
}
Derived& from(const wildcard&) { Derived& from(const wildcard&) {
return dref(); return dref();
} }
...@@ -191,7 +197,7 @@ public: ...@@ -191,7 +197,7 @@ public:
auto ptr = peek_mailbox(dest_); auto ptr = peek_mailbox(dest_);
CAF_REQUIRE(ptr != nullptr); CAF_REQUIRE(ptr != nullptr);
if (src_) if (src_)
CAF_REQUIRE_EQUAL(ptr->sender, src_); CAF_CHECK_EQUAL(ptr->sender, src_);
return dref(); return dref();
} }
...@@ -237,6 +243,7 @@ protected: ...@@ -237,6 +243,7 @@ protected:
bool mock_dest_; bool mock_dest_;
caf::strong_actor_ptr src_; caf::strong_actor_ptr src_;
caf::local_actor* dest_; caf::local_actor* dest_;
std::function<void ()> peek_;
}; };
template <class... Ts> template <class... Ts>
...@@ -245,16 +252,20 @@ public: ...@@ -245,16 +252,20 @@ public:
template <class... Us> template <class... Us>
expect_clause(Us&&... xs) expect_clause(Us&&... xs)
: expect_clause_base<expect_clause<Ts...>>(std::forward<Us>(xs)...) { : expect_clause_base<expect_clause<Ts...>>(std::forward<Us>(xs)...) {
// nop this->peek_ = [=] {
this->template peek<Ts...>();
};
} }
template <class... Us> template <class... Us>
void with(Us&&... xs) { void with(Us&&... xs) {
// TODO: move tmp into lambda when switching to C++14
auto tmp = std::make_tuple(std::forward<Us>(xs)...); auto tmp = std::make_tuple(std::forward<Us>(xs)...);
this->peek_ = [=] {
elementwise_compare_inspector<decltype(tmp)> inspector{tmp}; elementwise_compare_inspector<decltype(tmp)> inspector{tmp};
auto ys = this->template peek<Ts...>(); auto ys = this->template peek<Ts...>();
CAF_CHECK(inspector(get<0>(ys))); CAF_CHECK(inspector(get<0>(ys)));
this->run_once(); };
} }
}; };
...@@ -266,15 +277,21 @@ public: ...@@ -266,15 +277,21 @@ public:
template <class... Us> template <class... Us>
expect_clause(Us&&... xs) expect_clause(Us&&... xs)
: expect_clause_base<expect_clause<T>>(std::forward<Us>(xs)...) { : expect_clause_base<expect_clause<T>>(std::forward<Us>(xs)...) {
// nop this->peek_ = [=] {
std::integral_constant<bool, has_outer_type<T>::value> token;
type_check<T>(token);
};
} }
template <class... Us> template <class... Us>
void with(Us&&... xs) { void with(Us&&... xs) {
std::integral_constant<bool, has_outer_type<T>::value> token; // TODO: move tmp into lambda when switching to C++14
auto tmp = std::make_tuple(std::forward<Us>(xs)...); auto tmp = std::make_tuple(std::forward<Us>(xs)...);
this->peek_ = [=] {
std::integral_constant<bool, has_outer_type<T>::value> token;
with_content(token, tmp); with_content(token, tmp);
this->run_once(); };
} }
private: private:
...@@ -296,6 +313,19 @@ private: ...@@ -296,6 +313,19 @@ private:
CAF_CHECK(inspect(inspector, const_cast<T&>(get<T>(x0)))); CAF_CHECK(inspect(inspector, const_cast<T&>(get<T>(x0))));
} }
template <class U>
void type_check(std::integral_constant<bool, false>) {
this->template peek<U>();
}
template <class U>
void type_check(std::integral_constant<bool, true>) {
auto xs = this->template peek<typename U::outer_type>();
auto& x0 = get<0>(xs);
if (!is<U>(x0)) {
CAF_FAIL("is<T>(x0) !! " << caf::deep_to_string(x0));
}
}
}; };
template <> template <>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment