2007-11-21 16:14:40 +00:00
|
|
|
#include "Sequence.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <deque>
|
2007-11-21 16:14:40 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-11-21 16:14:40 +00:00
|
|
|
|
|
|
|
class SequenceTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(SequenceTest);
|
|
|
|
CPPUNIT_TEST(testParseAndNext);
|
|
|
|
CPPUNIT_TEST(testParseAndNext2);
|
|
|
|
CPPUNIT_TEST(testFlush);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void testParseAndNext();
|
|
|
|
void testParseAndNext2();
|
|
|
|
void testFlush();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(SequenceTest);
|
|
|
|
|
2008-03-11 12:31:14 +00:00
|
|
|
typedef Sequence<int> IntSequence;
|
2007-11-21 16:14:40 +00:00
|
|
|
|
|
|
|
void SequenceTest::testParseAndNext()
|
|
|
|
{
|
|
|
|
IntSequence::Value params[] = {
|
|
|
|
IntSequence::Value(1, 2),
|
|
|
|
IntSequence::Value(3, 9),
|
|
|
|
IntSequence::Value(10, 11),
|
|
|
|
};
|
2007-11-25 11:57:17 +00:00
|
|
|
IntSequence seq = IntSequence(IntSequence::Values(¶ms[0], ¶ms[3]));
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(3, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(4, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(5, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(6, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(7, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(8, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(10, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(!seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(0, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceTest::testParseAndNext2()
|
|
|
|
{
|
|
|
|
IntSequence::Value params[] = {
|
|
|
|
IntSequence::Value(1, 2),
|
|
|
|
};
|
2007-11-25 11:57:17 +00:00
|
|
|
IntSequence seq = IntSequence(IntSequence::Values(¶ms[0], ¶ms[1]));
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
CPPUNIT_ASSERT(!seq.hasNext());
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(0, seq.next());
|
2007-11-21 16:14:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceTest::testFlush()
|
|
|
|
{
|
|
|
|
IntSequence::Value params[] = {
|
|
|
|
IntSequence::Value(1, 2),
|
|
|
|
IntSequence::Value(3, 9),
|
|
|
|
IntSequence::Value(10, 11),
|
|
|
|
};
|
2007-11-25 11:57:17 +00:00
|
|
|
IntSequence seq = IntSequence(IntSequence::Values(¶ms[0], ¶ms[3]));
|
2008-03-11 12:31:14 +00:00
|
|
|
std::deque<int> r = seq.flush();
|
2007-11-21 16:14:40 +00:00
|
|
|
|
2008-03-11 12:31:14 +00:00
|
|
|
int answers[] = { 1, 3, 4, 5, 6, 7, 8, 10 };
|
2007-11-21 16:14:40 +00:00
|
|
|
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT(std::equal(r.begin(), r.end(), &answers[0]));
|
2007-11-21 16:14:40 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|