chiark / gitweb /
b5a833e9e431f1775ccf37512f5415a70138cdb2
[elogind.git] / src / test / test-utf8.c
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
22 #include "utf8.h"
23 #include "util.h"
24
25 static 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));
29 }
30
31 static void test_utf8_is_valid(void) {
32         assert_se(utf8_is_valid("ascii is valid unicode"));
33         assert_se(utf8_is_valid("\342\204\242"));
34         assert_se(!utf8_is_valid("\341\204"));
35 }
36
37 int main(int argc, char *argv[]) {
38         test_utf8_is_valid();
39         test_utf8_is_printable();
40
41         return 0;
42 }