mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-01 17:11:17 +01:00
converting char array+int in runtimeerror compiles but throws at runtime.Fixed.Tested for it. Also check if string or int before using getregisterdefinitonbyvalue to see if it threw to call the other function. because both of it can throw and we should differentiate the issues for both
This commit is contained in:
@@ -1480,13 +1480,20 @@ std::string Caller::define(int action) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
if (mode == "reg") {
|
||||
bool value_found = false;
|
||||
try {
|
||||
// get name from address
|
||||
StringTo<int>(args[1]);
|
||||
value_found = true;
|
||||
} catch (...) {
|
||||
}
|
||||
// get name from address
|
||||
if (value_found) {
|
||||
int addr = StringTo<int>(args[1]);
|
||||
auto t = det->getRegisterDefinitionByValue(addr);
|
||||
os << t << '\n';
|
||||
} catch (...) {
|
||||
// get address from name
|
||||
}
|
||||
// get address from name
|
||||
else {
|
||||
auto t = det->getRegisterDefinitionByName(args[1]);
|
||||
os << ToStringHex(t) << '\n';
|
||||
}
|
||||
|
||||
@@ -2092,7 +2092,7 @@ std::string DetectorImpl::getRegisterDefinitionByValue(const int value) const {
|
||||
auto val = ctb_shm()->getRegisterName(value);
|
||||
if (!val.has_value()) {
|
||||
throw RuntimeError("No register definition found for address: " +
|
||||
value);
|
||||
ToStringHex(value));
|
||||
}
|
||||
return val.value();
|
||||
}
|
||||
|
||||
@@ -1409,8 +1409,21 @@ TEST_CASE("define", "[.cmdcall]") {
|
||||
REQUIRE_NOTHROW(
|
||||
caller.call("define", {"bit", "MICRO_BIT", "4"}, -1, PUT));
|
||||
std::ostringstream oss, oss1;
|
||||
caller.call("define", {"reg", "REG_MACRO"}, -1, GET, oss);
|
||||
caller.call("define", {"bit", "MACRO_BIT"}, -1, GET, oss1);
|
||||
REQUIRE_NOTHROW(
|
||||
caller.call("define", {"reg", "REG_MACRO"}, -1, GET, oss));
|
||||
REQUIRE_NOTHROW(
|
||||
caller.call("define", {"bit", "MACRO_BIT"}, -1, GET, oss1));
|
||||
|
||||
REQUIRE_NOTHROW(caller.call("define", {"reg", "0x202"}, -1, GET));
|
||||
REQUIRE_THROWS(caller.call("define", {"reg", "0x203"}, -1, GET));
|
||||
|
||||
try {
|
||||
caller.call("define", {"reg", "0x203"}, -1, GET, oss);
|
||||
} catch (const std::exception &e) {
|
||||
REQUIRE(std::string(e.what()) ==
|
||||
"No register definition found for address: 0x203");
|
||||
}
|
||||
|
||||
REQUIRE(oss.str() == "define 0x202\n");
|
||||
REQUIRE(oss1.str() == "define 2\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user