#pragma once #if !defined(RXCPP_RX_TEST_HPP) #define RXCPP_RX_TEST_HPP #include "rx-includes.hpp" namespace rxcpp { namespace test { namespace detail { template struct test_subject_base : public std::enable_shared_from_this> { typedef rxn::recorded::type> recorded_type; typedef std::shared_ptr> type; virtual ~test_subject_base() {} virtual void on_subscribe(subscriber) const =0; virtual std::vector messages() const =0; virtual std::vector subscriptions() const =0; }; template struct test_source : public rxs::source_base { explicit test_source(typename test_subject_base::type ts) : ts(std::move(ts)) { if (!this->ts) std::terminate(); } typename test_subject_base::type ts; void on_subscribe(subscriber o) const { ts->on_subscribe(std::move(o)); } template typename std::enable_if>::value, void>::type on_subscribe(Subscriber o) const { static_assert(is_subscriber::value, "on_subscribe must be passed a subscriber."); ts->on_subscribe(o.as_dynamic()); } }; } template class testable_observer : public observer { typedef observer observer_base; typedef typename detail::test_subject_base::type test_subject; test_subject ts; public: typedef typename detail::test_subject_base::recorded_type recorded_type; testable_observer(test_subject ts, observer_base ob) : observer_base(std::move(ob)) , ts(std::move(ts)) { } std::vector messages() const { return ts->messages(); } }; //struct tag_test_observable : public tag_observable {}; /*! \brief a source of values that records the time of each subscription/unsubscription and all the values and the time they were emitted. \ingroup group-observable */ template class testable_observable : public observable> { typedef observable> observable_base; typedef typename detail::test_subject_base::type test_subject; test_subject ts; //typedef tag_test_observable observable_tag; public: typedef typename detail::test_subject_base::recorded_type recorded_type; explicit testable_observable(test_subject ts) : observable_base(detail::test_source(ts)) , ts(ts) { } std::vector subscriptions() const { return ts->subscriptions(); } std::vector messages() const { return ts->messages(); } }; } namespace rxt=test; } // // support range() >> filter() >> subscribe() syntax // '>>' is spelled 'stream' // template auto operator >> (const rxcpp::test::testable_observable& source, OperatorFactory&& of) -> decltype(source.op(std::forward(of))) { return source.op(std::forward(of)); } // // support range() | filter() | subscribe() syntax // '|' is spelled 'pipe' // template auto operator | (const rxcpp::test::testable_observable& source, OperatorFactory&& of) -> decltype(source.op(std::forward(of))) { return source.op(std::forward(of)); } #include "schedulers/rx-test.hpp" #endif