2008-02-08 15:53:45 +00:00
|
|
|
#include "UriListParser.h"
|
2008-11-11 14:56:46 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
2008-03-13 13:13:53 +00:00
|
|
|
#include <fstream>
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <iterator>
|
2008-11-11 14:56:46 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-11-11 14:56:46 +00:00
|
|
|
#include "Exception.h"
|
|
|
|
#include "Util.h"
|
|
|
|
#include "prefs.h"
|
2009-03-08 10:17:34 +00:00
|
|
|
#include "OptionHandler.h"
|
2008-11-11 14:56:46 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class UriListParserTest : public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(UriListParserTest);
|
|
|
|
CPPUNIT_TEST(testHasNext);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
std::string list2String(const std::deque<std::string>& src);
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testHasNext();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( UriListParserTest );
|
|
|
|
|
|
|
|
std::string UriListParserTest::list2String(const std::deque<std::string>& src)
|
|
|
|
{
|
|
|
|
std::ostringstream strm;
|
|
|
|
std::copy(src.begin(), src.end(), std::ostream_iterator<std::string>(strm, " "));
|
2009-10-22 15:09:00 +00:00
|
|
|
return util::trim(strm.str());
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UriListParserTest::testHasNext()
|
|
|
|
{
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ifstream in("filelist1.txt", std::ios::binary);
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-11-11 14:56:46 +00:00
|
|
|
UriListParser flp(in);
|
|
|
|
|
|
|
|
std::deque<std::string> uris;
|
|
|
|
Option reqOp;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(flp.hasNext());
|
|
|
|
|
|
|
|
flp.parseNext(uris, reqOp);
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string("http://localhost/index.html http://localhost2/index.html"),
|
|
|
|
list2String(uris));
|
|
|
|
|
|
|
|
uris.clear();
|
|
|
|
reqOp.clear();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(flp.hasNext());
|
|
|
|
|
|
|
|
flp.parseNext(uris, reqOp);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ftp://localhost/aria2.tar.bz2"),
|
2008-11-11 14:56:46 +00:00
|
|
|
list2String(uris));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), reqOp.get(PREF_DIR));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("chunky_chocolate"), reqOp.get(PREF_OUT));
|
|
|
|
|
|
|
|
uris.clear();
|
|
|
|
reqOp.clear();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!flp.hasNext());
|
|
|
|
|
|
|
|
flp.parseNext(uris, reqOp);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), list2String(uris));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!flp.hasNext());
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|