blob: e37957a104a1e17047beb6d8e8d2c81d2fff0cf3 [file] [log] [blame]
Ashlesh Gawanded51690a2019-11-11 22:51:06 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2020, The University of Memphis
4 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU Lesser General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License along with
17 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20#include "PSync/detail/util.hpp"
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060021
Davide Pesavento5b3cf762020-04-03 16:20:04 -040022#include "tests/boost-test.hpp"
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060023
24namespace psync {
Davide Pesaventodb789562020-12-19 23:01:08 -050025namespace detail {
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060026
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060027BOOST_AUTO_TEST_SUITE(TestUtil)
28
Davide Pesaventodb789562020-12-19 23:01:08 -050029BOOST_AUTO_TEST_CASE(Compression)
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060030{
31 std::vector<CompressionScheme> available = {CompressionScheme::ZLIB, CompressionScheme::GZIP,
32 CompressionScheme::BZIP2, CompressionScheme::LZMA,
33 CompressionScheme::ZSTD};
34 std::vector<CompressionScheme> supported;
35 std::vector<CompressionScheme> notSupported;
36
37#ifdef PSYNC_HAVE_ZLIB
38 supported.push_back(CompressionScheme::ZLIB);
39#endif
40#ifdef PSYNC_HAVE_GZIP
41 supported.push_back(CompressionScheme::GZIP);
42#endif
43#ifdef PSYNC_HAVE_BZIP2
44 supported.push_back(CompressionScheme::BZIP2);
45#endif
46#ifdef PSYNC_HAVE_LZMA
47 supported.push_back(CompressionScheme::LZMA);
48#endif
49#ifdef PSYNC_HAVE_ZSTD
50 supported.push_back(CompressionScheme::ZSTD);
51#endif
52
Davide Pesaventodb789562020-12-19 23:01:08 -050053 std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(),
54 std::inserter(notSupported, notSupported.begin()));
55
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060056 const uint8_t uncompressed[] = {'t', 'e', 's', 't'};
57
58 for (const auto& s : supported) {
59 BOOST_CHECK_NO_THROW(compress(s, uncompressed, sizeof(uncompressed)));
60 auto compressed = compress(s, uncompressed, sizeof(uncompressed));
61 BOOST_CHECK_NO_THROW(decompress(s, compressed->data(), compressed->size()));
62 }
63
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060064 for (const auto& s : notSupported) {
Davide Pesaventodb789562020-12-19 23:01:08 -050065 BOOST_CHECK_THROW(compress(s, uncompressed, sizeof(uncompressed)), CompressionError);
66 BOOST_CHECK_THROW(decompress(s, uncompressed, sizeof(uncompressed)), CompressionError);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060067 }
68}
69
70BOOST_AUTO_TEST_SUITE_END()
71
Davide Pesaventodb789562020-12-19 23:01:08 -050072} // namespace detail
Davide Pesavento5b3cf762020-04-03 16:20:04 -040073} // namespace psync