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>
|
|
|
|
#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"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-11-11 14:56:46 +00:00
|
|
|
#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:
|
2010-02-28 12:30:11 +00:00
|
|
|
std::string list2String(const std::vector<std::string>& src);
|
2008-02-08 15:53:45 +00:00
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testHasNext();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( UriListParserTest );
|
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::string UriListParserTest::list2String(const std::vector<std::string>& src)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
|
|
|
std::ostringstream strm;
|
|
|
|
std::copy(src.begin(), src.end(), std::ostream_iterator<std::string>(strm, " "));
|
2010-10-09 16:49:02 +00:00
|
|
|
return util::strip(strm.str());
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UriListParserTest::testHasNext()
|
|
|
|
{
|
2011-08-06 16:05:02 +00:00
|
|
|
std::string filename = A2_TEST_DIR"/filelist1.txt";
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2011-08-06 16:05:02 +00:00
|
|
|
UriListParser flp(filename);
|
2008-11-11 14:56:46 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2008-11-11 14:56:46 +00:00
|
|
|
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"),
|
2010-01-05 16:01:46 +00:00
|
|
|
list2String(uris));
|
2008-11-11 14:56:46 +00:00
|
|
|
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
|