Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 1 | /* -*- 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 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 | |
| 24 | namespace psync { |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame^] | 25 | namespace detail { |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 26 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 27 | BOOST_AUTO_TEST_SUITE(TestUtil) |
| 28 | |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame^] | 29 | BOOST_AUTO_TEST_CASE(Compression) |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 30 | { |
| 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 Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame^] | 53 | std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(), |
| 54 | std::inserter(notSupported, notSupported.begin())); |
| 55 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 56 | 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 Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 64 | for (const auto& s : notSupported) { |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame^] | 65 | BOOST_CHECK_THROW(compress(s, uncompressed, sizeof(uncompressed)), CompressionError); |
| 66 | BOOST_CHECK_THROW(decompress(s, uncompressed, sizeof(uncompressed)), CompressionError); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_SUITE_END() |
| 71 | |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame^] | 72 | } // namespace detail |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 73 | } // namespace psync |