Beispiel #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);
}
Beispiel #2
0
void test_clone2()
{
    auto ctx = vle::utils::make_context();
    vpz::Vpz file(ctx->getTemplate("unittest.vpz").string());

    CoupledModel* oldtop = dynamic_cast < CoupledModel* >(
        file.project().model().node());
    Ensures(oldtop);

    CoupledModel* top = dynamic_cast < CoupledModel* >(oldtop->clone());
    Ensures(top);
    CoupledModel* top1(dynamic_cast < CoupledModel*
                       >(top->findModel("top1")));
    Ensures(top1);
    CoupledModel* top2(dynamic_cast < CoupledModel*
                       >(top->findModel("top2")));
    Ensures(top2);

    AtomicModel* f(dynamic_cast < AtomicModel* >(top2->findModel("f")));
    Ensures(f);
    AtomicModel* g(dynamic_cast < AtomicModel* >(top2->findModel("g")));
    Ensures(g);

    delete top;
}
Beispiel #3
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;
}
Beispiel #4
0
void
test_rename_model()
{
    auto ctx = vle::utils::make_context();

    vpz::Vpz file(VPZ_TEST_DIR "/unittest.vpz");

    CoupledModel* top =
      dynamic_cast<CoupledModel*>(file.project().model().node());
    Ensures(top);

    if (not top)
        return;

    EnsuresNotThrow(vpz::BaseModel::rename(top, "new_top"), std::exception);

    AtomicModel* d = dynamic_cast<AtomicModel*>(top->findModel("d"));
    Ensures(d);

    if (not d)
        return;

    EnsuresThrow(vpz::BaseModel::rename(d, "e"), utils::DevsGraphError);
    EnsuresNotThrow(vpz::BaseModel::rename(d, "new_d"), std::exception);

    CoupledModel* top1 = dynamic_cast<CoupledModel*>(top->findModel("top1"));
    Ensures(top1);

    if (not top1)
        return;

    EnsuresThrow(vpz::BaseModel::rename(top1, "top2"), utils::DevsGraphError);
    EnsuresNotThrow(vpz::BaseModel::rename(top1, "new_top1"), std::exception);
}
Beispiel #5
0
void
test_clone2()
{
    auto ctx = vle::utils::make_context();
    vpz::Vpz file(VPZ_TEST_DIR "/unittest.vpz");

    CoupledModel* oldtop =
      dynamic_cast<CoupledModel*>(file.project().model().node());
    Ensures(oldtop);

    auto top = std::unique_ptr<CoupledModel>(
      dynamic_cast<CoupledModel*>(oldtop->clone()));

    Ensures(top);
    if (not top)
        return;

    CoupledModel* top1(dynamic_cast<CoupledModel*>(top->findModel("top1")));
    Ensures(top1);
    if (not top1)
        return;

    CoupledModel* top2(dynamic_cast<CoupledModel*>(top->findModel("top2")));
    Ensures(top2);
    if (not top2)
        return;

    AtomicModel* f(dynamic_cast<AtomicModel*>(top2->findModel("f")));
    Ensures(f);
    AtomicModel* g(dynamic_cast<AtomicModel*>(top2->findModel("g")));
    Ensures(g);
}
Beispiel #6
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);
}
Beispiel #7
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;
}
Beispiel #8
0
void test_bug_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);
    CoupledModel* top1 =
        dynamic_cast<CoupledModel*>(top->findModel("top1"));
    Ensures(top1);

    CoupledModel* top2 =
        dynamic_cast<CoupledModel*>(top->findModel("top2"));
    Ensures(top2);

    EnsuresEqual(top->existInternalConnection("top2", "out", "top1",
                                                     "in"), true);

    EnsuresEqual(top2->existOutputPort("out"), true);
    top2->delOutputPort("out");
    EnsuresEqual(top2->existOutputPort("out"), false);

    EnsuresEqual(top->existInternalConnection("top2", "out", "top1",
                                                     "in"), false);

    EnsuresEqual(top1->existInputPort("in"), true);
    EnsuresNotThrow(top1->delInputPort("in"), std::exception);
    EnsuresEqual(top1->existInputPort("in"), false);

    EnsuresEqual(top->existInternalConnection("top2", "out", "top1",
                                                     "in"), false);
}
Beispiel #9
0
void test_rename_model()
{
    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);
    EnsuresNotThrow(vpz::BaseModel::rename(top, "new_top"), std::exception);

    AtomicModel* d = dynamic_cast<AtomicModel*>(top->findModel("d"));
    EnsuresThrow(vpz::BaseModel::rename(d, "e"), utils::DevsGraphError);
    EnsuresNotThrow(vpz::BaseModel::rename(d, "new_d"), std::exception);

    CoupledModel * top1 = dynamic_cast<CoupledModel*>(top->findModel("top1"));
    EnsuresThrow(vpz::BaseModel::rename(top1, "top2"), utils::DevsGraphError);
    EnsuresNotThrow(vpz::BaseModel::rename(top1, "new_top1"), std::exception);
}
Beispiel #10
0
void test_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");

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

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

    top->displace(lst, newtop);

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

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

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

    delete top;
    delete newtop;
}
Beispiel #11
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;
}
Beispiel #12
0
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);
}
Beispiel #13
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;
}
Beispiel #14
0
void
test_del_port()
{
    auto ctx = vle::utils::make_context();
    vpz::Vpz file(VPZ_TEST_DIR "/unittest.vpz");

    CoupledModel* 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);
}