aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-07-16 17:19:32 +0200
committerSimon Warta <[email protected]>2015-07-16 19:01:37 +0200
commit2ea885ffe9f44fada457b9cc8e169418c57f1bdb (patch)
tree73897ab4cca1050e9c4bb7f57a3ef3508514c6f6 /src/tests
parentacac09fc411eeb8d52f4565ba50c057298552679 (diff)
Refactor internal/filesystem.h
Closes #198
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/nist_x509.cpp24
-rw-r--r--src/tests/tests.cpp21
2 files changed, 29 insertions, 16 deletions
diff --git a/src/tests/nist_x509.cpp b/src/tests/nist_x509.cpp
index 734f2b355..25578d239 100644
--- a/src/tests/nist_x509.cpp
+++ b/src/tests/nist_x509.cpp
@@ -18,7 +18,7 @@
#if defined(BOTAN_HAS_X509_CERTIFICATES)
#include <botan/x509path.h>
-#include <botan/fs.h>
+#include <botan/internal/filesystem.h>
#include <algorithm>
#include <iostream>
@@ -37,10 +37,14 @@ size_t test_nist_x509()
const std::string root_test_dir = "src/tests/data/nist_x509/";
const size_t total_tests = 76;
- if(list_all_readable_files_in_or_under(root_test_dir).empty())
+ try
{
- std::cout << "No FS access, skipping NIST X.509 validation tests" << std::endl;
- test_report("NIST X.509 path validation", 0, 0);
+ // Do nothing, just test filesystem access
+ get_files_recursive(root_test_dir);
+ }
+ catch(No_Filesystem_Access)
+ {
+ std::cout << "Warning: No filesystem access, skipping NIST X.509 validation tests" << std::endl;
return 0;
}
@@ -57,17 +61,17 @@ size_t test_nist_x509()
for(size_t test_no = 1; test_no <= total_tests; ++test_no)
{
const std::string test_dir = root_test_dir + "/test" + (test_no <= 9 ? "0" : "") + std::to_string(test_no);
- const std::vector<std::string> all_files = list_all_readable_files_in_or_under(test_dir);
+
+ const std::vector<std::string> all_files = get_files_recursive(test_dir);
+ if (all_files.empty())
+ std::cout << "Warning: No test files found in '" << test_dir << "'" << std::endl;
std::vector<std::string> certs, crls;
std::string root_cert, to_verify;
- for(size_t k = 0; k != all_files.size(); k++)
+ for(const auto &current : all_files)
{
- const std::string current = all_files[k];
-
- if(current.find("int") != std::string::npos &&
- current.find(".crt") != std::string::npos)
+ if(current.find("int") != std::string::npos && current.find(".crt") != std::string::npos)
certs.push_back(current);
else if(current.find("root.crt") != std::string::npos)
root_cert = current;
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index de83965f1..a0fd17879 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -8,7 +8,7 @@
#include <iostream>
#include <fstream>
#include <botan/auto_rng.h>
-#include <botan/fs.h>
+#include <botan/internal/filesystem.h>
#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_CONSOLE_WIDTH 60
@@ -19,6 +19,8 @@
#include <botan/system_rng.h>
#endif
+using namespace Botan;
+
Botan::RandomNumberGenerator& test_rng()
{
#if defined(BOTAN_HAS_SYSTEM_RNG)
@@ -33,14 +35,21 @@ size_t run_tests_in_dir(const std::string& dir, std::function<size_t (const std:
{
size_t fails = 0;
- auto files = Botan::list_all_readable_files_in_or_under(dir);
- if (files.empty())
+ try
+ {
+ auto files = get_files_recursive(dir);
+
+ if (files.empty())
+ std::cout << "Warning: No test files found in '" << dir << "'" << std::endl;
+
+ for(const auto file: files)
+ fails += fn(file);
+ }
+ catch(No_Filesystem_Access)
{
- std::cout << "Warning: No test files found in '" << dir << "'" << std::endl;
+ std::cout << "Warning: No filesystem access available to read test files in '" << dir << "'" << std::endl;
}
- for(const auto file: files)
- fails += fn(file);
return fails;
}