void test_rename_port() { auto ctx = vle::utils::make_context(); vpz::Vpz file(ctx->getTemplate("unittest.vpz").string()); CoupledModel* top = dynamic_cast<CoupledModel*>(file.project().model().node()); Ensures(top); EnsuresEqual(top->existInternalConnection("top1", "out", "top2", "in"), true); //Atomic Model AtomicModel* d = dynamic_cast<AtomicModel*>(top->findModel("d")); Ensures(d); EnsuresEqual(d->existInputPort("in"), true); EnsuresEqual(d->existOutputPort("out"), true); EnsuresEqual(top->existInternalConnection("top1", "out", "d", "in"), true); //Atomic Model -- Input Port d->renameInputPort("in", "new_in"); EnsuresEqual(d->existInputPort("in"), false); EnsuresEqual(top->existInternalConnection("top1", "out", "d", "in"), false); EnsuresEqual(d->existInputPort("new_in"), true); EnsuresEqual(top->existInternalConnection("top1", "out", "d", "new_in"), true); //Atomic Model -- Output Port d->renameOutputPort("out", "new_out"); EnsuresEqual(d->existOutputPort("out"), false); EnsuresEqual(d->existOutputPort("new_out"), true); //Coupled Model CoupledModel* top1 = dynamic_cast<CoupledModel*>(top->findModel("top1")); Ensures(top1); //Coupled Model -- Input Port EnsuresEqual(top1->existInputPort("in"), true); EnsuresEqual(top->existInternalConnection("top2", "out", "top1", "in"), true); EnsuresEqual(top1->existInputConnection("in", "x", "in"), true); top1->renameInputPort("in", "new_in"); EnsuresEqual(top1->existInputPort("in"), false); EnsuresEqual(top->existInternalConnection("top2", "out", "top1", "in"), false); EnsuresEqual(top1->existInputConnection("in", "x", "in"), false); EnsuresEqual(top1->existInputPort("new_in"), true); EnsuresEqual(top->existInternalConnection("top2", "out", "top1", "new_in"), true); EnsuresEqual(top1->existInputConnection("new_in", "x", "in"), true); EnsuresEqual(top1->nbInputConnection("new_in", "x", "in"), 1); //Coupled Model -- Output Port EnsuresEqual(top1->existOutputPort("out"), true); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in1"), true); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in2"), true); EnsuresEqual(top1->existOutputConnection("x", "out", "out"), true); top1->renameOutputPort("out", "new_out"); EnsuresEqual(top1->existOutputPort("out"), false); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in1"), false); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in2"), false); EnsuresEqual(top1->existOutputConnection("x", "out", "out"), false); EnsuresEqual(top1->existOutputPort("new_out"), true); EnsuresEqual(top->existInternalConnection("top1", "new_out", "e", "in1"), true); EnsuresEqual(top->existInternalConnection("top1", "new_out", "e", "in2"), true); EnsuresEqual(top1->existOutputConnection("x", "out", "new_out"), true); EnsuresEqual(top1->nbOutputConnection("x", "out", "new_out"), 1); }
void test_del_port() { auto ctx = vle::utils::make_context(); vpz::Vpz file(VPZ_TEST_DIR "/unittest.vpz"); auto* top = dynamic_cast<CoupledModel*>(file.project().model().node()); Ensures(top); if (not top) return; EnsuresEqual(top->existInternalConnection("top1", "out", "top2", "in"), true); // Atomic Model AtomicModel* d = dynamic_cast<AtomicModel*>(top->findModel("d")); Ensures(d); if (not d) return; EnsuresEqual(d->existInputPort("in"), true); EnsuresEqual(d->existOutputPort("out"), true); EnsuresEqual(top->existInternalConnection("top1", "out", "d", "in"), true); // Atomic Model -- Input Port d->delInputPort("in"); EnsuresEqual(d->existInputPort("in"), false); EnsuresEqual(top->existInternalConnection("top1", "out", "d", "in"), false); // Atomic Model -- Output Port d->delOutputPort("out"); EnsuresEqual(d->existOutputPort("out"), false); // Coupled Model CoupledModel* top1 = dynamic_cast<CoupledModel*>(top->findModel("top1")); Ensures(top1); if (not top1) return; // Coupled Model -- Input Port EnsuresEqual(top1->existInputPort("in"), true); EnsuresEqual(top->existInternalConnection("top2", "out", "top1", "in"), true); EnsuresEqual(top1->existInputConnection("in", "x", "in"), true); top1->delInputPort("in"); EnsuresEqual(top1->existInputPort("in"), false); EnsuresEqual(top->existInternalConnection("top2", "out", "top1", "in"), false); EnsuresEqual(top1->existInputConnection("in", "x", "in"), false); // Coupled Model -- Output Port EnsuresEqual(top1->existOutputPort("out"), true); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in1"), true); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in2"), true); EnsuresEqual(top1->existOutputConnection("x", "out", "out"), true); top1->delOutputPort("out"); EnsuresEqual(top1->existOutputPort("out"), false); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in1"), false); EnsuresEqual(top->existInternalConnection("top1", "out", "e", "in2"), false); EnsuresEqual(top1->existOutputConnection("x", "out", "out"), false); }