forked from aria2/aria2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHTIDCloserTest.cc
72 lines (52 loc) · 1.71 KB
/
DHTIDCloserTest.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "DHTIDCloser.h"
#include <cstring>
#include <algorithm>
#include <cppunit/extensions/HelperMacros.h>
#include "DHTNode.h"
#include "DHTNodeLookupEntry.h"
#include "Exception.h"
#include "util.h"
namespace aria2 {
class DHTIDCloserTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DHTIDCloserTest);
CPPUNIT_TEST(testOperator);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testOperator();
};
CPPUNIT_TEST_SUITE_REGISTRATION(DHTIDCloserTest);
void DHTIDCloserTest::testOperator()
{
unsigned char id[DHT_ID_LENGTH];
memset(id, 0xf0, DHT_ID_LENGTH);
auto e1 = make_unique<DHTNodeLookupEntry>(std::make_shared<DHTNode>(id));
auto ep1 = e1.get();
id[0] = 0xb0;
auto e2 = make_unique<DHTNodeLookupEntry>(std::make_shared<DHTNode>(id));
auto ep2 = e2.get();
id[0] = 0xa0;
auto e3 = make_unique<DHTNodeLookupEntry>(std::make_shared<DHTNode>(id));
auto ep3 = e3.get();
id[0] = 0x80;
auto e4 = make_unique<DHTNodeLookupEntry>(std::make_shared<DHTNode>(id));
auto ep4 = e4.get();
id[0] = 0x00;
auto e5 = make_unique<DHTNodeLookupEntry>(std::make_shared<DHTNode>(id));
auto ep5 = e5.get();
auto entries = std::vector<std::unique_ptr<DHTNodeLookupEntry>>{};
entries.push_back(std::move(e1));
entries.push_back(std::move(e2));
entries.push_back(std::move(e3));
entries.push_back(std::move(e4));
entries.push_back(std::move(e5));
std::sort(std::begin(entries), std::end(entries),
DHTIDCloser(ep3->node->getID()));
CPPUNIT_ASSERT(*ep3 == *entries[0]);
CPPUNIT_ASSERT(*ep2 == *entries[1]);
CPPUNIT_ASSERT(*ep4 == *entries[2]);
CPPUNIT_ASSERT(*ep1 == *entries[3]);
CPPUNIT_ASSERT(*ep5 == *entries[4]);
}
} // namespace aria2