]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
unit test for github issue #30
authorMatthew Barr <matthew.barr@intel.com>
Thu, 25 Aug 2016 22:30:12 +0000 (08:30 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 29 Aug 2016 01:30:15 +0000 (11:30 +1000)
unit/hyperscan/stream_op.cpp

index 48cb6b8d28349f01e5a93019ed5ad549194ea23b..339f546329152da4fd653a0698bd2107a339b740 100644 (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;