/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2020-09-25 * Changed: 2021-07-16 * * */ #include #include #include namespace { class XmlNodeTest : public ::testing::Test { protected: XmlNodeTest() = default; ~XmlNodeTest() override = default; void SetUp() override {} void TearDown() override {} }; TEST_F(XmlNodeTest, addAttributeAfter) { ls_std::XmlNode dialogNode{"dialog"}; std::shared_ptr currentAttribute{}; dialogNode.addAttributeToEnd(std::make_shared("events")); dialogNode.addAttributeToEnd(std::make_shared("assets")); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); // add id after events ASSERT_TRUE(dialogNode.addAttributeAfter(std::make_shared("id"), "events")); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("id", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 2); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); // add tasks after assets ASSERT_TRUE(dialogNode.addAttributeAfter(std::make_shared("tasks"), "assets")); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("id", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 2); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 3); ASSERT_STREQ("tasks", currentAttribute->getName().c_str()); } TEST_F(XmlNodeTest, addAttributeAfter_name_not_found) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_FALSE(dialogNode.addAttributeAfter(std::make_shared("id"), "events")); } TEST_F(XmlNodeTest, addAttributeAfter_no_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addAttributeAfter(nullptr, "assets"); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addAttributeAfter_empty_name) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addAttributeAfter(std::make_shared("id"), ""); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addAttributeBefore) { ls_std::XmlNode dialogNode{"dialog"}; std::shared_ptr currentAttribute{}; dialogNode.addAttributeToEnd(std::make_shared("events")); dialogNode.addAttributeToEnd(std::make_shared("assets")); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); // add id before events ASSERT_TRUE(dialogNode.addAttributeBefore(std::make_shared("id"), "events")); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("id", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 2); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); // add tasks before assets ASSERT_TRUE(dialogNode.addAttributeBefore(std::make_shared("tasks"), "assets")); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("id", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 2); ASSERT_STREQ("tasks", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 3); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); } TEST_F(XmlNodeTest, addAttributeBefore_name_not_found) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_FALSE(dialogNode.addAttributeBefore(std::make_shared("tasks"), "assets")); } TEST_F(XmlNodeTest, addAttributeBefore_no_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addAttributeBefore(nullptr, "assets"); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addAttributeBefore_empty_name) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addAttributeBefore(std::make_shared("id"), ""); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addAttributeToBeginning) { ls_std::XmlNode dialogNode{"dialog"}; std::shared_ptr currentAttribute{}; dialogNode.addAttributeToBeginning(std::make_shared("id")); ASSERT_EQ(1, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("id", currentAttribute->getName().c_str()); dialogNode.addAttributeToBeginning(std::make_shared("assets")); ASSERT_EQ(2, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("id", currentAttribute->getName().c_str()); dialogNode.addAttributeToBeginning(std::make_shared("events")); ASSERT_EQ(3, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 2); ASSERT_STREQ("id", currentAttribute->getName().c_str()); } TEST_F(XmlNodeTest, addAttributeToBeginning_no_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addAttributeToBeginning(nullptr); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addAttributeToEnd) { ls_std::XmlNode dialogNode{"dialog"}; std::shared_ptr currentAttribute{}; dialogNode.addAttributeToEnd(std::make_shared("id")); ASSERT_EQ(1, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("id", currentAttribute->getName().c_str()); dialogNode.addAttributeToEnd(std::make_shared("assets")); ASSERT_EQ(2, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("id", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); dialogNode.addAttributeToEnd(std::make_shared("events")); ASSERT_EQ(3, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("id", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 2); ASSERT_STREQ("events", currentAttribute->getName().c_str()); } TEST_F(XmlNodeTest, addAttributeToEnd_no_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addAttributeToEnd(nullptr); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addChildAfter) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr currentNode{}; std::shared_ptr dialogNodeA = std::make_shared("dialogNodeA"); std::shared_ptr dialogNodeB = std::make_shared("dialogNodeB"); std::shared_ptr dialogNodeC = std::make_shared("dialogNodeC"); std::shared_ptr dialogNodeD = std::make_shared("dialogNodeD"); ASSERT_TRUE(dialogsNode.addChildToEnd(dialogNodeB)); ASSERT_TRUE(dialogsNode.addChildToEnd(dialogNodeC)); ASSERT_EQ(2, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); // add A after B ASSERT_TRUE(dialogsNode.addChildAfter(dialogNodeA, dialogNodeB)); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); // add D after C ASSERT_TRUE(dialogsNode.addChildAfter(dialogNodeD, dialogNodeC)); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 3); ASSERT_STREQ("dialogNodeD", currentNode->getName().c_str()); } TEST_F(XmlNodeTest, addChildAfter_no_search_node_available) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr newChild = std::make_shared("newChild"); std::shared_ptr searchNode = std::make_shared("searchNode"); ASSERT_FALSE(dialogsNode.addChildAfter(newChild, searchNode)); } TEST_F(XmlNodeTest, addChildAfter_no_child_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addChildAfter(nullptr, std::make_shared("children")); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addChildAfter_no_search_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addChildAfter(std::make_shared("newChild"), nullptr); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addChildBefore) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr currentNode{}; std::shared_ptr dialogNodeA = std::make_shared("dialogNodeA"); std::shared_ptr dialogNodeB = std::make_shared("dialogNodeB"); std::shared_ptr dialogNodeC = std::make_shared("dialogNodeC"); std::shared_ptr dialogNodeD = std::make_shared("dialogNodeD"); ASSERT_TRUE(dialogsNode.addChildToEnd(dialogNodeB)); ASSERT_TRUE(dialogsNode.addChildToEnd(dialogNodeC)); ASSERT_EQ(2, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); // add A before C ASSERT_TRUE(dialogsNode.addChildBefore(dialogNodeA, dialogNodeC)); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); // add D before B ASSERT_TRUE(dialogsNode.addChildBefore(dialogNodeD, dialogNodeB)); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeD", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogNodeA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 3); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); } TEST_F(XmlNodeTest, addChildBefore_no_search_node_available) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr newChild = std::make_shared("newChild"); std::shared_ptr searchNode = std::make_shared("searchNode"); ASSERT_FALSE(dialogsNode.addChildBefore(newChild, searchNode)); } TEST_F(XmlNodeTest, addChildBefore_no_child_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addChildBefore(nullptr, std::make_shared("children")); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addChildBefore_no_search_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addChildBefore(std::make_shared("newChild"), nullptr); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addChildToBeginning) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr currentNode{}; ls_std::XmlNode dialogNodeA{"dialogNodeA"}; ls_std::XmlNode dialogNodeB{"dialogNodeB"}; ls_std::XmlNode dialogNodeC{"dialogNodeC"}; ASSERT_TRUE(dialogsNode.getChildren().empty()); ASSERT_EQ(0, dialogsNode.getChildren().size()); // adding C ASSERT_TRUE(dialogsNode.addChildToBeginning(std::make_shared(dialogNodeC))); ASSERT_TRUE(!dialogsNode.getChildren().empty()); ASSERT_EQ(1, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); // adding B ASSERT_TRUE(dialogsNode.addChildToBeginning(std::make_shared(dialogNodeB))); ASSERT_EQ(2, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); // adding A ASSERT_TRUE(dialogsNode.addChildToBeginning(std::make_shared(dialogNodeA))); ASSERT_EQ(3, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); } TEST_F(XmlNodeTest, addChildToBeginning_no_child_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addChildToBeginning(nullptr); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, addChildToEnd) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr currentNode{}; ls_std::XmlNode dialogNodeA{"dialogNodeA"}; ls_std::XmlNode dialogNodeB{"dialogNodeB"}; ls_std::XmlNode dialogNodeC{"dialogNodeC"}; ASSERT_TRUE(dialogsNode.getChildren().empty()); ASSERT_EQ(0, dialogsNode.getChildren().size()); // adding C ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(dialogNodeC))); ASSERT_TRUE(!dialogsNode.getChildren().empty()); ASSERT_EQ(1, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); // adding B ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(dialogNodeB))); ASSERT_EQ(2, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); // adding A ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(dialogNodeA))); ASSERT_EQ(3, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogNodeC", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogNodeB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogNodeA", currentNode->getName().c_str()); } TEST_F(XmlNodeTest, addChildToEnd_no_child_reference) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.addChildToEnd(nullptr); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, clearValue) { ls_std::XmlNode dialogNode{"dialog"}; dialogNode.setValue("Something"); ASSERT_STREQ("Something", dialogNode.getValue().c_str()); dialogNode.clearValue(); ASSERT_TRUE(dialogNode.getValue().empty()); ASSERT_STREQ("", dialogNode.getValue().c_str()); } TEST_F(XmlNodeTest, getAttributes) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_TRUE(dialogNode.getAttributes().empty()); } TEST_F(XmlNodeTest, getChildren) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_TRUE(dialogNode.getChildren().empty()); } TEST_F(XmlNodeTest, getChildrenV2) { ls_std::XmlNode dialogsNode{"dialogs"}; ls_std::XmlNode dialogNode{"dialog"}; ls_std::XmlNode otherNode{"something"}; // preparation ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(dialogNode))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(otherNode))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(otherNode))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(dialogNode))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared(otherNode))); // check ASSERT_TRUE(!dialogsNode.getChildren().empty()); ASSERT_EQ(5, dialogsNode.getChildren().size()); ASSERT_EQ(2, dialogsNode.getChildren("dialog").size()); ASSERT_EQ(3, dialogsNode.getChildren("something").size()); } TEST_F(XmlNodeTest, getName) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_STREQ("dialog", dialogNode.getName().c_str()); } TEST_F(XmlNodeTest, getValue) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_TRUE(dialogNode.getValue().empty()); } TEST_F(XmlNodeTest, hasAttribute) { ls_std::XmlNode dialogNode{"dialogNode"}; dialogNode.addAttributeToEnd(std::make_shared("id")); dialogNode.addAttributeToEnd(std::make_shared("events")); dialogNode.addAttributeToEnd(std::make_shared("assets")); ASSERT_TRUE(dialogNode.hasAttribute("id")); ASSERT_TRUE(dialogNode.hasAttribute("events")); ASSERT_TRUE(dialogNode.hasAttribute("assets")); } TEST_F(XmlNodeTest, hasAttribute_attribute_not_available) { ls_std::XmlNode dialogNode{"dialogNode"}; ASSERT_FALSE(dialogNode.hasAttribute("fields")); } TEST_F(XmlNodeTest, hasAttribute_empty_name) { ls_std::XmlNode dialogNode{"dialogNode"}; EXPECT_THROW({ try { dialogNode.hasAttribute(""); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, hasChild) { ls_std::XmlNode dialogsNode{"dialogsNode"}; dialogsNode.addChildToEnd(std::make_shared("dialogA")); dialogsNode.addChildToEnd(std::make_shared("dialogB")); dialogsNode.addChildToEnd(std::make_shared("dialogC")); ASSERT_TRUE(dialogsNode.hasChild("dialogA")); ASSERT_TRUE(dialogsNode.hasChild("dialogB")); ASSERT_TRUE(dialogsNode.hasChild("dialogC")); } TEST_F(XmlNodeTest, hasChild_child_not_available) { ls_std::XmlNode dialogsNode{"dialogsNode"}; ASSERT_FALSE(dialogsNode.hasChild("dialogD")); } TEST_F(XmlNodeTest, hasChild_empty_name) { ls_std::XmlNode dialogNode{"dialogNode"}; EXPECT_THROW({ try { dialogNode.hasChild(""); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, hasChildV2) { ls_std::XmlNode dialogsNode{"dialogsNode"}; std::shared_ptr searchNode = std::make_shared("dialogB"); dialogsNode.addChildToEnd(std::make_shared("dialogA")); dialogsNode.addChildToEnd(searchNode); dialogsNode.addChildToEnd(std::make_shared("dialogC")); ASSERT_TRUE(dialogsNode.hasChild(searchNode)); } TEST_F(XmlNodeTest, hasChildV2_child_not_available) { ls_std::XmlNode dialogsNode{"dialogsNode"}; std::shared_ptr searchNode = std::make_shared("dialogB"); ASSERT_FALSE(dialogsNode.hasChild(searchNode)); } TEST_F(XmlNodeTest, hasChildV2_no_child_reference) { ls_std::XmlNode dialogNode{"dialog"}; std::shared_ptr searchNode{}; EXPECT_THROW({ try { dialogNode.hasChild(searchNode); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, removeFirstAttribute) { ls_std::XmlNode dialogNode{"dialog"}; std::shared_ptr currentAttribute{}; dialogNode.addAttributeToEnd(std::make_shared("id")); dialogNode.addAttributeToEnd(std::make_shared("events")); dialogNode.addAttributeToEnd(std::make_shared("assets")); ASSERT_TRUE(!dialogNode.getAttributes().empty()); ASSERT_EQ(3, dialogNode.getAttributes().size()); ASSERT_TRUE(dialogNode.removeFirstAttribute()); ASSERT_EQ(2, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("events", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("assets", currentAttribute->getName().c_str()); } TEST_F(XmlNodeTest, removeFirstAttribute_no_attributes_available) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_FALSE(dialogNode.removeFirstAttribute()); } TEST_F(XmlNodeTest, removeLastAttribute) { ls_std::XmlNode dialogNode{"dialog"}; std::shared_ptr currentAttribute{}; dialogNode.addAttributeToEnd(std::make_shared("id")); dialogNode.addAttributeToEnd(std::make_shared("events")); dialogNode.addAttributeToEnd(std::make_shared("assets")); ASSERT_TRUE(!dialogNode.getAttributes().empty()); ASSERT_EQ(3, dialogNode.getAttributes().size()); ASSERT_TRUE(dialogNode.removeLastAttribute()); ASSERT_EQ(2, dialogNode.getAttributes().size()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 0); ASSERT_STREQ("id", currentAttribute->getName().c_str()); currentAttribute = *std::next(dialogNode.getAttributes().begin(), 1); ASSERT_STREQ("events", currentAttribute->getName().c_str()); } TEST_F(XmlNodeTest, removeLastAttribute_no_attributes_available) { ls_std::XmlNode dialogNode{"dialog"}; ASSERT_FALSE(dialogNode.removeLastAttribute()); } TEST_F(XmlNodeTest, removeFirstChild) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr currentNode{}; // preparation ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("dialogA"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("dialogB"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("dialogC"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("additionalInfo"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("event"))); ASSERT_EQ(5, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogC", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 3); ASSERT_STREQ("additionalInfo", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 4); ASSERT_STREQ("event", currentNode->getName().c_str()); // check ASSERT_TRUE(dialogsNode.removeFirstChild()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogC", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("additionalInfo", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 3); ASSERT_STREQ("event", currentNode->getName().c_str()); } TEST_F(XmlNodeTest, removeFirstChild_no_children_available) { ls_std::XmlNode dialogsNode{"dialogs"}; ASSERT_FALSE(dialogsNode.removeFirstChild()); } TEST_F(XmlNodeTest, removeLastChild) { ls_std::XmlNode dialogsNode{"dialogs"}; std::shared_ptr currentNode{}; // preparation ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("dialogA"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("dialogB"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("dialogC"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("additionalInfo"))); ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared("event"))); ASSERT_EQ(5, dialogsNode.getChildren().size()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogC", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 3); ASSERT_STREQ("additionalInfo", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 4); ASSERT_STREQ("event", currentNode->getName().c_str()); // check ASSERT_TRUE(dialogsNode.removeLastChild()); currentNode = *std::next(dialogsNode.getChildren().begin(), 0); ASSERT_STREQ("dialogA", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 1); ASSERT_STREQ("dialogB", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 2); ASSERT_STREQ("dialogC", currentNode->getName().c_str()); currentNode = *std::next(dialogsNode.getChildren().begin(), 3); ASSERT_STREQ("additionalInfo", currentNode->getName().c_str()); } TEST_F(XmlNodeTest, removeLastChild_no_children_available) { ls_std::XmlNode dialogsNode{"dialogs"}; ASSERT_FALSE(dialogsNode.removeLastChild()); } TEST_F(XmlNodeTest, setName) { ls_std::XmlNode dialogNode{"dialog"}; dialogNode.setName("dialog2"); ASSERT_STREQ("dialog2", dialogNode.getName().c_str()); } TEST_F(XmlNodeTest, setName_empty_name) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.setName(""); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, setValue) { ls_std::XmlNode dialogNode{"dialog"}; dialogNode.setValue("Something written"); ASSERT_STREQ("Something written", dialogNode.getValue().c_str()); } TEST_F(XmlNodeTest, setValue_empty_value) { ls_std::XmlNode dialogNode{"dialog"}; EXPECT_THROW({ try { dialogNode.setValue(""); } catch (const ls_std::IllegalArgumentException &_exception) { throw; } }, ls_std::IllegalArgumentException); } TEST_F(XmlNodeTest, toXml) { auto root = ls_std_test::TestDataFactory::createXmlContent(); std::string xmlContent = root->toXml(); ASSERT_TRUE(!xmlContent.empty()); } TEST_F(XmlNodeTest, toXml_no_value) { std::shared_ptr singleLineElement = std::make_shared("info"); std::shared_ptr attribute = std::make_shared("id"); attribute->setValue("important"); singleLineElement->addAttributeToEnd(attribute); ls_std::String xmlContent {singleLineElement->toXml()}; std::string expectedXmlString = R"()"; ASSERT_TRUE(xmlContent.contains(expectedXmlString)); } }