]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-utf8.c
pam-module: avoid (null) in debug message
[thirdparty/systemd.git] / src / test / test-utf8.c
CommitLineData
02a36bc9
DR
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Dave Reisner
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
02a36bc9
DR
22#include "utf8.h"
23#include "util.h"
24
7991ac34
DR
25static void test_utf8_is_printable(void) {
26 assert_se(utf8_is_printable("ascii is valid\tunicode", 22));
27 assert_se(utf8_is_printable("\342\204\242", 3));
28 assert_se(!utf8_is_printable("\341\204", 2));
a7176505 29 assert_se(utf8_is_printable("ąę", 4));
7991ac34
DR
30}
31
02a36bc9
DR
32static void test_utf8_is_valid(void) {
33 assert_se(utf8_is_valid("ascii is valid unicode"));
8f6ce71f 34 assert_se(utf8_is_valid("\342\204\242"));
02a36bc9
DR
35 assert_se(!utf8_is_valid("\341\204"));
36}
37
e7363c59
DR
38static void test_ascii_is_valid(void) {
39 assert_se(ascii_is_valid("alsdjf\t\vbarr\nba z"));
40 assert_se(!ascii_is_valid("\342\204\242"));
41 assert_se(!ascii_is_valid("\341\204"));
42}
43
e7363c59
DR
44static void test_utf8_encoded_valid_unichar(void) {
45 assert_se(utf8_encoded_valid_unichar("\342\204\242") == 3);
46 assert_se(utf8_encoded_valid_unichar("\302\256") == 2);
47 assert_se(utf8_encoded_valid_unichar("a") == 1);
48 assert_se(utf8_encoded_valid_unichar("\341\204") < 0);
49 assert_se(utf8_encoded_valid_unichar("\341\204\341\204") < 0);
50
51}
52
02a36bc9
DR
53int main(int argc, char *argv[]) {
54 test_utf8_is_valid();
7991ac34 55 test_utf8_is_printable();
e7363c59 56 test_ascii_is_valid();
e7363c59 57 test_utf8_encoded_valid_unichar();
7991ac34
DR
58
59 return 0;
02a36bc9 60}