Add a test program for charset.c.
[disorder] / lib / t-charset.c
1 /*
2 * This file is part of DisOrder.
3 * Copyright (C) 2008 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20 #include "test.h"
21 #include "charset.h"
22
23 static void test_charset(void) {
24 check_string(any2any("UTF-8", "ISO-8859-1", "\xC2\xA3"),
25 "\xA3");
26 check_string(any2any("ISO-8859-1", "UTF-8", "\xA3"),
27 "\xC2\xA3");
28 fprintf(stderr, "Expect a conversion error:\n");
29 insist(any2any("UTF-8", "ISO-8859-1", "\xC2""a") == 0);
30
31 #define EL "\xE2\x80\xA6" /* 2026 HORIZONTAL ELLIPSIS */
32 check_string(truncate_for_display("", 0), "");
33 check_string(truncate_for_display("", 1), "");
34 check_string(truncate_for_display("x", 1), "x");
35 check_string(truncate_for_display("xx", 1), EL);
36 check_string(truncate_for_display("xx", 2), "xx");
37 check_string(truncate_for_display("xxx", 2), "x"EL);
38 check_string(truncate_for_display("wibble", 6), "wibble");
39 check_string(truncate_for_display("wibble", 5), "wibb"EL);
40 }
41
42 TEST(charset);
43
44 /*
45 Local Variables:
46 c-basic-offset:2
47 comment-column:40
48 fill-column:79
49 indent-tabs-mode:nil
50 End:
51 */