Example #1
0
void test_delinput_port()
{
    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->existInternalConnection("a", "out", "b", "in"),
                        true);
    EnsuresEqual(top->existInternalConnection("b", "out", "a", "in"),
                        true);
    EnsuresEqual(top->existInternalConnection("a", "out", "c", "in"),
                        true);
    c->delInputPort("in");

    EnsuresEqual(top->existInputPort("in"), false);
    EnsuresEqual(top->existInternalConnection("a", "out", "c", "in"),
                        false);

    delete top;
}
Example #2
0
void test_have_connection()
{
    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");

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

    Ensures(not top->hasConnectionProblem(lst));

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

    Ensures(top->hasConnectionProblem(lst));

    delete top;
}
Example #3
0
void test_bug_duplication_connections()
{
    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);

    AtomicModel* atom1(top->addAtomicModel("atom1"));
    AtomicModel* atom2(top->addAtomicModel("atom2"));
    CoupledModel* coupled = new CoupledModel("coupled", top);
    ModelList mSelectedModels;

    Ensures(atom1);
    Ensures(atom2);
    Ensures(coupled);

    atom1->addOutputPort("out");
    atom2->addInputPort("in");

    EnsuresEqual(atom1->existOutputPort("out"), true);
    EnsuresEqual(atom2->existInputPort("in"), true);

    top->addInternalConnection("atom1", "out", "atom2", "in");
    EnsuresEqual(top->existInternalConnection("atom1", "out", "atom2", "in"),
                                                     true);

    mSelectedModels[atom1->getName()] = atom1;
    mSelectedModels[atom2->getName()] = atom2;
    EnsuresEqual(top->nbInternalConnection("atom1", "out", "atom2", "in"), 1);

    top->displace(mSelectedModels, coupled);
    EnsuresEqual(coupled->nbInternalConnection("atom1", "out", "atom2", "in"), 1);
}
Example #4
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;
}
Example #5
0
void test_clone1()
{
    CoupledModel* top = new CoupledModel("top", nullptr);
    top->addInputPort("in");
    top->addOutputPort("out");

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

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

    top->addInputConnection("in", "top", "in");
    top->addInternalConnection("top", "out", "b", "in");
    top->addInternalConnection("b", "out", "top", "in");
    top->addOutputConnection("top", "out", "out");

    Ensures(top->existInternalConnection("top", "out", "b", "in"));
    Ensures(top->existInternalConnection("b", "out", "top", "in"));

    CoupledModel* newtop(dynamic_cast < CoupledModel* >(top->clone()));
    Ensures(newtop != nullptr);
    Ensures(newtop->getModelList().size() == 2);

    AtomicModel* newa = dynamic_cast < AtomicModel* >(newtop->findModel("top"));
    Ensures(newa != a);
    AtomicModel* newb = dynamic_cast < AtomicModel* >(newtop->findModel("b"));
    Ensures(newb != b);

    Ensures(newtop->existInternalConnection("top", "out", "b", "in"));
    Ensures(newtop->existInternalConnection("b", "out", "top", "in"));
    Ensures(newtop->existInputConnection("in", "top", "in"));
    Ensures(newtop->existOutputConnection("top", "out", "out"));
    newtop->delAllConnection();
    Ensures(not newtop->existOutputConnection("top", "out", "out"));
    Ensures(not newtop->existInternalConnection("top", "out", "b", "in"));
    Ensures(not newtop->existInternalConnection("top", "out", "b", "in"));
    Ensures(not newtop->existInternalConnection("b", "out", "top", "in"));
    Ensures(top->existInternalConnection("top", "out", "b", "in"));
    Ensures(top->existInternalConnection("b", "out", "top", "in"));
    Ensures(top->existInputConnection("in", "top", "in"));
    Ensures(top->existOutputConnection("top", "out", "out"));

    delete newtop;
    delete top;
}
Example #6
0
void test_del_all_connection()
{
    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");

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

    Ensures(top->existInternalConnection("a", "out", "b", "in"));
    Ensures(top->existInternalConnection("b", "out", "a", "in"));
    top->delAllConnection();
    Ensures(not top->existInternalConnection("a", "out", "b", "in"));
    Ensures(not top->existInternalConnection("b", "out", "a", "in"));

    delete top;
}