TEST(XMLNodeTest, prependText) { XMLElement root("root"); root.prepend(util::make_unique<XMLText>("first string")); EXPECT_EQ(number_of_children(root), 1); XMLText *firstChild = root.firstChild()->toText(); ASSERT_NE(firstChild, nullptr); EXPECT_EQ(firstChild->getText(), "first string"); EXPECT_EQ(firstChild->parent(), &root); EXPECT_EQ(firstChild->prev(), nullptr); EXPECT_EQ(firstChild->next(), nullptr); root.prepend(util::make_unique<XMLText>("second string,")); EXPECT_EQ(number_of_children(root), 1); firstChild = root.firstChild()->toText(); ASSERT_NE(firstChild, nullptr); EXPECT_EQ(firstChild->getText(), "second string,first string"); EXPECT_EQ(firstChild->parent(), &root); EXPECT_EQ(firstChild->prev(), nullptr); EXPECT_EQ(firstChild->next(), nullptr); root.prepend(util::make_unique<XMLElement>("separator")); root.prepend(util::make_unique<XMLText>("third string,")); EXPECT_EQ(number_of_children(root), 3); firstChild = root.firstChild()->toText(); ASSERT_NE(firstChild, nullptr); EXPECT_EQ(firstChild->getText(), "third string,"); EXPECT_EQ(firstChild->parent(), &root); EXPECT_EQ(firstChild->prev(), nullptr); EXPECT_EQ(firstChild->next()->next(), root.lastChild()); EXPECT_EQ(root.lastChild()->prev()->prev(), root.firstChild()); }
TEST(XMLNodeTest, appendText) { XMLElement root("root"); root.append(util::make_unique<XMLText>("first string")); EXPECT_EQ(number_of_children(root), 1); XMLText *lastChild = root.lastChild()->toText(); ASSERT_NE(lastChild, nullptr); EXPECT_EQ(lastChild->getText(), "first string"); EXPECT_EQ(lastChild->parent(), &root); EXPECT_EQ(lastChild->prev(), nullptr); EXPECT_EQ(lastChild->next(), nullptr); EXPECT_EQ(root.firstChild(), root.lastChild()); root.append(util::make_unique<XMLText>(",second string")); EXPECT_EQ(number_of_children(root), 1); lastChild = root.lastChild()->toText(); ASSERT_NE(lastChild, nullptr); EXPECT_EQ(lastChild->getText(), "first string,second string"); EXPECT_EQ(lastChild->parent(), &root); EXPECT_EQ(lastChild->prev(), nullptr); EXPECT_EQ(lastChild->next(), nullptr); EXPECT_EQ(root.firstChild(), root.lastChild()); root.append(",third string"); EXPECT_EQ(number_of_children(root), 1); lastChild = root.lastChild()->toText(); ASSERT_NE(lastChild, nullptr); EXPECT_EQ(lastChild->getText(), "first string,second string,third string"); EXPECT_EQ(lastChild->parent(), &root); EXPECT_EQ(lastChild->prev(), nullptr); EXPECT_EQ(lastChild->next(), nullptr); root.append(util::make_unique<XMLElement>("separator")); root.append(",fourth string"); EXPECT_EQ(number_of_children(root), 3); lastChild = root.lastChild()->toText(); ASSERT_NE(lastChild, nullptr); EXPECT_EQ(lastChild->getText(), ",fourth string"); root.append(util::make_unique<XMLElement>("separator")); root.append(util::make_unique<XMLText>(",fifth string")); EXPECT_EQ(number_of_children(root), 5); lastChild = root.lastChild()->toText(); ASSERT_NE(lastChild, nullptr); EXPECT_EQ(lastChild->getText(), ",fifth string"); root.clear(); EXPECT_TRUE(root.empty()); }