Add on_snoop Lua callback
[lsnes.git] / movietrunctest.cpp
blobc3eeb860606c999ece4edb2b51b6b155901cccac
1 #include "movie.hpp"
2 #include <iostream>
4 void truncate_past_complete_frame()
6 short in1, in2;
7 std::cerr << "Test #1: Truncate past complete frame" << std::endl;
8 movie m;
9 std::vector<uint8_t> state;
10 controls_t c;
11 m.readonly_mode(false);
12 m.next_frame();
13 c(4) = 0x1;
14 c(5) = 0x2;
15 m.set_controls(c);
16 in1 = m.next_input(4);
17 if(in1 != 0x1) {
18 std::cerr << "FAIL: Unexpected return for m.next_input(4) (1)" << std::endl;
19 std::cerr << "Expected 1, got " << in1 << "." << std::endl;
20 return;
22 in2 = m.next_input(5);
23 if(in2 != 0x2) {
24 std::cerr << "FAIL: Unexpected return for m.next_input(5) (1)" << std::endl;
25 return;
27 m.next_frame();
28 c(4) = 0x3;
29 c(5) = 0x4;
30 m.set_controls(c);
31 in1 = m.next_input(4);
32 if(in1 != 0x3) {
33 std::cerr << "FAIL: Unexpected return for m.next_input(4) (2)" << std::endl;
34 return;
36 in2 = m.next_input(5);
37 if(in2 != 0x4) {
38 std::cerr << "FAIL: Unexpected return for m.next_input(5) (2)" << std::endl;
39 return;
41 c(4) = 0x5;
42 c(5) = 0x6;
43 m.set_controls(c);
44 in1 = m.next_input(4);
45 if(in1 != 0x5) {
46 std::cerr << "FAIL: Unexpected return for m.next_input(4) (3)" << std::endl;
47 return;
49 in2 = m.next_input(5);
50 if(in2 != 0x6) {
51 std::cerr << "FAIL: Unexpected return for m.next_input(5) (3)" << std::endl;
52 return;
54 m.next_frame();
55 state = m.save_state();
56 c(4) = 0x7;
57 c(5) = 0x8;
58 m.set_controls(c);
59 in1 = m.next_input(4);
60 if(in1 != 0x7) {
61 std::cerr << "FAIL: Unexpected return for m.next_input(4) (4)" << std::endl;
62 return;
64 in2 = m.next_input(5);
65 if(in2 != 0x8) {
66 std::cerr << "FAIL: Unexpected return for m.next_input(5) (4)" << std::endl;
67 return;
69 m.next_frame();
70 c(4) = 0x9;
71 c(5) = 0xa;
72 m.set_controls(c);
73 in1 = m.next_input(4);
74 if(in1 != 0x9) {
75 std::cerr << "FAIL: Unexpected return for m.next_input(4) (5)" << std::endl;
76 return;
78 in2 = m.next_input(5);
79 if(in2 != 0xa) {
80 std::cerr << "FAIL: Unexpected return for m.next_input(5) (5)" << std::endl;
81 return;
83 m.restore_state(state, false);
84 std::vector<controls_t> v = m.save();
85 if(v.size() != 3) {
86 std::cerr << "FAIL: Unexpected size for movie" << std::endl;
87 return;
89 if(v[0](0) != 1 || v[0](4) != 0x1 || v[0](5) != 0x2) {
90 std::cerr << "FAIL: Wrong input for first frame" << std::endl;
91 return;
93 if(v[1](0) != 1 || v[1](4) != 0x3 || v[1](5) != 0x4) {
94 std::cerr << "FAIL: Wrong input for second frame first subframe" << std::endl;
95 return;
97 if(v[2](0) != 0 || v[2](4) != 0x5 || v[2](5) != 0x6) {
98 std::cerr << "FAIL: Wrong input for second frame second subframe" << std::endl;
99 return;
101 std::cerr << "PASS!" << std::endl;
104 void truncate_past_incomplete_frame()
106 short in1, in2;
107 std::cerr << "Test #2: Truncate past incomplete frame" << std::endl;
108 movie m;
109 std::vector<uint8_t> state;
110 controls_t c;
111 m.readonly_mode(false);
112 m.next_frame();
113 c(4) = 0x1;
114 c(5) = 0x2;
115 m.set_controls(c);
116 in1 = m.next_input(4);
117 if(in1 != 0x1) {
118 std::cerr << "FAIL: Unexpected return for m.next_input(4) (1)" << std::endl;
119 std::cerr << "Expected 1, got " << in1 << "." << std::endl;
120 return;
122 in2 = m.next_input(5);
123 if(in2 != 0x2) {
124 std::cerr << "FAIL: Unexpected return for m.next_input(5) (1)" << std::endl;
125 return;
127 m.next_frame();
128 c(4) = 0x3;
129 c(5) = 0x4;
130 m.set_controls(c);
131 in1 = m.next_input(4);
132 if(in1 != 0x3) {
133 std::cerr << "FAIL: Unexpected return for m.next_input(4) (2)" << std::endl;
134 return;
136 in2 = m.next_input(5);
137 if(in2 != 0x4) {
138 std::cerr << "FAIL: Unexpected return for m.next_input(5) (2)" << std::endl;
139 return;
141 c(4) = 0x5;
142 c(5) = 0x6;
143 m.set_controls(c);
144 in1 = m.next_input(4);
145 if(in1 != 0x5) {
146 std::cerr << "FAIL: Unexpected return for m.next_input(4) (3)" << std::endl;
147 return;
149 in2 = m.next_input(5);
150 if(in2 != 0x6) {
151 std::cerr << "FAIL: Unexpected return for m.next_input(5) (3)" << std::endl;
152 return;
154 c(5) = 0x7;
155 c(6) = 0x8;
156 m.set_controls(c);
157 in1 = m.next_input(5);
158 if(in1 != 0x7) {
159 std::cerr << "FAIL: Unexpected return for m.next_input(5) (4)" << std::endl;
160 return;
162 in2 = m.next_input(6);
163 if(in2 != 0x8) {
164 std::cerr << "FAIL: Unexpected return for m.next_input(6) (4)" << std::endl;
165 return;
167 state = m.save_state();
168 //Now we have 2 subframes on 4, 3 on 5 and 1 on 6. Add 1 subframe for 4, 5 and 7.
169 c(4) = 0x9;
170 c(5) = 0xa;
171 c(7) = 0xb;
172 m.set_controls(c);
173 in1 = m.next_input(4);
174 if(in1 != 0x9) {
175 std::cerr << "FAIL: Unexpected return for m.next_input(4) (5)" << std::endl;
176 return;
178 in1 = m.next_input(5);
179 if(in1 != 0xa) {
180 std::cerr << "FAIL: Unexpected return for m.next_input(5) (5)" << std::endl;
181 return;
183 in2 = m.next_input(7);
184 if(in2 != 0xb) {
185 std::cerr << "FAIL: Unexpected return for m.next_input(7) (5)" << std::endl;
186 return;
188 m.next_frame();
189 c(4) = 0xc;
190 c(5) = 0xd;
191 m.set_controls(c);
192 in1 = m.next_input(4);
193 if(in1 != 0xc) {
194 std::cerr << "FAIL: Unexpected return for m.next_input(4) (6)" << std::endl;
195 return;
197 in2 = m.next_input(5);
198 if(in2 != 0xd) {
199 std::cerr << "FAIL: Unexpected return for m.next_input(5) (6)" << std::endl;
200 return;
202 m.next_frame();
203 c(4) = 0xe;
204 c(5) = 0xf;
205 m.set_controls(c);
206 in1 = m.next_input(4);
207 if(in1 != 0xe) {
208 std::cerr << "FAIL: Unexpected return for m.next_input(4) (7)" << std::endl;
209 return;
211 in2 = m.next_input(5);
212 if(in2 != 0xf) {
213 std::cerr << "FAIL: Unexpected return for m.next_input(5) (7)" << std::endl;
214 return;
216 m.restore_state(state, false);
217 std::vector<controls_t> v = m.save();
218 if(v.size() != 4) {
219 std::cerr << "FAIL: Unexpected size for movie" << std::endl;
220 return;
222 if(v[0](0) != 1 || v[0](4) != 0x1 || v[0](5) != 0x2) {
223 std::cerr << "FAIL: Wrong input for first frame" << std::endl;
224 return;
226 if(v[1](0) != 1 || v[1](4) != 0x3 || v[1](5) != 0x4 || v[1](6) != 0x8 || v[1](7) != 0xb) {
227 std::cerr << "FAIL: Wrong input for second frame first subframe" << std::endl;
228 return;
230 if(v[2](0) != 0 || v[2](4) != 0x5 || v[2](5) != 0x6 || v[2](6) != 0x8 || v[2](7) != 0xb) {
231 std::cerr << "FAIL: Wrong input for second frame second subframe" << std::endl;
232 std::cerr << v[2](0) << " " << v[2](4) << " " << v[2](5) << " " << v[2](6) << " " << v[2](7) << std::endl;
233 return;
235 if(v[3](0) != 0 || v[3](4) != 0x5 || v[3](5) != 0x7 || v[3](6) != 0x8 || v[3](7) != 0xb) {
236 std::cerr << "FAIL: Wrong input for second frame third subframe" << std::endl;
237 return;
239 std::cerr << "PASS!" << std::endl;
242 void truncate_current_complete_frame()
244 short in1, in2;
245 std::cerr << "Test #3: Truncate current complete frame" << std::endl;
246 movie m;
247 std::vector<uint8_t> state;
248 controls_t c;
249 m.readonly_mode(false);
250 m.next_frame();
251 c(4) = 0x1;
252 c(5) = 0x2;
253 m.set_controls(c);
254 in1 = m.next_input(4);
255 if(in1 != 0x1) {
256 std::cerr << "FAIL: Unexpected return for m.next_input(4) (1)" << std::endl;
257 std::cerr << "Expected 1, got " << in1 << "." << std::endl;
258 return;
260 in2 = m.next_input(5);
261 if(in2 != 0x2) {
262 std::cerr << "FAIL: Unexpected return for m.next_input(5) (1)" << std::endl;
263 return;
265 m.next_frame();
266 c(4) = 0x3;
267 c(5) = 0x4;
268 m.set_controls(c);
269 in1 = m.next_input(4);
270 if(in1 != 0x3) {
271 std::cerr << "FAIL: Unexpected return for m.next_input(4) (2)" << std::endl;
272 return;
274 in2 = m.next_input(5);
275 if(in2 != 0x4) {
276 std::cerr << "FAIL: Unexpected return for m.next_input(5) (2)" << std::endl;
277 return;
279 c(4) = 0x5;
280 c(5) = 0x6;
281 m.set_controls(c);
282 in1 = m.next_input(4);
283 if(in1 != 0x5) {
284 std::cerr << "FAIL: Unexpected return for m.next_input(4) (3)" << std::endl;
285 return;
287 in2 = m.next_input(5);
288 if(in2 != 0x6) {
289 std::cerr << "FAIL: Unexpected return for m.next_input(5) (3)" << std::endl;
290 return;
292 m.next_frame();
293 state = m.save_state();
294 c(4) = 0x7;
295 c(5) = 0x8;
296 m.set_controls(c);
297 in1 = m.next_input(4);
298 if(in1 != 0x7) {
299 std::cerr << "FAIL: Unexpected return for m.next_input(4) (4)" << std::endl;
300 return;
302 in2 = m.next_input(5);
303 if(in2 != 0x8) {
304 std::cerr << "FAIL: Unexpected return for m.next_input(5) (4)" << std::endl;
305 return;
307 m.restore_state(state, false);
308 std::vector<controls_t> v = m.save();
309 if(v.size() != 3) {
310 std::cerr << "FAIL: Unexpected size for movie" << std::endl;
311 return;
313 if(v[0](0) != 1 || v[0](4) != 0x1 || v[0](5) != 0x2) {
314 std::cerr << "FAIL: Wrong input for first frame" << std::endl;
315 return;
317 if(v[1](0) != 1 || v[1](4) != 0x3 || v[1](5) != 0x4) {
318 std::cerr << "FAIL: Wrong input for second frame first subframe" << std::endl;
319 return;
321 if(v[2](0) != 0 || v[2](4) != 0x5 || v[2](5) != 0x6) {
322 std::cerr << "FAIL: Wrong input for second frame second subframe" << std::endl;
323 return;
325 std::cerr << "PASS!" << std::endl;
328 void truncate_current_incomplete_frame()
330 short in1, in2;
331 std::cerr << "Test #4: Truncate current incomplete frame" << std::endl;
332 movie m;
333 std::vector<uint8_t> state;
334 controls_t c;
335 m.readonly_mode(false);
336 m.next_frame();
337 c(4) = 0x1;
338 c(5) = 0x2;
339 m.set_controls(c);
340 in1 = m.next_input(4);
341 if(in1 != 0x1) {
342 std::cerr << "FAIL: Unexpected return for m.next_input(4) (1)" << std::endl;
343 std::cerr << "Expected 1, got " << in1 << "." << std::endl;
344 return;
346 in2 = m.next_input(5);
347 if(in2 != 0x2) {
348 std::cerr << "FAIL: Unexpected return for m.next_input(5) (1)" << std::endl;
349 return;
351 m.next_frame();
352 c(4) = 0x3;
353 c(5) = 0x4;
354 m.set_controls(c);
355 in1 = m.next_input(4);
356 if(in1 != 0x3) {
357 std::cerr << "FAIL: Unexpected return for m.next_input(4) (2)" << std::endl;
358 return;
360 in2 = m.next_input(5);
361 if(in2 != 0x4) {
362 std::cerr << "FAIL: Unexpected return for m.next_input(5) (2)" << std::endl;
363 return;
365 c(4) = 0x5;
366 c(5) = 0x6;
367 m.set_controls(c);
368 in1 = m.next_input(4);
369 if(in1 != 0x5) {
370 std::cerr << "FAIL: Unexpected return for m.next_input(4) (3)" << std::endl;
371 return;
373 in2 = m.next_input(5);
374 if(in2 != 0x6) {
375 std::cerr << "FAIL: Unexpected return for m.next_input(5) (3)" << std::endl;
376 return;
378 c(5) = 0x7;
379 c(6) = 0x8;
380 m.set_controls(c);
381 in1 = m.next_input(5);
382 if(in1 != 0x7) {
383 std::cerr << "FAIL: Unexpected return for m.next_input(5) (4)" << std::endl;
384 return;
386 in2 = m.next_input(6);
387 if(in2 != 0x8) {
388 std::cerr << "FAIL: Unexpected return for m.next_input(6) (4)" << std::endl;
389 return;
391 state = m.save_state();
392 //Now we have 2 subframes on 4, 3 on 5 and 1 on 6. Add 1 subframe for 4, 5 and 7.
393 c(4) = 0x9;
394 c(5) = 0xa;
395 c(7) = 0xb;
396 m.set_controls(c);
397 in1 = m.next_input(4);
398 if(in1 != 0x9) {
399 std::cerr << "FAIL: Unexpected return for m.next_input(4) (5)" << std::endl;
400 return;
402 in1 = m.next_input(5);
403 if(in1 != 0xa) {
404 std::cerr << "FAIL: Unexpected return for m.next_input(5) (5)" << std::endl;
405 return;
407 in2 = m.next_input(7);
408 if(in2 != 0xb) {
409 std::cerr << "FAIL: Unexpected return for m.next_input(7) (5)" << std::endl;
410 return;
412 m.restore_state(state, false);
413 std::vector<controls_t> v = m.save();
414 if(v.size() != 4) {
415 std::cerr << "FAIL: Unexpected size for movie" << std::endl;
416 return;
418 if(v[0](0) != 1 || v[0](4) != 0x1 || v[0](5) != 0x2) {
419 std::cerr << "FAIL: Wrong input for first frame" << std::endl;
420 return;
422 if(v[1](0) != 1 || v[1](4) != 0x3 || v[1](5) != 0x4 || v[1](6) != 0x8 || v[1](7) != 0xb) {
423 std::cerr << "FAIL: Wrong input for second frame first subframe" << std::endl;
424 return;
426 if(v[2](0) != 0 || v[2](4) != 0x5 || v[2](5) != 0x6 || v[2](6) != 0x8 || v[2](7) != 0xb) {
427 std::cerr << "FAIL: Wrong input for second frame second subframe" << std::endl;
428 std::cerr << v[2](0) << " " << v[2](4) << " " << v[2](5) << " " << v[2](6) << " " << v[2](7) << std::endl;
429 return;
431 if(v[3](0) != 0 || v[3](4) != 0x5 || v[3](5) != 0x7 || v[3](6) != 0x8 || v[3](7) != 0xb) {
432 std::cerr << "FAIL: Wrong input for second frame third subframe" << std::endl;
433 return;
435 std::cerr << "PASS!" << std::endl;
438 void truncate_future_complete_frame()
440 short in1, in2;
441 std::cerr << "Test #5: Truncate future complete frame" << std::endl;
442 movie m;
443 std::vector<uint8_t> state;
444 controls_t c;
445 m.readonly_mode(false);
446 m.next_frame();
447 c(4) = 0x1;
448 c(5) = 0x2;
449 m.set_controls(c);
450 in1 = m.next_input(4);
451 if(in1 != 0x1) {
452 std::cerr << "FAIL: Unexpected return for m.next_input(4) (1)" << std::endl;
453 std::cerr << "Expected 1, got " << in1 << "." << std::endl;
454 return;
456 in2 = m.next_input(5);
457 if(in2 != 0x2) {
458 std::cerr << "FAIL: Unexpected return for m.next_input(5) (1)" << std::endl;
459 return;
461 m.next_frame();
462 c(4) = 0x3;
463 c(5) = 0x4;
464 m.set_controls(c);
465 in1 = m.next_input(4);
466 if(in1 != 0x3) {
467 std::cerr << "FAIL: Unexpected return for m.next_input(4) (2)" << std::endl;
468 return;
470 in2 = m.next_input(5);
471 if(in2 != 0x4) {
472 std::cerr << "FAIL: Unexpected return for m.next_input(5) (2)" << std::endl;
473 return;
475 c(4) = 0x5;
476 c(5) = 0x6;
477 m.set_controls(c);
478 in1 = m.next_input(4);
479 if(in1 != 0x5) {
480 std::cerr << "FAIL: Unexpected return for m.next_input(4) (3)" << std::endl;
481 return;
483 in2 = m.next_input(5);
484 if(in2 != 0x6) {
485 std::cerr << "FAIL: Unexpected return for m.next_input(5) (3)" << std::endl;
486 return;
488 m.next_frame();
489 m.readonly_mode(true);
490 m.next_frame();
491 m.next_frame();
492 m.next_frame();
493 m.readonly_mode(false);
494 std::vector<controls_t> v = m.save();
495 if(v.size() != 6) {
496 std::cerr << "FAIL: Unexpected size for movie" << std::endl;
497 return;
499 if(v[0](0) != 1 || v[0](4) != 0x1 || v[0](5) != 0x2) {
500 std::cerr << "FAIL: Wrong input for first frame" << std::endl;
501 return;
503 if(v[1](0) != 1 || v[1](4) != 0x3 || v[1](5) != 0x4) {
504 std::cerr << "FAIL: Wrong input for second frame first subframe" << std::endl;
505 return;
507 if(v[2](0) != 0 || v[2](4) != 0x5 || v[2](5) != 0x6) {
508 std::cerr << "FAIL: Wrong input for second frame second subframe" << std::endl;
509 return;
511 if(v[3](0) != 1 || v[3](4) != 0 || v[3](5) != 0) {
512 std::cerr << "FAIL: Wrong input for third frame" << std::endl;
513 return;
515 if(v[4](0) != 1 || v[4](4) != 0 || v[4](5) != 0) {
516 std::cerr << "FAIL: Wrong input for fourth frame" << std::endl;
517 return;
519 if(v[5](0) != 1 || v[5](4) != 0 || v[5](5) != 0) {
520 std::cerr << "FAIL: Wrong input for fifth frame" << std::endl;
521 return;
523 std::cerr << "PASS!" << std::endl;
526 void truncate_future_incomplete_frame()
528 short in1, in2;
529 std::cerr << "Test #6: Truncate future incomplete frame" << std::endl;
530 movie m;
531 std::vector<uint8_t> state;
532 controls_t c;
533 m.readonly_mode(false);
534 m.next_frame();
535 c(4) = 0x1;
536 c(5) = 0x2;
537 m.set_controls(c);
538 in1 = m.next_input(4);
539 if(in1 != 0x1) {
540 std::cerr << "FAIL: Unexpected return for m.next_input(4) (1)" << std::endl;
541 std::cerr << "Expected 1, got " << in1 << "." << std::endl;
542 return;
544 in2 = m.next_input(5);
545 if(in2 != 0x2) {
546 std::cerr << "FAIL: Unexpected return for m.next_input(5) (1)" << std::endl;
547 return;
549 m.next_frame();
550 c(4) = 0x3;
551 c(5) = 0x4;
552 m.set_controls(c);
553 in1 = m.next_input(4);
554 if(in1 != 0x3) {
555 std::cerr << "FAIL: Unexpected return for m.next_input(4) (2)" << std::endl;
556 return;
558 in2 = m.next_input(5);
559 if(in2 != 0x4) {
560 std::cerr << "FAIL: Unexpected return for m.next_input(5) (2)" << std::endl;
561 return;
563 c(4) = 0x5;
564 c(5) = 0x6;
565 m.set_controls(c);
566 in1 = m.next_input(4);
567 if(in1 != 0x5) {
568 std::cerr << "FAIL: Unexpected return for m.next_input(4) (3)" << std::endl;
569 return;
571 in2 = m.next_input(5);
572 if(in2 != 0x6) {
573 std::cerr << "FAIL: Unexpected return for m.next_input(5) (3)" << std::endl;
574 return;
576 m.next_frame();
577 m.readonly_mode(true);
578 m.next_frame();
579 m.next_frame();
580 m.next_frame();
581 in1 = m.next_input(4);
582 if(in1 != 0x0) {
583 std::cerr << "FAIL: Unexpected return for m.next_input(4) (4)" << std::endl;
584 return;
586 in1 = m.next_input(4);
587 if(in1 != 0x0) {
588 std::cerr << "FAIL: Unexpected return for m.next_input(4) (5)" << std::endl;
589 return;
591 m.readonly_mode(false);
592 std::vector<controls_t> v = m.save();
593 if(v.size() != 7) {
594 std::cerr << "FAIL: Unexpected size for movie (got " << v.size() << ")" << std::endl;
595 return;
597 if(v[0](0) != 1 || v[0](4) != 0x1 || v[0](5) != 0x2) {
598 std::cerr << "FAIL: Wrong input for first frame" << std::endl;
599 return;
601 if(v[1](0) != 1 || v[1](4) != 0x3 || v[1](5) != 0x4) {
602 std::cerr << "FAIL: Wrong input for second frame first subframe" << std::endl;
603 return;
605 if(v[2](0) != 0 || v[2](4) != 0x5 || v[2](5) != 0x6) {
606 std::cerr << "FAIL: Wrong input for second frame second subframe" << std::endl;
607 return;
609 if(v[3](0) != 1 || v[3](4) != 0 || v[3](5) != 0) {
610 std::cerr << "FAIL: Wrong input for third frame" << std::endl;
611 return;
613 if(v[4](0) != 1 || v[4](4) != 0 || v[4](5) != 0) {
614 std::cerr << "FAIL: Wrong input for fourth frame" << std::endl;
615 return;
617 if(v[5](0) != 1 || v[5](4) != 0 || v[5](5) != 0) {
618 std::cerr << "FAIL: Wrong input for fifth frame" << std::endl;
619 return;
621 if(v[6](0) != 1 || v[6](4) != 0 || v[6](5) != 0) {
622 std::cerr << "FAIL: Wrong input for sixth frame" << std::endl;
623 return;
625 std::cerr << "PASS!" << std::endl;
628 int main()
630 truncate_past_complete_frame();
631 truncate_past_incomplete_frame();
632 truncate_current_complete_frame();
633 truncate_current_incomplete_frame();
634 truncate_future_complete_frame();
635 truncate_future_incomplete_frame();
636 return 0;