forked from aria2/aria2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeomStreamPieceSelectorTest.cc
51 lines (41 loc) · 1.31 KB
/
GeomStreamPieceSelectorTest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "GeomStreamPieceSelector.h"
#include <cstring>
#include <cppunit/extensions/HelperMacros.h>
#include "Exception.h"
#include "util.h"
#include "BitfieldMan.h"
namespace aria2 {
class GeomStreamPieceSelectorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(GeomStreamPieceSelectorTest);
CPPUNIT_TEST(testOnBitfieldInit);
CPPUNIT_TEST_SUITE_END();
public:
void testOnBitfieldInit();
};
CPPUNIT_TEST_SUITE_REGISTRATION(GeomStreamPieceSelectorTest);
void GeomStreamPieceSelectorTest::testOnBitfieldInit()
{
BitfieldMan bf(1_k, 20_k);
bf.setBitRange(0, 10);
GeomStreamPieceSelector sel(&bf, 2);
sel.onBitfieldInit();
unsigned char igbf[3];
memset(igbf, 0, 3);
size_t index;
// 11111|11111|00000|00000
CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf)));
CPPUNIT_ASSERT_EQUAL((size_t)11, index);
bf.setUseBit(11);
// 11111|11111|10000|00000
CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf)));
CPPUNIT_ASSERT_EQUAL((size_t)12, index);
bf.setUseBit(12);
// 11111|11111|11000|00000
CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf)));
CPPUNIT_ASSERT_EQUAL((size_t)13, index);
bf.setUseBit(13);
// 11111|11111|11100|00000
CPPUNIT_ASSERT(sel.select(index, 20_k, igbf, sizeof(igbf)));
CPPUNIT_ASSERT_EQUAL((size_t)15, index);
}
} // namespace aria2