Esempio n. 1
0
TEST(TestMeiDocument, RootElement) {
    MeiDocument *doc = new MeiDocument();
    Mei *m = new Mei();
    doc->setRootElement(m);

    ASSERT_EQ(m, doc->getRootElement());
}
Esempio n. 2
0
TEST(TestMeiElement, GetPositionInDocument) {
    MeiElement* m = new MeiElement("mei");
    MeiElement *m1 = new MeiElement("music");
    string musicId = m1->getId();
    MeiElement *b1 = new MeiElement("body");
    MeiElement *s1 = new MeiElement("staff");
    MeiElement *n1 = new MeiElement("note");
    string nId = n1->getId();
    MeiElement *n2 = new MeiElement("note");
    MeiElement *n3 = new MeiElement("note");
    MeiElement *n4 = new MeiElement("note");    
    string n4Id = n4->getId();
    
    m->addChild(m1);
    m1->addChild(b1);
    b1->addChild(s1);
    s1->addChild(n1);
    s1->addChild(n2);
    s1->addChild(n3);
    
    MeiDocument* doc = new MeiDocument();
    doc->setRootElement(m);
    
    ASSERT_EQ(4, n1->getPositionInDocument());
    ASSERT_EQ(-1, n4->getPositionInDocument());
    
}
Esempio n. 3
0
TEST(TestMeiElement, TestPrintElement) {
    MeiElement *m = new MeiElement("mei");
    MeiElement *music = new MeiElement("music");
    MeiElement *body = new MeiElement("body");
    MeiElement *staff = new MeiElement("staff");
    Note *note = new Note();
    Note *note2 = new Note();
    
    MeiDocument *doc = new MeiDocument();
    doc->setRootElement(m);
    
    m->addChild(music);
    music->addChild(body);
    body->addChild(staff);
    staff->addChild(note);
    staff->addChild(note2);
    
    note->m_NoteVis.setHeadshape("diamond");
    note->m_Pitch.setPname("c");

    note2->m_Pitch.setPname("d");
    
    m->printElement();
    
    /* 
        The printElement method does not return anything, so the value of it can't really be tested.
        This test simply ensures that it is capable of being called without failing. 
        So we just assert that everything's OK here if we haven't segfaulted by now.
    */
    ASSERT_TRUE(true);
}
Esempio n. 4
0
TEST(TestMeiDocument, FlattenedDocTree) {
    Mei *mei = new Mei();
    Music *mus = new Music();
    Body *body = new Body();
    Staff *staff = new Staff();
    Staff *s2 = new Staff();
    Note *n1 = new Note();
    Note *n2 = new Note();
    Note *n3 = new Note();
    
    MeiDocument *doc = new MeiDocument();

    mei->addChild(mus);
    // empty since mei not added as document root yet
    ASSERT_TRUE(doc->getFlattenedTree().empty());

    doc->setRootElement(mei);
    ASSERT_EQ(2, doc->getFlattenedTree().size());

    mus->addChild(body);    
    body->addChild(staff);
    body->addChild(s2);
    staff->addChild(n1);
    staff->addChild(n2);
    s2->addChild(n3);

    
    doc->lookBack(n2, "mei");
    ASSERT_EQ(8, doc->getFlattenedTree().size());

    staff->removeChild(n2);
    ASSERT_EQ(7, doc->getFlattenedTree().size());
    ASSERT_EQ(s2, doc->getFlattenedTree()[5]);
    
    staff->removeChildrenWithName("note");
    ASSERT_EQ(6, doc->getFlattenedTree().size());
    
    body->deleteAllChildren();
    ASSERT_EQ(3, doc->getFlattenedTree().size());

    std::vector<MeiElement*> newChildren;
    Staff *newStaff1 = new Staff();
    Staff *newStaff2 = new Staff();
    newChildren.push_back(newStaff1);
    newChildren.push_back(newStaff2);
    body->setChildren(newChildren);
    ASSERT_EQ(5, doc->getFlattenedTree().size());

    // check contents
    MeiElement* elements[] = { mei, mus, body, newStaff1, newStaff2 };
    std::vector<MeiElement*> rightOrder (elements, elements + sizeof(elements) / sizeof(MeiElement));

    for (int i = 0; i < rightOrder.size(); i++) {
        // check don't overshoot memory allocation
        ASSERT_LT(i, doc->getFlattenedTree().size());
        ASSERT_EQ(rightOrder[i], doc->getFlattenedTree()[i]);
    }
        
}
Esempio n. 5
0
TEST(TestMeiElement, TestSetDocument) {
    MeiElement *m = new MeiElement("mei");
    MeiDocument *doc = new MeiDocument();
    
    ASSERT_THROW(m->setDocument(doc), mei::DocumentRootNotSetException);
    
    doc->setRootElement(m);
    ASSERT_EQ(doc->getRootElement(), m);
}
Esempio n. 6
0
TEST(TestMeiDocument, SetsDefaultNamespace) {
    MeiDocument *doc = new MeiDocument();
    MeiElement *root = new MeiElement("mei");
    
    doc->setRootElement(root);
    
    ASSERT_TRUE(root->hasAttribute("xmlns"));
    ASSERT_EQ(root->getAttribute("xmlns")->getValue(), MEI_NS);
}
Esempio n. 7
0
void XmlImportImpl::init() {
    // get mei version from document
    xmlAttrPtr meiversAttr = xmlHasProp(this->rootXmlNode, (const xmlChar*)"meiversion");
    string meiVersion = string((const char*)meiversAttr->children->content);
    
    MeiDocument *doc = new MeiDocument(meiVersion);
    this->meiDocument = doc;

    this->rootMeiElement = this->xmlNodeToMeiElement(this->rootXmlNode);
    doc->setRootElement(this->rootMeiElement);
}
Esempio n. 8
0
TEST(TestMeiElement, TestLookBack) {
    MeiElement *m = new MeiElement("mei");
    MeiElement *music = new MeiElement("music");
    MeiElement *body = new MeiElement("body");
    MeiElement *staff = new MeiElement("staff");
    MeiElement *note = new MeiElement("note");
    
    MeiDocument *doc = new MeiDocument();
    doc->setRootElement(m);

    m->addChild(music);
    music->addChild(body);
    body->addChild(staff);
    staff->addChild(note);

    ASSERT_EQ(music->lookBack("mei"), m);
    ASSERT_EQ(staff->lookBack("mei"), m);
}
Esempio n. 9
0
TEST(TestMeiElement, TestRemoveManyChildren) {
    MeiDocument *doc = new MeiDocument();
    MeiElement *mei = new MeiElement("mei");
    MeiElement *sd1 = new MeiElement("staffDef");
    MeiElement *sd2 = new MeiElement("staffDef");
    MeiElement *sd3 = new MeiElement("staffDef");
    MeiElement *sd4 = new MeiElement("staffDef");
    MeiElement *sd5 = new MeiElement("staffDef");
    MeiElement *sd6 = new MeiElement("staffDef");
    
    doc->setRootElement(mei);
    
    MeiElement *music = new mei::MeiElement("music");
    MeiElement *scoreDef = new mei::MeiElement("scoreDef");
    
    mei->addChild(music);
    music->addChild(scoreDef);
    scoreDef->addChild(sd1);
    scoreDef->addChild(sd2);
    scoreDef->addChild(sd3);
    scoreDef->addChild(sd4);
    scoreDef->addChild(sd5);
    scoreDef->addChild(sd6);
    
    sd1->addAttribute("n", "1");
    sd2->addAttribute("n", "2");
    sd3->addAttribute("n", "3");
    sd4->addAttribute("n", "4");
    sd5->addAttribute("n", "5");
    sd6->addAttribute("n", "6");
    
    vector<MeiElement*> scoreDefs = doc->getRootElement()->getDescendantsByName("scoreDef");
    vector<MeiElement*> staffDefs = doc->getRootElement()->getDescendantsByName("staffDef");
    
    for (vector<MeiElement*>::iterator iter = staffDefs.begin(); iter != staffDefs.end(); ++iter) {
        if ((*iter)->getAttribute("n")->getValue() == "3" || (*iter)->getAttribute("n")->getValue() == "6") {
            (*iter)->getParent()->removeChild((*iter));
        }
    }
    ASSERT_EQ(4, music->getDescendantsByName("staffDef").size());
    
}
Esempio n. 10
0
// after adding a root to a document, you can find an element
TEST(TestMeiDocument, ElementById) {
    Mei *mei = new Mei();
    Music *mus = new Music();
    Body *body = new Body();
    Staff *staff = new Staff();
    Staff *s2 = new Staff();
    Note *n1 = new Note();
    string wantedId = n1->getId();
    Note *n2 = new Note();
    Note *n3 = new Note();
    Note *n4 = new Note();
    MeiDocument *doc = new MeiDocument();

    ASSERT_EQ(NULL, doc->getElementById(wantedId));

    mei->addChild(mus);
    mus->addChild(body);
    body->addChild(staff);
    body->addChild(s2);
    staff->addChild(n1);
    staff->addChild(n2);
    staff->addChild(n3);
    s2->addChild(n4);

    doc->setRootElement(mei);

    ASSERT_EQ(n1, doc->getElementById(wantedId));

    ASSERT_EQ(NULL, doc->getElementById("some-unknown-id"));

    // After adding the root element, making a new element works
    Note *n5 = new Note();
    string newid = n5->getId();
    s2->addChild(n5);
    ASSERT_EQ(n5, doc->getElementById(newid));

    // removing the element from the document, clear from document map
    s2->removeChild(n5);
    ASSERT_EQ(NULL, doc->getElementById(newid));
}
Esempio n. 11
0
TEST(TestMeiDocument, ElementsByName) {
    Mei *mei = new Mei();
    Music *mus = new Music();
    Body *body = new Body();
    Staff *staff = new Staff();
    Staff *s2 = new Staff();
    Note *n1 = new Note();
    string wantedId = n1->getId();
    Note *n2 = new Note();
    Note *n3 = new Note();
    Note *n4 = new Note();
    
    mei->addChild(mus);
    mus->addChild(body);
    body->addChild(staff);
    body->addChild(s2);
    staff->addChild(n1);
    staff->addChild(n2);
    staff->addChild(n3);
    s2->addChild(n4);
    
    MeiDocument *doc = new MeiDocument();
    doc->setRootElement(mei);
    
    std::vector<MeiElement*> notes = doc->getElementsByName("note");
    ASSERT_EQ(4, notes.size());
    
    std::vector<MeiElement*> rests = doc->getElementsByName("rest");
    ASSERT_EQ(0, rests.size());

    // After adding the root element, making a new element works
    Note *n5 = new Note();
    staff->addChild(n5);
    
    std::vector<MeiElement*> notes_new = doc->getElementsByName("note");
    ASSERT_EQ(5, notes_new.size());
    
}
Esempio n. 12
0
TEST(TestMeiDocument, DocumentPointers) {
    Mei *mei = new Mei();
    Music *mus = new Music();
    Body *body = new Body();
    Staff *staff = new Staff();

    // If an element is added as a child and neither element is attached to a document, nothing happens. 
    ASSERT_EQ(NULL, mei->getDocument());
    mei->addChild(mus);
    ASSERT_EQ(NULL, mus->getDocument());

    MeiDocument *doc = new MeiDocument();

    // add root to document, all elements should have their document pointer updated
    mus->addChild(body);
    doc->setRootElement(mei);
    ASSERT_EQ(doc, mei->getDocument());
    ASSERT_EQ(doc, mus->getDocument());
    ASSERT_EQ(doc, body->getDocument());

    // add another element as a child, child element should be linked to the same document
    body->addChild(staff);
    ASSERT_EQ(doc, staff->getDocument());
}