blob: c7fa664aa8361b32d1c6960b70730bdc5cdc1a63 [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
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070026namespace ndn {
27namespace delorean {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070028namespace tests {
29
30BOOST_AUTO_TEST_SUITE(TestTreeGenerator)
31
32BOOST_AUTO_TEST_CASE(HashGeneration)
33{
34 for (size_t n = 5; n <= 8; n++) {
35 auto hash1 = TreeGenerator::getHash(Node::Index(0, 3), n);
36 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(0, 5),
37 [&] (const Node::Index&) {},
38 [&] (const Node::Index&,
39 const NonNegativeInteger&,
40 ndn::ConstBufferPtr) {});
41 for (size_t i = 0; i < n; i++) {
42 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
43 tree.addLeaf(node);
44 }
45 auto hash2 = tree.getRoot()->getHash();
46 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
47 }
48
49 for (size_t n = 33; n <= 64; n++) {
50 auto hash1 = TreeGenerator::getHash(Node::Index(32, 5), n);
51 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(32, 5),
52 [&] (const Node::Index&) {},
53 [&] (const Node::Index&,
54 const NonNegativeInteger&,
55 ndn::ConstBufferPtr) {});
56 for (size_t i = 32; i < n; i++) {
57 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
58 tree.addLeaf(node);
59 }
60 auto hash2 = tree.getRoot()->getHash();
61 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
62 }
63}
64
65BOOST_AUTO_TEST_CASE(TreeGeneration)
66{
67 for (size_t n = 1; n <= 32; n++) {
68 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(0, 5), n)->getRoot()->getHash();
69 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(0, 5),
70 [&] (const Node::Index&) {},
71 [&] (const Node::Index&,
72 const NonNegativeInteger&,
73 ndn::ConstBufferPtr) {});
74 for (size_t i = 0; i < n; i++) {
75 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
76 tree.addLeaf(node);
77 }
78 auto hash2 = tree.getRoot()->getHash();
79 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
80 }
81
82 for (size_t n = 33; n <= 64; n++) {
83 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(32, 5), n)->getRoot()->getHash();
84 SubTreeBinary tree(TreeGenerator::LOGGER_NAME, Node::Index(32, 5),
85 [&] (const Node::Index&) {},
86 [&] (const Node::Index&,
87 const NonNegativeInteger&,
88 ndn::ConstBufferPtr) {});
89 for (size_t i = 32; i < n; i++) {
90 auto node = make_shared<Node>(i, 0, i + 1, Node::getEmptyHash());
91 tree.addLeaf(node);
92 }
93 auto hash2 = tree.getRoot()->getHash();
94 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
95 }
96
97 for (size_t n = 513; n <= 1024; n++) {
98 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(0, 10), n)->getRoot()->getHash();
99 auto hash2 = TreeGenerator::getHash(Node::Index(0, 10), n);
100 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
101 }
102
103 for (size_t n = 1025; n <= 2048; n++) {
104 auto hash1 = TreeGenerator::getSubTreeBinary(Node::Index(1024, 10), n)->getRoot()->getHash();
105 auto hash2 = TreeGenerator::getHash(Node::Index(1024, 10), n);
106 BOOST_CHECK_EQUAL_COLLECTIONS(hash1->begin(), hash1->end(), hash2->begin(), hash2->end());
107 }
108}
109
110BOOST_AUTO_TEST_SUITE_END()
111
112} // namespace tests
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -0700113} // namespace delorean
114} // namespace ndn