|
| 1 | +#include "dshow_webcam_capture.h" |
| 2 | + |
| 3 | +#include <cstdio> |
| 4 | + |
| 5 | +namespace { |
| 6 | + |
| 7 | +int failures = 0; |
| 8 | + |
| 9 | +void expect(const char* label, bool condition) { |
| 10 | + if (condition) { |
| 11 | + return; |
| 12 | + } |
| 13 | + std::printf("FAIL %s\n", label); |
| 14 | + ++failures; |
| 15 | +} |
| 16 | + |
| 17 | +} // namespace |
| 18 | + |
| 19 | +int main() { |
| 20 | + const std::vector<BYTE> frame(4 * 2 * 2, 0x80); |
| 21 | + |
| 22 | + // A new sequence is copied, with the size and sequence it was stored with. |
| 23 | + WebcamFrameSnapshot fresh; |
| 24 | + expect("new sequence is copied", snapshotWebcamFrame(frame, 2, 2, 7, 6, fresh)); |
| 25 | + expect("new sequence carries its data", fresh.data == frame); |
| 26 | + expect("new sequence carries its size", fresh.width == 2 && fresh.height == 2); |
| 27 | + expect("new sequence carries its number", fresh.sequence == 7); |
| 28 | + |
| 29 | + // The regression this file exists for: the writer polls at the screen's |
| 30 | + // rate, twice the camera's, and a frame it already holds must cost nothing. |
| 31 | + WebcamFrameSnapshot unchanged; |
| 32 | + expect("unchanged sequence reports nothing new", !snapshotWebcamFrame(frame, 2, 2, 7, 7, unchanged)); |
| 33 | + expect("unchanged sequence copies nothing", unchanged.data.empty() && unchanged.sequence == 0); |
| 34 | + |
| 35 | + // No frame stored yet: nothing to hand out, whatever the caller last saw. |
| 36 | + WebcamFrameSnapshot empty; |
| 37 | + expect("empty frame is not copied", !snapshotWebcamFrame({}, 2, 2, 1, 0, empty)); |
| 38 | + expect("unknown size is not copied", !snapshotWebcamFrame(frame, 0, 2, 1, 0, empty)); |
| 39 | + |
| 40 | + if (failures > 0) { |
| 41 | + std::printf("%d webcam snapshot check(s) failed\n", failures); |
| 42 | + return 1; |
| 43 | + } |
| 44 | + std::printf("webcam snapshot checks passed\n"); |
| 45 | + return 0; |
| 46 | +} |
0 commit comments