2007-11-07 12:36:33 +00:00
|
|
|
#include "a2functional.h"
|
2009-06-07 07:50:50 +00:00
|
|
|
|
2007-11-07 12:36:33 +00:00
|
|
|
#include <string>
|
|
|
|
#include <numeric>
|
2010-01-28 14:01:50 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
2007-11-07 12:36:33 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-11-07 12:36:33 +00:00
|
|
|
|
|
|
|
class a2functionalTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(a2functionalTest);
|
|
|
|
CPPUNIT_TEST(testMemFunSh);
|
|
|
|
CPPUNIT_TEST(testAdopt2nd);
|
2009-06-07 07:50:50 +00:00
|
|
|
CPPUNIT_TEST(testStrjoin);
|
|
|
|
CPPUNIT_TEST(testStrconcat);
|
|
|
|
CPPUNIT_TEST(testStrappend);
|
2010-01-28 14:01:50 +00:00
|
|
|
CPPUNIT_TEST(testLeastRecentAccess);
|
2007-11-07 12:36:33 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void testMemFunSh();
|
|
|
|
void testAdopt2nd();
|
2009-06-07 07:50:50 +00:00
|
|
|
void testStrjoin();
|
|
|
|
void testStrconcat();
|
|
|
|
void testStrappend();
|
2010-01-28 14:01:50 +00:00
|
|
|
void testLeastRecentAccess();
|
|
|
|
|
2007-11-07 12:36:33 +00:00
|
|
|
class Greeting {
|
|
|
|
public:
|
|
|
|
virtual ~Greeting() {}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
virtual std::string sayGreeting() = 0;
|
2007-11-07 12:36:33 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
virtual std::string sayGreetingConst() const = 0;
|
2007-11-07 12:36:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef SharedHandle<Greeting> GreetingHandle;
|
|
|
|
|
|
|
|
class JapaneseGreeting:public Greeting
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
virtual std::string sayGreeting()
|
2007-11-07 12:36:33 +00:00
|
|
|
{
|
|
|
|
return "HAROO WAARUDO";
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
virtual std::string sayGreetingConst() const
|
2007-11-07 12:36:33 +00:00
|
|
|
{
|
|
|
|
return "HAROO WAARUDO";
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-01-28 14:01:50 +00:00
|
|
|
struct LastAccess {
|
2010-06-21 13:51:56 +00:00
|
|
|
time_t lastAccess_;
|
|
|
|
LastAccess(time_t lastAccess):lastAccess_(lastAccess) {}
|
2010-01-28 14:01:50 +00:00
|
|
|
|
2010-10-09 14:22:49 +00:00
|
|
|
time_t getLastAccessTime() const
|
2010-01-28 14:01:50 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return lastAccess_;
|
2010-01-28 14:01:50 +00:00
|
|
|
}
|
|
|
|
};
|
2007-11-07 12:36:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(a2functionalTest);
|
|
|
|
|
|
|
|
void a2functionalTest::testMemFunSh()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
GreetingHandle greeting(new JapaneseGreeting());
|
2007-11-07 12:36:33 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("HAROO WAARUDO"), mem_fun_sh(&Greeting::sayGreeting)(greeting));
|
2007-11-07 12:36:33 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("HAROO WAARUDO"), mem_fun_sh(&Greeting::sayGreetingConst)(greeting));
|
2007-11-07 12:36:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void a2functionalTest::testAdopt2nd()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
GreetingHandle greeting(new JapaneseGreeting());
|
2007-11-07 12:36:33 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("A Japanese said:HAROO WAARUDO"),
|
2010-01-05 16:01:46 +00:00
|
|
|
adopt2nd(std::plus<std::string>(), mem_fun_sh(&Greeting::sayGreeting))("A Japanese said:", greeting));
|
2007-11-07 12:36:33 +00:00
|
|
|
}
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
|
2009-06-07 07:50:50 +00:00
|
|
|
void a2functionalTest::testStrjoin()
|
|
|
|
{
|
|
|
|
std::vector<std::string> v;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), strjoin(v.begin(), v.end(), " "));
|
|
|
|
|
|
|
|
v.push_back("A");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("A"), strjoin(v.begin(), v.end(), " "));
|
|
|
|
|
|
|
|
v.push_back("hero");
|
|
|
|
v.push_back("is");
|
|
|
|
v.push_back("lonely");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("A hero is lonely"),
|
2010-01-05 16:01:46 +00:00
|
|
|
strjoin(v.begin(), v.end(), " "));
|
2009-06-07 07:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void a2functionalTest::testStrconcat()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("X=3"), strconcat("X=", "3"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void a2functionalTest::testStrappend()
|
|
|
|
{
|
|
|
|
std::string str = "X=";
|
|
|
|
strappend(str, "3", ",Y=", "5");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("X=3,Y=5"), str);
|
|
|
|
}
|
|
|
|
|
2010-01-28 14:01:50 +00:00
|
|
|
void a2functionalTest::testLeastRecentAccess()
|
|
|
|
{
|
|
|
|
std::vector<LastAccess> v;
|
|
|
|
for(int i = 99; i >= 0; --i) {
|
|
|
|
v.push_back(LastAccess(i));
|
|
|
|
}
|
|
|
|
std::sort(v.begin(), v.end(), LeastRecentAccess<LastAccess>());
|
|
|
|
for(int i = 0; i < 100; ++i) {
|
2010-06-21 13:51:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)i, v[i].lastAccess_);
|
2010-01-28 14:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|