blob: 2ec1de890243b45526259c32b5046ab8062ba803 [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"
21#include "PSync/detail/config.hpp"
22#include "unit-test-time-fixture.hpp"
23
24#include <boost/test/unit_test.hpp>
25#include <iostream>
26
27namespace psync {
28
29using namespace ndn;
30using namespace std;
31
32BOOST_AUTO_TEST_SUITE(TestUtil)
33
34BOOST_AUTO_TEST_CASE(Basic)
35{
36 std::vector<CompressionScheme> available = {CompressionScheme::ZLIB, CompressionScheme::GZIP,
37 CompressionScheme::BZIP2, CompressionScheme::LZMA,
38 CompressionScheme::ZSTD};
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
58 const uint8_t uncompressed[] = {'t', 'e', 's', 't'};
59
60 for (const auto& s : supported) {
61 BOOST_CHECK_NO_THROW(compress(s, uncompressed, sizeof(uncompressed)));
62 auto compressed = compress(s, uncompressed, sizeof(uncompressed));
63 BOOST_CHECK_NO_THROW(decompress(s, compressed->data(), compressed->size()));
64 }
65
66 std::set_difference(available.begin(), available.end(), supported.begin(), supported.end(),
67 std::inserter(notSupported, notSupported.begin()));
68
69 for (const auto& s : notSupported) {
70 BOOST_CHECK_THROW(compress(s, uncompressed, sizeof(uncompressed)),
71 std::runtime_error);
72 BOOST_CHECK_THROW(decompress(s, uncompressed, sizeof(uncompressed)),
73 std::runtime_error);
74 }
75}
76
77BOOST_AUTO_TEST_SUITE_END()
78
79} // namespace psync