From 8559ef6b030605612cdcced0587936c6949f385d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> Date: Thu, 5 Jul 2007 15:45:37 +0000 Subject: [PATCH] Added 2 test classes. --- test/FileUriListParserTest.cc | 49 ++++++++++++++++++++++++++++++ test/StreamUriListParserTest.cc | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 test/FileUriListParserTest.cc create mode 100644 test/StreamUriListParserTest.cc diff --git a/test/FileUriListParserTest.cc b/test/FileUriListParserTest.cc new file mode 100644 index 00000000..c0090145 --- /dev/null +++ b/test/FileUriListParserTest.cc @@ -0,0 +1,49 @@ +#include "FileUriListParser.h" +#include "Exception.h" +#include "Util.h" +#include <sstream> +#include <algorithm> +#include <iostream> +#include <iterator> +#include <cppunit/extensions/HelperMacros.h> + +using namespace std; + +class FileUriListParserTest : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(FileUriListParserTest); + CPPUNIT_TEST(testHasNext); + CPPUNIT_TEST_SUITE_END(); +private: + string list2String(const Strings& src); +public: + void setUp() { + } + + void testHasNext(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( FileUriListParserTest ); + +string FileUriListParserTest::list2String(const Strings& src) +{ + ostringstream strm; + copy(src.begin(), src.end(), ostream_iterator<string>(strm, " ")); + return Util::trim(strm.str()); +} + +void FileUriListParserTest::testHasNext() +{ + FileUriListParser flp("filelist1.txt"); + + CPPUNIT_ASSERT(flp.hasNext()); + CPPUNIT_ASSERT_EQUAL(string("http://localhost/index.html http://localhost2/index.html"), list2String(flp.next())); + CPPUNIT_ASSERT(flp.hasNext()); + CPPUNIT_ASSERT_EQUAL(string("ftp://localhost/aria2.tar.bz2"), + list2String(flp.next())); + CPPUNIT_ASSERT(flp.hasNext()); + CPPUNIT_ASSERT_EQUAL(string(""), + list2String(flp.next())); + CPPUNIT_ASSERT(!flp.hasNext()); +} diff --git a/test/StreamUriListParserTest.cc b/test/StreamUriListParserTest.cc new file mode 100644 index 00000000..670f0341 --- /dev/null +++ b/test/StreamUriListParserTest.cc @@ -0,0 +1,53 @@ +#include "StreamUriListParser.h" +#include "Exception.h" +#include "Util.h" +#include <sstream> +#include <algorithm> +#include <iostream> +#include <iterator> +#include <cppunit/extensions/HelperMacros.h> + +using namespace std; + +class StreamUriListParserTest : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(StreamUriListParserTest); + CPPUNIT_TEST(testHasNext); + CPPUNIT_TEST_SUITE_END(); +private: + string list2String(const Strings& src); +public: + void setUp() { + } + + void testHasNext(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( StreamUriListParserTest ); + +string StreamUriListParserTest::list2String(const Strings& src) +{ + ostringstream strm; + copy(src.begin(), src.end(), ostream_iterator<string>(strm, " ")); + return Util::trim(strm.str()); +} + +void StreamUriListParserTest::testHasNext() +{ + stringstream s; + s << "http://localhost/index.html http://localhost2/index.html\n" + << "ftp://localhost/aria2.tar.bz2"; + + StreamUriListParser flp(s); + + CPPUNIT_ASSERT(flp.hasNext()); + CPPUNIT_ASSERT_EQUAL(string("http://localhost/index.html http://localhost2/index.html"), list2String(flp.next())); + CPPUNIT_ASSERT(flp.hasNext()); + CPPUNIT_ASSERT_EQUAL(string("ftp://localhost/aria2.tar.bz2"), + list2String(flp.next())); + CPPUNIT_ASSERT(flp.hasNext()); + CPPUNIT_ASSERT_EQUAL(string(""), + list2String(flp.next())); + CPPUNIT_ASSERT(!flp.hasNext()); +}