blob: eaf94e6d69c709a15ffb3a267d64b512a1042c6c [file] [log] [blame]
Yingdi Yu0c3e5912015-03-17 14:22:38 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
Yingdi Yu0c3e5912015-03-17 14:22:38 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * This file is part of NDN DeLorean, An Authentication System for Data Archives in
6 * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
7 * and contributors.
Yingdi Yu0c3e5912015-03-17 14:22:38 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * NDN DeLorean is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
Yingdi Yu0c3e5912015-03-17 14:22:38 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Yingdi Yu0c3e5912015-03-17 14:22:38 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * You should have received a copy of the GNU General Public License along with NDN
19 * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yu0c3e5912015-03-17 14:22:38 -070020 */
21
22#include "../tree-generator.hpp"
23
24#include "boost-test.hpp"
25
26namespace nsl {
27namespace tests {
28
29BOOST_AUTO_TEST_SUITE(TestTreeGenerator)
30
31BOOST_AUTO_TEST_CASE(HashGeneration)
32{
33 for (size_t n = 5; n <= 8; n++) {
34 auto hash1 = TreeGenerator::getHash(Node::Index(0, 3), n);
35 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(0, 5),
36 [&] (const Node::Index&) {},
37 [&] (const Node::Index&,
38 const NonNegativeInteger&,
39 ndn::ConstBufferPtr) {});
40 for (size_t i = 0; i < n; i++) {
41 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
42 tree.addLeaf(node);
43 }
44 auto hash2 = tree.getRoot()->getHash();
45 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
46 }
47
48 for (size_t n = 33; n <= 64; n++) {
49 auto hash1 = TreeGenerator::getHash(Node::Index(32, 5), n);
50 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(32, 5),
51 [&] (const Node::Index&) {},
52 [&] (const Node::Index&,
53 const NonNegativeInteger&,
54 ndn::ConstBufferPtr) {});
55 for (size_t i = 32; i < n; i++) {
56 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
57 tree.addLeaf(node);
58 }
59 auto hash2 = tree.getRoot()->getHash();
60 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
61 }
62}
63
64BOOST_AUTO_TEST_CASE(TreeGeneration)
65{
66 for (size_t n = 1; n <= 32; n++) {
67 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(0, 5), n)->getRoot()->getHash();
68 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(0, 5),
69 [&] (const Node::Index&) {},
70 [&] (const Node::Index&,
71 const NonNegativeInteger&,
72 ndn::ConstBufferPtr) {});
73 for (size_t i = 0; i < n; i++) {
74 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
75 tree.addLeaf(node);
76 }
77 auto hash2 = tree.getRoot()->getHash();
78 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
79 }
80
81 for (size_t n = 33; n <= 64; n++) {
82 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(32, 5), n)->getRoot()->getHash();
83 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(32, 5),
84 [&] (const Node::Index&) {},
85 [&] (const Node::Index&,
86 const NonNegativeInteger&,
87 ndn::ConstBufferPtr) {});
88 for (size_t i = 32; i < n; i++) {
89 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
90 tree.addLeaf(node);
91 }
92 auto hash2 = tree.getRoot()->getHash();
93 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
94 }
95
96 for (size_t n = 513; n <= 1024; n++) {
97 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(0, 10), n)->getRoot()->getHash();
98 auto hash2 = TreeGenerator::getHash(Node::Index(0, 10), n);
99 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
100 }
101
102 for (size_t n = 1025; n <= 2048; n++) {
103 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(1024, 10), n)->getRoot()->getHash();
104 auto hash2 = TreeGenerator::getHash(Node::Index(1024, 10), n);
105 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
106 }
107}
108
109BOOST_AUTO_TEST_SUITE_END()
110
111} // namespace tests
112} // namespace nsl