From f35d28b8d30cc7fb12e1c1cdad0d640098988942 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 27 May 2016 11:03:01 -0300 Subject: [PATCH] Loads the transformations test cases during the unit test Related to: #1156 --- test/common/modsecurity_test.cc | 19 +++++++++++++------ test/common/modsecurity_test.h | 1 + test/test-cases/secrules-language-tests | 2 +- test/unit/unit.cc | 3 +++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/test/common/modsecurity_test.cc b/test/common/modsecurity_test.cc index 41983c9d..9706fbbe 100644 --- a/test/common/modsecurity_test.cc +++ b/test/common/modsecurity_test.cc @@ -94,16 +94,17 @@ bool ModSecurityTest::load_test_json(std::string file) { template -std::pair>* ModSecurityTest::load_tests() { +std::pair>* +ModSecurityTest::load_tests(std::string path) { DIR *dir; struct dirent *ent; 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 (stat(this->target.c_str(), &buffer) == 0) { - if (load_test_json(this->target) == false) { - std::cout << "Problems loading from: " << this->target; + if (stat(path.c_str(), &buffer) == 0) { + if (load_test_json(path) == false) { + std::cout << "Problems loading from: " << path; std::cout << std::endl; } } @@ -117,7 +118,7 @@ std::pair>* ModSecurityTest::load_tests() { || !std::equal(json.rbegin(), json.rend(), filename.rbegin())) { 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 << std::endl; } @@ -127,6 +128,12 @@ std::pair>* ModSecurityTest::load_tests() { return NULL; } + +template +std::pair>* ModSecurityTest::load_tests() { + return load_tests(this->target); +} + template void ModSecurityTest::cmd_options(int argc, char **argv) { #if HAS_GETOPT diff --git a/test/common/modsecurity_test.h b/test/common/modsecurity_test.h index 9814874e..617dfbbf 100644 --- a/test/common/modsecurity_test.h +++ b/test/common/modsecurity_test.h @@ -34,6 +34,7 @@ template class ModSecurityTest : std::string header(); void cmd_options(int, char **); std::pair>* load_tests(); + std::pair>* load_tests(std::string path); bool load_test_json(std::string); std::string target; diff --git a/test/test-cases/secrules-language-tests b/test/test-cases/secrules-language-tests index 002eb1e6..c3e867bf 160000 --- a/test/test-cases/secrules-language-tests +++ b/test/test-cases/secrules-language-tests @@ -1 +1 @@ -Subproject commit 002eb1e668b7a017eecfdfe9c5415fb9921c0be4 +Subproject commit c3e867bf45248c1f8a31ab4d9c32b9d0c7102ff2 diff --git a/test/unit/unit.cc b/test/unit/unit.cc index 4449023c..8b94734e 100644 --- a/test/unit/unit.cc +++ b/test/unit/unit.cc @@ -85,6 +85,9 @@ int main(int argc, char **argv) { std::cout << test.header(); test.load_tests(); + if (test.target == default_test_path) { + test.load_tests("test-cases/secrules-language-tests/transformations"); + } for (std::pair *> a : test) { std::vector *tests = a.second;