diff options
author | Marcus Brinkmann <[email protected]> | 2017-11-25 20:22:57 +0100 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2017-11-25 20:22:57 +0100 |
commit | 34aa73d0f9c3bf817a0a46889206003f0becd3f1 (patch) | |
tree | 18b9858383756fb12727d7cbed61d6b9ace0fd39 /src/tests | |
parent | c23eb5eb3463459654e0f6601a3b2304eb2076ee (diff) |
Add create and create_or_throw factories for Compression_Algorithm and Decompression_Algorithm.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_compression.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/tests/test_compression.cpp b/src/tests/test_compression.cpp index 04eb26200..d9045b23e 100644 --- a/src/tests/test_compression.cpp +++ b/src/tests/test_compression.cpp @@ -154,6 +154,64 @@ class Compression_Tests final : public Test BOTAN_REGISTER_TEST("compression", Compression_Tests); +class CompressionCreate_Tests final : public Test + { + public: + std::vector<Test::Result> run() override + { + std::vector<Test::Result> results; + + for(std::string algo : { "zlib", "deflate", "gzip", "bz2", "lzma" }) + { + try + { + Test::Result result(algo + " create compression"); + + std::unique_ptr<Botan::Compression_Algorithm> c1(Botan::Compression_Algorithm::create(algo)); + std::unique_ptr<Botan::Decompression_Algorithm> d1(Botan::Decompression_Algorithm::create(algo)); + + if(!c1 || !d1) + { + result.note_missing(algo); + continue; + } + result.test_ne("Not the same name after create", c1->name(), d1->name()); + + std::unique_ptr<Botan::Compression_Algorithm> c2(Botan::Compression_Algorithm::create_or_throw(algo)); + std::unique_ptr<Botan::Decompression_Algorithm> d2(Botan::Decompression_Algorithm::create_or_throw(algo)); + + if(!c2 || !d2) + { + result.note_missing(algo); + continue; + } + result.test_ne("Not the same name after create_or_throw", c2->name(), d2->name()); + + results.push_back(result); + } + catch(std::exception& e) + { + results.push_back(Test::Result::Failure("testing " + algo, e.what())); + } + } + + { + Test::Result result("create invalid compression"); + result.test_throws("lookup error", + "Unavailable Compression bogocompress", + [&]() { Botan::Compression_Algorithm::create_or_throw("bogocompress"); }); + result.test_throws("lookup error", + "Unavailable Decompression bogocompress", + [&]() { Botan::Decompression_Algorithm::create_or_throw("bogocompress"); }); + results.push_back(result); + } + + return results; + } + }; + +BOTAN_REGISTER_TEST("create_compression", CompressionCreate_Tests); + } #endif |