Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 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 Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 21 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 22 | #include "tests/boost-test.hpp" |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 23 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 24 | namespace psync::tests { |
| 25 | |
| 26 | using namespace psync::detail; |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 27 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 28 | BOOST_AUTO_TEST_SUITE(TestUtil) |
| 29 | |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 30 | BOOST_AUTO_TEST_CASE(Compression) |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 31 | { |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 32 | const std::vector<CompressionScheme> available{ |
| 33 | CompressionScheme::ZLIB, |
| 34 | CompressionScheme::GZIP, |
| 35 | CompressionScheme::BZIP2, |
| 36 | CompressionScheme::LZMA, |
| 37 | CompressionScheme::ZSTD |
| 38 | }; |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 39 | 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 Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 58 | std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(), |
| 59 | std::inserter(notSupported, notSupported.begin())); |
| 60 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 61 | const uint8_t uncompressed[] = {'t', 'e', 's', 't'}; |
| 62 | |
| 63 | for (const auto& s : supported) { |
Davide Pesavento | f6fd2fb | 2022-03-18 21:00:36 -0400 | [diff] [blame] | 64 | BOOST_CHECK_NO_THROW(compress(s, uncompressed)); |
| 65 | auto compressed = compress(s, uncompressed); |
| 66 | BOOST_CHECK_NO_THROW(decompress(s, *compressed)); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 69 | for (const auto& s : notSupported) { |
Davide Pesavento | f6fd2fb | 2022-03-18 21:00:36 -0400 | [diff] [blame] | 70 | BOOST_CHECK_THROW(compress(s, uncompressed), CompressionError); |
| 71 | BOOST_CHECK_THROW(decompress(s, uncompressed), CompressionError); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | BOOST_AUTO_TEST_SUITE_END() |
| 76 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 77 | } // namespace psync::tests |