diff options
author | Jack Lloyd <[email protected]> | 2018-01-01 11:16:01 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-01-01 11:20:09 -0500 |
commit | 8591e6de8c7bea614d4ed33037d48cff3a281afa (patch) | |
tree | 1b0695f2ecf38257d295536a82686ff7ce2cec91 /src | |
parent | 903d8042a987f3d56cb121498d183e7433f69b34 (diff) |
Add some basic tests of Data_Store class
It's deprecated, but still exposed API and still used internally.
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_datastore.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/tests/test_datastore.cpp b/src/tests/test_datastore.cpp new file mode 100644 index 000000000..ef1f55cd8 --- /dev/null +++ b/src/tests/test_datastore.cpp @@ -0,0 +1,71 @@ +/* +* (C) 2018 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include "tests.h" + +#if defined(BOTAN_HAS_X509_CERTIFICATES) + +#include <botan/datastor.h> + +namespace Botan_Tests { + +class Datastore_Tests : public Test + { + public: + std::vector<Test::Result> run() override + { + Test::Result result("Data_Store"); + + Botan::Data_Store ds1; + Botan::Data_Store ds2; + + result.confirm("equality", ds1 == ds2); + + result.test_eq("has_value", ds1.has_value("key"), false); + result.test_eq("get1 with default", ds1.get1("key", "default"), "default"); + + result.test_throws("get1", "Data_Store::get1: No values set for missing_key", + [&ds1]() { ds1.get1("missing_key"); }); + + result.test_eq("search_for", ds1.search_for([](std::string, std::string) { return true; }).size(), 0); + + ds1.add("key", "value"); + + result.test_eq("search_for", ds1.search_for([](std::string, std::string) { return true; }).size(), 1); + + result.test_eq("equality", ds1 == ds2, false); + + result.test_eq("has_value", ds1.has_value("key"), true); + result.test_eq("get1 with default", ds1.get1("key", "default"), "value"); + result.test_eq("get1", ds1.get1("key"), "value"); + + result.test_eq("get1_memvec", ds1.get1_memvec("memvec").size(), 0); + + const std::vector<uint8_t> memvec = { 9, 1, 1, 4 }; + ds1.add("memvec", memvec); + + result.test_eq("get1_memvec", ds1.get1_memvec("memvec"), memvec); + + result.test_eq("get1_uint32", ds1.get1_uint32("memvec"), size_t(9010104)); + + result.test_eq("get1_uint32", ds1.get1_uint32("missing", 999), size_t(999)); + + ds1.add("key", "value2"); + + result.test_throws("get1", "Data_Store::get1: More than one value for key", + [&ds1]() { ds1.get1("key"); }); + + result.test_eq("get multiple", ds1.get("key").size(), 2); + + return {result}; + } + }; + +BOTAN_REGISTER_TEST("x509_datastore", Datastore_Tests); + +} + +#endif |