*/
#include "config.h"
-#include <cstring>
-#include <string>
-#include <vector>
-
#include "gtest/gtest.h"
#include "hs.h"
#include "hs_internal.h"
#include "test_util.h"
+#include <cstring>
+#include <string>
+#include <vector>
+
namespace {
using namespace std;
plat.cpu_features = 0;
plat.tune = HS_TUNE_FAMILY_GENERIC;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
const unsigned mode = HS_MODE_STREAM
| HS_MODE_SOM_HORIZON_LARGE;
- hs_database_t *db = buildDB(pattern, HS_FLAG_SOM_LEFTMOST, 1000, mode,
- &plat);
+ hs_database_t *db = buildDB(pat, HS_FLAG_SOM_LEFTMOST, 1000, mode, &plat);
ASSERT_TRUE(db != nullptr) << "database build failed.";
size_t db_len;
free(c - 1);
}
-// make sure that serializing/deserializing to null or an unaligned address fails
+// make sure that serializing/deserializing to null or an unaligned address
+// fails
TEST(Serialize, CompileNullMalloc) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
// mallocing null should fail compile
hs_set_allocator(null_malloc, nullptr);
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_NE(HS_SUCCESS, err);
ASSERT_TRUE(db == nullptr);
ASSERT_TRUE(c_err != nullptr);
TEST(Serialize, CompileErrorAllocator) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatsta^nd.*(badgerbrush|teakettle)";
+ static const char *pat = "hatsta^nd.*(badgerbrush|teakettle)";
// failing to compile should use the misc allocator
allocated_count = 0;
allocated_count_b = 0;
hs_set_allocator(count_malloc_b, count_free_b);
hs_set_misc_allocator(count_malloc, count_free);
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_NE(HS_SUCCESS, err);
ASSERT_TRUE(db == nullptr);
ASSERT_TRUE(c_err != nullptr);
TEST(Serialize, AllocatorsUsed) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
allocated_count = 0;
allocated_count_b = 0;
hs_set_allocator(count_malloc_b, count_free_b);
hs_set_database_allocator(count_malloc, count_free);
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_EQ(HS_SUCCESS, err);
ASSERT_TRUE(db != nullptr);
ASSERT_TRUE(c_err == nullptr);
ASSERT_EQ(0, allocated_count_b);
}
-
TEST(Serialize, CompileUnalignedMalloc) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
// unaligned malloc should fail compile
hs_set_allocator(misaligned_malloc, misaligned_free);
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_NE(HS_SUCCESS, err);
ASSERT_TRUE(db == nullptr);
ASSERT_TRUE(c_err != nullptr);
TEST(Serialize, SerializeNullMalloc) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_EQ(HS_SUCCESS, err);
ASSERT_TRUE(db != nullptr);
hs_free_database(db);
}
-// make sure that serializing/deserializing to null or an unaligned address fails
+// make sure that serializing/deserializing to null or an unaligned address
+// fails
TEST(Serialize, SerializeUnalignedMalloc) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat= "hatstand.*(badgerbrush|teakettle)";
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_EQ(HS_SUCCESS, err);
ASSERT_TRUE(db != nullptr);
TEST(Serialize, DeserializeNullMalloc) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_EQ(HS_SUCCESS, err);
ASSERT_TRUE(db != nullptr);
TEST(Serialize, DeserializeUnalignedMalloc) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_EQ(HS_SUCCESS, err);
ASSERT_TRUE(db != nullptr);
TEST(Serialize, DeserializeGarbage) {
hs_database_t *db;
hs_compile_error_t *c_err;
- static const char *pattern = "hatstand.*(badgerbrush|teakettle)";
+ static const char *pat = "hatstand.*(badgerbrush|teakettle)";
- hs_error_t err = hs_compile(pattern, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
+ hs_error_t err = hs_compile(pat, 0, HS_MODE_BLOCK, nullptr, &db, &c_err);
ASSERT_EQ(HS_SUCCESS, err);
ASSERT_TRUE(db != nullptr);