TEST(TestMeiElement, TestAddAttribute) { MeiElement *p = new MeiElement("note"); MeiAttribute *attr1 = new MeiAttribute("pname", "c"); MeiAttribute *attr2 = new MeiAttribute("pname", "d"); p->addAttribute(attr1); ASSERT_TRUE(p->hasAttribute("pname")); ASSERT_EQ("c", p->getAttribute("pname")->getValue()); // Adding the same named attribute replaces it p->addAttribute(attr2); ASSERT_EQ("d", p->getAttribute("pname")->getValue()); }
TEST(TestMeiElement, TestAddAttributeByStrings) { MeiElement *p = new MeiElement("note"); p->addAttribute("pname", "c"); ASSERT_TRUE(p->hasAttribute("pname")); ASSERT_EQ("c", p->getAttribute("pname")->getValue()); }
// If we get a pointer to an attribute, we can change it TEST(TestMeiElement, TestChangeAttributeValue) { MeiElement *p = new MeiElement("note"); MeiAttribute *attr1 = new MeiAttribute("pname", "c"); p->addAttribute(attr1); vector<MeiAttribute*> atts = p->getAttributes(); atts[0]->setValue("d"); ASSERT_EQ("d", p->getAttribute("pname")->getValue()); }
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); }
void MusMeiInput::ReadFacsTable(MeiElement *element, FacsTable *table) { if (element->getChildren().size() > 0) { for (vector<MeiElement*>::iterator i = element->getChildren().begin(); i != element->getChildren().end(); i++) { MeiElement e = **i; if (e.getName() == "zone") { std::string id; if (e.getId() != "") { id = e.getId(); } else { throw "missing xml:id attribute on zone element"; } int ulx = atoi(e.getAttribute("ulx")->getValue().c_str()); int uly = atoi(e.getAttribute("uly")->getValue().c_str()); int lry = atoi(e.getAttribute("lry")->getValue().c_str()); table->add(id, ulx, uly, lry); } else if (e.getName() == "system") { std::string id; if (e.getId() != "") { id = e.getId(); } else { throw "missing xml:id attribute on system element"; } std::string facs; if (e.getFacs() != NULL) { facs = e.getFacs()->getValue(); } else { throw "missing facs attribute on system element"; } int ulx = table->GetX(facs); //what if they haven't been stored yet? zones are always defined before systems, as the facs needs to refer to something. int uly = table->GetUY(facs); //" int lry = table->GetLY(facs); table->add(id, ulx, uly, lry); } ReadFacsTable(*i,&*table); } } }
TEST(TestMeiElement, TestGetSetHasAttributes) { MeiElement *p = new MeiElement("note"); MeiAttribute *attr1 = new MeiAttribute("pname", "c"); MeiAttribute *attr2 = new MeiAttribute("stem.dir", "down"); vector<MeiAttribute*> attrs; attrs.push_back(attr1); attrs.push_back(attr2); p->setAttributes(attrs); ASSERT_EQ(2, p->getAttributes().size()); ASSERT_TRUE(p->hasAttribute("pname")); ASSERT_TRUE(p->hasAttribute("stem.dir")); ASSERT_EQ("c", p->getAttribute("pname")->getValue()); // Adding a new attribute to the initial list doesn't // affect the attributes in the element attrs.push_back(new MeiAttribute("oct", "4")); ASSERT_EQ(2, p->getAttributes().size()); }
TEST(TestMeiElement, TestGetNoAttribute) { MeiElement *p = new MeiElement("note"); ASSERT_EQ(NULL, p->getAttribute("color")); }