#include "sfrim.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
-#include "utils/util.h"
+#ifdef UNIT_TEST
+#include "test/catch.hpp"
+#endif
struct rule_number_t
{
return false;
}
+//--------------------------------------------------------------------------
+// unit tests
+//--------------------------------------------------------------------------
+
+#ifdef UNIT_TEST
+
+TEST_CASE("basic", "[RuleIndexMap]")
+{
+ rule_index_map_t* rim = RuleIndexMapCreate();
+ unsigned gid, sid;
+
+ CHECK(RuleIndexMapAdd(rim, 1, 2) == 0);
+ CHECK(RuleIndexMapAdd(rim, 2, 4) == 1);
+ CHECK(RuleIndexMapAdd(rim, 4, 8) == 2);
+
+ SECTION("valid")
+ {
+ CHECK(RuleIndexMapGet(rim, 1, gid, sid));
+
+ CHECK(gid == 2);
+ CHECK(sid == 4);
+ }
+ SECTION("invalid")
+ {
+ CHECK(!RuleIndexMapGet(rim, 3, gid, sid));
+
+ CHECK(gid == 0);
+ CHECK(sid == 0);
+ }
+ RuleIndexMapFree(rim);
+}
+
+#endif
+
static bool set_mode()
{
#ifdef PIGLET
-#ifdef UNIT_TEST
- if ( unit_test_enabled() )
- {
- if ( Piglet::piglet_mode() )
- exit(unit_test() || Piglet::main());
- else
- exit(unit_test());
- }
- else
-#endif // UNIT_TEST
if ( Piglet::piglet_mode() )
exit(Piglet::main());
-#else
+#endif
#ifdef UNIT_TEST
- if ( unit_test_enabled() )
- exit(unit_test());
-#endif // UNIT_TEST
-#endif // PIGLET
+ if ( check_enabled() )
+ exit(check_test());
+
+ if ( catch_enabled() )
+ exit(catch_test());
+#endif
if ( int k = get_parse_errors() )
{
"use drop, sdrop, and reject rules to ignore session traffic when not inline" },
#ifdef UNIT_TEST
- { "--unit-test", Parameter::PT_SELECT,
+ { "--check-test", Parameter::PT_SELECT,
"silent | minimal | normal | verbose | env (export CK_VERBOSITY)", nullptr,
"<verbosity> run unit tests with given libcheck output mode" },
- { "--catch-tags", Parameter::PT_STRING, nullptr, nullptr,
- "comma separated list of cat unit test tags" },
+
+ { "--catch-test", Parameter::PT_STRING, nullptr, nullptr,
+ "comma separated list of cat unit test tags or 'all'" },
#endif
{ "--version", Parameter::PT_IMPLIED, nullptr, nullptr,
"show version number (same as -V)" },
ConfigTreatDropAsIgnore(sc, v.get_string());
#ifdef UNIT_TEST
- else if ( v.is("--unit-test") )
+ else if ( v.is("--check-test") )
unit_test_mode(v.get_string());
- else if ( v.is("--catch-tags") )
+
+ else if ( v.is("--catch-test") )
unit_test_catch_test_filter(v.get_string());
#endif
else if ( v.is("--version") )
#include "suite_decl.h"
static print_output s_mode = CK_LAST;
+static bool s_catch = false;
static std::vector<std::string> test_tags;
typedef Suite* (* SuiteCtor_f)();
void unit_test_catch_test_filter(const char* s)
{
- test_tags.push_back( s );
+ if ( s && strcmp(s, "all") )
+ test_tags.push_back( s );
+
+ s_catch = true;
}
-bool unit_test_enabled()
+bool check_enabled()
{
return s_mode != CK_LAST;
}
+bool catch_enabled()
+{
+ return s_catch;
+}
+
static bool run_check()
{
int nErr;
static bool run_catch()
{
Catch::Session session;
+
// write to session.configData() or session.Config() to customize
if( s_mode == CK_VERBOSE )
session.configData().showSuccessfulTests = true;
+
if( test_tags.size() > 0 )
session.configData().testsOrTags = test_tags;
return session.run() == 0;
}
-int unit_test()
+int check_test()
{
- int ok = 0;
-
if ( !run_check() )
- ok = -1;
+ return -1;
+ return 0;
+}
+
+int catch_test()
+{
if ( !run_catch() )
- ok = -1;
+ return -1;
- return ok;
+ return 0;
}
#define UNIT_TEST_MODE_ENVVAR "CK_VERBOSITY"
void unit_test_mode(const char* = nullptr);
-bool unit_test_enabled();
-int unit_test();
void unit_test_catch_test_filter(const char* s);
+bool check_enabled();
+bool catch_enabled();
+
+int check_test();
+int catch_test();
#endif