From 8656eeec25b0cd981b8220ea871310d10d0163a3 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil <33750417+thattil@users.noreply.github.com> Date: Fri, 20 May 2022 15:43:48 +0200 Subject: [PATCH] Revert "tests add to namespace sls (#464)" (#465) This reverts commit f5745fcf18ae9c6953227a0cd3fe03b9b157ae9e. --- integrationTests/test-eigerIntegration.cpp | 6 +- .../test-integrationDectector.cpp | 22 +++---- integrationTests/test-integrationMulti.cpp | 7 +-- slsDetectorSoftware/tests/CMakeLists.txt | 7 +-- slsDetectorSoftware/tests/test-CmdParser.cpp | 7 +-- .../tests/test-CmdProxy-chiptestboard.cpp | 10 ++-- .../tests/test-CmdProxy-eiger.cpp | 8 +-- .../tests/test-CmdProxy-global.cpp | 10 ++-- .../tests/test-CmdProxy-global.h | 5 -- .../tests/test-CmdProxy-gotthard.cpp | 8 +-- .../tests/test-CmdProxy-gotthard2.cpp | 10 ++-- .../tests/test-CmdProxy-jungfrau.cpp | 6 +- .../tests/test-CmdProxy-moench.cpp | 6 +- .../tests/test-CmdProxy-mythen3.cpp | 14 ++--- .../tests/test-CmdProxy-pattern.cpp | 10 ++-- .../tests/test-CmdProxy-rx.cpp | 8 +-- slsDetectorSoftware/tests/test-CmdProxy.cpp | 54 +++++++++--------- slsDetectorSoftware/tests/test-CtbConfig.cpp | 6 +- slsDetectorSoftware/tests/test-Module.cpp | 22 +++---- slsDetectorSoftware/tests/test-Pattern.cpp | 4 +- slsDetectorSoftware/tests/test-Result.cpp | 6 +- .../tests/test-SharedMemory.cpp | 12 ++-- .../tests/test-slsDetector.cpp | 2 +- .../tests/test-CircularFifo.cpp | 7 +-- slsSupportLib/tests/test-Sockets.cpp | 12 ++-- slsSupportLib/tests/test-StaticVector.cpp | 17 +++--- slsSupportLib/tests/test-Timer.cpp | 10 +--- slsSupportLib/tests/test-ToString.cpp | 57 ++++++++++--------- slsSupportLib/tests/test-TypeTraits.cpp | 34 +++++------ slsSupportLib/tests/test-UdpRxSocket.cpp | 22 +++---- slsSupportLib/tests/test-ZmqSocket.cpp | 7 +-- slsSupportLib/tests/test-bit_utils.cpp | 16 ++---- slsSupportLib/tests/test-container_utils.cpp | 18 +++--- slsSupportLib/tests/test-file_utils.cpp | 8 +-- slsSupportLib/tests/test-logger.cpp | 6 +- slsSupportLib/tests/test-network_utils.cpp | 4 +- .../tests/test-sls_detector_defs.cpp | 6 +- slsSupportLib/tests/test-string_utils.cpp | 40 ++++++------- tests/include/tests/config.h | 4 -- tests/include/tests/globals.h | 5 -- tests/include/tests/testenum.h | 7 +-- tests/src/testclient.cpp | 20 +++---- tests/src/testserver.cpp | 20 +++---- tests/test.cpp | 8 +-- 44 files changed, 228 insertions(+), 350 deletions(-) diff --git a/integrationTests/test-eigerIntegration.cpp b/integrationTests/test-eigerIntegration.cpp index 6fa4124d2..0f7fea11f 100644 --- a/integrationTests/test-eigerIntegration.cpp +++ b/integrationTests/test-eigerIntegration.cpp @@ -6,8 +6,6 @@ #include "tests/globals.h" #include -namespace sls { - class MultiDetectorFixture { protected: DetectorImpl d; @@ -138,7 +136,7 @@ TEST_CASE_METHOD(MultiDetectorFixture, "Get ID", "[.eigerintegration][cli]") { std::string hn = test::hostname; hn.erase(std::remove(begin(hn), end(hn), 'b'), end(hn)); hn.erase(std::remove(begin(hn), end(hn), 'e'), end(hn)); - auto hostnames = split(hn, '+'); + auto hostnames = sls::split(hn, '+'); CHECK(hostnames.size() == d.getNumberOfDetectors()); for (int i = 0; i != d.getNumberOfDetectors(); ++i) { CHECK(d.getId(defs::DETECTOR_SERIAL_NUMBER, 0) == @@ -200,5 +198,3 @@ TEST_CASE_METHOD(MultiDetectorFixture, "rate correction", d.setRateCorrection(200); CHECK(d.getRateCorrection() == 200); } - -} // namespace sls diff --git a/integrationTests/test-integrationDectector.cpp b/integrationTests/test-integrationDectector.cpp index 977c66cdc..9d0847b4f 100644 --- a/integrationTests/test-integrationDectector.cpp +++ b/integrationTests/test-integrationDectector.cpp @@ -24,8 +24,6 @@ // extern std::string detector_type; // extern dt type; -namespace sls { - TEST_CASE("Single detector no receiver", "[.integration][.single]") { auto t = Module::getTypeFromDetector(test::hostname); CHECK(t == test::type); @@ -285,14 +283,14 @@ TEST_CASE( CHECK(m.getRateCorrection() == ratecorr); // ratecorr fail with dr 4 or 8 - CHECK_THROWS_AS(m.setDynamicRange(8), RuntimeError); + CHECK_THROWS_AS(m.setDynamicRange(8), sls::RuntimeError); CHECK(m.getRateCorrection() == 0); m.setDynamicRange(16); m.setDynamicRange(16); m.setRateCorrection(ratecorr); m.setDynamicRange(16); m.setRateCorrection(ratecorr); - CHECK_THROWS_AS(m.setDynamicRange(4), RuntimeError); + CHECK_THROWS_AS(m.setDynamicRange(4), sls::RuntimeError); CHECK(m.getRateCorrection() == 0); } @@ -331,11 +329,11 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") { m.setPatternWord(addr, word); CHECK(m.setPatternWord(addr, -1) == word); addr = MAX_ADDR; - CHECK_THROWS_AS(m.setPatternWord(addr, word), RuntimeError); + CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::RuntimeError); CHECK_THROWS_WITH(m.setPatternWord(addr, word), Catch::Matchers::Contains("be between 0 and")); addr = -1; - CHECK_THROWS_AS(m.setPatternWord(addr, word), RuntimeError); + CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::RuntimeError); CHECK_THROWS_WITH(m.setPatternWord(addr, word), Catch::Matchers::Contains("be between 0 and")); @@ -410,7 +408,7 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", CHECK(m.getReceiverDbitList().size() == 10); list.push_back(64); - CHECK_THROWS_AS(m.setReceiverDbitList(list), RuntimeError); + CHECK_THROWS_AS(m.setReceiverDbitList(list), sls::RuntimeError); CHECK_THROWS_WITH(m.setReceiverDbitList(list), Catch::Matchers::Contains("be between 0 and 63")); @@ -478,7 +476,7 @@ TEST_CASE("Eiger or Jungfrau nextframenumber", CHECK(m.acquire() == slsDetectorDefs::OK); CHECK(m.getReceiverCurrentFrameIndex() == val); - CHECK_THROWS_AS(m.setNextFrameNumber(0), RuntimeError); + CHECK_THROWS_AS(m.setNextFrameNumber(0), sls::RuntimeError); if (m.getDetectorTypeAsString() == "Eiger") { val = 281474976710655; @@ -513,10 +511,8 @@ TEST_CASE("Eiger partialread", "[.eigerintegration][partialread]") { m.setDynamicRange(8); m.setPartialReadout(256); CHECK(m.getPartialReadout() == 256); - CHECK_THROWS_AS(m.setPartialReadout(1), RuntimeError); + CHECK_THROWS_AS(m.setPartialReadout(1), sls::RuntimeError); CHECK(m.getPartialReadout() == 256); - CHECK_THROWS_AS(m.setPartialReadout(0), RuntimeError); + CHECK_THROWS_AS(m.setPartialReadout(0), sls::RuntimeError); m.setPartialReadout(256); -} - -} // namespace sls +} \ No newline at end of file diff --git a/integrationTests/test-integrationMulti.cpp b/integrationTests/test-integrationMulti.cpp index 64716e45c..3dd6b1903 100644 --- a/integrationTests/test-integrationMulti.cpp +++ b/integrationTests/test-integrationMulti.cpp @@ -6,12 +6,10 @@ #include "tests/globals.h" #include -namespace sls { - using namespace Catch::literals; TEST_CASE("Initialize a multi detector", "[.integration][.multi]") { - auto hostnames = split(test::hostname, '+'); + auto hostnames = sls::split(test::hostname, '+'); DetectorImpl d(0, true, true); d.setHostname(test::hostname.c_str()); @@ -104,6 +102,3 @@ TEST_CASE("Set and read timers", "[.integration][.multi]") { d.freeSharedMemory(); } - -} // namespace sls - diff --git a/slsDetectorSoftware/tests/CMakeLists.txt b/slsDetectorSoftware/tests/CMakeLists.txt index 14a522639..5a39e615e 100755 --- a/slsDetectorSoftware/tests/CMakeLists.txt +++ b/slsDetectorSoftware/tests/CMakeLists.txt @@ -21,9 +21,4 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-CtbConfig.cpp ) -target_include_directories(tests - PUBLIC - "$" - PRIVATE - ${SLS_INTERNAL_RAPIDJSON_DIR} -) \ No newline at end of file +target_include_directories(tests PUBLIC "$") \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdParser.cpp b/slsDetectorSoftware/tests/test-CmdParser.cpp index 84a4b1f6d..a95b7eeee 100644 --- a/slsDetectorSoftware/tests/test-CmdParser.cpp +++ b/slsDetectorSoftware/tests/test-CmdParser.cpp @@ -9,9 +9,8 @@ // help for all docs // command for all depreciated commands -namespace sls { - using vs = std::vector; +using sls::CmdParser; SCENARIO("Construction", "[support]") { GIVEN("A default constructed CmdParser") { @@ -407,6 +406,4 @@ TEST_CASE("Parse a command in the form 0-1:command") { REQUIRE(p.multi_id() == 3); REQUIRE(p.detector_id() == 5); REQUIRE(p.command() == "exptime"); -} - -} // namespace sls \ No newline at end of file +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp b/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp index 5f9402b5b..e750bc6a4 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp @@ -12,8 +12,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -141,7 +141,7 @@ TEST_CASE("samples", "[.cmd]") { if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH) { auto prev_asamples = det.getNumberOfAnalogSamples(); - Result prev_dsamples = 0; + sls::Result prev_dsamples = 0; if (det_type == defs::CHIPTESTBOARD) { prev_dsamples = det.getNumberOfDigitalSamples(); } @@ -865,6 +865,4 @@ TEST_CASE("led", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("led", {}, -1, GET)); } -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp index 4aadf686c..6536275cf 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp @@ -12,8 +12,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -657,6 +657,4 @@ TEST_CASE("top", "[.cmd]") { REQUIRE_THROWS(proxy.Call("top", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("top", {"1"}, -1, PUT)); } -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-global.cpp b/slsDetectorSoftware/tests/test-CmdProxy-global.cpp index e89c38aef..b8a0ca624 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-global.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-global.cpp @@ -6,8 +6,8 @@ #include "sls/Detector.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -52,7 +52,7 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname, int chipIndex = -1; // for now, it is -1 only auto prev_val = det.getOnChipDAC(index, chipIndex); - auto dacValueStr = ToStringHex(dacvalue); + auto dacValueStr = sls::ToStringHex(dacvalue); auto chipIndexStr = std::to_string(chipIndex); std::ostringstream oss_set, oss_get; proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set); @@ -66,6 +66,4 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname, for (int i = 0; i != det.size(); ++i) { det.setOnChipDAC(index, chipIndex, prev_val[i], {i}); } -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-global.h b/slsDetectorSoftware/tests/test-CmdProxy-global.h index c794601a8..899462ad5 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-global.h +++ b/slsDetectorSoftware/tests/test-CmdProxy-global.h @@ -3,12 +3,7 @@ #pragma once #include "sls/sls_detector_defs.h" -namespace sls { - void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname, int dacvalue); void test_onchip_dac(slsDetectorDefs::dacIndex index, const std::string &dacname, int dacvalue); - - -} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard.cpp index 0f48f16b3..cbb737a1f 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard.cpp @@ -12,8 +12,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -154,6 +154,4 @@ TEST_CASE("exptimel", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("exptimel", {}, -1, GET)); } -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp index 6d799830f..cdba5d406 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp @@ -12,8 +12,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -467,7 +467,7 @@ TEST_CASE("burstmode", "[.cmd]") { if (det_type == defs::GOTTHARD2) { auto burst = det.getBurstMode(); - auto burststr = ToString(burst); + auto burststr = sls::ToString(burst); { std::ostringstream oss; proxy.Call("burstmode", {"burst_internal"}, -1, PUT, oss); @@ -743,6 +743,4 @@ TEST_CASE("badchannels", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET)); } -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp index 7a4e24698..4ab690977 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp @@ -10,8 +10,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -538,5 +538,3 @@ TEST_CASE("filtercells", "[.cmd]") { REQUIRE_THROWS(proxy.Call("filtercells", {"0"}, -1, PUT)); } } - -} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-moench.cpp b/slsDetectorSoftware/tests/test-CmdProxy-moench.cpp index b7656db3a..a3f8838e4 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-moench.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-moench.cpp @@ -12,8 +12,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -108,5 +108,3 @@ TEST_CASE("Setting and reading back MOENCH dacs", "[.cmd][.dacs]") { REQUIRE_THROWS(proxy.Call("dac", {"vcom_adc2"}, -1, GET)); } } - -} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp b/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp index 3eedd9ea4..21c958594 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp @@ -12,8 +12,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -216,9 +216,9 @@ TEST_CASE("counters", "[.cmd]") { REQUIRE(oss_set2.str() == "counters [0, 2]\n"); // put back old value proxy.Call("counters", list_str, -1, PUT, oss_set3); - REQUIRE(oss_set3.str() == "counters " + ToString(list_str) + "\n"); + REQUIRE(oss_set3.str() == "counters " + sls::ToString(list_str) + "\n"); proxy.Call("counters", {}, -1, GET, oss_get); - REQUIRE(oss_get.str() == "counters " + ToString(list_str) + "\n"); + REQUIRE(oss_get.str() == "counters " + sls::ToString(list_str) + "\n"); } else { REQUIRE_THROWS(proxy.Call("counters", {}, -1, GET)); } @@ -349,7 +349,7 @@ TEST_CASE("gatedelay", "[.cmd]") { auto prev_val = det.getExptimeForAllGates().tsquash( "inconsistent gatedelay to test"); if (prev_val[0] != prev_val[1] || prev_val[1] != prev_val[2]) { - throw RuntimeError("inconsistent gatedelay for all gates"); + throw sls::RuntimeError("inconsistent gatedelay for all gates"); } { std::ostringstream oss; @@ -610,6 +610,4 @@ TEST_CASE("dpulse", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("dpulse", {}, -1, GET)); } -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp b/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp index 661bab5d5..739ca10f9 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp @@ -12,8 +12,8 @@ #include "test-CmdProxy-global.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -99,7 +99,7 @@ TEST_CASE("patword", "[.cmd]") { if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH || det_type == defs::MYTHEN3) { int addr = 0x23; - std::string saddr = ToStringHex(addr, 4); + std::string saddr = sls::ToStringHex(addr, 4); auto prev_val = det.getPatternWord(addr); { std::ostringstream oss; @@ -528,6 +528,4 @@ TEST_CASE("patternstart", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("patternstart", {}, -1, PUT)); } -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index aa733a6c0..34d433591 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp @@ -9,8 +9,8 @@ #include "sls/versionAPI.h" #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -449,7 +449,7 @@ TEST_CASE("rx_roi", "[.cmd]") { REQUIRE_THROWS(proxy.Call("rx_roi", {"5", "10"}, -1, PUT)); } else { auto prev_val = det.getRxROI(); - defs::xy detsize = det.getDetectorSize(); + defs::xy detsize = det.getDetectrSize(); // 1d if (det_type == defs::GOTTHARD || det_type == defs::GOTTHARD2 || @@ -991,5 +991,3 @@ TEST_CASE("rx_jsonpara", "[.cmd][.rx]") { } /* Insignificant */ - -} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 156f82b2f..5ed8e6e86 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -11,8 +11,8 @@ #include "tests/globals.h" -namespace sls { - +using sls::CmdProxy; +using sls::Detector; using test::GET; using test::PUT; @@ -152,7 +152,7 @@ TEST_CASE("type", "[.cmd]") { std::ostringstream oss; proxy.Call("type", {}, -1, GET, oss); auto ans = oss.str().erase(0, strlen("type ")); - REQUIRE(ans == ToString(dt) + '\n'); + REQUIRE(ans == sls::ToString(dt) + '\n'); // REQUIRE(dt == test::type); } @@ -339,7 +339,7 @@ TEST_CASE("threshold", "[.cmd]") { for (int i = 0; i != det.size(); ++i) { if (prev_threshold[i][0] >= 0) { std::cout - << "prev cvalues:" << ToString(prev_threshold[i]) + << "prev cvalues:" << sls::ToString(prev_threshold[i]) << std::endl; det.setThresholdEnergy(prev_threshold[i], prev_settings, true, {i}); @@ -684,7 +684,7 @@ TEST_CASE("exptime", "[.cmd][.time]") { auto t = det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); if (t[0] != t[1] || t[1] != t[2]) { - throw RuntimeError("inconsistent exptime for all gates"); + throw sls::RuntimeError("inconsistent exptime for all gates"); } prev_val = t[0]; } @@ -1867,7 +1867,7 @@ TEST_CASE("defaultdac", "[.cmd]") { if (it == defs::VTHRESHOLD) { continue; } - auto dacname = ToString(it); + auto dacname = sls::ToString(it); auto prev_val = det.getDefaultDac(it); { std::ostringstream oss; @@ -1889,7 +1889,7 @@ TEST_CASE("defaultdac", "[.cmd]") { std::vector daclist = { defs::VREF_PRECH, defs::VREF_DS, defs::VREF_COMP}; for (auto it : daclist) { - auto dacname = ToString(it); + auto dacname = sls::ToString(it); auto prev_val = det.getDefaultDac(it, defs::GAIN0); { std::ostringstream oss; @@ -2044,7 +2044,7 @@ TEST_CASE("start", "[.cmd]") { auto t = det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); if (t[0] != t[1] || t[1] != t[2]) { - throw RuntimeError("inconsistent exptime for all gates"); + throw sls::RuntimeError("inconsistent exptime for all gates"); } prev_val = t[0]; } @@ -2083,7 +2083,7 @@ TEST_CASE("stop", "[.cmd]") { auto t = det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); if (t[0] != t[1] || t[1] != t[2]) { - throw RuntimeError("inconsistent exptime for all gates"); + throw sls::RuntimeError("inconsistent exptime for all gates"); } prev_val = t[0]; } @@ -2126,7 +2126,7 @@ TEST_CASE("status", "[.cmd]") { auto t = det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); if (t[0] != t[1] || t[1] != t[2]) { - throw RuntimeError("inconsistent exptime for all gates"); + throw sls::RuntimeError("inconsistent exptime for all gates"); } prev_val = t[0]; } @@ -2265,29 +2265,29 @@ TEST_CASE("scan", "[.cmd]") { { std::ostringstream oss; - proxy.Call("scan", {ToString(ind), "500", "1500", "500"}, -1, PUT, + proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500"}, -1, PUT, oss); CHECK(oss.str() == - "scan [" + ToString(ind) + ", 500, 1500, 500]\n"); + "scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n"); } { std::ostringstream oss; proxy.Call("scan", {}, -1, GET, oss); - CHECK(oss.str() == "scan [enabled\ndac " + ToString(ind) + + CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) + "\nstart 500\nstop 1500\nstep " "500\nsettleTime 1ms\n]\n"); } { std::ostringstream oss; - proxy.Call("scan", {ToString(ind), "500", "1500", "500", "2s"}, -1, + proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500", "2s"}, -1, PUT, oss); CHECK(oss.str() == - "scan [" + ToString(ind) + ", 500, 1500, 500, 2s]\n"); + "scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n"); } { std::ostringstream oss; proxy.Call("scan", {}, -1, GET, oss); - CHECK(oss.str() == "scan [enabled\ndac " + ToString(ind) + + CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) + "\nstart 500\nstop 1500\nstep " "500\nsettleTime 2s\n]\n"); } @@ -2303,17 +2303,17 @@ TEST_CASE("scan", "[.cmd]") { } { std::ostringstream oss; - proxy.Call("scan", {ToString(ind), "1500", "500", "-500"}, -1, PUT, + proxy.Call("scan", {sls::ToString(ind), "1500", "500", "-500"}, -1, PUT, oss); CHECK(oss.str() == - "scan [" + ToString(ind) + ", 1500, 500, -500]\n"); + "scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n"); } CHECK_THROWS(proxy.Call( - "scan", {ToString(notImplementedInd), "500", "1500", "500"}, -1, + "scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1, PUT)); - CHECK_THROWS(proxy.Call("scan", {ToString(ind), "500", "1500", "-500"}, + CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "500", "1500", "-500"}, -1, PUT)); - CHECK_THROWS(proxy.Call("scan", {ToString(ind), "1500", "500", "500"}, + CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "1500", "500", "500"}, -1, PUT)); if (det_type == defs::MYTHEN3 || defs::EIGER) { @@ -2491,7 +2491,7 @@ TEST_CASE("udp_srcip2", "[.cmd]") { REQUIRE(oss.str() == "udp_srcip2 129.129.205.12\n"); } for (int i = 0; i != det.size(); ++i) { - if (prev_val[i] != IpAddr{"0.0.0.0"}) + if (prev_val[i] != sls::IpAddr{"0.0.0.0"}) det.setSourceUDPIP2(prev_val[i], {i}); } } else { @@ -2846,7 +2846,7 @@ TEST_CASE("reg", "[.cmd]") { auto det_type = det.getDetectorType().squash(); if (det_type != defs::EIGER) { uint32_t addr = 0x64; - std::string saddr = ToStringHex(addr); + std::string saddr = sls::ToStringHex(addr); auto prev_val = det.readRegister(addr); { std::ostringstream oss1, oss2; @@ -2889,7 +2889,7 @@ TEST_CASE("setbit", "[.cmd]") { auto det_type = det.getDetectorType().squash(); if (det_type != defs::EIGER) { uint32_t addr = 0x64; - std::string saddr = ToStringHex(addr); + std::string saddr = sls::ToStringHex(addr); auto prev_val = det.readRegister(addr); { std::ostringstream oss1, oss2; @@ -2911,7 +2911,7 @@ TEST_CASE("clearbit", "[.cmd]") { auto det_type = det.getDetectorType().squash(); if (det_type != defs::EIGER) { uint32_t addr = 0x64; - std::string saddr = ToStringHex(addr); + std::string saddr = sls::ToStringHex(addr); auto prev_val = det.readRegister(addr); { std::ostringstream oss1, oss2; @@ -2933,7 +2933,7 @@ TEST_CASE("getbit", "[.cmd]") { auto det_type = det.getDetectorType().squash(); if (det_type != defs::EIGER) { uint32_t addr = 0x64; - std::string saddr = ToStringHex(addr); + std::string saddr = sls::ToStringHex(addr); auto prev_val = det.readRegister(addr); { std::ostringstream oss1, oss2; @@ -3162,5 +3162,3 @@ TEST_CASE("user", "[.cmd]") { REQUIRE_THROWS(proxy.Call("user", {}, -1, PUT)); REQUIRE_NOTHROW(proxy.Call("user", {}, -1, GET)); } - -} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CtbConfig.cpp b/slsDetectorSoftware/tests/test-CtbConfig.cpp index f8a683cf9..15a22e852 100644 --- a/slsDetectorSoftware/tests/test-CtbConfig.cpp +++ b/slsDetectorSoftware/tests/test-CtbConfig.cpp @@ -5,9 +5,9 @@ #include "SharedMemory.h" #include "CtbConfig.h" +using namespace sls; #include -namespace sls { TEST_CASE("Default construction"){ static_assert(sizeof(CtbConfig) == 360); // 18*20 @@ -56,6 +56,4 @@ TEST_CASE("Move CtbConfig "){ c1.setDacName(3, "yetanothername"); CtbConfig c2(std::move(c1)); REQUIRE(c2.getDacName(3) == "yetanothername"); -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-Module.cpp b/slsDetectorSoftware/tests/test-Module.cpp index 203ee30f3..2fdb60998 100644 --- a/slsDetectorSoftware/tests/test-Module.cpp +++ b/slsDetectorSoftware/tests/test-Module.cpp @@ -4,21 +4,19 @@ #include "SharedMemory.h" #include "catch.hpp" -namespace sls { - using dt = slsDetectorDefs::detectorType; TEST_CASE("Construction with a defined detector type") { - Module m(dt::EIGER); + sls::Module m(dt::EIGER); REQUIRE(m.getDetectorType() == dt::EIGER); m.freeSharedMemory(); // clean up } TEST_CASE("Read back detector type from shm") { // Create specific detector in order to create shm - Module m(dt::JUNGFRAU); + sls::Module m(dt::JUNGFRAU); // New detector that reads type from shm - Module m2; + sls::Module m2; REQUIRE(m2.getDetectorType() == dt::JUNGFRAU); // Now both objects point to the same shm so we can only @@ -27,13 +25,13 @@ TEST_CASE("Read back detector type from shm") { } TEST_CASE("Is shm fixed pattern shm compatible") { - Module m(dt::JUNGFRAU); + sls::Module m(dt::JUNGFRAU); // Should be true since we just created the shm REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true); // Set shm version to 0 - SharedMemory shm(0, 0); + sls::SharedMemory shm(0, 0); REQUIRE(shm.exists() == true); shm.openSharedMemory(true); shm()->shmversion = 0; @@ -45,21 +43,19 @@ TEST_CASE("Is shm fixed pattern shm compatible") { } TEST_CASE("Get default control port") { - Module m(dt::MYTHEN3); + sls::Module m(dt::MYTHEN3); REQUIRE(m.getControlPort() == 1952); m.freeSharedMemory(); } TEST_CASE("Get default stop port") { - Module m(dt::GOTTHARD2); + sls::Module m(dt::GOTTHARD2); REQUIRE(m.getStopPort() == 1953); m.freeSharedMemory(); } TEST_CASE("Get default receiver TCP port") { - Module m(dt::MYTHEN3); + sls::Module m(dt::MYTHEN3); REQUIRE(m.getReceiverPort() == 1954); m.freeSharedMemory(); -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-Pattern.cpp b/slsDetectorSoftware/tests/test-Pattern.cpp index 3c7c6abd5..6128fe0b8 100644 --- a/slsDetectorSoftware/tests/test-Pattern.cpp +++ b/slsDetectorSoftware/tests/test-Pattern.cpp @@ -3,7 +3,7 @@ #include "catch.hpp" #include "sls/Pattern.h" -namespace sls { +using sls::Pattern; TEST_CASE("Pattern is default constructable and has zeroed fields") { Pattern p; @@ -27,5 +27,3 @@ TEST_CASE("Compare patterns") { p1.data()->word[500] = 1; REQUIRE_FALSE(p == p1); } - -} // namespace sls diff --git a/slsDetectorSoftware/tests/test-Result.cpp b/slsDetectorSoftware/tests/test-Result.cpp index 6763a43d0..72e1993f0 100644 --- a/slsDetectorSoftware/tests/test-Result.cpp +++ b/slsDetectorSoftware/tests/test-Result.cpp @@ -6,10 +6,10 @@ #include "sls/TypeTraits.h" #include -namespace sls { +using sls::Result; TEST_CASE("Result looks and behaves like a standard container") { - REQUIRE(is_container>::value == true); + REQUIRE(sls::is_container>::value == true); } TEST_CASE("Default construction is possible and gives an empty result") { @@ -195,5 +195,3 @@ TEST_CASE("String conversions") { REQUIRE(ToString(res4) == "[{one: 1}, {one: 1, three: 3, two: 2}, {one: 1}]"); } - -} // namespace sls diff --git a/slsDetectorSoftware/tests/test-SharedMemory.cpp b/slsDetectorSoftware/tests/test-SharedMemory.cpp index ad5743e15..67df21efb 100644 --- a/slsDetectorSoftware/tests/test-SharedMemory.cpp +++ b/slsDetectorSoftware/tests/test-SharedMemory.cpp @@ -7,14 +7,14 @@ #include -namespace sls { - struct Data { int x; double y; char mess[50]; }; +using namespace sls; + constexpr int shm_id = 10; TEST_CASE("Create SharedMemory read and write", "[detector]") { @@ -26,7 +26,7 @@ TEST_CASE("Create SharedMemory read and write", "[detector]") { shm()->x = 3; shm()->y = 5.7; - strcpy_safe(shm()->mess, "Some string"); + sls::strcpy_safe(shm()->mess, "Some string"); CHECK(shm()->x == 3); CHECK(shm()->y == 5.7); @@ -168,6 +168,8 @@ TEST_CASE("map int64 to int32 throws"){ REQUIRE_THROWS(shm2.openSharedMemory(true)); shm.removeSharedMemory(); -} + -} // namespace sls + + +} \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-slsDetector.cpp b/slsDetectorSoftware/tests/test-slsDetector.cpp index 966bb721b..f68c68b9e 100644 --- a/slsDetectorSoftware/tests/test-slsDetector.cpp +++ b/slsDetectorSoftware/tests/test-slsDetector.cpp @@ -238,7 +238,7 @@ // CHECK(d.getReceiverDbitList().size() == 10); // list.push_back(64); -// CHECK_THROWS_AS(d.setReceiverDbitList(list), RuntimeError); +// CHECK_THROWS_AS(d.setReceiverDbitList(list), sls::RuntimeError); // CHECK_THROWS_WITH(d.setReceiverDbitList(list), // Catch::Matchers::Contains("be between 0 and 63")); diff --git a/slsReceiverSoftware/tests/test-CircularFifo.cpp b/slsReceiverSoftware/tests/test-CircularFifo.cpp index b83075065..db1523c0b 100644 --- a/slsReceiverSoftware/tests/test-CircularFifo.cpp +++ b/slsReceiverSoftware/tests/test-CircularFifo.cpp @@ -4,8 +4,7 @@ #include "sls/CircularFifo.h" #include -namespace sls { - +using sls::CircularFifo; TEST_CASE("Empty buffer") { CircularFifo fifo(0); @@ -51,6 +50,4 @@ TEST_CASE("Push pop") { CHECK(fifo.isEmpty() == true); CHECK(fifo.isFull() == false); -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-Sockets.cpp b/slsSupportLib/tests/test-Sockets.cpp index b41c44cb4..f8d7e80c5 100644 --- a/slsSupportLib/tests/test-Sockets.cpp +++ b/slsSupportLib/tests/test-Sockets.cpp @@ -8,11 +8,9 @@ #include #include -namespace sls { - std::vector server() { std::cout << "starting server\n"; - auto server = ServerSocket(1950); + auto server = sls::ServerSocket(1950); auto s = server.accept(); std::vector buffer(100, '\0'); s.Receive(buffer.data(), buffer.size()); @@ -35,7 +33,7 @@ TEST_CASE("The server recive the same message as we send", "[support]") { auto s = std::async(std::launch::async, server); std::this_thread::sleep_for(std::chrono::milliseconds(100)); - auto client = DetectorSocket("localhost", 1950); + auto client = sls::DetectorSocket("localhost", 1950); client.Send(sent_message.data(), sent_message.size()); client.Receive(received_message.data(), received_message.size()); client.close(); @@ -47,7 +45,5 @@ TEST_CASE("The server recive the same message as we send", "[support]") { } TEST_CASE("throws on no server", "[support]") { - CHECK_THROWS(DetectorSocket("localhost", 1950)); -} - -} // namespace sls + CHECK_THROWS(sls::DetectorSocket("localhost", 1950)); +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-StaticVector.cpp b/slsSupportLib/tests/test-StaticVector.cpp index 6f9f5da50..8b5fa7cca 100644 --- a/slsSupportLib/tests/test-StaticVector.cpp +++ b/slsSupportLib/tests/test-StaticVector.cpp @@ -7,11 +7,10 @@ #include #include #include - -namespace sls { +using sls::StaticVector; TEST_CASE("StaticVector is a container") { - REQUIRE(is_container>::value == true); + REQUIRE(sls::is_container>::value == true); } TEST_CASE("Comparing StaticVector containers") { @@ -318,15 +317,15 @@ SCENARIO("Converting to vector", "[support]") { } } -TEST_CASE("StaticVector") { - StaticVector vec; +TEST_CASE("sls::StaticVector") { + sls::StaticVector vec; vec.push_back(3); vec.push_back(8); - REQUIRE(ToString(vec) == "[3, 8]"); + REQUIRE(sls::ToString(vec) == "[3, 8]"); } -TEST_CASE("StaticVector stream") { - StaticVector vec; +TEST_CASE("sls::StaticVector stream") { + sls::StaticVector vec; vec.push_back(33); vec.push_back(85667); vec.push_back(2); @@ -334,5 +333,3 @@ TEST_CASE("StaticVector stream") { oss << vec; REQUIRE(oss.str() == "[33, 85667, 2]"); } - -} // namespace sls diff --git a/slsSupportLib/tests/test-Timer.cpp b/slsSupportLib/tests/test-Timer.cpp index 6d94f1f7b..9d3ae69cb 100644 --- a/slsSupportLib/tests/test-Timer.cpp +++ b/slsSupportLib/tests/test-Timer.cpp @@ -6,11 +6,9 @@ #include #include -namespace sls { - TEST_CASE("Time 1s restart then time 2s", "[.timer]") { auto sleep_duration = std::chrono::seconds(1); - auto t = Timer(); + auto t = sls::Timer(); std::this_thread::sleep_for(sleep_duration); REQUIRE(t.elapsed_s() == Approx(1).epsilon(0.01)); @@ -21,9 +19,7 @@ TEST_CASE("Time 1s restart then time 2s", "[.timer]") { TEST_CASE("Return ms", "[.timer]") { auto sleep_duration = std::chrono::milliseconds(1300); - auto t = Timer(); + auto t = sls::Timer(); std::this_thread::sleep_for(sleep_duration); REQUIRE(t.elapsed_ms() == Approx(1300).epsilon(0.5)); -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index ac246fda6..995b971b5 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -12,8 +12,11 @@ #include #include -namespace sls { - +// using namespace sls; +using sls::defs; +using sls::StringTo; +using sls::ToString; +using sls::ToStringHex; using namespace sls::time; TEST_CASE("Integer conversions", "[support]") { @@ -88,9 +91,9 @@ TEST_CASE("Array") { } TEST_CASE("Convert types with str method") { - IpAddr addr; + sls::IpAddr addr; REQUIRE(ToString(addr) == "0.0.0.0"); - REQUIRE(ToString(IpAddr{}) == "0.0.0.0"); + REQUIRE(ToString(sls::IpAddr{}) == "0.0.0.0"); } TEST_CASE("String to string", "[support]") { @@ -322,41 +325,39 @@ TEST_CASE("Printing c style arrays of double") { } TEST_CASE("Print a member of patternParameters") { - auto pat = make_unique(); + auto pat = sls::make_unique(); pat->limits[0] = 4; pat->limits[1] = 100; REQUIRE(ToString(pat->limits) == "[4, 100]"); } TEST_CASE("streamingInterface") { - REQUIRE(ToString(defs::streamingInterface::NONE) == "none"); - REQUIRE(ToString(defs::streamingInterface::ETHERNET_10GB) == "10gbe"); - REQUIRE(ToString(defs::streamingInterface::LOW_LATENCY_LINK) == "lll"); - REQUIRE(ToString(defs::streamingInterface::LOW_LATENCY_LINK | - defs::streamingInterface::ETHERNET_10GB) == + REQUIRE(ToString(sls::defs::streamingInterface::NONE) == "none"); + REQUIRE(ToString(sls::defs::streamingInterface::ETHERNET_10GB) == "10gbe"); + REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK) == "lll"); + REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK | + sls::defs::streamingInterface::ETHERNET_10GB) == "lll, 10gbe"); } // Speed level TEST_CASE("speedLevel to string") { - REQUIRE(ToString(defs::speedLevel::FULL_SPEED) == "full_speed"); - REQUIRE(ToString(defs::speedLevel::HALF_SPEED) == "half_speed"); - REQUIRE(ToString(defs::speedLevel::QUARTER_SPEED) == "quarter_speed"); - REQUIRE(ToString(defs::speedLevel::G2_108MHZ) == "108"); - REQUIRE(ToString(defs::speedLevel::G2_144MHZ) == "144"); + REQUIRE(ToString(sls::defs::speedLevel::FULL_SPEED) == "full_speed"); + REQUIRE(ToString(sls::defs::speedLevel::HALF_SPEED) == "half_speed"); + REQUIRE(ToString(sls::defs::speedLevel::QUARTER_SPEED) == "quarter_speed"); + REQUIRE(ToString(sls::defs::speedLevel::G2_108MHZ) == "108"); + REQUIRE(ToString(sls::defs::speedLevel::G2_144MHZ) == "144"); } TEST_CASE("string to speedLevel") { - REQUIRE(StringTo("full_speed") == - defs::speedLevel::FULL_SPEED); - REQUIRE(StringTo("half_speed") == - defs::speedLevel::HALF_SPEED); - REQUIRE(StringTo("quarter_speed") == - defs::speedLevel::QUARTER_SPEED); - REQUIRE(StringTo("108") == - defs::speedLevel::G2_108MHZ); - REQUIRE(StringTo("144") == - defs::speedLevel::G2_144MHZ); -} - -} // namespace sls + REQUIRE(StringTo("full_speed") == + sls::defs::speedLevel::FULL_SPEED); + REQUIRE(StringTo("half_speed") == + sls::defs::speedLevel::HALF_SPEED); + REQUIRE(StringTo("quarter_speed") == + sls::defs::speedLevel::QUARTER_SPEED); + REQUIRE(StringTo("108") == + sls::defs::speedLevel::G2_108MHZ); + REQUIRE(StringTo("144") == + sls::defs::speedLevel::G2_144MHZ); +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-TypeTraits.cpp b/slsSupportLib/tests/test-TypeTraits.cpp index bacfc0d4b..7e8190f28 100644 --- a/slsSupportLib/tests/test-TypeTraits.cpp +++ b/slsSupportLib/tests/test-TypeTraits.cpp @@ -8,8 +8,6 @@ #include #include -namespace sls { - // Dummy classes only used here for testing class DummyWithStr { public: @@ -21,37 +19,35 @@ class DummyNoStr { std::string somethingelse(); }; -TEST_CASE("is_container") { +TEST_CASE("sls::is_container") { - CHECK(is_container>::value == true); - CHECK(is_container>::value == true); + CHECK(sls::is_container>::value == true); + CHECK(sls::is_container>::value == true); } TEST_CASE("Check for str() method") { - REQUIRE(has_str::value == true); - REQUIRE(has_str::value == false); + REQUIRE(sls::has_str::value == true); + REQUIRE(sls::has_str::value == false); } TEST_CASE("Check for str() on ostream") { - REQUIRE(has_str::value == true); + REQUIRE(sls::has_str::value == true); } -TEST_CASE("is_duration") { - REQUIRE(is_duration::value == true); - REQUIRE(is_duration::value == true); - REQUIRE(is_duration::value == true); +TEST_CASE("sls::is_duration") { + REQUIRE(sls::is_duration::value == true); + REQUIRE(sls::is_duration::value == true); + REQUIRE(sls::is_duration::value == true); - REQUIRE(is_duration::value == false); - REQUIRE(is_duration>::value == false); + REQUIRE(sls::is_duration::value == false); + REQUIRE(sls::is_duration>::value == false); } TEST_CASE("initializer list") { - REQUIRE(is_light_container>::value == true); + REQUIRE(sls::is_light_container>::value == true); } TEST_CASE("Check for emplace back") { // we know vector should have this its the type trait that is tested - REQUIRE(has_emplace_back>::value == true); -} - -} // namespace sls + REQUIRE(sls::has_emplace_back>::value == true); +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-UdpRxSocket.cpp b/slsSupportLib/tests/test-UdpRxSocket.cpp index c0345671c..cca5373c7 100644 --- a/slsSupportLib/tests/test-UdpRxSocket.cpp +++ b/slsSupportLib/tests/test-UdpRxSocket.cpp @@ -15,8 +15,6 @@ #include #include -namespace sls { - constexpr int default_port = 50001; int open_socket(int port) { @@ -33,16 +31,16 @@ int open_socket(int port) { const std::string portname = std::to_string(port); if (getaddrinfo(host, portname.c_str(), &hints, &res)) { - throw RuntimeError("Failed at getaddrinfo with " + + throw sls::RuntimeError("Failed at getaddrinfo with " + std::string(host)); } int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (fd == -1) { - throw RuntimeError("Failed to create UDP RX socket"); + throw sls::RuntimeError("Failed to create UDP RX socket"); } if (connect(fd, res->ai_addr, res->ai_addrlen)) { - throw RuntimeError("Failed to connect socket"); + throw sls::RuntimeError("Failed to connect socket"); } freeaddrinfo(res); return fd; @@ -51,7 +49,7 @@ int open_socket(int port) { TEST_CASE("Get packet size returns the packet size we set in the constructor") { constexpr int port = 50001; constexpr ssize_t packet_size = 8000; - UdpRxSocket s{port, packet_size}; + sls::UdpRxSocket s{port, packet_size}; CHECK(s.getPacketSize() == packet_size); } @@ -62,7 +60,7 @@ TEST_CASE("Receive data from a vector") { ssize_t packet_size = sizeof(decltype(data_to_send)::value_type) * data_to_send.size(); - UdpRxSocket udpsock{port, packet_size}; + sls::UdpRxSocket udpsock{port, packet_size}; int fd = open_socket(port); auto n = write(fd, data_to_send.data(), packet_size); @@ -76,13 +74,13 @@ TEST_CASE("Receive data from a vector") { TEST_CASE("Shutdown socket without hanging when waiting for data") { constexpr int port = 50001; constexpr ssize_t packet_size = 8000; - UdpRxSocket s{port, packet_size}; + sls::UdpRxSocket s{port, packet_size}; char buff[packet_size]; // Start a thread and wait for package // if the socket is left open we would block std::future ret = - std::async(&UdpRxSocket::ReceivePacket, &s, (char *)&buff); + std::async(&sls::UdpRxSocket::ReceivePacket, &s, (char *)&buff); s.Shutdown(); auto r = ret.get(); @@ -92,7 +90,7 @@ TEST_CASE("Shutdown socket without hanging when waiting for data") { TEST_CASE("Too small packet") { constexpr int port = 50001; - UdpRxSocket s(port, 2 * sizeof(uint32_t)); + sls::UdpRxSocket s(port, 2 * sizeof(uint32_t)); auto fd = open_socket(port); uint32_t val = 10; write(fd, &val, sizeof(val)); @@ -105,10 +103,8 @@ TEST_CASE("Receive an int to an external buffer") { int to_send = 5; int received = -1; auto fd = open_socket(default_port); - UdpRxSocket s(default_port, sizeof(int)); + sls::UdpRxSocket s(default_port, sizeof(int)); write(fd, &to_send, sizeof(to_send)); CHECK(s.ReceivePacket(reinterpret_cast(&received))); CHECK(received == to_send); } - -} // namespace sls diff --git a/slsSupportLib/tests/test-ZmqSocket.cpp b/slsSupportLib/tests/test-ZmqSocket.cpp index 7697d952d..5dc51ddc0 100644 --- a/slsSupportLib/tests/test-ZmqSocket.cpp +++ b/slsSupportLib/tests/test-ZmqSocket.cpp @@ -3,9 +3,6 @@ #include "catch.hpp" #include "sls/ZmqSocket.h" -namespace sls { - - TEST_CASE("Throws when cannot create socket") { REQUIRE_THROWS(ZmqSocket("sdiasodjajpvv", 5076001)); } @@ -116,6 +113,4 @@ TEST_CASE("Send header and data") { for (size_t i = 0; i != data.size(); ++i) { REQUIRE(data[i] == received_data[i]); } -} - -} //namespace \ No newline at end of file +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-bit_utils.cpp b/slsSupportLib/tests/test-bit_utils.cpp index 9217f9ec0..2205c46df 100644 --- a/slsSupportLib/tests/test-bit_utils.cpp +++ b/slsSupportLib/tests/test-bit_utils.cpp @@ -4,27 +4,25 @@ #include "sls/bit_utils.h" #include -namespace sls { - TEST_CASE("Get set bits from 0") { - auto vec = getSetBits(0); + auto vec = sls::getSetBits(0); REQUIRE(vec.empty()); } TEST_CASE("Get set bits from 1") { - auto vec = getSetBits(1); + auto vec = sls::getSetBits(1); REQUIRE(vec.size() == 1); REQUIRE(vec[0] == 0); } TEST_CASE("Get set bits from 2") { - auto vec = getSetBits(2ul); + auto vec = sls::getSetBits(2ul); REQUIRE(vec.size() == 1); REQUIRE(vec[0] == 1); } TEST_CASE("Get set bits from 3") { - auto vec = getSetBits(3u); + auto vec = sls::getSetBits(3u); REQUIRE(vec.size() == 2); REQUIRE(vec[0] == 0); REQUIRE(vec[1] == 1); @@ -32,14 +30,12 @@ TEST_CASE("Get set bits from 3") { TEST_CASE("All bits set") { uint8_t val = -1; - auto vec = getSetBits(val); + auto vec = sls::getSetBits(val); REQUIRE(vec == std::vector{0, 1, 2, 3, 4, 5, 6, 7}); } TEST_CASE("Get set bits from 523") { // 0b1000001011 == 523 - auto vec = getSetBits(523); + auto vec = sls::getSetBits(523); REQUIRE(vec == std::vector{0, 1, 3, 9}); } - -} // namespace sls diff --git a/slsSupportLib/tests/test-container_utils.cpp b/slsSupportLib/tests/test-container_utils.cpp index ea98c084a..f791223c9 100644 --- a/slsSupportLib/tests/test-container_utils.cpp +++ b/slsSupportLib/tests/test-container_utils.cpp @@ -6,7 +6,7 @@ #include #include -namespace sls { +using namespace sls; TEST_CASE("Equality of an empty vector", "[support]") { std::vector v; @@ -64,36 +64,36 @@ TEST_CASE("A vector of double with different values", "[support]") { TEST_CASE("Sum of empty vector", "[support]") { std::vector v; - REQUIRE(sum(v) == Approx(0)); + REQUIRE(sls::sum(v) == Approx(0)); } TEST_CASE("Sum of vector", "[support]") { std::vector v{1.2, 2., 4.2, 4, 1.13}; - REQUIRE(sum(v) == Approx(12.53)); + REQUIRE(sls::sum(v) == Approx(12.53)); } TEST_CASE("Minus one if different", "[support]") { std::vector v; REQUIRE(v.empty()); double d = -1; - REQUIRE(minusOneIfDifferent(v) == d); + REQUIRE(sls::minusOneIfDifferent(v) == d); SECTION("single element") { v.push_back(7.3); REQUIRE(v.size() == 1); - REQUIRE(minusOneIfDifferent(v) == Approx(7.3)); + REQUIRE(sls::minusOneIfDifferent(v) == Approx(7.3)); } SECTION("different elements") { v.push_back(7.3); v.push_back(1.0); v.push_back(62.1); - REQUIRE(minusOneIfDifferent(v) == Approx(-1.0)); + REQUIRE(sls::minusOneIfDifferent(v) == Approx(-1.0)); } } TEST_CASE("minus one does not have side effects", "[support]") { std::vector v{1, 1, 1}; - int i = minusOneIfDifferent(v); + int i = sls::minusOneIfDifferent(v); REQUIRE(i == 1); i = 5; REQUIRE(v[0] == 1); @@ -134,6 +134,4 @@ TEST_CASE("compare a vector of arrays", "[support]") { arr.fill(-1); std::vector> vec1{{5, 90, 8}, {5, 6, 8}, {5, 6, 8}}; CHECK(minusOneIfDifferent(vec1) == arr); -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-file_utils.cpp b/slsSupportLib/tests/test-file_utils.cpp index 896409936..49544c83c 100644 --- a/slsSupportLib/tests/test-file_utils.cpp +++ b/slsSupportLib/tests/test-file_utils.cpp @@ -7,12 +7,10 @@ #include #include -namespace sls { - TEST_CASE("Get size of empty file") { char fname[] = "temfile_XXXXXX"; std::ifstream ifs(fname); - auto size = getFileSize(ifs); + auto size = sls::getFileSize(ifs); REQUIRE(size <= 0); // -1 or zero } @@ -24,9 +22,7 @@ TEST_CASE("Get size of file with data") { write(fh, data.data(), n_bytes); std::ifstream ifs(fname); - auto size = getFileSize(ifs); + auto size = sls::getFileSize(ifs); REQUIRE(size == n_bytes); REQUIRE(ifs.tellg() == 0); // getting size resets pos! } - -} // namespace sls diff --git a/slsSupportLib/tests/test-logger.cpp b/slsSupportLib/tests/test-logger.cpp index 320b2fb30..c1997c1f6 100644 --- a/slsSupportLib/tests/test-logger.cpp +++ b/slsSupportLib/tests/test-logger.cpp @@ -6,7 +6,7 @@ #include #include -namespace sls { +using sls::Logger; TEST_CASE("LogLevel to string") { CHECK(Logger::ToString(logERROR) == "ERROR"); @@ -48,6 +48,4 @@ TEST_CASE("Test output") { auto r = local.str(); auto pos = r.find("This should be printed"); CHECK(pos != std::string::npos); -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index b5beab9b3..d02296f1f 100644 --- a/slsSupportLib/tests/test-network_utils.cpp +++ b/slsSupportLib/tests/test-network_utils.cpp @@ -10,7 +10,7 @@ #include "sls/sls_detector_exceptions.h" #include "sls/string_utils.h" -namespace sls { +using namespace sls; TEST_CASE("Convert mac address using classes", "[support]") { @@ -128,5 +128,3 @@ TEST_CASE("udp dst struct basic properties") { } // TODO!(Erik) Look up a real hostname and verify the IP - -} // namespace sls diff --git a/slsSupportLib/tests/test-sls_detector_defs.cpp b/slsSupportLib/tests/test-sls_detector_defs.cpp index b7f2421c5..077c9ecfa 100644 --- a/slsSupportLib/tests/test-sls_detector_defs.cpp +++ b/slsSupportLib/tests/test-sls_detector_defs.cpp @@ -3,8 +3,6 @@ #include "catch.hpp" #include "sls/sls_detector_defs.h" -namespace sls { - using dt = slsDetectorDefs::detectorType; TEST_CASE("sls_detector_module default construction", "[support][new]") { @@ -77,6 +75,4 @@ TEST_CASE("compare two scanParameters") { p0.enable = 1; CHECK_FALSE(p0 == p1); -} - -} // namespace sls +} \ No newline at end of file diff --git a/slsSupportLib/tests/test-string_utils.cpp b/slsSupportLib/tests/test-string_utils.cpp index a562151d0..860f155bd 100644 --- a/slsSupportLib/tests/test-string_utils.cpp +++ b/slsSupportLib/tests/test-string_utils.cpp @@ -7,8 +7,6 @@ #include "sls/string_utils.h" -namespace sls { - TEST_CASE("copy a string") { char src[10] = "hej"; @@ -16,7 +14,7 @@ TEST_CASE("copy a string") { char dst[20]; - strcpy_safe(dst, src); + sls::strcpy_safe(dst, src); REQUIRE(dst[0] == 'h'); REQUIRE(dst[1] == 'e'); REQUIRE(dst[2] == 'j'); @@ -28,7 +26,7 @@ TEST_CASE("copy a string") { TEST_CASE("copy a long string") { auto src = "some very very long sting that does not fit"; char dst[3]; - strcpy_safe(dst, src); + sls::strcpy_safe(dst, src); REQUIRE(dst[0] == 's'); REQUIRE(dst[1] == 'o'); REQUIRE(dst[2] == '\0'); @@ -37,7 +35,7 @@ TEST_CASE("copy a long string") { TEST_CASE("split a string with end delimiter") { std::string s("abra+kadabra+"); - auto r = split(s, '+'); + auto r = sls::split(s, '+'); REQUIRE(r.size() == 2); REQUIRE(r[0] == "abra"); REQUIRE(r[1] == "kadabra"); @@ -45,7 +43,7 @@ TEST_CASE("split a string with end delimiter") { TEST_CASE("split a string without end delimiter") { std::string s("abra+kadabra+filibom"); - auto r = split(s, '+'); + auto r = sls::split(s, '+'); REQUIRE(r.size() == 3); REQUIRE(r[0] == "abra"); REQUIRE(r[1] == "kadabra"); @@ -54,60 +52,58 @@ TEST_CASE("split a string without end delimiter") { TEST_CASE("Remove char from string") { char str[] = "sometest"; - removeChar(str, 'e'); + sls::removeChar(str, 'e'); REQUIRE(std::string(str) == "somtst"); } TEST_CASE("Remove char from empty string") { char str[50] = {}; - removeChar(str, 'e'); + sls::removeChar(str, 'e'); REQUIRE(std::string(str).empty()); } TEST_CASE("Many characters in a row") { char str[] = "someeequitellll::ongstring"; - removeChar(str, 'l'); + sls::removeChar(str, 'l'); REQUIRE(std::string(str) == "someeequite::ongstring"); } TEST_CASE("Check is string is integer") { - REQUIRE(is_int("75")); - REQUIRE(is_int("11675")); - REQUIRE_FALSE(is_int("7.5")); - REQUIRE_FALSE(is_int("hej")); - REQUIRE_FALSE(is_int("7a")); - REQUIRE_FALSE(is_int("")); + REQUIRE(sls::is_int("75")); + REQUIRE(sls::is_int("11675")); + REQUIRE_FALSE(sls::is_int("7.5")); + REQUIRE_FALSE(sls::is_int("hej")); + REQUIRE_FALSE(sls::is_int("7a")); + REQUIRE_FALSE(sls::is_int("")); } TEST_CASE("Replace substring in string") { std::string s = "this string should be replaced"; - auto r = replace_first(&s, "string ", ""); + auto r = sls::replace_first(&s, "string ", ""); REQUIRE(r == true); REQUIRE(s == "this should be replaced"); } TEST_CASE("Replace --help in command") { std::string s = "sls_detector_get --help exptime"; - auto r = replace_first(&s, " --help", ""); + auto r = sls::replace_first(&s, " --help", ""); REQUIRE(r == true); REQUIRE(s == "sls_detector_get exptime"); } TEST_CASE("Replace -h in command") { std::string s = "sls_detector_get -h exptime"; - auto r = replace_first(&s, " -h", ""); + auto r = sls::replace_first(&s, " -h", ""); REQUIRE(r == true); REQUIRE(s == "sls_detector_get exptime"); } TEST_CASE("replace --help") { std::string s = "list --help"; - auto r = replace_first(&s, " --help", ""); + auto r = sls::replace_first(&s, " --help", ""); REQUIRE(r == true); REQUIRE(s == "list"); } -// TEST_CASE("concat things not being strings") - -} // namespace sls +// TEST_CASE("concat things not being strings") \ No newline at end of file diff --git a/tests/include/tests/config.h b/tests/include/tests/config.h index 835bf0e42..f6b541cbf 100644 --- a/tests/include/tests/config.h +++ b/tests/include/tests/config.h @@ -4,8 +4,6 @@ #include "sls/sls_detector_defs.h" #include -namespace sls { - struct SingleDetectorConfig { slsDetectorDefs::detectorType type_enum = slsDetectorDefs::detectorType::EIGER; @@ -13,5 +11,3 @@ struct SingleDetectorConfig { const std::string type_string = "Eiger"; const std::string my_ip = "129.129.205.171"; }; - -} // namespace sls diff --git a/tests/include/tests/globals.h b/tests/include/tests/globals.h index 3d4b2187a..ff7b86a64 100644 --- a/tests/include/tests/globals.h +++ b/tests/include/tests/globals.h @@ -2,9 +2,6 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #pragma once #include "sls/sls_detector_defs.h" - -namespace sls { - using dt = slsDetectorDefs::detectorType; using di = slsDetectorDefs::dacIndex; using defs = slsDetectorDefs; @@ -18,5 +15,3 @@ extern decltype(defs::GET_ACTION) GET; extern decltype(defs::PUT_ACTION) PUT; } // namespace test - -} // namespace sls diff --git a/tests/include/tests/testenum.h b/tests/include/tests/testenum.h index 2e35f911e..64405f12d 100644 --- a/tests/include/tests/testenum.h +++ b/tests/include/tests/testenum.h @@ -2,11 +2,6 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #pragma once #include - -namespace sls { - enum class func_id { read_data, read_int, read_half_data, combined }; constexpr size_t MB = 1048576; -constexpr size_t DATA_SIZE = 50 * MB; - -} // namespace sls +constexpr size_t DATA_SIZE = 50 * MB; \ No newline at end of file diff --git a/tests/src/testclient.cpp b/tests/src/testclient.cpp index b4bece3f5..6607b60d1 100644 --- a/tests/src/testclient.cpp +++ b/tests/src/testclient.cpp @@ -32,13 +32,13 @@ int main(int argc, char **argv) { std::cout << "Sending to: " << hostname << ":" << port << "\n"; - auto data = sls::make_unique(sls::DATA_SIZE); + auto data = sls::make_unique(DATA_SIZE); // Many connections sending small amounts for (int i = 0; i != 100; ++i) { std::cout << "Sending: " << i << "\n"; auto socket = sls::ClientSocket("test", hostname, port); - std::cout << "Sent: " << socket.Send(sls::func_id::read_int) << " bytes\n"; + std::cout << "Sent: " << socket.Send(func_id::read_int) << " bytes\n"; std::cout << "Sent: " << socket.Send(i) << " bytes\n"; } @@ -46,24 +46,24 @@ int main(int argc, char **argv) { for (int i = 0; i != 5; ++i) { std::cout << "Sending data\n"; auto socket = sls::ClientSocket("test", hostname, port); - std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n"; - std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE) + std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n"; + std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE) << " bytes\n"; } // Send too little data { auto socket = sls::ClientSocket("test", hostname, port); - std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n"; - std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE / 2) + std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n"; + std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE / 2) << " bytes\n"; } // Send too much data try { auto socket = sls::ClientSocket("test", hostname, port); - std::cout << "Sent: " << socket.Send(sls::func_id::read_half_data) + std::cout << "Sent: " << socket.Send(func_id::read_half_data) << " bytes\n"; - std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE) + std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE) << " bytes\n"; } catch (const sls::SocketError &e) { } @@ -71,7 +71,7 @@ int main(int argc, char **argv) { for (int i = 0; i != 10; ++i) { std::cout << "Sending: " << i << "\n"; auto socket = sls::ClientSocket("test", hostname, port); - std::cout << "Sent: " << socket.Send(sls::func_id::read_int) << " bytes\n"; + std::cout << "Sent: " << socket.Send(func_id::read_int) << " bytes\n"; std::cout << "Sent: " << socket.Send(i) << " bytes\n"; } @@ -81,7 +81,7 @@ int main(int argc, char **argv) { double b = 18.3; float c = -1.2; auto socket = sls::ClientSocket("test", hostname, port); - int s = socket.SendAll(sls::func_id::combined, a, b, c); + int s = socket.SendAll(func_id::combined, a, b, c); std::cout << "send all: " << s << "\n"; } } diff --git a/tests/src/testserver.cpp b/tests/src/testserver.cpp index b11835a1b..81fcac66f 100644 --- a/tests/src/testserver.cpp +++ b/tests/src/testserver.cpp @@ -25,14 +25,14 @@ using func_ptr = void (*)(Interface &); ********************************************/ void read_data(Interface &socket) { - auto data = sls::make_unique(sls::DATA_SIZE); - std::cout << "Read: " << socket.Receive(data.get(), sls::DATA_SIZE) + auto data = sls::make_unique(DATA_SIZE); + std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE) << " bytes into buffer\n"; } void read_half_data(Interface &socket) { - auto data = sls::make_unique(sls::DATA_SIZE); - std::cout << "Read: " << socket.Receive(data.get(), sls::DATA_SIZE / 2) + auto data = sls::make_unique(DATA_SIZE); + std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE / 2) << " bytes into buffer\n"; } @@ -49,11 +49,11 @@ void read_combined(Interface &socket) { } // Map from int to function pointer, in this case probably a map would be faster -std::unordered_map fmap{ - {sls::func_id::read_data, &read_data}, - {sls::func_id::read_int, &read_int}, - {sls::func_id::read_half_data, &read_half_data}, - {sls::func_id::combined, &read_combined}}; +std::unordered_map fmap{ + {func_id::read_data, &read_data}, + {func_id::read_int, &read_int}, + {func_id::read_half_data, &read_half_data}, + {func_id::combined, &read_combined}}; int main(int argc, char **argv) { std::cout << "Starting test server...\n"; @@ -73,7 +73,7 @@ int main(int argc, char **argv) { while (true) { try { auto socket = server.accept(); - auto fnum = socket.Receive(); + auto fnum = socket.Receive(); std::cout << "Calling func: " << (int)fnum << "\n"; (*fmap[fnum])(socket); // call mapped function diff --git a/tests/test.cpp b/tests/test.cpp index c3cf8d468..076f489e7 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -11,8 +11,6 @@ #include "tests/config.h" #include -namespace sls { - // using namespace Catch::clara; using Opt = Catch::clara::Opt; using dt = slsDetectorDefs::detectorType; @@ -48,10 +46,8 @@ int main(int argc, char *argv[]) { test::type = slsDetectorDefs::GENERIC; if (!test::detector_type.empty()) { test::type = - StringTo(test::detector_type); + sls::StringTo(test::detector_type); } return session.run(); -} - -} // namespace sls +} \ No newline at end of file