support various compression schemes
refs: #5061, #4917
Change-Id: Icba04b8693e40c4f065293b8d688ba32c63bd7bb
diff --git a/tests/test-full-producer.cpp b/tests/test-full-producer.cpp
index 2bd7db4..fc56a0c 100644
--- a/tests/test-full-producer.cpp
+++ b/tests/test-full-producer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, The University of Memphis
+ * Copyright (c) 2014-2020, The University of Memphis
*
* This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors.
@@ -65,6 +65,26 @@
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
}
+BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
+{
+ Name syncPrefix("/psync"), userNode("/testUser");
+ util::DummyClientFace face({true, true});
+
+ FullProducer node(40, face, syncPrefix, userNode, nullptr);
+
+ ndn::Name syncInterestName(syncPrefix);
+ node.m_iblt.appendToName(syncInterestName);
+ ndn::Interest syncInterest(syncInterestName);
+
+ auto badCompress = std::make_shared<const ndn::Buffer>(5);
+
+ BOOST_REQUIRE_NO_THROW(node.onSyncData(syncInterest, badCompress));
+
+ const uint8_t test[] = {'t', 'e', 's', 't'};
+ auto goodCompressBadBlock = compress(node.m_contentCompression, &test[0], sizeof(test));
+ BOOST_REQUIRE_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace psync
\ No newline at end of file
diff --git a/tests/test-full-sync.cpp b/tests/test-full-sync.cpp
index af7c238..d79e012 100644
--- a/tests/test-full-sync.cpp
+++ b/tests/test-full-sync.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, The University of Memphis
+ * Copyright (c) 2014-2020, The University of Memphis
*
* This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors.
@@ -398,7 +398,7 @@
{
addNode(0);
- for (int i = 0; i < 300; i++) {
+ for (int i = 0; i < 2000; i++) {
Name prefixToPublish("userNode0-" + to_string(i));
nodes[0]->addUserNode(prefixToPublish);
nodes[0]->publishName(prefixToPublish);
@@ -421,7 +421,7 @@
// Get data name from face and increase segment number to form next interest
Name dataName = faces[0]->sentData.front().getName();
- Name interestName = dataName.getSubName(0, dataName.size() - 1);
+ Name interestName = dataName.getSubName(0, dataName.size() - 2);
interestName.appendSegment(1);
faces[0]->sentData.clear();
@@ -436,4 +436,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace psync
\ No newline at end of file
+} // namespace psync
diff --git a/tests/test-util.cpp b/tests/test-util.cpp
new file mode 100644
index 0000000..2ec1de8
--- /dev/null
+++ b/tests/test-util.cpp
@@ -0,0 +1,79 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2020, The University of Memphis
+ *
+ * This file is part of PSync.
+ * See AUTHORS.md for complete list of PSync authors and contributors.
+ *
+ * PSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * PSync 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "PSync/detail/util.hpp"
+#include "PSync/detail/config.hpp"
+#include "unit-test-time-fixture.hpp"
+
+#include <boost/test/unit_test.hpp>
+#include <iostream>
+
+namespace psync {
+
+using namespace ndn;
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(TestUtil)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+ std::vector<CompressionScheme> available = {CompressionScheme::ZLIB, CompressionScheme::GZIP,
+ CompressionScheme::BZIP2, CompressionScheme::LZMA,
+ CompressionScheme::ZSTD};
+ std::vector<CompressionScheme> supported;
+ std::vector<CompressionScheme> notSupported;
+
+#ifdef PSYNC_HAVE_ZLIB
+ supported.push_back(CompressionScheme::ZLIB);
+#endif
+#ifdef PSYNC_HAVE_GZIP
+ supported.push_back(CompressionScheme::GZIP);
+#endif
+#ifdef PSYNC_HAVE_BZIP2
+ supported.push_back(CompressionScheme::BZIP2);
+#endif
+#ifdef PSYNC_HAVE_LZMA
+ supported.push_back(CompressionScheme::LZMA);
+#endif
+#ifdef PSYNC_HAVE_ZSTD
+ supported.push_back(CompressionScheme::ZSTD);
+#endif
+
+ const uint8_t uncompressed[] = {'t', 'e', 's', 't'};
+
+ for (const auto& s : supported) {
+ BOOST_CHECK_NO_THROW(compress(s, uncompressed, sizeof(uncompressed)));
+ auto compressed = compress(s, uncompressed, sizeof(uncompressed));
+ BOOST_CHECK_NO_THROW(decompress(s, compressed->data(), compressed->size()));
+ }
+
+ std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(),
+ std::inserter(notSupported, notSupported.begin()));
+
+ for (const auto& s : notSupported) {
+ BOOST_CHECK_THROW(compress(s, uncompressed, sizeof(uncompressed)),
+ std::runtime_error);
+ BOOST_CHECK_THROW(decompress(s, uncompressed, sizeof(uncompressed)),
+ std::runtime_error);
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace psync
\ No newline at end of file