test-str-find.c revision 48acc31adebfdd4e4945ee76e1f5259e4b1b6fff
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainenstatic bool test_str_find_substring(const char *key, int expected_pos)
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen const unsigned char *text = (const unsigned char *)str_find_text;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen const unsigned int text_len = strlen(str_find_text);
7ef3553585e556f35d5919589cfdc1de3329e4bbTimo Sirainen ctx = str_find_init(pool_datastack_create(), key);
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen /* divide text into every possible block combination and test that
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen it matches */
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen for (i = 0; i < max; i++) {
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen for (j = 0; j < text_len; j++) {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen if ((i & (1 << j)) != 0) {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen const char *str;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen static const char *fail_input[] = {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen const char *key, *p;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen unsigned int i;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen for (idx = 0; idx < strlen(str_find_text); idx++) {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen for (len = strlen(str_find_text)-idx; len > 0; len--) {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen /* we'll get a search key for all substrings of text */
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen success = test_str_find_substring(key, p - str_find_text);
eac60b7aef3924a611656b184412be1e80b2ed5bTimo Sirainen for (i = 0; i < N_ELEMENTS(fail_input) && success; i++)