Debugging NameInfo, FullState, and DiffState
Now NameInfo is thread-safe and has automatic garbage collector.
Internal container is managed by weak_ptr instead of shared_ptr as it
was before.
diff --git a/test/test.cc b/test/test.cc
deleted file mode 100644
index 55745d9..0000000
--- a/test/test.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#define BOOST_TEST_MODULE Digest
-#include <boost/test/unit_test.hpp>
-
diff --git a/test/test_digest.cc b/test/test_digest.cc
index a1ae6a3..cbbc385 100644
--- a/test/test_digest.cc
+++ b/test/test_digest.cc
@@ -20,6 +20,7 @@
* Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
+#define BOOST_TEST_MAIN 1
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
@@ -32,7 +33,7 @@
using namespace std;
using namespace boost;
-BOOST_AUTO_TEST_SUITE(DigestTestSuite)
+BOOST_AUTO_TEST_SUITE(DigestTests)
BOOST_AUTO_TEST_CASE (BasicTest)
{
@@ -96,4 +97,3 @@
}
BOOST_AUTO_TEST_SUITE_END()
-
diff --git a/test/test_leaf.cc b/test/test_leaf.cc
index 991e14b..76b517c 100644
--- a/test/test_leaf.cc
+++ b/test/test_leaf.cc
@@ -34,7 +34,7 @@
using namespace std;
using namespace boost;
-BOOST_AUTO_TEST_SUITE(LeafTestSuite)
+BOOST_AUTO_TEST_SUITE(LeafTests)
BOOST_AUTO_TEST_CASE (LeafBase)
{
@@ -43,19 +43,19 @@
// find the same name
BOOST_CHECK (name.get () == StdNameInfo::FindOrCreate ("/test/name").get ());
- BOOST_CHECK_EQUAL (name.use_count (), 2);
+ BOOST_CHECK_EQUAL (name.use_count (), 1);
BOOST_CHECK_NO_THROW (DiffLeaf x (name, SeqNo (12)));
- BOOST_CHECK_EQUAL (name.use_count (), 2);
+ BOOST_CHECK_EQUAL (name.use_count (), 1);
BOOST_CHECK_NO_THROW (DiffLeaf x (name));
- BOOST_CHECK_EQUAL (name.use_count (), 2);
+ BOOST_CHECK_EQUAL (name.use_count (), 1);
DiffLeaf updateLeaf (name, SeqNo (12));
- BOOST_CHECK_EQUAL (name.use_count (), 3);
+ BOOST_CHECK_EQUAL (name.use_count (), 2);
DiffLeaf removeLeaf (name);
- BOOST_CHECK_EQUAL (name.use_count (), 4);
+ BOOST_CHECK_EQUAL (name.use_count (), 3);
BOOST_CHECK_EQUAL (updateLeaf.getOperation (), UPDATE);
BOOST_CHECK_EQUAL (updateLeaf.getSeq ().getSession (), 0);
@@ -67,12 +67,12 @@
BOOST_REQUIRE_NO_THROW (FullLeaf x (name, SeqNo (12)));
FullLeaf fullLeaf (name, SeqNo (12));
- BOOST_CHECK_EQUAL (name.use_count (), 5);
+ BOOST_CHECK_EQUAL (name.use_count (), 4);
}
BOOST_AUTO_TEST_CASE (LeafDigest)
{
- BOOST_CHECK_EQUAL (StdNameInfo::FindOrCreate ("/test/name").use_count (), 2);
+ BOOST_CHECK_EQUAL (StdNameInfo::FindOrCreate ("/test/name").use_count (), 1);
NameInfoConstPtr name = StdNameInfo::FindOrCreate ("/test/name");
FullLeaf fullLeaf (name, SeqNo (12));
diff --git a/test/test_state.cc b/test/test_state.cc
index 00be3c4..ff0a8a1 100644
--- a/test/test_state.cc
+++ b/test/test_state.cc
@@ -20,6 +20,9 @@
* Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
+#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_NO_MAIN 1
+// #define BOOST_TEST_MODULE StateTests
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
@@ -35,7 +38,7 @@
using namespace std;
using namespace boost;
-BOOST_AUTO_TEST_SUITE(StateTestSuite)
+BOOST_AUTO_TEST_SUITE(StateTests)
BOOST_AUTO_TEST_CASE (FullStateTest)
{
@@ -84,4 +87,52 @@
BOOST_CHECK_EQUAL ((*state.getLeaves ().begin ())->getSeq ().getSeq (), 0);
}
+BOOST_AUTO_TEST_CASE (FullStateDigestTest)
+{
+ FullState state;
+ BOOST_CHECK_EQUAL (state.getLeaves ().size (), 0);
+
+ NameInfoConstPtr name3 = StdNameInfo::FindOrCreate ("3");
+ NameInfoConstPtr name2 = StdNameInfo::FindOrCreate ("2");
+ NameInfoConstPtr name1 = StdNameInfo::FindOrCreate ("1");
+
+ state.update (name1, SeqNo (10));
+ DigestConstPtr digest1 = state.getDigest ();
+
+ state.update (name2, SeqNo (12));
+ DigestConstPtr digest2 = state.getDigest ();
+
+ BOOST_CHECK (digest1.get () != digest2.get ());
+ BOOST_CHECK (!digest1->empty ());
+ BOOST_CHECK (!digest2->empty ());
+
+ state.update (name3, SeqNo (8));
+ DigestConstPtr digest3 = state.getDigest ();
+
+ BOOST_CHECK (digest1.get () != digest2.get ());
+ BOOST_CHECK (digest2.get () != digest3.get ());
+ BOOST_CHECK (digest1.get () != digest3.get ());
+
+ BOOST_CHECK (*digest1 != *digest2);
+ BOOST_CHECK (*digest2 != *digest3);
+ BOOST_CHECK (*digest1 != *digest3);
+
+ // removing elements. Digest should get reverted to digest1
+ state.remove (name2);
+ state.remove (name3);
+ DigestConstPtr digest4 = state.getDigest ();
+ BOOST_CHECK (*digest1 == *digest4);
+
+ name2.reset (); // force destructor
+ name3.reset (); // force destructor
+ name3 = StdNameInfo::FindOrCreate ("3"); // this will enforce different (larger) hashing ID of name
+ name2 = StdNameInfo::FindOrCreate ("2"); // this will enforce different (larger) hashing ID of name
+
+ // adding in different order
+ state.update (name3, SeqNo (8));
+ state.update (name2, SeqNo (12));
+ DigestConstPtr digest5 = state.getDigest ();
+ BOOST_CHECK (*digest5 == *digest3);
+}
+
BOOST_AUTO_TEST_SUITE_END()