diff --git a/integrationTests/test-eigerIntegration.cpp b/integrationTests/test-eigerIntegration.cpp index 0f7fea11f..6fa4124d2 100644 --- a/integrationTests/test-eigerIntegration.cpp +++ b/integrationTests/test-eigerIntegration.cpp @@ -6,6 +6,8 @@ #include "tests/globals.h" #include +namespace sls { + class MultiDetectorFixture { protected: DetectorImpl d; @@ -136,7 +138,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 = sls::split(hn, '+'); + auto hostnames = split(hn, '+'); CHECK(hostnames.size() == d.getNumberOfDetectors()); for (int i = 0; i != d.getNumberOfDetectors(); ++i) { CHECK(d.getId(defs::DETECTOR_SERIAL_NUMBER, 0) == @@ -198,3 +200,5 @@ 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 9d0847b4f..977c66cdc 100644 --- a/integrationTests/test-integrationDectector.cpp +++ b/integrationTests/test-integrationDectector.cpp @@ -24,6 +24,8 @@ // 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); @@ -283,14 +285,14 @@ TEST_CASE( CHECK(m.getRateCorrection() == ratecorr); // ratecorr fail with dr 4 or 8 - CHECK_THROWS_AS(m.setDynamicRange(8), sls::RuntimeError); + CHECK_THROWS_AS(m.setDynamicRange(8), 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), sls::RuntimeError); + CHECK_THROWS_AS(m.setDynamicRange(4), RuntimeError); CHECK(m.getRateCorrection() == 0); } @@ -329,11 +331,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), sls::RuntimeError); + CHECK_THROWS_AS(m.setPatternWord(addr, word), RuntimeError); CHECK_THROWS_WITH(m.setPatternWord(addr, word), Catch::Matchers::Contains("be between 0 and")); addr = -1; - CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::RuntimeError); + CHECK_THROWS_AS(m.setPatternWord(addr, word), RuntimeError); CHECK_THROWS_WITH(m.setPatternWord(addr, word), Catch::Matchers::Contains("be between 0 and")); @@ -408,7 +410,7 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", CHECK(m.getReceiverDbitList().size() == 10); list.push_back(64); - CHECK_THROWS_AS(m.setReceiverDbitList(list), sls::RuntimeError); + CHECK_THROWS_AS(m.setReceiverDbitList(list), RuntimeError); CHECK_THROWS_WITH(m.setReceiverDbitList(list), Catch::Matchers::Contains("be between 0 and 63")); @@ -476,7 +478,7 @@ TEST_CASE("Eiger or Jungfrau nextframenumber", CHECK(m.acquire() == slsDetectorDefs::OK); CHECK(m.getReceiverCurrentFrameIndex() == val); - CHECK_THROWS_AS(m.setNextFrameNumber(0), sls::RuntimeError); + CHECK_THROWS_AS(m.setNextFrameNumber(0), RuntimeError); if (m.getDetectorTypeAsString() == "Eiger") { val = 281474976710655; @@ -511,8 +513,10 @@ TEST_CASE("Eiger partialread", "[.eigerintegration][partialread]") { m.setDynamicRange(8); m.setPartialReadout(256); CHECK(m.getPartialReadout() == 256); - CHECK_THROWS_AS(m.setPartialReadout(1), sls::RuntimeError); + CHECK_THROWS_AS(m.setPartialReadout(1), RuntimeError); CHECK(m.getPartialReadout() == 256); - CHECK_THROWS_AS(m.setPartialReadout(0), sls::RuntimeError); + CHECK_THROWS_AS(m.setPartialReadout(0), RuntimeError); m.setPartialReadout(256); -} \ No newline at end of file +} + +} // namespace sls diff --git a/integrationTests/test-integrationMulti.cpp b/integrationTests/test-integrationMulti.cpp index 3dd6b1903..64716e45c 100644 --- a/integrationTests/test-integrationMulti.cpp +++ b/integrationTests/test-integrationMulti.cpp @@ -6,10 +6,12 @@ #include "tests/globals.h" #include +namespace sls { + using namespace Catch::literals; TEST_CASE("Initialize a multi detector", "[.integration][.multi]") { - auto hostnames = sls::split(test::hostname, '+'); + auto hostnames = split(test::hostname, '+'); DetectorImpl d(0, true, true); d.setHostname(test::hostname.c_str()); @@ -102,3 +104,6 @@ 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 5a39e615e..14a522639 100755 --- a/slsDetectorSoftware/tests/CMakeLists.txt +++ b/slsDetectorSoftware/tests/CMakeLists.txt @@ -21,4 +21,9 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-CtbConfig.cpp ) -target_include_directories(tests PUBLIC "$") \ No newline at end of file +target_include_directories(tests + PUBLIC + "$" + PRIVATE + ${SLS_INTERNAL_RAPIDJSON_DIR} +) \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdParser.cpp b/slsDetectorSoftware/tests/test-CmdParser.cpp index a95b7eeee..84a4b1f6d 100644 --- a/slsDetectorSoftware/tests/test-CmdParser.cpp +++ b/slsDetectorSoftware/tests/test-CmdParser.cpp @@ -9,8 +9,9 @@ // 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") { @@ -406,4 +407,6 @@ 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"); -} \ No newline at end of file +} + +} // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp b/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp index e750bc6a4..5f9402b5b 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + 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(); - sls::Result prev_dsamples = 0; + Result prev_dsamples = 0; if (det_type == defs::CHIPTESTBOARD) { prev_dsamples = det.getNumberOfDigitalSamples(); } @@ -865,4 +865,6 @@ TEST_CASE("led", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("led", {}, -1, GET)); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp index 6536275cf..4aadf686c 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + using test::GET; using test::PUT; @@ -657,4 +657,6 @@ TEST_CASE("top", "[.cmd]") { REQUIRE_THROWS(proxy.Call("top", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("top", {"1"}, -1, PUT)); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-global.cpp b/slsDetectorSoftware/tests/test-CmdProxy-global.cpp index b8a0ca624..e89c38aef 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + 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 = sls::ToStringHex(dacvalue); + auto dacValueStr = ToStringHex(dacvalue); auto chipIndexStr = std::to_string(chipIndex); std::ostringstream oss_set, oss_get; proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set); @@ -66,4 +66,6 @@ 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}); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-global.h b/slsDetectorSoftware/tests/test-CmdProxy-global.h index 899462ad5..c794601a8 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-global.h +++ b/slsDetectorSoftware/tests/test-CmdProxy-global.h @@ -3,7 +3,12 @@ #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 cbb737a1f..0f48f16b3 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + using test::GET; using test::PUT; @@ -154,4 +154,6 @@ TEST_CASE("exptimel", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("exptimel", {}, -1, GET)); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp index cdba5d406..6d799830f 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + 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 = sls::ToString(burst); + auto burststr = ToString(burst); { std::ostringstream oss; proxy.Call("burstmode", {"burst_internal"}, -1, PUT, oss); @@ -743,4 +743,6 @@ TEST_CASE("badchannels", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET)); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp index 4ab690977..7a4e24698 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + using test::GET; using test::PUT; @@ -538,3 +538,5 @@ 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 a3f8838e4..b7656db3a 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + using test::GET; using test::PUT; @@ -108,3 +108,5 @@ 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 21c958594..3eedd9ea4 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + 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 " + sls::ToString(list_str) + "\n"); + REQUIRE(oss_set3.str() == "counters " + ToString(list_str) + "\n"); proxy.Call("counters", {}, -1, GET, oss_get); - REQUIRE(oss_get.str() == "counters " + sls::ToString(list_str) + "\n"); + REQUIRE(oss_get.str() == "counters " + 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 sls::RuntimeError("inconsistent gatedelay for all gates"); + throw RuntimeError("inconsistent gatedelay for all gates"); } { std::ostringstream oss; @@ -610,4 +610,6 @@ TEST_CASE("dpulse", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("dpulse", {}, -1, GET)); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp b/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp index 739ca10f9..661bab5d5 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + 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 = sls::ToStringHex(addr, 4); + std::string saddr = ToStringHex(addr, 4); auto prev_val = det.getPatternWord(addr); { std::ostringstream oss; @@ -528,4 +528,6 @@ TEST_CASE("patternstart", "[.cmd]") { } else { REQUIRE_THROWS(proxy.Call("patternstart", {}, -1, PUT)); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index 34d433591..aa733a6c0 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" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + 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.getDetectrSize(); + defs::xy detsize = det.getDetectorSize(); // 1d if (det_type == defs::GOTTHARD || det_type == defs::GOTTHARD2 || @@ -991,3 +991,5 @@ TEST_CASE("rx_jsonpara", "[.cmd][.rx]") { } /* Insignificant */ + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 5ed8e6e86..156f82b2f 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -11,8 +11,8 @@ #include "tests/globals.h" -using sls::CmdProxy; -using sls::Detector; +namespace sls { + 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 == sls::ToString(dt) + '\n'); + REQUIRE(ans == 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:" << sls::ToString(prev_threshold[i]) + << "prev cvalues:" << 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 sls::RuntimeError("inconsistent exptime for all gates"); + throw 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 = sls::ToString(it); + auto dacname = 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 = sls::ToString(it); + auto dacname = 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 sls::RuntimeError("inconsistent exptime for all gates"); + throw 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 sls::RuntimeError("inconsistent exptime for all gates"); + throw 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 sls::RuntimeError("inconsistent exptime for all gates"); + throw RuntimeError("inconsistent exptime for all gates"); } prev_val = t[0]; } @@ -2265,29 +2265,29 @@ TEST_CASE("scan", "[.cmd]") { { std::ostringstream oss; - proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500"}, -1, PUT, + proxy.Call("scan", {ToString(ind), "500", "1500", "500"}, -1, PUT, oss); CHECK(oss.str() == - "scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n"); + "scan [" + ToString(ind) + ", 500, 1500, 500]\n"); } { std::ostringstream oss; proxy.Call("scan", {}, -1, GET, oss); - CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) + + CHECK(oss.str() == "scan [enabled\ndac " + ToString(ind) + "\nstart 500\nstop 1500\nstep " "500\nsettleTime 1ms\n]\n"); } { std::ostringstream oss; - proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500", "2s"}, -1, + proxy.Call("scan", {ToString(ind), "500", "1500", "500", "2s"}, -1, PUT, oss); CHECK(oss.str() == - "scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n"); + "scan [" + ToString(ind) + ", 500, 1500, 500, 2s]\n"); } { std::ostringstream oss; proxy.Call("scan", {}, -1, GET, oss); - CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) + + CHECK(oss.str() == "scan [enabled\ndac " + 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", {sls::ToString(ind), "1500", "500", "-500"}, -1, PUT, + proxy.Call("scan", {ToString(ind), "1500", "500", "-500"}, -1, PUT, oss); CHECK(oss.str() == - "scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n"); + "scan [" + ToString(ind) + ", 1500, 500, -500]\n"); } CHECK_THROWS(proxy.Call( - "scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1, + "scan", {ToString(notImplementedInd), "500", "1500", "500"}, -1, PUT)); - CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "500", "1500", "-500"}, + CHECK_THROWS(proxy.Call("scan", {ToString(ind), "500", "1500", "-500"}, -1, PUT)); - CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "1500", "500", "500"}, + CHECK_THROWS(proxy.Call("scan", {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] != sls::IpAddr{"0.0.0.0"}) + if (prev_val[i] != 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 = sls::ToStringHex(addr); + std::string saddr = 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 = sls::ToStringHex(addr); + std::string saddr = 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 = sls::ToStringHex(addr); + std::string saddr = 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 = sls::ToStringHex(addr); + std::string saddr = ToStringHex(addr); auto prev_val = det.readRegister(addr); { std::ostringstream oss1, oss2; @@ -3162,3 +3162,5 @@ 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 15a22e852..f8a683cf9 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,4 +56,6 @@ TEST_CASE("Move CtbConfig "){ c1.setDacName(3, "yetanothername"); CtbConfig c2(std::move(c1)); REQUIRE(c2.getDacName(3) == "yetanothername"); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-Module.cpp b/slsDetectorSoftware/tests/test-Module.cpp index 2fdb60998..203ee30f3 100644 --- a/slsDetectorSoftware/tests/test-Module.cpp +++ b/slsDetectorSoftware/tests/test-Module.cpp @@ -4,19 +4,21 @@ #include "SharedMemory.h" #include "catch.hpp" +namespace sls { + using dt = slsDetectorDefs::detectorType; TEST_CASE("Construction with a defined detector type") { - sls::Module m(dt::EIGER); + 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 - sls::Module m(dt::JUNGFRAU); + Module m(dt::JUNGFRAU); // New detector that reads type from shm - sls::Module m2; + Module m2; REQUIRE(m2.getDetectorType() == dt::JUNGFRAU); // Now both objects point to the same shm so we can only @@ -25,13 +27,13 @@ TEST_CASE("Read back detector type from shm") { } TEST_CASE("Is shm fixed pattern shm compatible") { - sls::Module m(dt::JUNGFRAU); + Module m(dt::JUNGFRAU); // Should be true since we just created the shm REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true); // Set shm version to 0 - sls::SharedMemory shm(0, 0); + SharedMemory shm(0, 0); REQUIRE(shm.exists() == true); shm.openSharedMemory(true); shm()->shmversion = 0; @@ -43,19 +45,21 @@ TEST_CASE("Is shm fixed pattern shm compatible") { } TEST_CASE("Get default control port") { - sls::Module m(dt::MYTHEN3); + Module m(dt::MYTHEN3); REQUIRE(m.getControlPort() == 1952); m.freeSharedMemory(); } TEST_CASE("Get default stop port") { - sls::Module m(dt::GOTTHARD2); + Module m(dt::GOTTHARD2); REQUIRE(m.getStopPort() == 1953); m.freeSharedMemory(); } TEST_CASE("Get default receiver TCP port") { - sls::Module m(dt::MYTHEN3); + Module m(dt::MYTHEN3); REQUIRE(m.getReceiverPort() == 1954); m.freeSharedMemory(); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-Pattern.cpp b/slsDetectorSoftware/tests/test-Pattern.cpp index 6128fe0b8..3c7c6abd5 100644 --- a/slsDetectorSoftware/tests/test-Pattern.cpp +++ b/slsDetectorSoftware/tests/test-Pattern.cpp @@ -3,7 +3,7 @@ #include "catch.hpp" #include "sls/Pattern.h" -using sls::Pattern; +namespace sls { TEST_CASE("Pattern is default constructable and has zeroed fields") { Pattern p; @@ -27,3 +27,5 @@ 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 72e1993f0..6763a43d0 100644 --- a/slsDetectorSoftware/tests/test-Result.cpp +++ b/slsDetectorSoftware/tests/test-Result.cpp @@ -6,10 +6,10 @@ #include "sls/TypeTraits.h" #include -using sls::Result; +namespace sls { TEST_CASE("Result looks and behaves like a standard container") { - REQUIRE(sls::is_container>::value == true); + REQUIRE(is_container>::value == true); } TEST_CASE("Default construction is possible and gives an empty result") { @@ -195,3 +195,5 @@ 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 67df21efb..ad5743e15 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; - sls::strcpy_safe(shm()->mess, "Some string"); + strcpy_safe(shm()->mess, "Some string"); CHECK(shm()->x == 3); CHECK(shm()->y == 5.7); @@ -168,8 +168,6 @@ TEST_CASE("map int64 to int32 throws"){ REQUIRE_THROWS(shm2.openSharedMemory(true)); shm.removeSharedMemory(); - +} - - -} \ No newline at end of file +} // namespace sls diff --git a/slsDetectorSoftware/tests/test-slsDetector.cpp b/slsDetectorSoftware/tests/test-slsDetector.cpp index f68c68b9e..966bb721b 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), sls::RuntimeError); +// CHECK_THROWS_AS(d.setReceiverDbitList(list), 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 db1523c0b..b83075065 100644 --- a/slsReceiverSoftware/tests/test-CircularFifo.cpp +++ b/slsReceiverSoftware/tests/test-CircularFifo.cpp @@ -4,7 +4,8 @@ #include "sls/CircularFifo.h" #include -using sls::CircularFifo; +namespace sls { + TEST_CASE("Empty buffer") { CircularFifo fifo(0); @@ -50,4 +51,6 @@ TEST_CASE("Push pop") { CHECK(fifo.isEmpty() == true); CHECK(fifo.isFull() == false); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsSupportLib/tests/test-Sockets.cpp b/slsSupportLib/tests/test-Sockets.cpp index f8d7e80c5..b41c44cb4 100644 --- a/slsSupportLib/tests/test-Sockets.cpp +++ b/slsSupportLib/tests/test-Sockets.cpp @@ -8,9 +8,11 @@ #include #include +namespace sls { + std::vector server() { std::cout << "starting server\n"; - auto server = sls::ServerSocket(1950); + auto server = ServerSocket(1950); auto s = server.accept(); std::vector buffer(100, '\0'); s.Receive(buffer.data(), buffer.size()); @@ -33,7 +35,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 = sls::DetectorSocket("localhost", 1950); + auto client = DetectorSocket("localhost", 1950); client.Send(sent_message.data(), sent_message.size()); client.Receive(received_message.data(), received_message.size()); client.close(); @@ -45,5 +47,7 @@ TEST_CASE("The server recive the same message as we send", "[support]") { } TEST_CASE("throws on no server", "[support]") { - CHECK_THROWS(sls::DetectorSocket("localhost", 1950)); -} \ No newline at end of file + CHECK_THROWS(DetectorSocket("localhost", 1950)); +} + +} // namespace sls diff --git a/slsSupportLib/tests/test-StaticVector.cpp b/slsSupportLib/tests/test-StaticVector.cpp index 8b5fa7cca..6f9f5da50 100644 --- a/slsSupportLib/tests/test-StaticVector.cpp +++ b/slsSupportLib/tests/test-StaticVector.cpp @@ -7,10 +7,11 @@ #include #include #include -using sls::StaticVector; + +namespace sls { TEST_CASE("StaticVector is a container") { - REQUIRE(sls::is_container>::value == true); + REQUIRE(is_container>::value == true); } TEST_CASE("Comparing StaticVector containers") { @@ -317,15 +318,15 @@ SCENARIO("Converting to vector", "[support]") { } } -TEST_CASE("sls::StaticVector") { - sls::StaticVector vec; +TEST_CASE("StaticVector") { + StaticVector vec; vec.push_back(3); vec.push_back(8); - REQUIRE(sls::ToString(vec) == "[3, 8]"); + REQUIRE(ToString(vec) == "[3, 8]"); } -TEST_CASE("sls::StaticVector stream") { - sls::StaticVector vec; +TEST_CASE("StaticVector stream") { + StaticVector vec; vec.push_back(33); vec.push_back(85667); vec.push_back(2); @@ -333,3 +334,5 @@ TEST_CASE("sls::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 9d3ae69cb..6d94f1f7b 100644 --- a/slsSupportLib/tests/test-Timer.cpp +++ b/slsSupportLib/tests/test-Timer.cpp @@ -6,9 +6,11 @@ #include #include +namespace sls { + TEST_CASE("Time 1s restart then time 2s", "[.timer]") { auto sleep_duration = std::chrono::seconds(1); - auto t = sls::Timer(); + auto t = Timer(); std::this_thread::sleep_for(sleep_duration); REQUIRE(t.elapsed_s() == Approx(1).epsilon(0.01)); @@ -19,7 +21,9 @@ TEST_CASE("Time 1s restart then time 2s", "[.timer]") { TEST_CASE("Return ms", "[.timer]") { auto sleep_duration = std::chrono::milliseconds(1300); - auto t = sls::Timer(); + auto t = Timer(); std::this_thread::sleep_for(sleep_duration); REQUIRE(t.elapsed_ms() == Approx(1300).epsilon(0.5)); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index 995b971b5..ac246fda6 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -12,11 +12,8 @@ #include #include -// using namespace sls; -using sls::defs; -using sls::StringTo; -using sls::ToString; -using sls::ToStringHex; +namespace sls { + using namespace sls::time; TEST_CASE("Integer conversions", "[support]") { @@ -91,9 +88,9 @@ TEST_CASE("Array") { } TEST_CASE("Convert types with str method") { - sls::IpAddr addr; + IpAddr addr; REQUIRE(ToString(addr) == "0.0.0.0"); - REQUIRE(ToString(sls::IpAddr{}) == "0.0.0.0"); + REQUIRE(ToString(IpAddr{}) == "0.0.0.0"); } TEST_CASE("String to string", "[support]") { @@ -325,39 +322,41 @@ TEST_CASE("Printing c style arrays of double") { } TEST_CASE("Print a member of patternParameters") { - auto pat = sls::make_unique(); + auto pat = make_unique(); pat->limits[0] = 4; pat->limits[1] = 100; REQUIRE(ToString(pat->limits) == "[4, 100]"); } TEST_CASE("streamingInterface") { - 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) == + 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) == "lll, 10gbe"); } // Speed level TEST_CASE("speedLevel to string") { - 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"); + 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"); } TEST_CASE("string to speedLevel") { - 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 + 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 diff --git a/slsSupportLib/tests/test-TypeTraits.cpp b/slsSupportLib/tests/test-TypeTraits.cpp index 7e8190f28..bacfc0d4b 100644 --- a/slsSupportLib/tests/test-TypeTraits.cpp +++ b/slsSupportLib/tests/test-TypeTraits.cpp @@ -8,6 +8,8 @@ #include #include +namespace sls { + // Dummy classes only used here for testing class DummyWithStr { public: @@ -19,35 +21,37 @@ class DummyNoStr { std::string somethingelse(); }; -TEST_CASE("sls::is_container") { +TEST_CASE("is_container") { - CHECK(sls::is_container>::value == true); - CHECK(sls::is_container>::value == true); + CHECK(is_container>::value == true); + CHECK(is_container>::value == true); } TEST_CASE("Check for str() method") { - REQUIRE(sls::has_str::value == true); - REQUIRE(sls::has_str::value == false); + REQUIRE(has_str::value == true); + REQUIRE(has_str::value == false); } TEST_CASE("Check for str() on ostream") { - REQUIRE(sls::has_str::value == true); + REQUIRE(has_str::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); +TEST_CASE("is_duration") { + REQUIRE(is_duration::value == true); + REQUIRE(is_duration::value == true); + REQUIRE(is_duration::value == true); - REQUIRE(sls::is_duration::value == false); - REQUIRE(sls::is_duration>::value == false); + REQUIRE(is_duration::value == false); + REQUIRE(is_duration>::value == false); } TEST_CASE("initializer list") { - REQUIRE(sls::is_light_container>::value == true); + REQUIRE(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(sls::has_emplace_back>::value == true); -} \ No newline at end of file + REQUIRE(has_emplace_back>::value == true); +} + +} // namespace sls diff --git a/slsSupportLib/tests/test-UdpRxSocket.cpp b/slsSupportLib/tests/test-UdpRxSocket.cpp index cca5373c7..c0345671c 100644 --- a/slsSupportLib/tests/test-UdpRxSocket.cpp +++ b/slsSupportLib/tests/test-UdpRxSocket.cpp @@ -15,6 +15,8 @@ #include #include +namespace sls { + constexpr int default_port = 50001; int open_socket(int port) { @@ -31,16 +33,16 @@ int open_socket(int port) { const std::string portname = std::to_string(port); if (getaddrinfo(host, portname.c_str(), &hints, &res)) { - throw sls::RuntimeError("Failed at getaddrinfo with " + + throw RuntimeError("Failed at getaddrinfo with " + std::string(host)); } int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (fd == -1) { - throw sls::RuntimeError("Failed to create UDP RX socket"); + throw RuntimeError("Failed to create UDP RX socket"); } if (connect(fd, res->ai_addr, res->ai_addrlen)) { - throw sls::RuntimeError("Failed to connect socket"); + throw RuntimeError("Failed to connect socket"); } freeaddrinfo(res); return fd; @@ -49,7 +51,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; - sls::UdpRxSocket s{port, packet_size}; + UdpRxSocket s{port, packet_size}; CHECK(s.getPacketSize() == packet_size); } @@ -60,7 +62,7 @@ TEST_CASE("Receive data from a vector") { ssize_t packet_size = sizeof(decltype(data_to_send)::value_type) * data_to_send.size(); - sls::UdpRxSocket udpsock{port, packet_size}; + UdpRxSocket udpsock{port, packet_size}; int fd = open_socket(port); auto n = write(fd, data_to_send.data(), packet_size); @@ -74,13 +76,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; - sls::UdpRxSocket s{port, packet_size}; + 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(&sls::UdpRxSocket::ReceivePacket, &s, (char *)&buff); + std::async(&UdpRxSocket::ReceivePacket, &s, (char *)&buff); s.Shutdown(); auto r = ret.get(); @@ -90,7 +92,7 @@ TEST_CASE("Shutdown socket without hanging when waiting for data") { TEST_CASE("Too small packet") { constexpr int port = 50001; - sls::UdpRxSocket s(port, 2 * sizeof(uint32_t)); + UdpRxSocket s(port, 2 * sizeof(uint32_t)); auto fd = open_socket(port); uint32_t val = 10; write(fd, &val, sizeof(val)); @@ -103,8 +105,10 @@ TEST_CASE("Receive an int to an external buffer") { int to_send = 5; int received = -1; auto fd = open_socket(default_port); - sls::UdpRxSocket s(default_port, sizeof(int)); + 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 5dc51ddc0..7697d952d 100644 --- a/slsSupportLib/tests/test-ZmqSocket.cpp +++ b/slsSupportLib/tests/test-ZmqSocket.cpp @@ -3,6 +3,9 @@ #include "catch.hpp" #include "sls/ZmqSocket.h" +namespace sls { + + TEST_CASE("Throws when cannot create socket") { REQUIRE_THROWS(ZmqSocket("sdiasodjajpvv", 5076001)); } @@ -113,4 +116,6 @@ TEST_CASE("Send header and data") { for (size_t i = 0; i != data.size(); ++i) { REQUIRE(data[i] == received_data[i]); } -} \ No newline at end of file +} + +} //namespace \ No newline at end of file diff --git a/slsSupportLib/tests/test-bit_utils.cpp b/slsSupportLib/tests/test-bit_utils.cpp index 2205c46df..9217f9ec0 100644 --- a/slsSupportLib/tests/test-bit_utils.cpp +++ b/slsSupportLib/tests/test-bit_utils.cpp @@ -4,25 +4,27 @@ #include "sls/bit_utils.h" #include +namespace sls { + TEST_CASE("Get set bits from 0") { - auto vec = sls::getSetBits(0); + auto vec = getSetBits(0); REQUIRE(vec.empty()); } TEST_CASE("Get set bits from 1") { - auto vec = sls::getSetBits(1); + auto vec = getSetBits(1); REQUIRE(vec.size() == 1); REQUIRE(vec[0] == 0); } TEST_CASE("Get set bits from 2") { - auto vec = sls::getSetBits(2ul); + auto vec = getSetBits(2ul); REQUIRE(vec.size() == 1); REQUIRE(vec[0] == 1); } TEST_CASE("Get set bits from 3") { - auto vec = sls::getSetBits(3u); + auto vec = getSetBits(3u); REQUIRE(vec.size() == 2); REQUIRE(vec[0] == 0); REQUIRE(vec[1] == 1); @@ -30,12 +32,14 @@ TEST_CASE("Get set bits from 3") { TEST_CASE("All bits set") { uint8_t val = -1; - auto vec = sls::getSetBits(val); + auto vec = 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 = sls::getSetBits(523); + auto vec = 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 f791223c9..ea98c084a 100644 --- a/slsSupportLib/tests/test-container_utils.cpp +++ b/slsSupportLib/tests/test-container_utils.cpp @@ -6,7 +6,7 @@ #include #include -using namespace sls; +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(sls::sum(v) == Approx(0)); + REQUIRE(sum(v) == Approx(0)); } TEST_CASE("Sum of vector", "[support]") { std::vector v{1.2, 2., 4.2, 4, 1.13}; - REQUIRE(sls::sum(v) == Approx(12.53)); + REQUIRE(sum(v) == Approx(12.53)); } TEST_CASE("Minus one if different", "[support]") { std::vector v; REQUIRE(v.empty()); double d = -1; - REQUIRE(sls::minusOneIfDifferent(v) == d); + REQUIRE(minusOneIfDifferent(v) == d); SECTION("single element") { v.push_back(7.3); REQUIRE(v.size() == 1); - REQUIRE(sls::minusOneIfDifferent(v) == Approx(7.3)); + REQUIRE(minusOneIfDifferent(v) == Approx(7.3)); } SECTION("different elements") { v.push_back(7.3); v.push_back(1.0); v.push_back(62.1); - REQUIRE(sls::minusOneIfDifferent(v) == Approx(-1.0)); + REQUIRE(minusOneIfDifferent(v) == Approx(-1.0)); } } TEST_CASE("minus one does not have side effects", "[support]") { std::vector v{1, 1, 1}; - int i = sls::minusOneIfDifferent(v); + int i = minusOneIfDifferent(v); REQUIRE(i == 1); i = 5; REQUIRE(v[0] == 1); @@ -134,4 +134,6 @@ 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); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsSupportLib/tests/test-file_utils.cpp b/slsSupportLib/tests/test-file_utils.cpp index 49544c83c..896409936 100644 --- a/slsSupportLib/tests/test-file_utils.cpp +++ b/slsSupportLib/tests/test-file_utils.cpp @@ -7,10 +7,12 @@ #include #include +namespace sls { + TEST_CASE("Get size of empty file") { char fname[] = "temfile_XXXXXX"; std::ifstream ifs(fname); - auto size = sls::getFileSize(ifs); + auto size = getFileSize(ifs); REQUIRE(size <= 0); // -1 or zero } @@ -22,7 +24,9 @@ TEST_CASE("Get size of file with data") { write(fh, data.data(), n_bytes); std::ifstream ifs(fname); - auto size = sls::getFileSize(ifs); + auto size = 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 c1997c1f6..320b2fb30 100644 --- a/slsSupportLib/tests/test-logger.cpp +++ b/slsSupportLib/tests/test-logger.cpp @@ -6,7 +6,7 @@ #include #include -using sls::Logger; +namespace sls { TEST_CASE("LogLevel to string") { CHECK(Logger::ToString(logERROR) == "ERROR"); @@ -48,4 +48,6 @@ TEST_CASE("Test output") { auto r = local.str(); auto pos = r.find("This should be printed"); CHECK(pos != std::string::npos); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index d02296f1f..b5beab9b3 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" -using namespace sls; +namespace sls { TEST_CASE("Convert mac address using classes", "[support]") { @@ -128,3 +128,5 @@ 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 077c9ecfa..b7f2421c5 100644 --- a/slsSupportLib/tests/test-sls_detector_defs.cpp +++ b/slsSupportLib/tests/test-sls_detector_defs.cpp @@ -3,6 +3,8 @@ #include "catch.hpp" #include "sls/sls_detector_defs.h" +namespace sls { + using dt = slsDetectorDefs::detectorType; TEST_CASE("sls_detector_module default construction", "[support][new]") { @@ -75,4 +77,6 @@ TEST_CASE("compare two scanParameters") { p0.enable = 1; CHECK_FALSE(p0 == p1); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsSupportLib/tests/test-string_utils.cpp b/slsSupportLib/tests/test-string_utils.cpp index 860f155bd..a562151d0 100644 --- a/slsSupportLib/tests/test-string_utils.cpp +++ b/slsSupportLib/tests/test-string_utils.cpp @@ -7,6 +7,8 @@ #include "sls/string_utils.h" +namespace sls { + TEST_CASE("copy a string") { char src[10] = "hej"; @@ -14,7 +16,7 @@ TEST_CASE("copy a string") { char dst[20]; - sls::strcpy_safe(dst, src); + strcpy_safe(dst, src); REQUIRE(dst[0] == 'h'); REQUIRE(dst[1] == 'e'); REQUIRE(dst[2] == 'j'); @@ -26,7 +28,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]; - sls::strcpy_safe(dst, src); + strcpy_safe(dst, src); REQUIRE(dst[0] == 's'); REQUIRE(dst[1] == 'o'); REQUIRE(dst[2] == '\0'); @@ -35,7 +37,7 @@ TEST_CASE("copy a long string") { TEST_CASE("split a string with end delimiter") { std::string s("abra+kadabra+"); - auto r = sls::split(s, '+'); + auto r = split(s, '+'); REQUIRE(r.size() == 2); REQUIRE(r[0] == "abra"); REQUIRE(r[1] == "kadabra"); @@ -43,7 +45,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 = sls::split(s, '+'); + auto r = split(s, '+'); REQUIRE(r.size() == 3); REQUIRE(r[0] == "abra"); REQUIRE(r[1] == "kadabra"); @@ -52,58 +54,60 @@ TEST_CASE("split a string without end delimiter") { TEST_CASE("Remove char from string") { char str[] = "sometest"; - sls::removeChar(str, 'e'); + removeChar(str, 'e'); REQUIRE(std::string(str) == "somtst"); } TEST_CASE("Remove char from empty string") { char str[50] = {}; - sls::removeChar(str, 'e'); + removeChar(str, 'e'); REQUIRE(std::string(str).empty()); } TEST_CASE("Many characters in a row") { char str[] = "someeequitellll::ongstring"; - sls::removeChar(str, 'l'); + removeChar(str, 'l'); REQUIRE(std::string(str) == "someeequite::ongstring"); } TEST_CASE("Check is string is integer") { - 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("")); + 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("")); } TEST_CASE("Replace substring in string") { std::string s = "this string should be replaced"; - auto r = sls::replace_first(&s, "string ", ""); + auto r = 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 = sls::replace_first(&s, " --help", ""); + auto r = 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 = sls::replace_first(&s, " -h", ""); + auto r = replace_first(&s, " -h", ""); REQUIRE(r == true); REQUIRE(s == "sls_detector_get exptime"); } TEST_CASE("replace --help") { std::string s = "list --help"; - auto r = sls::replace_first(&s, " --help", ""); + auto r = replace_first(&s, " --help", ""); REQUIRE(r == true); REQUIRE(s == "list"); } -// TEST_CASE("concat things not being strings") \ No newline at end of file +// TEST_CASE("concat things not being strings") + +} // namespace sls diff --git a/tests/include/tests/config.h b/tests/include/tests/config.h index f6b541cbf..835bf0e42 100644 --- a/tests/include/tests/config.h +++ b/tests/include/tests/config.h @@ -4,6 +4,8 @@ #include "sls/sls_detector_defs.h" #include +namespace sls { + struct SingleDetectorConfig { slsDetectorDefs::detectorType type_enum = slsDetectorDefs::detectorType::EIGER; @@ -11,3 +13,5 @@ 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 ff7b86a64..3d4b2187a 100644 --- a/tests/include/tests/globals.h +++ b/tests/include/tests/globals.h @@ -2,6 +2,9 @@ // 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; @@ -15,3 +18,5 @@ 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 64405f12d..2e35f911e 100644 --- a/tests/include/tests/testenum.h +++ b/tests/include/tests/testenum.h @@ -2,6 +2,11 @@ // 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; \ No newline at end of file +constexpr size_t DATA_SIZE = 50 * MB; + +} // namespace sls diff --git a/tests/src/testclient.cpp b/tests/src/testclient.cpp index 6607b60d1..b4bece3f5 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(DATA_SIZE); + auto data = sls::make_unique(sls::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(func_id::read_int) << " bytes\n"; + std::cout << "Sent: " << socket.Send(sls::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(func_id::read_data) << " bytes\n"; - std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE) + std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n"; + std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE) << " bytes\n"; } // Send too little data { auto socket = sls::ClientSocket("test", hostname, port); - std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n"; - std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE / 2) + std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n"; + std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE / 2) << " bytes\n"; } // Send too much data try { auto socket = sls::ClientSocket("test", hostname, port); - std::cout << "Sent: " << socket.Send(func_id::read_half_data) + std::cout << "Sent: " << socket.Send(sls::func_id::read_half_data) << " bytes\n"; - std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE) + std::cout << "Sent: " << socket.Send(data.get(), sls::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(func_id::read_int) << " bytes\n"; + std::cout << "Sent: " << socket.Send(sls::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(func_id::combined, a, b, c); + int s = socket.SendAll(sls::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 81fcac66f..b11835a1b 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(DATA_SIZE); - std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE) + auto data = sls::make_unique(sls::DATA_SIZE); + std::cout << "Read: " << socket.Receive(data.get(), sls::DATA_SIZE) << " bytes into buffer\n"; } void read_half_data(Interface &socket) { - auto data = sls::make_unique(DATA_SIZE); - std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE / 2) + auto data = sls::make_unique(sls::DATA_SIZE); + std::cout << "Read: " << socket.Receive(data.get(), sls::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{ - {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}}; +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}}; 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 076f489e7..c3cf8d468 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -11,6 +11,8 @@ #include "tests/config.h" #include +namespace sls { + // using namespace Catch::clara; using Opt = Catch::clara::Opt; using dt = slsDetectorDefs::detectorType; @@ -46,8 +48,10 @@ int main(int argc, char *argv[]) { test::type = slsDetectorDefs::GENERIC; if (!test::detector_type.empty()) { test::type = - sls::StringTo(test::detector_type); + StringTo(test::detector_type); } return session.run(); -} \ No newline at end of file +} + +} // namespace sls