2010-10-02 14:38:37 +00:00
|
|
|
#include "DHTTaskExecutor.h"
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include "MockDHTTask.h"
|
|
|
|
#include "array_fun.h"
|
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class DHTTaskExecutorTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DHTTaskExecutorTest);
|
|
|
|
CPPUNIT_TEST(testUpdate);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void testUpdate();
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DHTTaskExecutorTest);
|
|
|
|
|
|
|
|
void DHTTaskExecutorTest::testUpdate()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DHTNode> rn;
|
2010-10-02 14:38:37 +00:00
|
|
|
DHTTaskExecutor tex(2);
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<MockDHTTask> tasks[] = {
|
|
|
|
std::shared_ptr<MockDHTTask>(new MockDHTTask(rn)),
|
|
|
|
std::shared_ptr<MockDHTTask>(new MockDHTTask(rn)),
|
|
|
|
std::shared_ptr<MockDHTTask>(new MockDHTTask(rn)),
|
|
|
|
std::shared_ptr<MockDHTTask>(new MockDHTTask(rn))
|
2010-10-02 14:38:37 +00:00
|
|
|
};
|
|
|
|
tasks[1]->finished_ = true;
|
2014-08-29 14:37:31 +00:00
|
|
|
for(size_t i = 0; i < arraySize(tasks); ++i) {
|
2010-10-02 14:38:37 +00:00
|
|
|
tex.addTask(tasks[i]);
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, tex.getExecutingTaskSize());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, tex.getQueueSize());
|
|
|
|
tex.update();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, tex.getExecutingTaskSize());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, tex.getQueueSize());
|
|
|
|
tasks[0]->finished_ = true;
|
|
|
|
tasks[2]->finished_ = true;
|
|
|
|
tasks[3]->finished_ = true;
|
|
|
|
tex.update();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, tex.getExecutingTaskSize());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, tex.getQueueSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|