1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "rxcpp/rx.hpp"
namespace rxu=rxcpp::util;
namespace rxsc=rxcpp::schedulers;
#include "rxcpp/rx-test.hpp"
#include "catch.hpp"
SCENARIO("map stops on completion", "[map][operators]"){
GIVEN("a test hot observable of ints"){
auto sc = rxsc::make_test();
auto w = sc.create_worker();
const rxsc::test::messages<int> on;
long invoked = 0;
auto xs = sc.make_hot_observable({
on.next(180, 1),
on.next(210, 2),
on.next(240, 3),
on.next(290, 4),
on.next(350, 5),
on.completed(400),
on.next(410, -1),
on.completed(420),
on.error(430, std::runtime_error("error on unsubscribed stream"))
});
WHEN("mapped to ints that are one larger"){
auto res = w.start(
[xs, &invoked]() {
return xs
.map([&invoked](int x) {
invoked++;
return x + 1;
})
// forget type to workaround lambda deduction bug on msvc 2013
.as_dynamic();
}
);
THEN("the output stops on completion"){
auto required = rxu::to_vector({
on.next(210, 3),
on.next(240, 4),
on.next(290, 5),
on.next(350, 6),
on.completed(400)
});
auto actual = res.get_observer().messages();
REQUIRE(required == actual);
}
THEN("there was one subscription and one unsubscription"){
auto required = rxu::to_vector({
on.subscribe(200, 400)
});
auto actual = xs.subscriptions();
REQUIRE(required == actual);
}
THEN("map was called until completed"){
REQUIRE(4 == invoked);
}
}
}
}
|