f6fd2fbd34
Change-Id: I260639ef4c13e6a492b29d3b976cca0ae29876cb
74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/*
|
|
* Copyright (c) 2014-2022, 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 "tests/boost-test.hpp"
|
|
|
|
namespace psync {
|
|
namespace detail {
|
|
|
|
BOOST_AUTO_TEST_SUITE(TestUtil)
|
|
|
|
BOOST_AUTO_TEST_CASE(Compression)
|
|
{
|
|
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
|
|
|
|
std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(),
|
|
std::inserter(notSupported, notSupported.begin()));
|
|
|
|
const uint8_t uncompressed[] = {'t', 'e', 's', 't'};
|
|
|
|
for (const auto& s : supported) {
|
|
BOOST_CHECK_NO_THROW(compress(s, uncompressed));
|
|
auto compressed = compress(s, uncompressed);
|
|
BOOST_CHECK_NO_THROW(decompress(s, *compressed));
|
|
}
|
|
|
|
for (const auto& s : notSupported) {
|
|
BOOST_CHECK_THROW(compress(s, uncompressed), CompressionError);
|
|
BOOST_CHECK_THROW(decompress(s, uncompressed), CompressionError);
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
} // namespace detail
|
|
} // namespace psync
|