mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 20:37:15 +02:00
Integration tests for the command line (#26)
* WIP * first test * format * test frames * also 0:
This commit is contained in:

committed by
Dhanya Thattil

parent
0eec57f8a2
commit
4b1a9bea32
@ -5,10 +5,10 @@
|
||||
#include "CmdLineParser.h"
|
||||
#include "CmdProxy.h"
|
||||
#include "container_utils.h"
|
||||
#include "string_utils.h"
|
||||
#include "multiSlsDetector.h"
|
||||
#include "slsDetectorCommand.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
@ -23,14 +23,17 @@ inline int dummyCallback(detectorData *d, int p, void *) {
|
||||
class multiSlsDetectorClient {
|
||||
public:
|
||||
multiSlsDetectorClient(int argc, char *argv[], int action,
|
||||
multiSlsDetector *myDetector = nullptr)
|
||||
: action_(action), detPtr(myDetector) {
|
||||
multiSlsDetector *myDetector = nullptr,
|
||||
std::ostream &output = std::cout)
|
||||
: action_(action), detPtr(myDetector), os(output) {
|
||||
parser.Parse(argc, argv);
|
||||
runCommand();
|
||||
|
||||
}
|
||||
multiSlsDetectorClient(const std::string &args, int action,
|
||||
multiSlsDetector *myDetector = nullptr)
|
||||
: action_(action), detPtr(myDetector) {
|
||||
multiSlsDetector *myDetector = nullptr,
|
||||
std::ostream &output = std::cout)
|
||||
: action_(action), detPtr(myDetector), os(output) {
|
||||
parser.Parse(args);
|
||||
runCommand();
|
||||
}
|
||||
@ -39,30 +42,31 @@ class multiSlsDetectorClient {
|
||||
int action_;
|
||||
CmdLineParser parser;
|
||||
multiSlsDetector *detPtr = nullptr;
|
||||
std::ostream &os;
|
||||
|
||||
void runCommand() {
|
||||
bool verify = true;
|
||||
bool update = true;
|
||||
if (action_ == slsDetectorDefs::PUT_ACTION &&
|
||||
parser.n_arguments() == 0) {
|
||||
std::cout << "Wrong usage - should be: " << parser.executable()
|
||||
<< "[id-][pos:]channel arg" << std::endl;
|
||||
std::cout << std::endl;
|
||||
os << "Wrong usage - should be: " << parser.executable()
|
||||
<< "[id-][pos:]channel arg" << std::endl;
|
||||
os << std::endl;
|
||||
return;
|
||||
};
|
||||
if (action_ == slsDetectorDefs::GET_ACTION &&
|
||||
parser.command().empty()) {
|
||||
std::cout << "Wrong usage - should be: " << parser.executable()
|
||||
<< "[id-][pos:]channel arg" << std::endl;
|
||||
std::cout << std::endl;
|
||||
os << "Wrong usage - should be: " << parser.executable()
|
||||
<< "[id-][pos:]channel arg" << std::endl;
|
||||
os << std::endl;
|
||||
return;
|
||||
};
|
||||
|
||||
if (action_ == slsDetectorDefs::READOUT_ACTION &&
|
||||
parser.detector_id() != -1) {
|
||||
std::cout << "detector_id: " << parser.detector_id()
|
||||
<< " ,readout of individual detectors is not allowed!"
|
||||
<< std::endl;
|
||||
os << "detector_id: " << parser.detector_id()
|
||||
<< " ,readout of individual detectors is not allowed!"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,7 +82,6 @@ class multiSlsDetectorClient {
|
||||
update = false;
|
||||
}
|
||||
|
||||
// std::cout<<"id:"<<id<<" pos:"<<pos<<std::endl;
|
||||
// create multiSlsDetector class if required
|
||||
std::unique_ptr<multiSlsDetector> localDet;
|
||||
if (detPtr == nullptr) {
|
||||
@ -87,15 +90,15 @@ class multiSlsDetectorClient {
|
||||
verify, update);
|
||||
detPtr = localDet.get();
|
||||
} catch (const RuntimeError &e) {
|
||||
/*std::cout << e.GetMessage() << std::endl;*/
|
||||
/*os << e.GetMessage() << std::endl;*/
|
||||
return;
|
||||
} catch (...) {
|
||||
std::cout << " caught exception\n";
|
||||
os << " caught exception\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (parser.detector_id() >= detPtr->getNumberOfDetectors()) {
|
||||
std::cout << "position is out of bounds.\n";
|
||||
os << "position is out of bounds.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -120,13 +123,13 @@ class multiSlsDetectorClient {
|
||||
action_, parser.detector_id());
|
||||
|
||||
if (parser.multi_id() != 0)
|
||||
std::cout << parser.multi_id() << '-';
|
||||
os << parser.multi_id() << '-';
|
||||
if (parser.detector_id() != -1)
|
||||
std::cout << parser.detector_id() << ':';
|
||||
os << parser.detector_id() << ':';
|
||||
|
||||
if (action_ != slsDetectorDefs::READOUT_ACTION) {
|
||||
std::cout << parser.command() << " ";
|
||||
os << parser.command() << " ";
|
||||
}
|
||||
std::cout << answer << std::endl;
|
||||
os << answer << std::endl;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user