Files
slsDetectorPackage/slsDetectorSoftware/tests/test-Module.cpp
2025-12-16 14:26:14 +01:00

80 lines
2.3 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Detector.h"
#include "Module.h"
#include "SharedMemory.h"
#include "catch.hpp"
namespace sls {
using dt = slsDetectorDefs::detectorType;
TEST_CASE("Construction with a defined detector type") {
freeSharedMemory(0, 0); // clean up to start test
Module const m(dt::EIGER);
REQUIRE(m.getDetectorType() == dt::EIGER);
freeSharedMemory(0, 0); // clean up
SharedMemory<sharedModule> moduleShm(0, 0);
REQUIRE(moduleShm.exists() == false);
}
TEST_CASE("Read back detector type from shm") {
// Create specific detector in order to create shm
Module const m(dt::JUNGFRAU);
// New detector that reads type from shm
Module const m2;
REQUIRE(m2.getDetectorType() == dt::JUNGFRAU);
// Now both objects point to the same shm so we can only
// free one!
freeSharedMemory(0, 0);
SharedMemory<sharedModule> moduleShm(0, 0);
REQUIRE(moduleShm.exists() == false);
}
TEST_CASE("Is shm fixed pattern shm compatible") {
Module const m(dt::JUNGFRAU);
// Should be true since we just created the shm
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true);
// Set shm version to 0
SharedMemory<sharedModule> shm(0, 0);
REQUIRE(shm.exists() == true);
shm.openSharedMemory(true);
shm()->shmversion = 0;
// Should fail since version is set to 0
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == false);
freeSharedMemory(0, 0);
SharedMemory<sharedModule> moduleShm(0, 0);
REQUIRE(moduleShm.exists() == false);
}
TEST_CASE("Get default control port") {
Module const m(dt::MYTHEN3);
REQUIRE(m.getControlPort() == 1952);
freeSharedMemory(0, 0);
SharedMemory<sharedModule> moduleShm(0, 0);
REQUIRE(moduleShm.exists() == false);
}
TEST_CASE("Get default stop port") {
Module const m(dt::GOTTHARD2);
REQUIRE(m.getStopPort() == 1953);
freeSharedMemory(0, 0);
SharedMemory<sharedModule> moduleShm(0, 0);
REQUIRE(moduleShm.exists() == false);
}
TEST_CASE("Get default receiver TCP port") {
Module const m(dt::MYTHEN3);
REQUIRE(m.getReceiverPort() == 1954);
freeSharedMemory(0, 0);
SharedMemory<sharedModule> moduleShm(0, 0);
REQUIRE(moduleShm.exists() == false);
}
} // namespace sls