From b4f3c0586fb9ac3da072481ddd989a66f749a5af Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 1 Oct 2019 13:56:35 +0200 Subject: [PATCH] string to detector type --- slsSupportLib/include/ToString.h | 5 +++++ slsSupportLib/tests/test-ToString.cpp | 30 +++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index 5a5da95ec..187ab91d4 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -164,6 +164,11 @@ template T StringTo(std::string t) { return StringTo(t, unit); } +template <> +inline slsDetectorDefs::detectorType StringTo(std::string s){ + return slsDetectorDefs::detectorTypeToEnum(s); +} + /** For types with a .str() method use this for conversion */ template typename std::enable_if::value, std::string>::type diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index 9f8da0832..a7dfc5a17 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -43,15 +43,6 @@ TEST_CASE("conversion from duration to string", "[support]") { REQUIRE(ToString(us(-100)) == "-100us"); } -TEST_CASE("string to std::chrono::duration", "[support]") { - REQUIRE(StringTo("150", "ns") == ns(150)); - REQUIRE(StringTo("150ns") == ns(150)); - REQUIRE(StringTo("150s") == s(150)); - REQUIRE(StringTo("3 s") == s(3)); - - REQUIRE_THROWS(StringTo("5xs")); - REQUIRE_THROWS(StringTo("asvn")); -} TEST_CASE("Convert vector of time", "[support]") { std::vector vec{ns(150), us(10), ns(600)}; @@ -122,5 +113,26 @@ TEST_CASE("run status"){ REQUIRE(ToString(defs::runStatus::IDLE) == "idle"); } +/** Conversion from string (break out in it's own file?) */ +TEST_CASE("string to std::chrono::duration", "[support]") { + REQUIRE(StringTo("150", "ns") == ns(150)); + REQUIRE(StringTo("150ns") == ns(150)); + REQUIRE(StringTo("150s") == s(150)); + REQUIRE(StringTo("3 s") == s(3)); + + REQUIRE_THROWS(StringTo("5xs")); + REQUIRE_THROWS(StringTo("asvn")); +} + +TEST_CASE("string to detectorType"){ + using dt = slsDetectorDefs::detectorType; + REQUIRE(StringTo
("Eiger") == dt::EIGER); + REQUIRE(StringTo
("Gotthard") == dt::GOTTHARD); + REQUIRE(StringTo
("Jungfrau") == dt::JUNGFRAU); + REQUIRE(StringTo
("JungfrauCTB") == dt::CHIPTESTBOARD); + REQUIRE(StringTo
("Moench") == dt::MOENCH); + REQUIRE(StringTo
("Mythen3") == dt::MYTHEN3); + REQUIRE(StringTo
("Gotthard2") == dt::GOTTHARD2); +}