format support lib

This commit is contained in:
Erik Frojdh 2020-05-05 10:07:19 +02:00
parent e599bb7c24
commit ea4044e4b1
38 changed files with 775 additions and 854 deletions

View File

@ -52,7 +52,6 @@ set(ClangFormat_EXCLUDE_PATTERNS "build/"
"slsDetectorCalibration/"
"slsDetectorServers/"
"ctbGui/"
"slsSupportLib/"
"manual/"
"slsDetectorGui/"
"python/"

View File

@ -344,7 +344,8 @@ uint32_t Listener::ListenToAnImage(char *buf) {
// copy packet
switch (myDetectorType) {
// for gotthard, 1st packet: 4 bytes fnum, CACA
// + CACA, 639*2 bytes data 2nd packet: 4 bytes fnum, previous 1*2 bytes
// + CACA, 639*2 bytes data 2nd packet: 4 bytes
// fnum, previous 1*2 bytes
// data + 640*2 bytes data !!
case GOTTHARD:
if (!pnum)
@ -514,7 +515,8 @@ uint32_t Listener::ListenToAnImage(char *buf) {
// copy packet
switch (myDetectorType) {
// for gotthard, 1st packet: 4 bytes fnum, CACA
// + CACA, 639*2 bytes data 2nd packet: 4 bytes fnum, previous 1*2 bytes
// + CACA, 639*2 bytes data 2nd packet: 4 bytes
// fnum, previous 1*2 bytes
// data + 640*2 bytes data !!
case GOTTHARD:
if (!pnum)

1
slsSupportLib/include/DataSocket.h Executable file → Normal file
View File

@ -23,7 +23,6 @@ class DataSocket {
DataSocket &operator=(DataSocket const &) = delete;
int getSocketId() const { return sockfd_; }
int Send(const void *buffer, size_t size);
template <typename T> int Send(T &&data) {
return Send(&data, sizeof(data));

View File

@ -104,7 +104,8 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
}
}
template <typename Container> bool is_equal(const Container &c) const noexcept {
template <typename Container>
bool is_equal(const Container &c) const noexcept {
if (current_size != c.size()) {
return false;
} else {

0
slsSupportLib/include/ServerSocket.h Executable file → Normal file
View File

View File

@ -11,7 +11,8 @@ using s = std::chrono::seconds;
// Absolute value of std::chrono::duration
template <class Rep, class Period>
constexpr std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d) {
constexpr std::chrono::duration<Rep, Period>
abs(std::chrono::duration<Rep, Period> d) {
return d >= d.zero() ? d : -d;
}

15
slsSupportLib/include/Timer.h Executable file → Normal file
View File

@ -11,28 +11,25 @@ class Timer {
using time_point = std::chrono::time_point<clock>;
public:
Timer(std::string name = "0")
: t0(clock::now()), name_(name) {
}
Timer(std::string name = "0") : t0(clock::now()), name_(name) {}
double elapsed_ms() {
return std::chrono::duration<double, std::milli>(clock::now() - t0).count();
return std::chrono::duration<double, std::milli>(clock::now() - t0)
.count();
}
double elapsed_s() {
return std::chrono::duration<double>(clock::now() - t0).count();
}
void print_elapsed() {
std::cout << "Timer \"" << name_ << "\": Elapsed time " << elapsed_ms() << " ms\n";
}
void restart() {
t0 = clock::now();
std::cout << "Timer \"" << name_ << "\": Elapsed time " << elapsed_ms()
<< " ms\n";
}
void restart() { t0 = clock::now(); }
private:
time_point t0;
std::string name_;
};
}; // namespace sls
#endif // TIMER_H

View File

@ -31,19 +31,20 @@ template <typename... Ts> struct has_str_helper {};
template <typename T>
struct has_str<T, typename std::conditional<
false,
has_str_helper<decltype(std::declval<T>().str())>,
false, has_str_helper<decltype(std::declval<T>().str())>,
void>::type> : public std::true_type {};
/**
* Has emplace_back method
*/
template <typename T, typename _ = void> struct has_emplace_back : std::false_type {};
template <typename T, typename _ = void>
struct has_emplace_back : std::false_type {};
template <typename... Ts> struct has_emplace_back_helper {};
template <typename T>
struct has_emplace_back<T, typename std::conditional<
struct has_emplace_back<
T, typename std::conditional<
false,
has_emplace_back_helper<decltype(std::declval<T>().emplace_back())>,
void>::type> : public std::true_type {};
@ -71,7 +72,6 @@ struct is_container<
decltype(std::declval<T>().empty())>,
void>::type> : public std::true_type {};
/**
* Type trait to evaluate if template parameter is
* complying with a standard container

16
slsSupportLib/include/ZmqSocket.h Executable file → Normal file
View File

@ -15,7 +15,6 @@
// #define ZMQ_DETAIL
#define ROIVERBOSITY
class zmq_msg_t;
#include <map>
@ -71,13 +70,11 @@ struct zmqHeader {
class ZmqSocket {
public:
// Socket Options for optimization
// ZMQ_LINGER default is already -1 means no messages discarded. use this
// options if optimizing required ZMQ_SNDHWM default is 0 means no limit. use
// this to optimize if optimizing required
// eg. int value = -1;
// if (zmq_setsockopt(socketDescriptor, ZMQ_LINGER, &value,sizeof(value))) {
// options if optimizing required ZMQ_SNDHWM default is 0 means no limit.
// use this to optimize if optimizing required eg. int value = -1; if
// (zmq_setsockopt(socketDescriptor, ZMQ_LINGER, &value,sizeof(value))) {
// Close();
/**
* Constructor for a client
@ -200,7 +197,6 @@ class ZmqSocket {
void PrintError();
private:
/**
* Receive Message
* @param index self index for debugging
@ -218,8 +214,8 @@ class ZmqSocket {
* @param version version that has to match, -1 to not care
* @returns true if successful else false
*/
int ParseHeader(const int index, int length, char *buff,
zmqHeader& zHeader, uint32_t version);
int ParseHeader(const int index, int length, char *buff, zmqHeader &zHeader,
uint32_t version);
/**
* Class to close socket descriptors automatically
@ -251,6 +247,4 @@ class ZmqSocket {
/** Socket descriptor */
mySocketDescriptors sockfd;
};

11
slsSupportLib/include/ansi.h Executable file → Normal file
View File

@ -18,7 +18,8 @@
#define BOLD "\x1b[1m"
// on background black
#define bprintf(code, format, ...) printf(code BG_BLACK format RESET, ##__VA_ARGS__)
#define bprintf(code, format, ...) \
printf(code BG_BLACK format RESET, ##__VA_ARGS__)
// normal printout
#define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__)
@ -30,11 +31,9 @@ example 1 (a snippet):
#ifdef MARTIN
cprintf(BLUE, "LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base);
for (i=0; i < buffer_len/4; i++)
cprintf(BLUE, "%.8X ",*(((unsigned *) buffer)+i));
printf("\n");
#endif
cprintf(BLUE, "LL Write - Len: %2d - If: %X - Data: ",buffer_len,
ll->ll_fifo_base); for (i=0; i < buffer_len/4; i++) cprintf(BLUE, "%.8X
",*(((unsigned *) buffer)+i)); printf("\n"); #endif
#ifdef MARTIN
cprintf(CYAN, "LL Read - If: %X - Data: ",ll->ll_fifo_base);

1
slsSupportLib/include/container_utils.h Executable file → Normal file
View File

@ -146,7 +146,6 @@ Squash(const Container &c, typename Container::value_type default_value = {}) {
return default_value;
}
} // namespace sls
#endif // CONTAINER_UTILS_H

14
slsSupportLib/include/file_utils.h Executable file → Normal file
View File

@ -1,13 +1,11 @@
#pragma once
#include "sls_detector_defs.h"
#include <cstdio>
#include <fstream>
#include <string>
/** (used by multi and sls)
* reads a short int raw data file
* @param infile input file stream
@ -16,8 +14,8 @@
* @param offset start channel value
* @returns OK or FAIL if it could not read the file or data=NULL
*/
int readDataFile(std::ifstream &infile, short int *data, int nch, int offset=0);
int readDataFile(std::ifstream &infile, short int *data, int nch,
int offset = 0);
/** (used by multi and sls)
* reads a short int rawdata file
@ -28,7 +26,6 @@ int readDataFile(std::ifstream &infile, short int *data, int nch, int offset=0);
*/
int readDataFile(std::string fname, short int *data, int nch);
/** (used by multi and sls)
* writes a short int raw data file
* @param outfile output file stream
@ -37,9 +34,8 @@ int readDataFile(std::string fname, short int *data, int nch);
* @param offset start channel number
* @returns OK or FAIL if it could not write the file or data=NULL
*/
int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset=0);
int writeDataFile(std::ofstream &outfile, int nch, short int *data,
int offset = 0);
/** (used by multi and sls)
* writes a short int raw data file
@ -50,7 +46,5 @@ int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset=0
*/
int writeDataFile(std::string fname, int nch, short int *data);
// mkdir -p path implemented by recursive calls
void mkdir_p(const std::string &path, std::string dir = "");

View File

@ -2,26 +2,38 @@
/*Utility to log to console*/
#include "ansi.h" //Colors
#include <sys/time.h>
#include <iostream>
#include <sstream>
#include <sys/time.h>
enum TLogLevel {logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFORED, logINFO,
logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
enum TLogLevel {
logERROR,
logWARNING,
logINFOBLUE,
logINFOGREEN,
logINFORED,
logINFO,
logDEBUG,
logDEBUG1,
logDEBUG2,
logDEBUG3,
logDEBUG4,
logDEBUG5
};
// Compiler should optimize away anything below this value
#ifndef LOG_MAX_REPORTING_LEVEL
#define LOG_MAX_REPORTING_LEVEL logINFO
#endif
#define __AT__ std::string(__FILE__) + std::string("::") + std::string(__func__) + std::string("(): ")
#define __AT__ \
std::string(__FILE__) + std::string("::") + std::string(__func__) + \
std::string("(): ")
#define __SHORT_FORM_OF_FILE__ \
(strrchr(__FILE__,'/') \
? strrchr(__FILE__,'/')+1 \
: __FILE__ \
)
#define __SHORT_AT__ std::string(__SHORT_FORM_OF_FILE__) + std::string("::") + std::string(__func__) + std::string("(): ")
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define __SHORT_AT__ \
std::string(__SHORT_FORM_OF_FILE__) + std::string("::") + \
std::string(__func__) + std::string("(): ")
namespace sls {
class Logger {

0
slsSupportLib/include/network_utils.h Executable file → Normal file
View File

32
slsSupportLib/include/sls_detector_defs.h Executable file → Normal file
View File

@ -26,7 +26,6 @@
#include <stdint.h>
#endif
#define BIT32_MASK 0xFFFFFFFF
#define MAX_RX_DBIT 64
@ -65,7 +64,6 @@
#define DEFAULT_STREAMING_TIMER_IN_MS 200
#ifdef __cplusplus
class slsDetectorDefs {
public:
@ -188,7 +186,6 @@ class slsDetectorDefs {
*/
enum { GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION };
/**
dimension indexes
*/
@ -206,7 +203,6 @@ class slsDetectorDefs {
} __attribute__((packed));
#endif
/**
use of the external signals
*/
@ -383,28 +379,15 @@ class slsDetectorDefs {
#define TRIMBITMASK 0x3f
enum clockIndex {
ADC_CLOCK,
DBIT_CLOCK,
RUN_CLOCK,
SYNC_CLOCK
};
enum clockIndex { ADC_CLOCK, DBIT_CLOCK, RUN_CLOCK, SYNC_CLOCK };
/**
* read out mode (ctb, moench)
*/
enum readoutMode {
ANALOG_ONLY,
DIGITAL_ONLY,
ANALOG_AND_DIGITAL
};
enum readoutMode { ANALOG_ONLY, DIGITAL_ONLY, ANALOG_AND_DIGITAL };
/** chip speed */
enum speedLevel {
FULL_SPEED,
HALF_SPEED,
QUARTER_SPEED
};
enum speedLevel { FULL_SPEED, HALF_SPEED, QUARTER_SPEED };
/** port type */
enum portType {
@ -455,10 +438,7 @@ class slsDetectorDefs {
/**
* timing source for gotthard2
*/
enum timingSourceType {
TIMING_INTERNAL,
TIMING_EXTERNAL
};
enum timingSourceType { TIMING_INTERNAL, TIMING_EXTERNAL };
#ifdef __cplusplus
/**
@ -573,7 +553,8 @@ struct detParameters {
nDacs = 14;
break;
default:
throw sls::RuntimeError("Unknown detector type! " + std::to_string(type));
throw sls::RuntimeError("Unknown detector type! " +
std::to_string(type));
}
}
};
@ -659,7 +640,6 @@ typedef struct {
} sls_detector_module;
#endif
#ifdef __cplusplus
// TODO! discuss this
#include <vector> //hmm... but currently no way around

7
slsSupportLib/include/sls_detector_exceptions.h Executable file → Normal file
View File

@ -14,9 +14,7 @@ public:
RuntimeError(const std::string &msg) : runtime_error(msg) {
LOG(logERROR) << msg;
}
RuntimeError(const char* msg): runtime_error(msg) {
LOG(logERROR) << msg;
}
RuntimeError(const char *msg) : runtime_error(msg) { LOG(logERROR) << msg; }
};
struct SharedMemoryError : public RuntimeError {
@ -55,6 +53,3 @@ public:
};
} // namespace sls

View File

@ -8,7 +8,6 @@
*@short functions indices to call on server (detector/receiver)
*/
enum detFuncs {
F_EXEC_COMMAND = 0,
F_GET_DETECTOR_TYPE,
@ -200,7 +199,8 @@ enum detFuncs{
F_GET_RECEIVER_PARAMETERS,
NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this (detector server should not compile anyway) */
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
(detector server should not compile anyway) */
F_EXEC_RECEIVER_COMMAND,
F_EXIT_RECEIVER,
@ -295,6 +295,7 @@ enum detFuncs{
NUM_REC_FUNCTIONS
};
// clang-format off
#ifdef __cplusplus
static const char* getFunctionNameFromEnum(enum detFuncs func) {
switch (func) {
@ -586,3 +587,4 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) {
};
#endif
// clang-format on

0
slsSupportLib/src/ClientSocket.cpp Executable file → Normal file
View File

4
slsSupportLib/src/DataSocket.cpp Executable file → Normal file
View File

@ -136,8 +136,6 @@ void DataSocket::shutDownSocket() {
close();
}
void DataSocket::shutdown(){
::shutdown(sockfd_, SHUT_RDWR);
}
void DataSocket::shutdown() { ::shutdown(sockfd_, SHUT_RDWR); }
} // namespace sls

5
slsSupportLib/src/ServerSocket.cpp Executable file → Normal file
View File

@ -1,5 +1,5 @@
#include "ServerInterface.h"
#include "ServerSocket.h"
#include "ServerInterface.h"
#include "DataSocket.h"
#include "logger.h"
@ -29,7 +29,8 @@ ServerSocket::ServerSocket(int port)
if (bind(getSocketId(), (struct sockaddr *)&serverAddr,
sizeof(serverAddr)) != 0) {
close();
throw sls::SocketError("Server ERROR: cannot bind socket. Please check if another instance is running.");
throw sls::SocketError("Server ERROR: cannot bind socket. Please check "
"if another instance is running.");
}
if (listen(getSocketId(), DEFAULT_BACKLOG) != 0) {
close();

View File

@ -403,7 +403,6 @@ template <> defs::burstMode StringTo(const std::string &s) {
throw sls::RuntimeError("Unknown burst mode " + s);
}
template <> defs::timingSourceType StringTo(const std::string &s) {
if (s == "internal")
return defs::TIMING_INTERNAL;

View File

@ -64,8 +64,7 @@ bool UdpRxSocket::ReceivePacket(char *dst) noexcept{
ssize_t UdpRxSocket::ReceiveDataOnly(char *dst) noexcept {
auto r = recvfrom(sockfd_, dst, packet_size_, 0, nullptr, nullptr);
constexpr ssize_t eiger_header_packet =
40; // only detector that has this
constexpr ssize_t eiger_header_packet = 40; // only detector that has this
if (r == eiger_header_packet) {
LOG(logWARNING) << "Got header pkg";
r = recvfrom(sockfd_, dst, packet_size_, 0, nullptr, nullptr);

View File

@ -1,12 +1,12 @@
#include "ZmqSocket.h"
#include <zmq.h>
#include <vector>
#include <arpa/inet.h> //inet_ntoa
#include <errno.h>
#include <iostream>
#include <netdb.h> //gethostbyname()
#include <string.h>
#include <unistd.h> //usleep in some machines
#include <vector>
#include <zmq.h>
using namespace rapidjson;
ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
@ -145,8 +145,7 @@ int ZmqSocket::ConvertInternetAddresstoIpString(struct addrinfo *res, char *ip,
return 1;
}
int ZmqSocket::SendHeader(
int index, zmqHeader header) {
int ZmqSocket::SendHeader(int index, zmqHeader header) {
/** Json Header Format */
const char jsonHeaderFormat[] = "{"
@ -183,44 +182,25 @@ int ZmqSocket::SendHeader(
; //"}\n";
char buf[MAX_STR_LENGTH] = "";
sprintf(buf, jsonHeaderFormat,
header.jsonversion,
header.dynamicRange,
header.fileIndex,
header.ndetx,
header.ndety,
header.npixelsx,
header.npixelsy,
header.imageSize,
header.acqIndex,
header.frameIndex,
header.progress,
header.fname.c_str(),
header.data ? 1 : 0,
header.completeImage ? 1 : 0,
sprintf(buf, jsonHeaderFormat, header.jsonversion, header.dynamicRange,
header.fileIndex, header.ndetx, header.ndety, header.npixelsx,
header.npixelsy, header.imageSize, header.acqIndex,
header.frameIndex, header.progress, header.fname.c_str(),
header.data ? 1 : 0, header.completeImage ? 1 : 0,
header.frameNumber,
header.expLength,
header.packetNumber,
header.bunchId,
header.timestamp,
header.modId,
header.row,
header.column,
header.reserved,
header.debug,
header.roundRNumber,
header.detType,
header.version,
header.frameNumber, header.expLength, header.packetNumber,
header.bunchId, header.timestamp, header.modId, header.row,
header.column, header.reserved, header.debug, header.roundRNumber,
header.detType, header.version,
// additional stuff
header.flippedDataX,
header.quad);
header.flippedDataX, header.quad);
if (header.addJsonHeader.size() > 0) {
strcat(buf, ", ");
strcat(buf, "\"addJsonHeader\": {");
for (auto it = header.addJsonHeader.begin(); it != header.addJsonHeader.end(); ++it) {
for (auto it = header.addJsonHeader.begin();
it != header.addJsonHeader.end(); ++it) {
if (it != header.addJsonHeader.begin()) {
strcat(buf, ", ");
}
@ -350,8 +330,10 @@ int ZmqSocket::ParseHeader(const int index, int length, char *buff,
if (document.HasMember("addJsonHeader")) {
const Value &V = document["addJsonHeader"];
zHeader.addJsonHeader.clear();
for (Value::ConstMemberIterator iter = V.MemberBegin(); iter != V.MemberEnd(); ++iter){
zHeader.addJsonHeader[iter->name.GetString()] = iter->value.GetString();
for (Value::ConstMemberIterator iter = V.MemberBegin();
iter != V.MemberEnd(); ++iter) {
zHeader.addJsonHeader[iter->name.GetString()] =
iter->value.GetString();
}
}

16
slsSupportLib/src/file_utils.cpp Executable file → Normal file
View File

@ -2,11 +2,11 @@
#include "logger.h"
#include "sls_detector_exceptions.h"
#include <errno.h>
#include <iostream>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) {
int ichan, iline = 0;
@ -35,8 +35,6 @@ int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) {
return iline;
}
int readDataFile(std::string fname, short int *data, int nch) {
std::ifstream infile;
int iline = 0;
@ -52,9 +50,8 @@ int readDataFile(std::string fname, short int *data, int nch) {
return iline;
}
int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset) {
int writeDataFile(std::ofstream &outfile, int nch, short int *data,
int offset) {
if (data == nullptr)
return slsDetectorDefs::FAIL;
for (int ichan = 0; ichan < nch; ichan++)
@ -62,7 +59,6 @@ int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset)
return slsDetectorDefs::OK;
}
int writeDataFile(std::string fname, int nch, short int *data) {
std::ofstream outfile;
if (data == nullptr)
@ -78,8 +74,6 @@ int writeDataFile(std::string fname,int nch, short int *data) {
}
}
void mkdir_p(const std::string &path, std::string dir) {
if (path.length() == 0)
return;
@ -98,7 +92,3 @@ void mkdir_p(const std::string& path, std::string dir) {
if (i + 1 < path.length())
mkdir_p(path.substr(i + 1), dir);
}

5
slsSupportLib/src/network_utils.cpp Executable file → Normal file
View File

@ -1,5 +1,6 @@
#include "sls_detector_exceptions.h"
#include "network_utils.h"
#include <algorithm>
#include <arpa/inet.h>
#include <cassert>
@ -15,7 +16,6 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "network_utils.h"
namespace sls {
@ -85,7 +85,8 @@ IpAddr HostnameToIp(const char *hostname) {
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(hostname, nullptr, &hints, &result)) {
freeaddrinfo(result);
throw RuntimeError("Could not convert hostname (" + std::string(hostname) + ") to ip");
throw RuntimeError("Could not convert hostname (" +
std::string(hostname) + ") to ip");
}
uint32_t ip = ((sockaddr_in *)result->ai_addr)->sin_addr.s_addr;
freeaddrinfo(result);

View File

@ -22,7 +22,6 @@ TEST_CASE("Comparing FixedCapacity containers"){
REQUIRE(c != a);
REQUIRE_FALSE(c == a);
REQUIRE_FALSE(b == c);
}
TEST_CASE("Compare array and fixed capacity container") {

View File

@ -1,16 +1,16 @@
#include "TimeHelper.h"
#include "ToString.h"
#include "catch.hpp"
#include "network_utils.h"
#include "sls_detector_defs.h"
#include "catch.hpp"
#include <array>
#include <map>
#include <vector>
// using namespace sls;
using sls::defs;
using sls::StringTo;
using sls::ToString;
using sls::defs;
using namespace sls::time;
TEST_CASE("Integer conversions", "[support]") {
@ -45,7 +45,6 @@ TEST_CASE("conversion from duration to string", "[support]") {
REQUIRE(ToString(us(-100)) == "-100us");
}
TEST_CASE("Convert vector of time", "[support]") {
std::vector<ns> vec{ns(150), us(10), ns(600)};
REQUIRE(ToString(vec) == "[150ns, 10us, 600ns]");
@ -102,7 +101,6 @@ TEST_CASE("vector of strings"){
std::vector<std::string> vec2{"some", "strange", "words", "75"};
REQUIRE(ToString(vec2) == "[some, strange, words, 75]");
}
TEST_CASE("run status") {
@ -143,7 +141,6 @@ TEST_CASE("vec"){
REQUIRE(ToString(vec) == "[error, idle]");
}
TEST_CASE("uint32 from string") {
REQUIRE(StringTo<uint32_t>("0") == 0);
REQUIRE(StringTo<uint32_t>("5") == 5u);
@ -153,7 +150,6 @@ TEST_CASE("uint32 from string"){
REQUIRE(StringTo<uint32_t>("0x15") == 21u);
REQUIRE(StringTo<uint32_t>("0x15") == 0x15);
REQUIRE(StringTo<uint32_t>("0xffffff") == 0xffffff);
}
TEST_CASE("uint64 from string") {
@ -164,10 +160,8 @@ TEST_CASE("uint64 from string"){
REQUIRE(StringTo<uint64_t>("0x14") == 20u);
REQUIRE(StringTo<uint64_t>("0x15") == 21u);
REQUIRE(StringTo<uint64_t>("0xffffff") == 0xffffff);
}
TEST_CASE("int from string") {
REQUIRE(StringTo<int>("-1") == -1);
REQUIRE(StringTo<int>("-0x1") == -0x1);
@ -179,10 +173,8 @@ TEST_CASE("int from string"){
REQUIRE(StringTo<int>("0x14") == 20);
REQUIRE(StringTo<int>("0x15") == 21);
REQUIRE(StringTo<int>("0xffffff") == 0xffffff);
}
TEST_CASE("int64_t from string") {
REQUIRE(StringTo<int64_t>("-1") == -1);
REQUIRE(StringTo<int64_t>("-0x1") == -0x1);
@ -194,10 +186,8 @@ TEST_CASE("int64_t from string"){
REQUIRE(StringTo<int64_t>("0x14") == 20);
REQUIRE(StringTo<int64_t>("0x15") == 21);
REQUIRE(StringTo<int64_t>("0xffffff") == 0xffffff);
}
TEST_CASE("std::map of strings") {
std::map<std::string, std::string> m;
m["key"] = "value";
@ -209,7 +199,6 @@ TEST_CASE("std::map of strings"){
m["test"] = "tree";
REQUIRE(ToString(m) == "{chrusi: musi, key: value, test: tree}");
}
TEST_CASE("std::map of ints") {
@ -221,7 +210,6 @@ TEST_CASE("std::map of ints"){
REQUIRE(ToString(m) == "{5: 10, 500: 50}");
m[372] = 999;
REQUIRE(ToString(m) == "{5: 10, 372: 999, 500: 50}");
}
TEST_CASE("Detector type") {

View File

@ -1,10 +1,10 @@
#include "TypeTraits.h"
#include "catch.hpp"
#include <array>
#include <vector>
#include <sstream>
#include <chrono>
#include <initializer_list>
#include <sstream>
#include <vector>
// Dummy classes only used here for testing
class DummyWithStr {

View File

@ -1,17 +1,17 @@
#include "UdpRxSocket.h"
#include "catch.hpp"
#include "sls_detector_exceptions.h"
#include <future>
#include <thread>
#include <vector>
#include <cstdint>
#include <errno.h>
#include <future>
#include <iostream>
#include <netdb.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <thread>
#include <unistd.h>
#include <vector>
constexpr int default_port = 50001;
@ -67,7 +67,6 @@ TEST_CASE("Receive data from a vector") {
CHECK(udpsock.ReceivePacket((char *)data_received.data()));
close(fd);
CHECK(data_to_send == data_received);
}
TEST_CASE("Shutdown socket without hanging when waiting for data") {

2
slsSupportLib/tests/test-container_utils.cpp Executable file → Normal file
View File

@ -113,7 +113,6 @@ TEST_CASE("Compare a vector containing two vectors", "[support]") {
CHECK(minusOneIfDifferent(d) == d[2]);
}
TEST_CASE("vector of bool", "[support]") {
std::vector<bool> a{true, true, true};
std::vector<bool> b{false, false, false};
@ -133,5 +132,4 @@ TEST_CASE("compare a vector of arrays", "[support]"){
arr.fill(-1);
std::vector<std::array<uint64_t, 3>> vec1{{5, 90, 8}, {5, 6, 8}, {5, 6, 8}};
CHECK(minusOneIfDifferent(vec1) == arr);
}

View File

@ -1,8 +1,8 @@
#include "catch.hpp"
#include "logger.h"
#include <iostream>
#include <fstream>
#include <chrono>
#include <fstream>
#include <iostream>
using sls::Logger;
@ -42,10 +42,8 @@ TEST_CASE("Test output") {
std::clog.rdbuf(clog_buff); // restore
Logger::ReportingLevel() = old_value; // reset
// Check that the message is in the printed string
auto r = local.str();
auto pos = r.find("This should be printed");
CHECK(pos != std::string::npos);
}

0
slsSupportLib/tests/test-network_utils.cpp Executable file → Normal file
View File

5
slsSupportLib/tests/test-string_utils.cpp Executable file → Normal file
View File

@ -5,7 +5,6 @@
#include "string_utils.h"
TEST_CASE("copy a string") {
char src[10] = "hej";
@ -18,10 +17,8 @@ TEST_CASE("copy a string") {
REQUIRE(dst[1] == 'e');
REQUIRE(dst[2] == 'j');
REQUIRE(dst[3] == '\0');
}
#ifdef NDEBUG
// This test can only run in release since we assert on the length of the string
TEST_CASE("copy a long string") {
@ -31,7 +28,6 @@ TEST_CASE("copy a long string"){
REQUIRE(dst[0] == 's');
REQUIRE(dst[1] == 'o');
REQUIRE(dst[2] == '\0');
}
#endif
TEST_CASE("Concat") {
@ -89,7 +85,6 @@ TEST_CASE("concatenate non empty strings with one element"){
REQUIRE(ret == "hej+");
}
TEST_CASE("Remove char from string") {
char str[] = "sometest";
sls::removeChar(str, 'e');