unit test for github issue #30

This commit is contained in:
Matthew Barr 2016-08-26 08:30:12 +10:00
parent 8cf0c41552
commit c1bc6acdea

View File

@ -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;