From cca8f1ca4c935d81876905dbc4377f4ae5151313 Mon Sep 17 00:00:00 2001 From: Paolo Fittipaldi Date: Wed, 19 Jun 2024 15:49:55 +0000 Subject: [PATCH] Renamed tests and changed cached parameters from references to pointers to facilitate testing. --- quisp/channels/FreeSpaceChannel.cc | 8 +++-- quisp/channels/FreeSpaceChannel.h | 4 +-- ...annel_test.cc => FreeSpaceChannel_test.cc} | 34 +++++++++---------- 3 files changed, 24 insertions(+), 22 deletions(-) rename quisp/channels/{FSChannel_test.cc => FreeSpaceChannel_test.cc} (84%) diff --git a/quisp/channels/FreeSpaceChannel.cc b/quisp/channels/FreeSpaceChannel.cc index 02b306020..b299acf16 100644 --- a/quisp/channels/FreeSpaceChannel.cc +++ b/quisp/channels/FreeSpaceChannel.cc @@ -11,10 +11,12 @@ using namespace omnetpp; namespace channels { -FreeSpaceChannel::FreeSpaceChannel() : parameter_distance(par("distance")), parameter_delay(par("delay")){}; +FreeSpaceChannel::FreeSpaceChannel(){}; void FreeSpaceChannel::initialize() { cDatarateChannel::initialize(); + parameter_distance = &par("distance"); + parameter_delay = &par("delay"); speed_of_light_in_freespace = par("speed_of_light_in_freespace").doubleValue(); const char *filename = par("distance_csv").stringValue(); csv_varies_delay = par("csv_varies_delay").boolValue(); @@ -60,7 +62,7 @@ SimTime FreeSpaceChannel::getNextCheckTime() { } void FreeSpaceChannel::recalculateChannelParameters() { - parameter_distance.setDoubleValue(dist_parser->getPropertyAtTime(simTime().dbl())); - if (csv_varies_delay) parameter_delay.setDoubleValue(parameter_distance.doubleValue() / speed_of_light_in_freespace); + parameter_distance->setDoubleValue(dist_parser->getPropertyAtTime(simTime().dbl())); + if (csv_varies_delay) parameter_delay->setDoubleValue(parameter_distance->doubleValue() / speed_of_light_in_freespace); } } // namespace channels diff --git a/quisp/channels/FreeSpaceChannel.h b/quisp/channels/FreeSpaceChannel.h index fede07c70..cf331677b 100644 --- a/quisp/channels/FreeSpaceChannel.h +++ b/quisp/channels/FreeSpaceChannel.h @@ -40,8 +40,8 @@ class FreeSpaceChannel : public cDatarateChannel { private: OrbitalParameters op; OrbitalDataParser *dist_parser; - cPar ¶meter_distance; - cPar ¶meter_delay; + cPar *parameter_distance; + cPar *parameter_delay; bool csv_varies_delay = true; double speed_of_light_in_freespace = 0; diff --git a/quisp/channels/FSChannel_test.cc b/quisp/channels/FreeSpaceChannel_test.cc similarity index 84% rename from quisp/channels/FSChannel_test.cc rename to quisp/channels/FreeSpaceChannel_test.cc index c24069348..c4088eb04 100644 --- a/quisp/channels/FSChannel_test.cc +++ b/quisp/channels/FreeSpaceChannel_test.cc @@ -3,7 +3,7 @@ #include #include -#include "FSChannel.h" +#include "FreeSpaceChannel.h" #include @@ -15,7 +15,7 @@ using namespace quisp::messages; using namespace quisp::modules::SharedResource; using namespace omnetpp; using namespace quisp_test::utils; -using OriginalFSChannel = channels::FSChannel; +using OriginalFreeSpaceChannel = channels::FreeSpaceChannel; using quisp_test::channel_type::TestChannelType; namespace { @@ -27,18 +27,18 @@ class MockNode : public quisp_test::TestQNode { bool is_qnode; }; -class FSChannel : public OriginalFSChannel { +class FreeSpaceChannel : public OriginalFreeSpaceChannel { public: - FSChannel() : OriginalFSChannel::FSChannel() { + FreeSpaceChannel() : OriginalFreeSpaceChannel::FreeSpaceChannel() { setParDouble(this, "distance", 0); 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_FS", 299792458); + setParDouble(this, "speed_of_light_in_freespace", 299792458); setParBool(this, "disabled", false); - setParBool(this, "CSV_varies_delay", true); + setParBool(this, "csv_varies_delay", true); setComponentType(new TestChannelType("test channel")); } @@ -80,7 +80,7 @@ class TestSimpleModule : public cSimpleModule { } }; -class FSChannelTest : public ::testing::Test { +class FreeSpaceChannelTest : public ::testing::Test { protected: void SetUp() { generateTestCSV("channels/test_dist_csv.csv"); @@ -95,11 +95,11 @@ class FSChannelTest : public ::testing::Test { sat_gate = sat_node->addGate("sat_gate", cGate::INOUT); ground_gate = ground_node->addGate("ground_gate", cGate::INOUT); - downlink_chl = new FSChannel(); + downlink_chl = new FreeSpaceChannel(); sim->registerComponent(downlink_chl); - utils::setParStr(downlink_chl, "distance_CSV", "channels/test_dist_csv.csv"); + utils::setParStr(downlink_chl, "distance_csv", "channels/test_dist_csv.csv"); sat_node->gate("sat_gate$o")->connectTo(ground_node->gate("ground_gate$i"), downlink_chl, true); @@ -130,19 +130,19 @@ class FSChannelTest : public ::testing::Test { TestSimpleModule* sat_simplemodule; MockNode* sat_node; MockNode* ground_node; - FSChannel* downlink_chl; + FreeSpaceChannel* downlink_chl; cGate* sat_gate; cGate* ground_gate; }; -TEST_F(FSChannelTest, messageWhenNonVisible) { +TEST_F(FreeSpaceChannelTest, messageWhenNonVisible) { cMessage* msg = new cMessage(); cChannel::Result res = downlink_chl->public_processMessage(msg); sim->run(); ASSERT_EQ(res.discard, true); } -TEST_F(FSChannelTest, messageWhenVisible) { +TEST_F(FreeSpaceChannelTest, messageWhenVisible) { auto timeout = new cMessage; sat_simplemodule->scheduleAfter(200, timeout); sim->executeNextEvent(); @@ -150,11 +150,11 @@ TEST_F(FSChannelTest, messageWhenVisible) { cChannel::Result res = downlink_chl->public_processMessage(msg); sim->run(); ASSERT_EQ(res.discard, false); - simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_FS").doubleValue(); + simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_freespace").doubleValue(); ASSERT_EQ(res.delay.raw(), delay.raw()); } -TEST_F(FSChannelTest, messageAfterVisible) { +TEST_F(FreeSpaceChannelTest, messageAfterVisible) { auto timeout = new cMessage; sat_simplemodule->scheduleAfter(600, timeout); sim->executeNextEvent(); @@ -164,7 +164,7 @@ TEST_F(FSChannelTest, messageAfterVisible) { ASSERT_EQ(res.discard, true); } -TEST_F(FSChannelTest, messageFollowingDayVisible) { +TEST_F(FreeSpaceChannelTest, messageFollowingDayVisible) { auto timeout = new cMessage; sat_simplemodule->scheduleAfter(86700, timeout); sim->executeNextEvent(); @@ -172,10 +172,10 @@ TEST_F(FSChannelTest, messageFollowingDayVisible) { cChannel::Result res = downlink_chl->public_processMessage(msg); sim->run(); ASSERT_EQ(res.discard, false); - simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_FS").doubleValue(); + simtime_t delay = downlink_chl->par("distance").doubleValue() / downlink_chl->par("speed_of_light_in_freespace").doubleValue(); ASSERT_EQ(res.delay.raw(), delay.raw()); // Comparing the raw int64_t values doesn't lose precision, unlike .dbl(). } -TEST_F(FSChannelTest, messageFollowingDayNonVisible) { +TEST_F(FreeSpaceChannelTest, messageFollowingDayNonVisible) { auto timeout = new cMessage; sat_simplemodule->scheduleAfter(86801, timeout); sim->executeNextEvent();