diff --git a/slsDetectorSoftware/include/multiSlsDetectorClient.h b/slsDetectorSoftware/include/multiSlsDetectorClient.h index d00f0c314..63104c3a8 100755 --- a/slsDetectorSoftware/include/multiSlsDetectorClient.h +++ b/slsDetectorSoftware/include/multiSlsDetectorClient.h @@ -5,10 +5,10 @@ #include "CmdLineParser.h" #include "CmdProxy.h" #include "container_utils.h" +#include "string_utils.h" #include "multiSlsDetector.h" #include "slsDetectorCommand.h" #include "sls_detector_exceptions.h" -#include "string_utils.h" #include #include @@ -23,14 +23,17 @@ inline int dummyCallback(detectorData *d, int p, void *) { class multiSlsDetectorClient { public: multiSlsDetectorClient(int argc, char *argv[], int action, - multiSlsDetector *myDetector = nullptr) - : action_(action), detPtr(myDetector) { + multiSlsDetector *myDetector = nullptr, + std::ostream &output = std::cout) + : action_(action), detPtr(myDetector), os(output) { parser.Parse(argc, argv); runCommand(); + } multiSlsDetectorClient(const std::string &args, int action, - multiSlsDetector *myDetector = nullptr) - : action_(action), detPtr(myDetector) { + multiSlsDetector *myDetector = nullptr, + std::ostream &output = std::cout) + : action_(action), detPtr(myDetector), os(output) { parser.Parse(args); runCommand(); } @@ -39,30 +42,31 @@ class multiSlsDetectorClient { int action_; CmdLineParser parser; multiSlsDetector *detPtr = nullptr; + std::ostream &os; void runCommand() { bool verify = true; bool update = true; if (action_ == slsDetectorDefs::PUT_ACTION && parser.n_arguments() == 0) { - std::cout << "Wrong usage - should be: " << parser.executable() - << "[id-][pos:]channel arg" << std::endl; - std::cout << std::endl; + os << "Wrong usage - should be: " << parser.executable() + << "[id-][pos:]channel arg" << std::endl; + os << std::endl; return; }; if (action_ == slsDetectorDefs::GET_ACTION && parser.command().empty()) { - std::cout << "Wrong usage - should be: " << parser.executable() - << "[id-][pos:]channel arg" << std::endl; - std::cout << std::endl; + os << "Wrong usage - should be: " << parser.executable() + << "[id-][pos:]channel arg" << std::endl; + os << std::endl; return; }; if (action_ == slsDetectorDefs::READOUT_ACTION && parser.detector_id() != -1) { - std::cout << "detector_id: " << parser.detector_id() - << " ,readout of individual detectors is not allowed!" - << std::endl; + os << "detector_id: " << parser.detector_id() + << " ,readout of individual detectors is not allowed!" + << std::endl; return; } @@ -78,7 +82,6 @@ class multiSlsDetectorClient { update = false; } - // std::cout<<"id:"< localDet; if (detPtr == nullptr) { @@ -87,15 +90,15 @@ class multiSlsDetectorClient { verify, update); detPtr = localDet.get(); } catch (const RuntimeError &e) { - /*std::cout << e.GetMessage() << std::endl;*/ + /*os << e.GetMessage() << std::endl;*/ return; } catch (...) { - std::cout << " caught exception\n"; + os << " caught exception\n"; return; } } if (parser.detector_id() >= detPtr->getNumberOfDetectors()) { - std::cout << "position is out of bounds.\n"; + os << "position is out of bounds.\n"; return; } @@ -120,13 +123,13 @@ class multiSlsDetectorClient { action_, parser.detector_id()); if (parser.multi_id() != 0) - std::cout << parser.multi_id() << '-'; + os << parser.multi_id() << '-'; if (parser.detector_id() != -1) - std::cout << parser.detector_id() << ':'; + os << parser.detector_id() << ':'; if (action_ != slsDetectorDefs::READOUT_ACTION) { - std::cout << parser.command() << " "; + os << parser.command() << " "; } - std::cout << answer << std::endl; + os << answer << std::endl; } }; diff --git a/slsDetectorSoftware/src/sls_detector_client.cpp b/slsDetectorSoftware/src/sls_detector_client.cpp index b1153a7fc..12f4ba7c7 100755 --- a/slsDetectorSoftware/src/sls_detector_client.cpp +++ b/slsDetectorSoftware/src/sls_detector_client.cpp @@ -26,5 +26,6 @@ int main(int argc, char *argv[]) { #ifdef HELP int action = slsDetectorDefs::HELP_ACTION; #endif + multiSlsDetectorClient(argc, argv, action); } diff --git a/slsDetectorSoftware/tests/CMakeLists.txt b/slsDetectorSoftware/tests/CMakeLists.txt index a30e9f3ac..dcde08ad2 100755 --- a/slsDetectorSoftware/tests/CMakeLists.txt +++ b/slsDetectorSoftware/tests/CMakeLists.txt @@ -2,4 +2,5 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-SharedMemory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-slsDetector.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-multiSlsDetector.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-multiSlsDetectorClient.cpp ) \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp new file mode 100644 index 000000000..861619256 --- /dev/null +++ b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp @@ -0,0 +1,40 @@ +#include "catch.hpp" +#include "multiSlsDetectorClient.h" +#include "sls_detector_defs.h" +#include + +auto GET = slsDetectorDefs::GET_ACTION; +auto PUT = slsDetectorDefs::PUT_ACTION; + +TEST_CASE("rx_fifodepth", "[.cmd]") { + auto oss = std::ostringstream{}; + multiSlsDetectorClient("rx_fifodepth 10", PUT, nullptr, oss); + REQUIRE(oss.str() == "rx_fifodepth 10\n"); + + oss = std::ostringstream{}; + multiSlsDetectorClient("rx_fifodepth 100", PUT, nullptr, oss); + REQUIRE(oss.str() == "rx_fifodepth 100\n"); + + oss = std::ostringstream{}; + multiSlsDetectorClient("rx_fifodepth", GET, nullptr, oss); + REQUIRE(oss.str() == "rx_fifodepth 100\n"); + + oss = std::ostringstream{}; + multiSlsDetectorClient("0:rx_fifodepth", GET, nullptr, oss); + REQUIRE(oss.str() == "0:rx_fifodepth 100\n"); +} + +TEST_CASE("frames", "[.cmd]"){ + auto oss = std::ostringstream{}; + multiSlsDetectorClient("frames 1000", PUT, nullptr, oss); + REQUIRE(oss.str() == "frames 1000\n"); + + oss = std::ostringstream{}; + multiSlsDetectorClient("frames", GET, nullptr, oss); + REQUIRE(oss.str() == "frames 1000\n"); + + oss = std::ostringstream{}; + multiSlsDetectorClient("frames 1", PUT, nullptr, oss); + REQUIRE(oss.str() == "frames 1\n"); + +} \ No newline at end of file