Пример #1
0
void test_get_port_index()
{
    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->getInputPortList().size(),
                        (ConnectionList::size_type)0);
    EnsuresEqual(top->getOutputPortList().size(),
                        (ConnectionList::size_type)0);

    AtomicModel* e = dynamic_cast < AtomicModel*> (top->getModelList()["e"]);

    Ensures(e);

    EnsuresEqual(e->getInputPortList().size(),
                        (ConnectionList::size_type)2);
    EnsuresEqual(e->getInputPortIndex("in1"), 0);
    EnsuresEqual(e->getInputPortIndex("in2"), 1);
    EnsuresEqual(e->getOutputPortList().size(),
                        (ConnectionList::size_type)1);
}
Пример #2
0
void test_complex_displace()
{
    CoupledModel* top = new CoupledModel("top", nullptr);

    AtomicModel* a(top->addAtomicModel("a"));
    a->addInputPort("in");
    a->addOutputPort("out");

    AtomicModel* b(top->addAtomicModel("b"));
    b->addInputPort("in");
    b->addOutputPort("out");

    AtomicModel* c(top->addAtomicModel("c"));
    c->addInputPort("in");
    c->addOutputPort("out");

    top->addInternalConnection("a", "out", "b", "in");
    top->addInternalConnection("b", "out", "a", "in");
    top->addInternalConnection("a", "out", "c", "in");

    EnsuresEqual(top->getModelList().size(),
                        (ModelList::size_type)3);

    CoupledModel* newtop = new CoupledModel("newtop", top);

    ModelList lst;
    lst["a"] = a;
    lst["b"] = b;

    EnsuresNotThrow(top->displace(lst, newtop), std::exception);

    EnsuresEqual(top->getModelList().size(),
                        (ModelList::size_type)2);
    EnsuresEqual(newtop->getModelList().size(),
                        (ModelList::size_type)2);

    newtop->existInternalConnection("a", "out", "b", "in");
    newtop->existInternalConnection("b", "out", "a", "in");
    newtop->existOutputPort("out");
    top->existInternalConnection("newtop", "out", "c", "in");

    delete top;
}