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()); }
TEST(TestMeiElement, TestChangeChildValue) { MeiElement *p = new MeiElement("note"); MeiElement *c = new Note(); c->addAttribute(new MeiAttribute("pname", "c")); p->addChild(c); vector<MeiElement*> get = p->getChildren(); get[0]->getAttribute("pname")->setValue("d"); ASSERT_EQ("d", p->getChildren()[0]->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(TestMeiElement, TestRemoveAttribute) { MeiElement *p = new MeiElement("note"); MeiAttribute *attr1 = new MeiAttribute("pname", "c"); p->addAttribute(attr1); ASSERT_TRUE(p->hasAttribute("pname")); p->removeAttribute("pname"); ASSERT_FALSE(p->hasAttribute("pname")); }
TEST(TestMeiElement, TestConstGetAttributes) { MeiElement *p = new MeiElement("note"); MeiAttribute *attr1 = new MeiAttribute("pname", "c"); MeiAttribute *attr2 = new MeiAttribute("oct", "4"); p->addAttribute(attr1); p->addAttribute(attr2); vector<MeiAttribute*> atts = p->getAttributes(); ASSERT_EQ(2, atts.size()); // Adding to the returned vector doesn't affect the element atts.push_back(new MeiAttribute("stem.dir", "up")); ASSERT_EQ(2, p->getAttributes().size()); }
// Adding an attribute to an element sets the attr's element. TEST(TestMeiElement, TestAttributeLink) { MeiElement *p = new MeiElement("note"); MeiAttribute *a = new MeiAttribute("pname", "c"); p->addAttribute(a); ASSERT_EQ(p, a->getElement()); // And when adding many attrs MeiAttribute *b = new MeiAttribute("pname", "d"); MeiAttribute *c = new MeiAttribute("stem.dir", "down"); vector<MeiAttribute*> atts; atts.push_back(b); atts.push_back(c); p->setAttributes(atts); ASSERT_EQ(2, p->getAttributes().size()); ASSERT_EQ(p, b->getElement()); ASSERT_EQ(p, c->getElement()); }