tests for bool in ToString/StringTo (#1230)
All checks were successful
Build on RHEL9 / build (push) Successful in 3m18s
Build on RHEL8 / build (push) Successful in 4m57s

- Added tests for ToString/StringTo<bool>
- Added overload for ToString of bool (previously went through int)
This commit is contained in:
Erik Fröjdh 2025-06-03 08:36:29 +02:00 committed by GitHub
parent c92830f854
commit f84454fbc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 1 deletions

View File

@ -100,7 +100,6 @@ if(SLS_USE_TEXTCLIENT)
target_link_libraries(${val1}
slsDetectorStatic
pthread
rt
)
SET_SOURCE_FILES_PROPERTIES( src/Caller.cpp PROPERTIES COMPILE_FLAGS "-Wno-unused-variable -Wno-unused-but-set-variable")

View File

@ -47,6 +47,8 @@ std::string ToString(const defs::polarity s);
std::string ToString(const defs::timingInfoDecoder s);
std::string ToString(const defs::collectionMode s);
std::string ToString(bool value);
std::string ToString(const slsDetectorDefs::xy &coord);
std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::xy &coord);
std::string ToString(const slsDetectorDefs::ROI &roi);

View File

@ -5,6 +5,13 @@
namespace sls {
std::string ToString(bool value) {
return value ? "1" : "0";
}
std::string ToString(const slsDetectorDefs::xy &coord) {
std::ostringstream oss;
oss << '[' << coord.x << ", " << coord.y << ']';

View File

@ -16,6 +16,17 @@ namespace sls {
using namespace sls::time;
TEST_CASE("Convert bool to string", "[support]") {
REQUIRE(ToString(true) == "1");
REQUIRE(ToString(false) == "0");
}
TEST_CASE("Convert string to bool", "[support]") {
REQUIRE(StringTo<bool>("1") == true);
REQUIRE(StringTo<bool>("0") == false);
}
TEST_CASE("Integer conversions", "[support]") {
REQUIRE(ToString(0) == "0");
REQUIRE(ToString(1) == "1");