test_string_utils.c revision 022c6b90bb37851c0e8704c0e5388ebc113c6470
/*
Authors:
Lukas Slebodnik <slebodnikl@redhat.com>
Copyright (C) 2014 Red Hat
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.
This program 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 <http://www.gnu.org/licenses/>.
*/
#include "tests/cmocka/common_mock.h"
void test_replace_whitespaces(void **state)
{
const char *input_str = "Lorem ipsum dolor sit amet";
const char *res;
size_t i;
struct {
const char *input;
const char *output;
const char *replace_string;
} data_set[] = {
{ "", "", "-" },
{ " ", "-", "-" },
{ "\t", "-", "-" },
{ "\n", "-", "-" },
{ " \t\n ", "----", "-" },
{ "abcd", "abcd", "-" },
{ "a b c d", "a-b-c-d", "-" },
{ " a b c d ", "-a-b-c-d-", "-" },
{ " ", "^", "^" },
{ "\t", "^", "^" },
{ "\n", "^", "^" },
{ " \t\n ", "^^^^", "^" },
{ "abcd", "abcd", "^" },
{ "a b c d", "a^b^c^d", "^" },
{ " a b c d ", "^a^b^c^d^", "^" },
{ " ", "^", "^" },
{ "\t", ";-)", ";-)" },
{ "\n", ";-)", ";-)" },
{ " \t\n ", ";-);-);-);-)", ";-)" },
{ "abcd", "abcd", ";-)" },
{ "a b c d", "a;-)b;-)c;-)d", ";-)" },
{ " a b c d ", ";-)a;-)b;-)c;-)d;-)", ";-)" },
{ " ", " ", " " },
{ " ", " ", " " },
{ "abcd", "abcd", " " },
{ "a b c d", "a b c d", " " },
{ " a b c d ", " a b c d ", " " },
{ " ", " \t", " \t" },
{ " ", " \t \t \t \t", " \t" },
{ "abcd", "abcd", " \t" },
{ "a b c d", "a \tb \tc \td", " \t" },
{ " a b c d ", " \ta \tb \tc \td \t", " \t" },
};
data_set[i].replace_string);
}
}
void test_reverse_replace_whitespaces(void **state)
{
char *res;
size_t i;
struct {
const char *input;
const char *output;
const char *replace_string;
} data_set[] = {
{ "", "", "-" },
{ "-", " ", "-" },
{ "----", " ", "-" },
{ "abcd", "abcd", "-" },
{ "a-b-c-d", "a b c d", "-" },
{ "-a-b-c-d-", " a b c d ", "-" },
{ "^", " ", "^" },
{ "^^^^", " ", "^" },
{ "abcd", "abcd", "^" },
{ "a^b^c^d", "a b c d", "^" },
{ "^a^b^c^d^", " a b c d ", "^" },
{ ";-)", " ", ";-)" },
{ ";-);-);-);-)", " ", ";-)" },
{ "abcd", "abcd", ";-)" },
{ "a;-)b;-)c;-)d", "a b c d", ";-)" },
{ ";-)a;-)b;-)c;-)d;-)", " a b c d ", ";-)" },
{ " ", " ", " " },
{ " ", " ", " " },
{ "abcd", "abcd", " " },
{ "a b c d", "a b c d", " " },
{ " a b c d ", " a b c d ", " " },
};
data_set[i].replace_string);
}
}