From c1bc6acdeae343bf556fd59c3cb44c159addc7a5 Mon Sep 17 00:00:00 2001 From: Matthew Barr Date: Fri, 26 Aug 2016 08:30:12 +1000 Subject: [PATCH] unit test for github issue #30 --- unit/hyperscan/stream_op.cpp | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/unit/hyperscan/stream_op.cpp b/unit/hyperscan/stream_op.cpp index 48cb6b8d..339f5463 100644 --- a/unit/hyperscan/stream_op.cpp +++ b/unit/hyperscan/stream_op.cpp @@ -157,6 +157,45 @@ TEST(StreamUtil, reset_matches) { hs_free_database(db); } +TEST(StreamUtil, reset_close) { + hs_error_t err; + hs_scratch_t *scratch = nullptr; + hs_database_t *db = buildDBAndScratch("foo", 0, 0, HS_MODE_STREAM, + &scratch); + + hs_stream_t *stream = nullptr; + CallBackContext c; + + err = hs_open_stream(db, 0, &stream); + ASSERT_EQ(HS_SUCCESS, err); + ASSERT_TRUE(stream != nullptr); + + // break matching string over two stream writes + const char part1[] = "---f"; + err = hs_scan_stream(stream, part1, strlen(part1), 0, scratch, record_cb, + (void *)&c); + ASSERT_EQ(HS_SUCCESS, err); + ASSERT_EQ(0U, c.matches.size()); + + const char part2[] = "oo--"; + err = hs_scan_stream(stream, part2, strlen(part2), 0, scratch, record_cb, + (void *)&c); + ASSERT_EQ(HS_SUCCESS, err); + ASSERT_EQ(1U, c.matches.size()); + ASSERT_EQ(MatchRecord(6, 0), c.matches[0]); + + err = hs_reset_stream(stream, 0, scratch, record_cb, (void *)&c); + ASSERT_EQ(HS_SUCCESS, err); + // still only one match + ASSERT_EQ(1U, c.matches.size()); + + err = hs_close_stream(stream, scratch, record_cb, (void *)&c); + ASSERT_EQ(HS_SUCCESS, err); + err = hs_free_scratch(scratch); + ASSERT_EQ(HS_SUCCESS, err); + hs_free_database(db); +} + TEST(StreamUtil, copy1) { hs_error_t err; hs_scratch_t *scratch = nullptr;