Simplify Leaf and its sub-classes.
Change-Id: I711db26bedee2bebdd39ffd8b637fa8918c16ff9
diff --git a/tests/test-leaf.cpp.outdated b/tests/test-leaf.cpp.outdated
deleted file mode 100644
index bad1971..0000000
--- a/tests/test-leaf.cpp.outdated
+++ /dev/null
@@ -1,105 +0,0 @@
-/* -*- 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()
diff --git a/tests/unit-tests/test-digest.cpp.outdated b/tests/unit-tests/test-digest.cpp.outdated
deleted file mode 100644
index cbc5ced..0000000
--- a/tests/unit-tests/test-digest.cpp.outdated
+++ /dev/null
@@ -1,101 +0,0 @@
-/* -*- 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 "sync-digest.h"
-#include <iostream>
-#include <sstream>
-
-using namespace Sync;
-using namespace Sync::Error;
-using namespace std;
-using namespace boost;
-
-BOOST_AUTO_TEST_SUITE(DigestTests)
-
-BOOST_AUTO_TEST_CASE (BasicTest)
-{
- Digest d0;
- BOOST_REQUIRE (d0.empty ());
-}
-
-BOOST_AUTO_TEST_CASE (DigestGenerationTest)
-{
- Digest d1;
- BOOST_CHECK_NO_THROW (d1 << "1\n");
-
- // without explicit finalizing, Digest will not be complete and printing out will cause assert
- BOOST_CHECK (d1.empty ());
-
- // fix hash
- d1.finalize ();
-
- BOOST_CHECK_NO_THROW (d1.getHash ());
- BOOST_CHECK (!d1.empty ());
- BOOST_CHECK (d1 == d1);
-
- BOOST_CHECK_THROW (d1 << "2", DigestCalculationError);
-
- output_test_stream output;
- BOOST_CHECK_NO_THROW (output << d1);
- // BOOST_CHECK (output.check_length (40, false) );
- // BOOST_CHECK (output.is_equal ("e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e", true)); // for sha1
- BOOST_CHECK (output.check_length (64, false) );
- BOOST_CHECK (output.is_equal ("4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865", true)); // for sha256
-}
-
-BOOST_AUTO_TEST_CASE (DigestComparison)
-{
- Digest d1;
- BOOST_CHECK_NO_THROW (d1 << "1\n");
- // BOOST_CHECK_THROW (d1 == d1, DigestCalculationError);
- BOOST_CHECK_NO_THROW (d1.finalize ());
- BOOST_CHECK (d1 == d1);
-
- Digest d2;
- BOOST_CHECK_NO_THROW (d2 << "2\n");
- BOOST_CHECK_NO_THROW (d2.finalize ());
- BOOST_CHECK (d1 != d2);
-
- Digest d3;
- // istringstream is (string ("e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e")); // real sha-1 for "1\n"
- istringstream is (string ("4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865")); // real sha256 for "1\n"
- BOOST_CHECK_NO_THROW (is >> d3);
- BOOST_CHECK (!d3.empty ());
- BOOST_CHECK (d3 == d1);
- BOOST_CHECK (d3 != d2);
-
- istringstream is2 (string ("25fa44f2b31c1fb553b6021e7360d07d5d91ff5e")); // some fake hash
- BOOST_CHECK_THROW (is2 >> d3, DigestCalculationError); // >> can be used only once
-
- Digest d4;
- BOOST_CHECK_THROW (is2 >> d4, DigestCalculationError); // is2 is now empty. empty >> is not allowed
-
- istringstream is3 (string ("25fa44f2b31c1fb553b6021e7360d07d5d91ff5e")); // some fake hash
- BOOST_CHECK_NO_THROW (is3 >> d4);
-
- BOOST_CHECK (d4 != d1);
- BOOST_CHECK (d4 != d2);
- BOOST_CHECK (d4 != d3);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit-tests/test-leaf.cpp b/tests/unit-tests/test-leaf.cpp
new file mode 100644
index 0000000..a8f3101
--- /dev/null
+++ b/tests/unit-tests/test-leaf.cpp
@@ -0,0 +1,69 @@
+/* -*- 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 "leaf.hpp"
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+
+#include "boost-test.hpp"
+
+
+namespace chronosync {
+namespace test {
+
+BOOST_AUTO_TEST_SUITE(LeafTests)
+
+BOOST_AUTO_TEST_CASE(LeafBasic)
+{
+ Name userPrefix("/test/name");
+ BOOST_CHECK_NO_THROW(Leaf leaf(userPrefix, 1, 10));
+
+ Leaf leaf(userPrefix, 1, 10);
+ Name sessionName = userPrefix;
+ sessionName.appendNumber(1);
+ BOOST_CHECK_EQUAL(leaf.getSessionName(), sessionName);
+ BOOST_CHECK_EQUAL(leaf.getSeq(), 10);
+
+ leaf.setSeq(9);
+ BOOST_CHECK_EQUAL(leaf.getSeq(), 10);
+ leaf.setSeq(11);
+ BOOST_CHECK_EQUAL(leaf.getSeq(), 11);
+}
+
+BOOST_AUTO_TEST_CASE(LeafDigest)
+{
+ using namespace CryptoPP;
+
+ std::string hexResult = "05fe7f728d3341e9eff82526277b02171044124d0a52e8c4610982261c20de2b";
+ ndn::OBufferStream os;
+ StringSource(hexResult, true, new HexDecoder(new FileSink(os)));
+ ndn::ConstBufferPtr result = os.buf();
+
+ Name userPrefix("/test/name");
+ Leaf leaf(userPrefix, 1, 10);
+
+ BOOST_CHECK_NO_THROW(leaf.getDigest());
+
+ ndn::ConstBufferPtr digest = leaf.getDigest();
+ BOOST_CHECK(*result == *digest);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace test
+} // namespace chronosync
diff --git a/tests/wscript b/tests/wscript
index bc847a9..d1a61ba 100644
--- a/tests/wscript
+++ b/tests/wscript
@@ -8,7 +8,7 @@
target='unit-tests-main',
name='unit-tests-main',
features='cxx',
- source=bld.path.ant_glob(['*.cpp']),
+ source=bld.path.ant_glob(['main.cpp']),
use='ChronoSync',
)