Usage
use TestUtils.h
and write using namespace quisp_test
in your test file.
first you need call prepareSimulation
in your test. this remove current simulation if it exists and create new simulation.
when you want to set value to your test component, use setPar~
functions. if you finish setting up the test network, call TestSimulation::run
and then it runs the simulation on the test network. if you want to run a simulation step by step, you can call TestSimulation::executeNextEvent
.
if you write a test for QRSA modules, you need QNode component because QRSA modules depends on QNode.
Grab a packet
you can use TestGate
to grab a packet from a test target module. TestGate
has messages
member and if the gate received cMessage
, TestGate
copies the message and store it into messages
field. After runnig the simulation, you can get messages
field of TestGate
Example
namespace {
public:
Strategy(
TestQNode *_qnode) : parent_qnode(_qnode) {}
cModule *getQNode() override { return parent_qnode; }
private:
};
public:
using quisp::modules::Application::getParentModule;
using quisp::modules::Application::par;
explicit AppTestTarget(
TestQNode *parent_qnode)
: Application(),
toRouterGate(new
TestGate(this,
"toRouter")) {
this->provider.setStrategy(std::make_unique<Strategy>(parent_qnode));
}
std::vector<int> getOtherEndNodeAdresses() { return this->other_end_node_addresses; }
int getAddress() { return this->my_address; }
cGate *gate(const char *gatename, int index = -1) override { return toRouterGate; };
};
TEST(AppTest, Init_OneConnection_Sender) {
auto *sim = prepareSimulation();
auto *app = new AppTestTarget{mock_qnode};
setParBool(app, "EndToEndConnection", true);
setParInt(app, "NumberOfResources", 5);
setParInt(app, "num_measure", 1);
setParInt(app, "TrafficPattern", 1);
setParInt(app, "LoneInitiatorAddress", mock_qnode->address);
sim->registerComponent(app);
app->callInitialize();
ASSERT_EQ(app->getAddress(), mock_qnode->address);
ASSERT_EQ(app->getOtherEndNodeAdresses().size(), 1);
sim->run();
ASSERT_EQ(app->toRouterGate->messages.size(), 1);
auto *msg = app->toRouterGate->messages.at(0);
ASSERT_NE(msg, nullptr);
auto *pkt = dynamic_cast<ConnectionSetupRequest *>(msg);
ASSERT_EQ(pkt->getActual_srcAddr(), 123);
ASSERT_EQ(pkt->getActual_destAddr(), mock_qnode2->address);
ASSERT_EQ(pkt->getSrcAddr(), 123);
ASSERT_EQ(pkt->getDestAddr(), 123);
ASSERT_EQ(pkt->getNumber_of_required_Bellpairs(), 5);
}
}
Application.
Definition Application.h:24
void initialize() override
Initialize module.
Definition Application.cc:25
this class can store received messages currently this class only for output gate. we may need to adap...
Definition Gate.h:30
Definition ModuleType.h:12
Definition TestComponentProviderStrategy.h:34