From d82f49f1cbe1847f502ecf3e9defc99f389e26b5 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 16 Nov 2012 13:04:37 +0300 Subject: [PATCH] Added tests for regex search Signed-off-by: Slava Zanko --- tests/lib/search/Makefile.am | 6 +- tests/lib/search/regex_search.c | 142 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 tests/lib/search/regex_search.c diff --git a/tests/lib/search/Makefile.am b/tests/lib/search/Makefile.am index db8931713..81e95f735 100644 --- a/tests/lib/search/Makefile.am +++ b/tests/lib/search/Makefile.am @@ -2,6 +2,7 @@ AM_CFLAGS = -I$(top_srcdir)/lib/search $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFL LIBS=@CHECK_LIBS@ $(top_builddir)/lib/libmc.la TESTS = \ + regex_search \ regex_replace_esc_seq \ regex_process_escape_sequence @@ -11,4 +12,7 @@ regex_replace_esc_seq_SOURCES = \ regex_replace_esc_seq.c regex_process_escape_sequence_SOURCES = \ - regex_process_escape_sequence.c \ No newline at end of file + regex_process_escape_sequence.c + +regex_search_SOURCES = \ + regex_search.c diff --git a/tests/lib/search/regex_search.c b/tests/lib/search/regex_search.c new file mode 100644 index 000000000..fa315317c --- /dev/null +++ b/tests/lib/search/regex_search.c @@ -0,0 +1,142 @@ +/* + libmc - checks for processing esc sequences in replace string + + Copyright (C) 2011 + The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011 + + This file is part of the Midnight Commander. + + The Midnight Commander is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#define TEST_SUITE_NAME "lib/search/regex" + +#include + +#include + +#include "lib/global.h" +#include "lib/strutil.h" +#include "lib/search.h" + + +static mc_search_t *search; + +static void +setup (void) +{ + str_init_strings (NULL); + search = mc_search_new ("search_type = MC_SEARCH_T_REGEX; +} + +static void +teardown (void) +{ + mc_search_free (search); + str_uninit_strings (); +} + + +/* --------------------------------------------------------------------------------------------- */ +START_TEST (regex_search_test) +{ + // given + gsize actual_found_len; + gboolean actual_result; + + + // when + actual_result = mc_search_run ( + search, + "some string with normal_offset, 17); +} +END_TEST + +/* --------------------------------------------------------------------------------------------- */ + +static mc_search_cbret_t +regex_search_callback (const void *user_data, gsize char_offset, int *current_char) { + static const char *data = "some string with search_fn = regex_search_callback; + + // when + actual_result = mc_search_run ( + search, + NULL, + 0, + -1, + &actual_found_len + ); + // then + ck_assert_int_eq (actual_result, TRUE); + ck_assert_int_eq (actual_found_len, 2); + ck_assert_int_eq (search->normal_offset, 17); + +} +END_TEST + +/* --------------------------------------------------------------------------------------------- */ + + +int +main (void) +{ + int number_failed; + + Suite *s = suite_create (TEST_SUITE_NAME); + TCase *tc_core = tcase_create ("Core"); + SRunner *sr; + + tcase_add_checked_fixture (tc_core, setup, teardown); + + /* Add new tests here: *************** */ + tcase_add_test (tc_core, regex_search_test); + tcase_add_test (tc_core, regex_search_callback_test); + /* *********************************** */ + + suite_add_tcase (s, tc_core); + sr = srunner_create (s); + srunner_run_all (sr, CK_NORMAL); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + return (number_failed == 0) ? 0 : 1; +} + +/* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT