1 #include "lib/shuffler.h"
3 #include "lib/content_video.h"
4 #include <boost/test/unit_test.hpp>
10 #if BOOST_VERSION >= 106100
11 using namespace boost::placeholders;
16 push (Shuffler& s, int frame, Eyes eyes)
18 shared_ptr<Piece> piece (new Piece (shared_ptr<Content>(), shared_ptr<Decoder>(), FrameRateChange(24, 24)));
25 list<ContentVideo> pending_cv;
28 receive (weak_ptr<Piece>, ContentVideo cv)
30 pending_cv.push_back (cv);
34 check (int frame, Eyes eyes, int line)
36 BOOST_REQUIRE_MESSAGE (!pending_cv.empty(), "Check at " << line << " failed.");
37 BOOST_CHECK_MESSAGE (pending_cv.front().frame == frame, "Check at " << line << " failed.");
38 BOOST_CHECK_MESSAGE (pending_cv.front().eyes == eyes, "Check at " << line << " failed.");
39 pending_cv.pop_front();
42 /** A perfect sequence */
43 BOOST_AUTO_TEST_CASE (shuffler_test1)
46 s.Video.connect (boost::bind (&receive, _1, _2));
48 for (int i = 0; i < 10; ++i) {
49 push (s, i, Eyes::LEFT);
50 push (s, i, Eyes::RIGHT);
51 check (i, Eyes::LEFT, __LINE__);
52 check (i, Eyes::RIGHT, __LINE__);
56 /** Everything present but some simple shuffling needed */
57 BOOST_AUTO_TEST_CASE (shuffler_test2)
60 s.Video.connect (boost::bind (&receive, _1, _2));
62 for (int i = 0; i < 10; i += 2) {
63 push (s, i, Eyes::LEFT);
64 push (s, i + 1, Eyes::LEFT);
65 push (s, i, Eyes::RIGHT);
66 push (s, i + 1, Eyes::RIGHT);
67 check (i, Eyes::LEFT, __LINE__);
68 check (i, Eyes::RIGHT, __LINE__);
69 check (i + 1, Eyes::LEFT, __LINE__);
70 check (i + 1, Eyes::RIGHT, __LINE__);
74 /** One missing left eye image */
75 BOOST_AUTO_TEST_CASE (shuffler_test3)
78 s.Video.connect (boost::bind (&receive, _1, _2));
80 push (s, 0, Eyes::LEFT);
81 check (0, Eyes::LEFT, __LINE__);
82 push (s, 0, Eyes::RIGHT);
83 check (0, Eyes::RIGHT, __LINE__);
84 push (s, 1, Eyes::LEFT);
85 check (1, Eyes::LEFT, __LINE__);
86 push (s, 1, Eyes::RIGHT);
87 check (1, Eyes::RIGHT, __LINE__);
88 push (s, 2, Eyes::RIGHT);
89 push (s, 3, Eyes::LEFT);
90 push (s, 3, Eyes::RIGHT);
91 push (s, 4, Eyes::LEFT);
92 push (s, 4, Eyes::RIGHT);
94 check (2, Eyes::RIGHT, __LINE__);
95 check (3, Eyes::LEFT, __LINE__);
96 check (3, Eyes::RIGHT, __LINE__);
97 check (4, Eyes::LEFT, __LINE__);
98 check (4, Eyes::RIGHT, __LINE__);
101 /** One missing right eye image */
102 BOOST_AUTO_TEST_CASE (shuffler_test4)
105 s.Video.connect (boost::bind (&receive, _1, _2));
107 push (s, 0, Eyes::LEFT);
108 check (0, Eyes::LEFT, __LINE__);
109 push (s, 0, Eyes::RIGHT);
110 check (0, Eyes::RIGHT, __LINE__);
111 push (s, 1, Eyes::LEFT);
112 check (1, Eyes::LEFT, __LINE__);
113 push (s, 1, Eyes::RIGHT);
114 check (1, Eyes::RIGHT, __LINE__);
115 push (s, 2, Eyes::LEFT);
116 push (s, 3, Eyes::LEFT);
117 push (s, 3, Eyes::RIGHT);
118 push (s, 4, Eyes::LEFT);
119 push (s, 4, Eyes::RIGHT);
121 check (2, Eyes::LEFT, __LINE__);
122 check (3, Eyes::LEFT, __LINE__);
123 check (3, Eyes::RIGHT, __LINE__);
124 check (4, Eyes::LEFT, __LINE__);
125 check (4, Eyes::RIGHT, __LINE__);
129 BOOST_AUTO_TEST_CASE (shuffler_test5)
132 s.Video.connect (boost::bind (&receive, _1, _2));
134 /* One left should come out straight away */
135 push (s, 0, Eyes::LEFT);
136 check (0, Eyes::LEFT, __LINE__);
138 /* More lefts should be kept in the shuffler in the hope that some rights arrive */
139 for (int i = 0; i < s._max_size; ++i) {
140 push (s, i + 1, Eyes::LEFT);
142 BOOST_CHECK (pending_cv.empty ());
144 /* If enough lefts come the shuffler should conclude that there's no rights and start
145 giving out the lefts.
147 push (s, s._max_size + 1, Eyes::LEFT);
148 check (1, Eyes::LEFT, __LINE__);
151 /** One complete frame (L+R) missing.
152 Shuffler should carry on, skipping this frame, as the player will cope with it.
154 BOOST_AUTO_TEST_CASE (shuffler_test6)
157 s.Video.connect (boost::bind (&receive, _1, _2));
159 push (s, 0, Eyes::LEFT);
160 check (0, Eyes::LEFT, __LINE__);
161 push (s, 0, Eyes::RIGHT);
162 check (0, Eyes::RIGHT, __LINE__);
164 push (s, 2, Eyes::LEFT);
165 push (s, 2, Eyes::RIGHT);
166 check (2, Eyes::LEFT, __LINE__);
167 check (2, Eyes::RIGHT, __LINE__);
169 push (s, 3, Eyes::LEFT);
170 check (3, Eyes::LEFT, __LINE__);
171 push (s, 3, Eyes::RIGHT);
172 check (3, Eyes::RIGHT, __LINE__);