Loads the transformations test cases during the unit test

Related to: #1156
This commit is contained in:
Felipe Zimmerle 2016-05-27 11:03:01 -03:00
parent 8d49903279
commit f35d28b8d3
4 changed files with 18 additions and 7 deletions

View File

@ -94,16 +94,17 @@ bool ModSecurityTest<T>::load_test_json(std::string file) {
template <class T> template <class T>
std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() { std::pair<std::string, std::vector<T *>>*
ModSecurityTest<T>::load_tests(std::string path) {
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
struct stat buffer; struct stat buffer;
if ((dir = opendir(this->target.c_str())) == NULL) { if ((dir = opendir(path.c_str())) == NULL) {
/* if target is a file, use it as a single test. */ /* if target is a file, use it as a single test. */
if (stat(this->target.c_str(), &buffer) == 0) { if (stat(path.c_str(), &buffer) == 0) {
if (load_test_json(this->target) == false) { if (load_test_json(path) == false) {
std::cout << "Problems loading from: " << this->target; std::cout << "Problems loading from: " << path;
std::cout << std::endl; std::cout << std::endl;
} }
} }
@ -117,7 +118,7 @@ std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
|| !std::equal(json.rbegin(), json.rend(), filename.rbegin())) { || !std::equal(json.rbegin(), json.rend(), filename.rbegin())) {
continue; continue;
} }
if (load_test_json(this->target + "/" + filename) == false) { if (load_test_json(path + "/" + filename) == false) {
std::cout << "Problems loading tests from: " << filename; std::cout << "Problems loading tests from: " << filename;
std::cout << std::endl; std::cout << std::endl;
} }
@ -127,6 +128,12 @@ std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
return NULL; return NULL;
} }
template <class T>
std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
return load_tests(this->target);
}
template <class T> template <class T>
void ModSecurityTest<T>::cmd_options(int argc, char **argv) { void ModSecurityTest<T>::cmd_options(int argc, char **argv) {
#if HAS_GETOPT #if HAS_GETOPT

View File

@ -34,6 +34,7 @@ template <class T> class ModSecurityTest :
std::string header(); std::string header();
void cmd_options(int, char **); void cmd_options(int, char **);
std::pair<std::string, std::vector<T *>>* load_tests(); std::pair<std::string, std::vector<T *>>* load_tests();
std::pair<std::string, std::vector<T *>>* load_tests(std::string path);
bool load_test_json(std::string); bool load_test_json(std::string);
std::string target; std::string target;

@ -1 +1 @@
Subproject commit 002eb1e668b7a017eecfdfe9c5415fb9921c0be4 Subproject commit c3e867bf45248c1f8a31ab4d9c32b9d0c7102ff2

View File

@ -85,6 +85,9 @@ int main(int argc, char **argv) {
std::cout << test.header(); std::cout << test.header();
test.load_tests(); test.load_tests();
if (test.target == default_test_path) {
test.load_tests("test-cases/secrules-language-tests/transformations");
}
for (std::pair<std::string, std::vector<UnitTest *> *> a : test) { for (std::pair<std::string, std::vector<UnitTest *> *> a : test) {
std::vector<UnitTest *> *tests = a.second; std::vector<UnitTest *> *tests = a.second;