Skip to content

Commit

Permalink
In TestUtils: Added setters with units to enable conversions of unit …
Browse files Browse the repository at this point in the history
…during testing
  • Loading branch information
Paolo Fittipaldi committed Jul 1, 2024
1 parent 9457697 commit e1860ef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions quisp/channels/FreeSpaceChannel_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class MockNode : public quisp_test::TestQNode {
class FreeSpaceChannel : public OriginalFreeSpaceChannel {
public:
FreeSpaceChannel() : OriginalFreeSpaceChannel::FreeSpaceChannel() {
setParDouble(this, "distance", 0);
setParDouble(this, "distance", 0, "km");
setParDouble(this, "delay", 0);
setParDouble(this, "datarate", 0);
setParDouble(this, "ber", 0);
setParDouble(this, "per", 0);
setParDouble(this, "orbital_period", 86400);
setParDouble(this, "speed_of_light_in_freespace", 299792458);
setParDouble(this, "speed_of_light_in_freespace", 299792.458, "km");
setParBool(this, "disabled", false);
setParBool(this, "csv_varies_delay", true);

Expand Down
26 changes: 26 additions & 0 deletions quisp/test_utils/TestUtilFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ void setParDouble(cModule *module, const char *name, const double val) {
module->addPar(p);
}

void setParDouble(cModule *module, const char *name, const double val, const char *unit) {
if (module->findPar(name) != -1) {
module->par(name) = val;
return;
}
cParImpl *p = new cDoubleParImpl();
p->setName(name);
p->setDoubleValue(val);
p->setUnit(unit);
p->setIsMutable(true);
module->addPar(p);
}

void setParStr(cModule *module, const char *name, const char *val) {
if (module->findPar(name) != -1) {
module->par(name) = val;
Expand Down Expand Up @@ -94,6 +107,19 @@ void setParDouble(cChannel *channel, const char *name, const double val) {
channel->addPar(p);
}

void setParDouble(cChannel *channel, const char *name, const double val, const char *unit) {
if (channel->findPar(name) != -1) {
channel->par(name) = val;
return;
}
cParImpl *p = new cDoubleParImpl();
p->setName(name);
p->setDoubleValue(val);
p->setUnit(unit);
p->setIsMutable(true);
channel->addPar(p);
}

void setParStr(cChannel *channel, const char *name, const char *val) {
if (channel->findPar(name) != -1) {
channel->par(name) = val;
Expand Down
2 changes: 2 additions & 0 deletions quisp/test_utils/TestUtilFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ using quisp_test::simulation::TestSimulation;

void setParInt(cModule *module, const char *name, const int val);
void setParDouble(cModule *module, const char *name, const double val);
void setParDouble(cModule *module, const char *name, const double val, const char *unit);
void setParBool(cModule *module, const char *name, const bool val);
void setParStr(cModule *module, const char *name, const char *val);
void setParObject(cModule *module, const char *name, omnetpp::cObject *val);
void setParInt(cChannel *channel, const char *name, const int val);
void setParDouble(cChannel *channel, const char *name, const double val);
void setParDouble(cChannel *channel, const char *name, const double val, const char *unit);
void setParBool(cChannel *channel, const char *name, const bool val);
void setParStr(cChannel *channel, const char *name, const char *val);
void setParObject(cChannel *channel, const char *name, omnetpp::cObject *val);
Expand Down

0 comments on commit e1860ef

Please sign in to comment.