123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-09-25
- * Changed: 2022-05-11
- *
- * */
- #include <gtest/gtest.h>
- #include <ls_std/ls_std.hpp>
- #include <TestDataFactory.hpp>
- namespace
- {
- class XmlNodeTest : public ::testing::Test
- {
- protected:
- XmlNodeTest() = default;
- ~XmlNodeTest() override = default;
- void SetUp() override
- {}
- void TearDown() override
- {}
- };
- TEST_F(XmlNodeTest, addAttributeAfter)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- std::shared_ptr<ls::std::io::XmlAttribute> currentAttribute{};
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("events"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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::io::XmlNode dialogNode{"dialog"};
- ASSERT_FALSE(dialogNode.addAttributeAfter(std::make_shared<ls::std::io::XmlAttribute>("id"), "events"));
- }
- TEST_F(XmlNodeTest, addAttributeAfter_no_reference)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addAttributeAfter(nullptr, "assets");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addAttributeAfter_empty_name)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addAttributeAfter(std::make_shared<ls::std::io::XmlAttribute>("id"), "");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addAttributeBefore)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- std::shared_ptr<ls::std::io::XmlAttribute> currentAttribute{};
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("events"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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::io::XmlNode dialogNode{"dialog"};
- ASSERT_FALSE(dialogNode.addAttributeBefore(std::make_shared<ls::std::io::XmlAttribute>("tasks"), "assets"));
- }
- TEST_F(XmlNodeTest, addAttributeBefore_no_reference)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addAttributeBefore(nullptr, "assets");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addAttributeBefore_empty_name)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addAttributeBefore(std::make_shared<ls::std::io::XmlAttribute>("id"), "");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addAttributeToBeginning)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- std::shared_ptr<ls::std::io::XmlAttribute> currentAttribute{};
- dialogNode.addAttributeToBeginning(std::make_shared<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addAttributeToBeginning(nullptr);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addAttributeToEnd)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- std::shared_ptr<ls::std::io::XmlAttribute> currentAttribute{};
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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<ls::std::io::XmlAttribute>("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::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addAttributeToEnd(nullptr);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addChildAfter)
- {
- ls::std::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> currentNode{};
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeA = std::make_shared<ls::std::io::XmlNode>("dialogNodeA");
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeB = std::make_shared<ls::std::io::XmlNode>("dialogNodeB");
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeC = std::make_shared<ls::std::io::XmlNode>("dialogNodeC");
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeD = std::make_shared<ls::std::io::XmlNode>("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::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> newChild = std::make_shared<ls::std::io::XmlNode>("newChild");
- std::shared_ptr<ls::std::io::XmlNode> searchNode = std::make_shared<ls::std::io::XmlNode>("searchNode");
- ASSERT_FALSE(dialogsNode.addChildAfter(newChild, searchNode));
- }
- TEST_F(XmlNodeTest, addChildAfter_no_child_reference)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addChildAfter(nullptr, std::make_shared<ls::std::io::XmlNode>("children"));
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addChildAfter_no_search_reference)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addChildAfter(std::make_shared<ls::std::io::XmlNode>("newChild"), nullptr);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addChildBefore)
- {
- ls::std::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> currentNode{};
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeA = std::make_shared<ls::std::io::XmlNode>("dialogNodeA");
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeB = std::make_shared<ls::std::io::XmlNode>("dialogNodeB");
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeC = std::make_shared<ls::std::io::XmlNode>("dialogNodeC");
- std::shared_ptr<ls::std::io::XmlNode> dialogNodeD = std::make_shared<ls::std::io::XmlNode>("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::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> newChild = std::make_shared<ls::std::io::XmlNode>("newChild");
- std::shared_ptr<ls::std::io::XmlNode> searchNode = std::make_shared<ls::std::io::XmlNode>("searchNode");
- ASSERT_FALSE(dialogsNode.addChildBefore(newChild, searchNode));
- }
- TEST_F(XmlNodeTest, addChildBefore_no_child_reference)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addChildBefore(nullptr, std::make_shared<ls::std::io::XmlNode>("children"));
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addChildBefore_no_search_reference)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addChildBefore(std::make_shared<ls::std::io::XmlNode>("newChild"), nullptr);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addChildToBeginning)
- {
- ls::std::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> currentNode{};
- ls::std::io::XmlNode dialogNodeA{"dialogNodeA"};
- ls::std::io::XmlNode dialogNodeB{"dialogNodeB"};
- ls::std::io::XmlNode dialogNodeC{"dialogNodeC"};
- ASSERT_TRUE(dialogsNode.getChildren().empty());
- ASSERT_EQ(0, dialogsNode.getChildren().size());
- // adding C
- ASSERT_TRUE(dialogsNode.addChildToBeginning(std::make_shared<ls::std::io::XmlNode>(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<ls::std::io::XmlNode>(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<ls::std::io::XmlNode>(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::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addChildToBeginning(nullptr);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, addChildToEnd)
- {
- ls::std::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> currentNode{};
- ls::std::io::XmlNode dialogNodeA{"dialogNodeA"};
- ls::std::io::XmlNode dialogNodeB{"dialogNodeB"};
- ls::std::io::XmlNode dialogNodeC{"dialogNodeC"};
- ASSERT_TRUE(dialogsNode.getChildren().empty());
- ASSERT_EQ(0, dialogsNode.getChildren().size());
- // adding C
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>(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<ls::std::io::XmlNode>(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<ls::std::io::XmlNode>(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::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.addChildToEnd(nullptr);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, clearValue)
- {
- ls::std::io::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::io::XmlNode dialogNode{"dialog"};
- ASSERT_TRUE(dialogNode.getAttributes().empty());
- }
- TEST_F(XmlNodeTest, getChildren)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- ASSERT_TRUE(dialogNode.getChildren().empty());
- }
- TEST_F(XmlNodeTest, getChildrenV2)
- {
- ls::std::io::XmlNode dialogsNode{"dialogs"};
- ls::std::io::XmlNode dialogNode{"dialog"};
- ls::std::io::XmlNode otherNode{"something"};
- // preparation
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>(dialogNode)));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>(otherNode)));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>(otherNode)));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>(dialogNode)));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>(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::io::XmlNode dialogNode{"dialog"};
- ASSERT_STREQ("dialog", dialogNode.getName().c_str());
- }
- TEST_F(XmlNodeTest, getValue)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- ASSERT_TRUE(dialogNode.getValue().empty());
- }
- TEST_F(XmlNodeTest, hasAttribute)
- {
- ls::std::io::XmlNode dialogNode{"dialogNode"};
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("id"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("events"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("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::io::XmlNode dialogNode{"dialogNode"};
- ASSERT_FALSE(dialogNode.hasAttribute("fields"));
- }
- TEST_F(XmlNodeTest, hasAttribute_empty_name)
- {
- ls::std::io::XmlNode dialogNode{"dialogNode"};
- EXPECT_THROW({
- try
- {
- dialogNode.hasAttribute("");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, hasChild)
- {
- ls::std::io::XmlNode dialogsNode{"dialogsNode"};
- dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogA"));
- dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogB"));
- dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("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::io::XmlNode dialogsNode{"dialogsNode"};
- ASSERT_FALSE(dialogsNode.hasChild("dialogD"));
- }
- TEST_F(XmlNodeTest, hasChild_empty_name)
- {
- ls::std::io::XmlNode dialogNode{"dialogNode"};
- EXPECT_THROW({
- try
- {
- dialogNode.hasChild("");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, hasChildV2)
- {
- ls::std::io::XmlNode dialogsNode{"dialogsNode"};
- std::shared_ptr<ls::std::io::XmlNode> searchNode = std::make_shared<ls::std::io::XmlNode>("dialogB");
- dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogA"));
- dialogsNode.addChildToEnd(searchNode);
- dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogC"));
- ASSERT_TRUE(dialogsNode.hasChild(searchNode));
- }
- TEST_F(XmlNodeTest, hasChildV2_child_not_available)
- {
- ls::std::io::XmlNode dialogsNode{"dialogsNode"};
- std::shared_ptr<ls::std::io::XmlNode> searchNode = std::make_shared<ls::std::io::XmlNode>("dialogB");
- ASSERT_FALSE(dialogsNode.hasChild(searchNode));
- }
- TEST_F(XmlNodeTest, hasChildV2_no_child_reference)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- std::shared_ptr<ls::std::io::XmlNode> searchNode{};
- EXPECT_THROW({
- try
- {
- dialogNode.hasChild(searchNode);
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, removeFirstAttribute)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- std::shared_ptr<ls::std::io::XmlAttribute> currentAttribute{};
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("id"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("events"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("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::io::XmlNode dialogNode{"dialog"};
- ASSERT_FALSE(dialogNode.removeFirstAttribute());
- }
- TEST_F(XmlNodeTest, removeLastAttribute)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- std::shared_ptr<ls::std::io::XmlAttribute> currentAttribute{};
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("id"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("events"));
- dialogNode.addAttributeToEnd(std::make_shared<ls::std::io::XmlAttribute>("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::io::XmlNode dialogNode{"dialog"};
- ASSERT_FALSE(dialogNode.removeLastAttribute());
- }
- TEST_F(XmlNodeTest, removeFirstChild)
- {
- ls::std::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> currentNode{};
- // preparation
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogA")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogB")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogC")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("additionalInfo")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("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::io::XmlNode dialogsNode{"dialogs"};
- ASSERT_FALSE(dialogsNode.removeFirstChild());
- }
- TEST_F(XmlNodeTest, removeLastChild)
- {
- ls::std::io::XmlNode dialogsNode{"dialogs"};
- std::shared_ptr<ls::std::io::XmlNode> currentNode{};
- // preparation
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogA")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogB")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("dialogC")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("additionalInfo")));
- ASSERT_TRUE(dialogsNode.addChildToEnd(std::make_shared<ls::std::io::XmlNode>("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::io::XmlNode dialogsNode{"dialogs"};
- ASSERT_FALSE(dialogsNode.removeLastChild());
- }
- TEST_F(XmlNodeTest, setName)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- dialogNode.setName("dialog2");
- ASSERT_STREQ("dialog2", dialogNode.getName().c_str());
- }
- TEST_F(XmlNodeTest, setName_empty_name)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.setName("");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::IllegalArgumentException);
- }
- TEST_F(XmlNodeTest, setValue)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- dialogNode.setValue("Something written");
- ASSERT_STREQ("Something written", dialogNode.getValue().c_str());
- }
- TEST_F(XmlNodeTest, setValue_empty_value)
- {
- ls::std::io::XmlNode dialogNode{"dialog"};
- EXPECT_THROW({
- try
- {
- dialogNode.setValue("");
- }
- catch (const ls::std::core::IllegalArgumentException &_exception)
- {
- throw;
- }
- }, ls::std::core::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<ls::std::io::XmlNode> singleLineElement = std::make_shared<ls::std::io::XmlNode>("info");
- std::shared_ptr<ls::std::io::XmlAttribute> attribute = std::make_shared<ls::std::io::XmlAttribute>("id");
- attribute->setValue("important");
- singleLineElement->addAttributeToEnd(attribute);
- ls::std::boxing::String xmlContent{singleLineElement->toXml()};
- std::string expectedXmlString = R"(<info id="important" />)";
- ASSERT_TRUE(xmlContent.contains(expectedXmlString));
- }
- }
|