78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
// Copyright (2019-2023) Paul Scherrer Institute
|
|
|
|
#include <catch2/catch.hpp>
|
|
#include "../common/ZMQPreviewPublisher.h"
|
|
|
|
TEST_CASE("ZMQPreviewPublisher","[ZMQ]") {
|
|
ZMQContext context;
|
|
ZMQPreviewPublisher publisher(context, "inproc://#5");
|
|
|
|
ZMQSocket socket(context, ZMQSocketType::Sub);
|
|
socket.Connect("inproc://#5");
|
|
socket.SubscribeAll();
|
|
|
|
DiffractionExperiment experiment(DetectorGeometry(1, 1, 0, 0, false));
|
|
|
|
std::string z = "Msg 0";
|
|
|
|
JFCalibration calibration(experiment);
|
|
publisher.StartDataCollection((uint8_t *) z.data(), z.size(), experiment.GetPreviewStride());
|
|
|
|
z = "Msg 1";
|
|
publisher.SendImage((uint8_t *) z.data(), z.size(), 0);
|
|
|
|
std::string s;
|
|
|
|
// Pixel mask
|
|
REQUIRE(socket.Receive(s, false) > 0);
|
|
REQUIRE(s == "Msg 0");
|
|
|
|
// Frame
|
|
REQUIRE(socket.Receive(s, false) > 0);
|
|
REQUIRE(s == "Msg 1");
|
|
|
|
REQUIRE(socket.Receive(s, false) < 0);
|
|
}
|
|
|
|
TEST_CASE("ZMQPreviewPublisher_FrameNumbers","[ZMQ]") {
|
|
ZMQContext context;
|
|
ZMQPreviewPublisher publisher(context, "inproc://#5");
|
|
|
|
ZMQSocket socket(context, ZMQSocketType::Sub);
|
|
socket.Connect("inproc://#5");
|
|
socket.SubscribeAll();
|
|
|
|
DiffractionExperiment experiment(DetectorGeometry(1, 1, 0, 0, false));
|
|
experiment.PreviewPeriod(std::chrono::milliseconds(10));
|
|
REQUIRE(experiment.GetPreviewStride() == 10);
|
|
|
|
JFCalibration calibration(experiment);
|
|
|
|
std::string z = "Start";
|
|
|
|
publisher.StartDataCollection((uint8_t *) z.data(), z.size(), experiment.GetPreviewStride());
|
|
|
|
for (const auto& i: {0, 9, 12, 10, 25, 20, 18}) {
|
|
z = "Msg " + std::to_string(i);
|
|
publisher.SendImage((uint8_t *) z.data(), z.size(), i);
|
|
}
|
|
|
|
std::string s;
|
|
|
|
// Pixel mask
|
|
REQUIRE(socket.Receive(s, false) > 0);
|
|
REQUIRE(s == "Start");
|
|
|
|
// Frame
|
|
REQUIRE(socket.Receive(s, false) > 0);
|
|
REQUIRE(s == "Msg 0");
|
|
|
|
REQUIRE(socket.Receive(s, false) > 0);
|
|
REQUIRE(s == "Msg 12");
|
|
|
|
REQUIRE(socket.Receive(s, false) > 0);
|
|
REQUIRE(s == "Msg 25");
|
|
|
|
REQUIRE(socket.Receive(s, false) < 0);
|
|
}
|