1 #include "../test.h"
2 
3 SCENARIO("subscriber traits", "[observer][traits]"){
4     GIVEN("given some subscriber types"){
5         int result = 0;
__anon7cebc36b0102(int i)6         auto next = [&result](int i){result += i;};
__anon7cebc36b0202(rxu::error_ptr)7         auto error = [&result](rxu::error_ptr){result += 10;};
__anon7cebc36b0302()8         auto completed = [&result](){result += 100;};
9 //        auto ra = rx::rxu::detail::arg_resolver_n<0, rx::tag_resumption_resolution::template predicate, typename rx::tag_resumption_resolution::default_type, rx::resumption, decltype(next), decltype(error), decltype(completed), rx::rxu::detail::tag_unresolvable, rx::rxu::detail::tag_unresolvable>(rx::resumption(), next, error, completed, rx::rxu::detail::tag_unresolvable(), rx::rxu::detail::tag_unresolvable());
10 //        auto ra = typename rx::rxu::detail::arg_resolver<rx::tag_resumption_resolution::template predicate, typename rx::tag_resumption_resolution::default_type, rx::resumption, decltype(next), decltype(error), decltype(completed)>::type(rx::resumption(), next, error, completed, rx::rxu::detail::tag_unresolvable(), rx::rxu::detail::tag_unresolvable());
11 //        auto arg = rx::rxu::detail::resolve_arg<rx::tag_resumption_resolution::template predicate, typename rx::tag_resumption_resolution::default_type>(rx::resumption(), next, error, completed);
12 //        auto argset = rx::rxu::detail::resolve_arg_set(rxcpp::detail::tag_subscriber_set<int>(), rx::resumption(), next, error, completed);
13 //        auto o = rx::detail::make_observer_resolved<int>(argset);
14 //        auto o = rx::detail::select_observer<int>(argset);
15 //        auto scrbResult = rx::subscriber<int, decltype(o)>(std::move(std::get<0>(argset).value), std::move(std::get<1>(argset).value), o);
16 //        static_assert(std::tuple_element<1, decltype(argset)>::type::is_arg, "resumption is a required parameter");
17 //        auto scrbResult = rx::detail::make_subscriber_resolved<int>(rx::rxu::detail::resolve_arg_set(rx::detail::tag_subscriber_set<int>(), rx::resumption(), next, error, completed));
18 //        auto scrbResult = rx::detail::make_subscriber_resolved<int>(argset);
19         auto scrbResult = rx::make_subscriber<int>(next, error, completed);
20         auto scrbdup = rx::make_subscriber<int>(scrbResult);
21         auto scrbop = rx::make_subscriber<int>(scrbResult, next, error, completed);
22         auto scrbsharelifetime = rx::make_subscriber<int>(scrbResult, scrbop.get_observer());
23         auto scrbuniquelifetime = rx::make_subscriber<int>(scrbResult, rx::composite_subscription());
24 
__anon7cebc36b0402(int)25         auto emptyNext = [](int){};
26         auto scrb = rx::make_subscriber<int>(emptyNext);
27         WHEN("tested"){
28             THEN("is_observer value is true for subscriber"){
29                 REQUIRE(rx::is_observer<decltype(scrb)>::value);
30             }
31             THEN("is_subscription value is true for subscriber"){
32                 REQUIRE(rx::is_subscription<decltype(scrb)>::value);
33             }
34         }
35         WHEN("nothing is called"){
36             THEN("static_observer result is 0"){
37                 REQUIRE(result == 0);
38             }
39         }
40         WHEN("onnext is called with 1"){
41             THEN("subscriber result is 1"){
42                 scrbResult.on_next(1);
43                 REQUIRE(result == 1);
44             }
45         }
46         WHEN("after error"){
47             THEN("subscriber result is 10"){
48                 scrbResult.on_error(rxu::current_exception());
49                 REQUIRE(result == 10);
50             }
51         }
52         WHEN("after completed"){
53             THEN("subscriber result is 100"){
54                 scrbResult.on_completed();
55                 REQUIRE(result == 100);
56             }
57         }
58     }
59 }
60 
61 SCENARIO("observer traits", "[observer][traits]"){
62     GIVEN("given some observer types"){
__anon7cebc36b0502(int)63         auto emptyNext = [](int){};
64         auto dob = rx::make_observer_dynamic<int>(emptyNext);
65         auto so = rx::make_observer<int>(emptyNext);
66         auto eo = rx::make_observer<int>();
67         WHEN("tested"){
68             THEN("is_observer value is true for dynamic_observer"){
69                 REQUIRE(rx::is_observer<decltype(dob)>::value);
70             }
71             THEN("is_observer value is true for static_observer"){
72                 REQUIRE(rx::is_observer<decltype(so)>::value);
73             }
74             THEN("is_observer value is true for observer<void>"){
75                 REQUIRE(rx::is_observer<decltype(eo)>::value);
76             }
77         }
78     }
79 }
80 
81 SCENARIO("non-observer traits", "[observer][traits]"){
82     GIVEN("given some subscription types"){
__anon7cebc36b0602()83         auto empty = [](){};
84         rx::static_subscription<decltype(empty)> ss(empty);
85         auto es = rx::make_subscription();
86         rx::composite_subscription cs;
87         WHEN("tested"){
88             THEN("is_observer value is false for static_subscription"){
89                 REQUIRE(!rx::is_observer<decltype(ss)>::value);
90             }
91             THEN("is_observer value is false for subscription<void>"){
92                 REQUIRE(!rx::is_observer<decltype(es)>::value);
93             }
94             THEN("is_observer value is false for composite_subscription"){
95                 REQUIRE(!rx::is_observer<decltype(cs)>::value);
96             }
97         }
98     }
99 }
100 
101 SCENARIO("subscriber behavior", "[observer][traits]"){
102     GIVEN("given some subscriber types"){
103         int result = 0;
__anon7cebc36b0702(int i)104         auto next = [&result](int i){result += i;};
__anon7cebc36b0802(rxu::error_ptr)105         auto error = [&result](rxu::error_ptr){result += 10;};
__anon7cebc36b0902()106         auto completed = [&result](){result += 100;};
107         auto dob = rx::make_subscriber<int>(rx::make_observer_dynamic<int>(next, error, completed));
108         auto so = rx::make_subscriber<int>(next, error, completed);
109         WHEN("nothing is called"){
110             THEN("dynamic_observer result is 0"){
111                 REQUIRE(result == 0);
112             }
113             THEN("static_observer result is 0"){
114                 REQUIRE(result == 0);
115             }
116             THEN("observer<void> result is 0"){
117                 REQUIRE(result == 0);
118             }
119             THEN("dynamic_observer is subscribed"){
120                 REQUIRE(dob.is_subscribed());
121             }
122             THEN("static_observer is subscribed"){
123                 REQUIRE(so.is_subscribed());
124             }
125         }
126         WHEN("onnext is called with 1"){
127             THEN("dynamic_observer result is 1"){
128                 dob.on_next(1);
129                 REQUIRE(result == 1);
130             }
131             THEN("static_observer result is 1"){
132                 so.on_next(1);
133                 REQUIRE(result == 1);
134             }
135             THEN("dynamic_observer is subscribed"){
136                 dob.on_next(1);
137                 REQUIRE(dob.is_subscribed());
138             }
139             THEN("static_observer is subscribed"){
140                 so.on_next(1);
141                 REQUIRE(so.is_subscribed());
142             }
143         }
144         WHEN("after error"){
145             THEN("dynamic_observer result is 10"){
146                 dob.on_error(rxu::current_exception());
147                 REQUIRE(result == 10);
148             }
149             THEN("static_observer result is 10"){
150                 so.on_error(rxu::current_exception());
151                 REQUIRE(result == 10);
152             }
153             THEN("dynamic_observer is not subscribed"){
154                 dob.on_error(rxu::current_exception());
155                 REQUIRE(!dob.is_subscribed());
156             }
157             THEN("static_observer is not subscribed"){
158                 so.on_error(rxu::current_exception());
159                 REQUIRE(!so.is_subscribed());
160             }
161         }
162         WHEN("after completed"){
163             THEN("dynamic_observer result is 100"){
164                 dob.on_completed();
165                 REQUIRE(result == 100);
166             }
167             THEN("static_observer result is 100"){
168                 so.on_completed();
169                 REQUIRE(result == 100);
170             }
171             THEN("dynamic_observer is not subscribed"){
172                 dob.on_completed();
173                 REQUIRE(!dob.is_subscribed());
174             }
175             THEN("static_observer is not subscribed"){
176                 so.on_completed();
177                 REQUIRE(!so.is_subscribed());
178             }
179         }
180     }
181 }
182