StreamUriListParserTest.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "StreamUriListParser.h"
  2. #include "Exception.h"
  3. #include "Util.h"
  4. #include <sstream>
  5. #include <algorithm>
  6. #include <iostream>
  7. #include <iterator>
  8. #include <cppunit/extensions/HelperMacros.h>
  9. using namespace std;
  10. class StreamUriListParserTest : public CppUnit::TestFixture {
  11. CPPUNIT_TEST_SUITE(StreamUriListParserTest);
  12. CPPUNIT_TEST(testHasNext);
  13. CPPUNIT_TEST_SUITE_END();
  14. private:
  15. string list2String(const Strings& src);
  16. public:
  17. void setUp() {
  18. }
  19. void testHasNext();
  20. };
  21. CPPUNIT_TEST_SUITE_REGISTRATION( StreamUriListParserTest );
  22. string StreamUriListParserTest::list2String(const Strings& src)
  23. {
  24. ostringstream strm;
  25. copy(src.begin(), src.end(), ostream_iterator<string>(strm, " "));
  26. return Util::trim(strm.str());
  27. }
  28. void StreamUriListParserTest::testHasNext()
  29. {
  30. stringstream s;
  31. s << "http://localhost/index.html http://localhost2/index.html\n"
  32. << "ftp://localhost/aria2.tar.bz2";
  33. StreamUriListParser flp(s);
  34. CPPUNIT_ASSERT(flp.hasNext());
  35. CPPUNIT_ASSERT_EQUAL(string("http://localhost/index.html http://localhost2/index.html"), list2String(flp.next()));
  36. CPPUNIT_ASSERT(flp.hasNext());
  37. CPPUNIT_ASSERT_EQUAL(string("ftp://localhost/aria2.tar.bz2"),
  38. list2String(flp.next()));
  39. CPPUNIT_ASSERT(flp.hasNext());
  40. CPPUNIT_ASSERT_EQUAL(string(""),
  41. list2String(flp.next()));
  42. CPPUNIT_ASSERT(!flp.hasNext());
  43. }