test-utf8.c revision e7363c59d69b71a4327429719e24cab9020e2796
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering This file is part of systemd.
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering Copyright 2013 Dave Reisner
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering systemd is free software; you can redistribute it and/or modify it
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering under the terms of the GNU Lesser General Public License as published by
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering (at your option) any later version.
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering systemd is distributed in the hope that it will be useful, but
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering Lesser General Public License for more details.
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering You should have received a copy of the GNU Lesser General Public License
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
4aa4d2ae9717d0f8656528a3197bbc0c256380b1Zbigniew Jędrzejewski-Szmekstatic void test_utf8_is_printable(void) {
4aa4d2ae9717d0f8656528a3197bbc0c256380b1Zbigniew Jędrzejewski-Szmek assert_se(utf8_is_printable("ascii is valid\tunicode", 22));
4aa4d2ae9717d0f8656528a3197bbc0c256380b1Zbigniew Jędrzejewski-Szmek assert_se(utf8_is_printable("\342\204\242", 3));
4aa4d2ae9717d0f8656528a3197bbc0c256380b1Zbigniew Jędrzejewski-Szmek assert_se(!utf8_is_printable("\341\204", 2));
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic void test_utf8_is_valid(void) {
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(utf8_is_valid("ascii is valid unicode"));
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(utf8_is_valid("\342\204\242"));
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic void test_ascii_is_valid(void) {
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(ascii_is_valid("alsdjf\t\vbarr\nba z"));
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(!ascii_is_valid("\342\204\242"));
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic void test_ascii_filter(void) {
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering f = ascii_filter("alsdjf\t\vbarr\nba z");
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(streq(f, "alsdjf\t\vbarr\nba z"));
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic void test_utf8_encoded_valid_unichar(void) {
7dbb1d08f66cd44b1296be3ee8e3629b989e19a8Zbigniew Jędrzejewski-Szmek assert_se(utf8_encoded_valid_unichar("\342\204\242") == 3);
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(utf8_encoded_valid_unichar("\302\256") == 2);
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(utf8_encoded_valid_unichar("a") == 1);
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering assert_se(utf8_encoded_valid_unichar("\341\204") < 0);
cc56fafeebf814ef035e549115cf1850e6473fa5WaLyong Cho assert_se(utf8_encoded_valid_unichar("\341\204\341\204") < 0);
7dbb1d08f66cd44b1296be3ee8e3629b989e19a8Zbigniew Jędrzejewski-Szmekint main(int argc, char *argv[]) {