summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2016-03-13 14:46:12 +0100
committerDavid Tardon <dtardon@redhat.com>2016-03-13 15:15:51 +0100
commit60206dfad3181d2aa5d0ee2bb3b7d827b023ba1a (patch)
tree7ff9c24f35a552cb134e0387c0b95e3c1a085b53
parent0a3b3ecb3eec2cc5c9eb9e481feef6023744577a (diff)
add test for stream iterator
-rw-r--r--src/test/Makefile.am1
-rw-r--r--src/test/SW602StreamIteratorTest.cpp113
2 files changed, 114 insertions, 0 deletions
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index 339e918..d204ae7 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -20,6 +20,7 @@ test_LDADD = \
$(REVENGE_STREAM_LIBS)
test_SOURCES = \
+ SW602StreamIteratorTest.cpp \
test.cpp
TESTS = $(target_test)
diff --git a/src/test/SW602StreamIteratorTest.cpp b/src/test/SW602StreamIteratorTest.cpp
new file mode 100644
index 0000000..b4b0e95
--- /dev/null
+++ b/src/test/SW602StreamIteratorTest.cpp
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libe-book project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <librevenge-stream/librevenge-stream.h>
+
+#include "SW602MemoryStream.h"
+#include "SW602StreamIterator.h"
+#include "libsw602_utils.h"
+
+namespace test
+{
+
+using namespace libsw602;
+
+class SW602StreamIteratorTest : public CPPUNIT_NS::TestFixture
+{
+public:
+ virtual void setUp();
+ virtual void tearDown();
+
+private:
+ CPPUNIT_TEST_SUITE(SW602StreamIteratorTest);
+ CPPUNIT_TEST(testEnd);
+ CPPUNIT_TEST(testIter);
+ CPPUNIT_TEST(testStartPos);
+ CPPUNIT_TEST(testEqual);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ void testEnd();
+ void testIter();
+ void testStartPos();
+ void testEqual();
+};
+
+void SW602StreamIteratorTest::setUp()
+{
+}
+
+void SW602StreamIteratorTest::tearDown()
+{
+}
+
+void SW602StreamIteratorTest::testEnd()
+{
+ SW602StreamIterator it1;
+ SW602StreamIterator it2;
+ CPPUNIT_ASSERT_MESSAGE("end iterators are always equal", it1 == it2);
+}
+
+void SW602StreamIteratorTest::testIter()
+{
+ const unsigned char data[] = "abc";
+ SW602MemoryStream input(data, SW602_NUM_ELEMENTS(data) - 1);
+ SW602StreamIterator it(input);
+
+ CPPUNIT_ASSERT_MESSAGE("the iterator is not at the end", it != SW602StreamIterator());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the iterator is at the first char", 'a', *it);
+ CPPUNIT_ASSERT_NO_THROW(++it);
+ CPPUNIT_ASSERT_MESSAGE("the iterator is not at the end", it != SW602StreamIterator());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the iterator is at the second char", 'b', *it);
+ CPPUNIT_ASSERT_NO_THROW(it++);
+ CPPUNIT_ASSERT_MESSAGE("the iterator is not at the end", it != SW602StreamIterator());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the iterator is at the last char", 'c', *it);
+ CPPUNIT_ASSERT_NO_THROW(++it);
+ CPPUNIT_ASSERT_MESSAGE("the iterator is at the end now", it == SW602StreamIterator());
+}
+
+void SW602StreamIteratorTest::testStartPos()
+{
+ const unsigned char data[] = "abc";
+ SW602MemoryStream input(data, SW602_NUM_ELEMENTS(data) - 1);
+ skip(input, 1);
+ SW602StreamIterator it(input);
+
+ CPPUNIT_ASSERT_MESSAGE("the iterator is not at the end", it != SW602StreamIterator());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the iterator is at the 2nd char", 'b', *it);
+}
+
+void SW602StreamIteratorTest::testEqual()
+{
+ const unsigned char data[] = "abc";
+ SW602MemoryStream input(data, SW602_NUM_ELEMENTS(data) - 1);
+ SW602StreamIterator it(input);
+
+ SW602StreamIterator copy(it);
+ CPPUNIT_ASSERT_MESSAGE("copies of iterator are equal", copy == it);
+
+ ++it;
+ CPPUNIT_ASSERT_MESSAGE("iterators at different positions are not equal", copy != it);
+
+ ++copy;
+ CPPUNIT_ASSERT_MESSAGE("copies of iterator are still equal after ++", copy == it);
+
+ SW602MemoryStream input2(data, SW602_NUM_ELEMENTS(data) - 1);
+ SW602StreamIterator it2(input2);
+ CPPUNIT_ASSERT_MESSAGE("iterators to different streams are not equal", it != it2);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SW602StreamIteratorTest);
+
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */