| /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| /* |
| * Copyright (c) 2012-2014 University of California, Los Angeles |
| * |
| * This file is part of ChronoSync, synchronization library for distributed realtime |
| * applications for NDN. |
| * |
| * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, either |
| * version 3 of the License, or (at your option) any later version. |
| * |
| * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| |
| #include <boost/test/unit_test.hpp> |
| #include <boost/test/output_test_stream.hpp> |
| using boost::test_tools::output_test_stream; |
| |
| #include <boost/make_shared.hpp> |
| |
| #include "sync-full-leaf.h" |
| #include "sync-diff-leaf.h" |
| #include "sync-std-name-info.h" |
| |
| using namespace Sync; |
| using namespace std; |
| using namespace boost; |
| |
| BOOST_AUTO_TEST_SUITE(LeafTests) |
| |
| BOOST_AUTO_TEST_CASE (LeafBase) |
| { |
| NameInfoConstPtr name = StdNameInfo::FindOrCreate ("/test/name"); |
| BOOST_CHECK (name != 0); |
| |
| // find the same name |
| BOOST_CHECK (name.get () == StdNameInfo::FindOrCreate ("/test/name").get ()); |
| BOOST_CHECK_EQUAL (name.use_count (), 1); |
| |
| BOOST_CHECK_NO_THROW (DiffLeaf x (name, SeqNo (12))); |
| BOOST_CHECK_EQUAL (name.use_count (), 1); |
| |
| BOOST_CHECK_NO_THROW (DiffLeaf x (name)); |
| BOOST_CHECK_EQUAL (name.use_count (), 1); |
| |
| DiffLeaf updateLeaf (name, SeqNo (12)); |
| BOOST_CHECK_EQUAL (name.use_count (), 2); |
| |
| DiffLeaf removeLeaf (name); |
| BOOST_CHECK_EQUAL (name.use_count (), 3); |
| |
| BOOST_CHECK_EQUAL (updateLeaf.getOperation (), UPDATE); |
| BOOST_CHECK_EQUAL (updateLeaf.getSeq ().getSession (), 0); |
| BOOST_CHECK_EQUAL (updateLeaf.getSeq ().getSeq (), 12); |
| |
| BOOST_CHECK_EQUAL (removeLeaf.getOperation (), REMOVE); |
| BOOST_CHECK_EQUAL (removeLeaf.getSeq ().getSession (), 0); |
| BOOST_CHECK_EQUAL (removeLeaf.getSeq ().getSeq (), 0); |
| |
| BOOST_REQUIRE_NO_THROW (FullLeaf x (name, SeqNo (12))); |
| FullLeaf fullLeaf (name, SeqNo (12)); |
| BOOST_CHECK_EQUAL (name.use_count (), 4); |
| } |
| |
| BOOST_AUTO_TEST_CASE (LeafDigest) |
| { |
| BOOST_CHECK_EQUAL (StdNameInfo::FindOrCreate ("/test/name").use_count (), 1); |
| NameInfoConstPtr name = StdNameInfo::FindOrCreate ("/test/name"); |
| FullLeaf fullLeaf (name, SeqNo (12)); |
| |
| // fullLeafDigest = hash ( hash(name), hash (session, seqNo) ) |
| |
| // Digest manualDigest; |
| |
| // Digest manualNameDigest; |
| // manualNameDigest << "/test/name"; |
| // manualNameDigest.finalize (); |
| |
| // Digest manualSeqNoDigest; |
| // manualSeqNoDigest << 0 << 13; |
| // manualSeqNoDigest.finalize (); |
| |
| // manualDigest << manualNameDigest << manualSeqNoDigest; |
| // manualDigest.finalize (); |
| |
| // cout << manualDigest << "\n\n"; |
| |
| output_test_stream output; |
| output << fullLeaf.getDigest (); |
| // BOOST_CHECK (output.is_equal ("991f8cf6262dfe0f519c63f6e9b92fe69e741a9b", true)); // for sha1 |
| BOOST_CHECK (output.is_equal ("526d63e6e1f05f97502fd500a1729c4907f3841483ae4561b7e6307c40188f35", true)); // for sha256 |
| |
| fullLeaf.setSeq (SeqNo (13)); |
| output << fullLeaf.getDigest (); |
| BOOST_CHECK (!output.is_equal ("991f8cf6262dfe0f519c63f6e9b92fe69e741a9b", false)); |
| // BOOST_CHECK (output.is_equal ("585a8687ab41d5c29f86e5906c8f188ddca816b3", true)); // for sha1 |
| BOOST_CHECK (output.is_equal ("39fefe65b3e1021776c07d3a9a3023c6c7cdf12724ee7f3a98b813b22f46d5ec", true)); // for sha256 |
| } |
| |
| BOOST_AUTO_TEST_SUITE_END() |