blob: 40534882418e7b7925884273cf35f4a35eb38e65 [file] [log] [blame]
Ashlesh Gawanded51690a2019-11-11 22:51:06 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento47eb6d92024-02-12 20:25:51 -05003 * Copyright (c) 2014-2024, The University of Memphis
Ashlesh Gawanded51690a2019-11-11 22:51:06 -06004 *
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
Davide Pesavento47eb6d92024-02-12 20:25:51 -050024namespace psync::tests {
25
26using namespace psync::detail;
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060027
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060028BOOST_AUTO_TEST_SUITE(TestUtil)
29
Davide Pesaventodb789562020-12-19 23:01:08 -050030BOOST_AUTO_TEST_CASE(Compression)
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060031{
Davide Pesavento47eb6d92024-02-12 20:25:51 -050032 const std::vector<CompressionScheme> available{
33 CompressionScheme::ZLIB,
34 CompressionScheme::GZIP,
35 CompressionScheme::BZIP2,
36 CompressionScheme::LZMA,
37 CompressionScheme::ZSTD
38 };
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060039 std::vector<CompressionScheme> supported;
40 std::vector<CompressionScheme> notSupported;
41
42#ifdef PSYNC_HAVE_ZLIB
43 supported.push_back(CompressionScheme::ZLIB);
44#endif
45#ifdef PSYNC_HAVE_GZIP
46 supported.push_back(CompressionScheme::GZIP);
47#endif
48#ifdef PSYNC_HAVE_BZIP2
49 supported.push_back(CompressionScheme::BZIP2);
50#endif
51#ifdef PSYNC_HAVE_LZMA
52 supported.push_back(CompressionScheme::LZMA);
53#endif
54#ifdef PSYNC_HAVE_ZSTD
55 supported.push_back(CompressionScheme::ZSTD);
56#endif
57
Davide Pesaventodb789562020-12-19 23:01:08 -050058 std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(),
59 std::inserter(notSupported, notSupported.begin()));
60
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060061 const uint8_t uncompressed[] = {'t', 'e', 's', 't'};
62
63 for (const auto& s : supported) {
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -040064 BOOST_CHECK_NO_THROW(compress(s, uncompressed));
65 auto compressed = compress(s, uncompressed);
66 BOOST_CHECK_NO_THROW(decompress(s, *compressed));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060067 }
68
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060069 for (const auto& s : notSupported) {
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -040070 BOOST_CHECK_THROW(compress(s, uncompressed), CompressionError);
71 BOOST_CHECK_THROW(decompress(s, uncompressed), CompressionError);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060072 }
73}
74
75BOOST_AUTO_TEST_SUITE_END()
76
Davide Pesavento47eb6d92024-02-12 20:25:51 -050077} // namespace psync::tests