Skip to content

Commit

Permalink
Tests: add unit tests for XMLReader::readNextElement()
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 9, 2023
1 parent a2c2e4f commit 1312b9d
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion tests/src/Base/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ TEST_F(ReaderTest, readDataLargerThanBufferSecondRead)
EXPECT_EQ(bufferSize, bytesRead);
}


TEST_F(ReaderTest, readDataNotStarted)
{
// Arrange
Expand All @@ -214,3 +213,55 @@ TEST_F(ReaderTest, readDataNotStarted)
// Assert
EXPECT_EQ(-1, bytesRead); // Because we didn't call beginCharStream
}

TEST_F(ReaderTest, readNextStartElement)
{
auto xmlBody = R"(
<node1 attr='1'>Node1</node1>
<node2 attr='2'>Node2</node2>
)";

givenDataAsXMLStream(xmlBody);

// start of document
Reader()->readElement("document");
EXPECT_STREQ(Reader()->localName(), "document");

// next element
EXPECT_TRUE(Reader()->readNextElement());
EXPECT_STREQ(Reader()->localName(), "node1");
EXPECT_STREQ(Reader()->getAttribute("attr"), "1");
Reader()->readEndElement("node1");
EXPECT_TRUE(Reader()->isEndOfElement());

// next element
EXPECT_TRUE(Reader()->readNextElement());
EXPECT_STREQ(Reader()->localName(), "node2");
EXPECT_STREQ(Reader()->getAttribute("attr"), "2");
Reader()->readEndElement("node2");
EXPECT_TRUE(Reader()->isEndOfElement());
}

TEST_F(ReaderTest, readNextStartEndElement)
{
auto xmlBody = R"(
<node1 attr='1'/>
<node2 attr='2'/>
)";

givenDataAsXMLStream(xmlBody);

// start of document
Reader()->readElement("document");
EXPECT_STREQ(Reader()->localName(), "document");

// next element
EXPECT_TRUE(Reader()->readNextElement());
EXPECT_STREQ(Reader()->localName(), "node1");
EXPECT_STREQ(Reader()->getAttribute("attr"), "1");

// next element
EXPECT_TRUE(Reader()->readNextElement());
EXPECT_STREQ(Reader()->localName(), "node2");
EXPECT_STREQ(Reader()->getAttribute("attr"), "2");
}

0 comments on commit 1312b9d

Please sign in to comment.