/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Fluent Bit * ========== * Copyright (C) 2019-2022 The Fluent Bit Authors * Copyright (C) 2015-2018 Treasure Data Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include "flb_tests_internal.h" struct kv_list { int index; size_t size; char **lists; }; static void cb_kv(const char *name, const char *value, size_t vlen, void *data) { size_t len; struct kv_list *l = (struct kv_list*)data; if (!TEST_CHECK(name != NULL && value != NULL && data != NULL)) { TEST_MSG("input is NULL"); return; } len = strlen(name); if (!TEST_CHECK(len == strlen(l->lists[l->index * 2]))) { TEST_MSG("name: lenght error. got:%zu expect:%zu", len, strlen(l->lists[l->index * 2])); TEST_MSG("name: got:%s expect:%s", name, l->lists[l->index * 2]); goto cb_kv_end; } if (!TEST_CHECK(strncmp(name, l->lists[l->index * 2], len) == 0)) { TEST_MSG("name: mismatch. got:%s expect:%s", name, l->lists[l->index * 2]); goto cb_kv_end; } if (!TEST_CHECK(vlen == strlen(l->lists[l->index * 2+1]))) { TEST_MSG("value: lenght error. got:%zu expect:%zu", vlen, strlen(l->lists[l->index * 2+1])); TEST_MSG("value: got:%s expect:%s", value, l->lists[l->index * 2+1]); goto cb_kv_end; } if (!TEST_CHECK(strncmp(value, l->lists[l->index * 2+1], vlen) == 0)) { TEST_MSG("value: mismatch. got:%s expect:%s", value, l->lists[l->index * 2+1]); goto cb_kv_end; } cb_kv_end: l->index++; } static void test_basic() { struct flb_regex *regex = NULL; struct flb_regex_search result; int ret; ssize_t size; const char *input = "string 1234 2022/10/24"; char *expected_strs[] = {"str","string", "num","1234", "time","2022/10/24"}; struct kv_list expected = { .index = 0, .size = sizeof(expected_strs)/sizeof(char *), .lists = &expected_strs[0], }; regex = flb_regex_create("/(?[a-z]+) (?\\d+) (?