summaryrefslogtreecommitdiff
path: root/test/StreamUriListParserTest.cc
blob: 670f0341029fed33897a7bb570e71dae13610810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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());
}