Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2014 University of California, Los Angeles |
| 4 | * |
| 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
| 7 | * |
| 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "leaf.hpp" |
| 21 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
| 22 | |
| 23 | #include "boost-test.hpp" |
| 24 | |
| 25 | |
| 26 | namespace chronosync { |
| 27 | namespace test { |
| 28 | |
| 29 | BOOST_AUTO_TEST_SUITE(LeafTests) |
| 30 | |
| 31 | BOOST_AUTO_TEST_CASE(LeafBasic) |
| 32 | { |
| 33 | Name userPrefix("/test/name"); |
| 34 | BOOST_CHECK_NO_THROW(Leaf leaf(userPrefix, 1, 10)); |
| 35 | |
| 36 | Leaf leaf(userPrefix, 1, 10); |
| 37 | Name sessionName = userPrefix; |
| 38 | sessionName.appendNumber(1); |
| 39 | BOOST_CHECK_EQUAL(leaf.getSessionName(), sessionName); |
| 40 | BOOST_CHECK_EQUAL(leaf.getSeq(), 10); |
| 41 | |
| 42 | leaf.setSeq(9); |
| 43 | BOOST_CHECK_EQUAL(leaf.getSeq(), 10); |
| 44 | leaf.setSeq(11); |
| 45 | BOOST_CHECK_EQUAL(leaf.getSeq(), 11); |
| 46 | } |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(LeafDigest) |
| 49 | { |
| 50 | using namespace CryptoPP; |
| 51 | |
| 52 | std::string hexResult = "05fe7f728d3341e9eff82526277b02171044124d0a52e8c4610982261c20de2b"; |
| 53 | ndn::OBufferStream os; |
| 54 | StringSource(hexResult, true, new HexDecoder(new FileSink(os))); |
| 55 | ndn::ConstBufferPtr result = os.buf(); |
| 56 | |
| 57 | Name userPrefix("/test/name"); |
| 58 | Leaf leaf(userPrefix, 1, 10); |
| 59 | |
| 60 | BOOST_CHECK_NO_THROW(leaf.getDigest()); |
| 61 | |
| 62 | ndn::ConstBufferPtr digest = leaf.getDigest(); |
| 63 | BOOST_CHECK(*result == *digest); |
| 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_SUITE_END() |
| 67 | |
| 68 | } // namespace test |
| 69 | } // namespace chronosync |