blob: bea4e68b2a7e6fc7c3acd60f2383b518e6c698f3 [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 {
25
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060026BOOST_AUTO_TEST_SUITE(TestUtil)
27
28BOOST_AUTO_TEST_CASE(Basic)
29{
30 std::vector<CompressionScheme> available = {CompressionScheme::ZLIB, CompressionScheme::GZIP,
31 CompressionScheme::BZIP2, CompressionScheme::LZMA,
32 CompressionScheme::ZSTD};
33 std::vector<CompressionScheme> supported;
34 std::vector<CompressionScheme> notSupported;
35
36#ifdef PSYNC_HAVE_ZLIB
37 supported.push_back(CompressionScheme::ZLIB);
38#endif
39#ifdef PSYNC_HAVE_GZIP
40 supported.push_back(CompressionScheme::GZIP);
41#endif
42#ifdef PSYNC_HAVE_BZIP2
43 supported.push_back(CompressionScheme::BZIP2);
44#endif
45#ifdef PSYNC_HAVE_LZMA
46 supported.push_back(CompressionScheme::LZMA);
47#endif
48#ifdef PSYNC_HAVE_ZSTD
49 supported.push_back(CompressionScheme::ZSTD);
50#endif
51
52 const uint8_t uncompressed[] = {'t', 'e', 's', 't'};
53
54 for (const auto& s : supported) {
55 BOOST_CHECK_NO_THROW(compress(s, uncompressed, sizeof(uncompressed)));
56 auto compressed = compress(s, uncompressed, sizeof(uncompressed));
57 BOOST_CHECK_NO_THROW(decompress(s, compressed->data(), compressed->size()));
58 }
59
60 std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(),
61 std::inserter(notSupported, notSupported.begin()));
62
63 for (const auto& s : notSupported) {
64 BOOST_CHECK_THROW(compress(s, uncompressed, sizeof(uncompressed)),
65 std::runtime_error);
66 BOOST_CHECK_THROW(decompress(s, uncompressed, sizeof(uncompressed)),
67 std::runtime_error);
68 }
69}
70
71BOOST_AUTO_TEST_SUITE_END()
72
Davide Pesavento5b3cf762020-04-03 16:20:04 -040073} // namespace psync