Debian Codegraph @

tests/language.c

raw
1 /* Copyright (C) 2008 Vincent Penquerc'h.
2 This file is part of the Kate codec library.
3 Written by Vincent Penquerc'h.
4
5 Use, distribution and reproduction of this library is governed
6 by a BSD style source license included with this source in the
7 file 'COPYING'. Please read these terms before distributing. */
8
9
10 #include <stdio.h>
11 #include <string.h>
12 #include "kate/kate.h"
13
14 static const struct {
15 const char * const tag;
16 const char *expected_tag;
17 int expected_return_code;
18 } langs_trunc[]={
19 { "", "", 0 },
20 { "en", "en", 0 },
21 { "_", NULL, KATE_E_INVALID_PARAMETER },
22 { "__", NULL, KATE_E_INVALID_PARAMETER },
23 { "___", NULL, KATE_E_INVALID_PARAMETER },
24 { "_a_", NULL, KATE_E_INVALID_PARAMETER },
25 { "_aa_", NULL, KATE_E_INVALID_PARAMETER },
26 { "_blah", NULL, KATE_E_INVALID_PARAMETER },
27 { "morethan3", NULL, KATE_E_INVALID_PARAMETER },
28 { "en_", NULL, KATE_E_INVALID_PARAMETER },
29 { "en_a", NULL, KATE_E_INVALID_PARAMETER },
30 { "a_", NULL, KATE_E_INVALID_PARAMETER },
31 { "a_EN", "a_EN", 0 },
32 { "en_GB", "en_GB", 0 },
33 { "i-navajo", "i-navajo", 0 },
34 { "a", NULL, KATE_E_INVALID_PARAMETER },
35 { "_en_GB", NULL, KATE_E_INVALID_PARAMETER },
36 { "en_GB_gb_GB-gb-gb-GB", "en_GB_gb_GB-gb", 1 },
37 { "0123456789abcdef", NULL, KATE_E_INVALID_PARAMETER },
38 { "en_some_very_long_string", "en_some_very", 1 },
39 { "en_GB_a_a_foobar", "en_GB", 1},
40 { "a_a-a-a-a-a-a-a-a-a-a-a--a", NULL, KATE_E_INVALID_PARAMETER },
41 { "en_GB ", NULL, KATE_E_INVALID_PARAMETER },
42 { " en_GB", NULL, KATE_E_INVALID_PARAMETER },
43 { " ", NULL, KATE_E_INVALID_PARAMETER },
44 { "en_a12345678_GB", NULL, KATE_E_INVALID_PARAMETER },
45 { "en_GB_GB_GB_RGB", "en_GB_GB_GB_RGB", 0 },
46 };
47
48 static const struct {
49 const char * const tag1;
50 const char * const tag2;
51 int expected_return_code;
52 } langs_cmp[]={
53 { "", "", 2 },
54 { "", "en", 2 },
55 { "en", "", 2 },
56 { "en_GB", "en_US", 2 },
57 { "en", "en_US", 2 },
58 { "en_GB", "en", 2 },
59 { "en", "de", 0 },
60 };
61
62 int main()
63 {
64 size_t i;
65 kate_info ki;
66 int ret;
67
68 ret=kate_info_init(&ki);
69 if (ret<0) {
70 fprintf(stderr,"kate_info_init failed: %d\n",ret);
71 return ret;
72 }
73
74 for (i=0;i<sizeof(langs_trunc)/sizeof(langs_trunc[0]);++i) {
75 /* printf("setting %s\n",langs_trunc[i].tag); */
76 ret=kate_info_set_language(&ki,langs_trunc[i].tag);
77 if (ret!=langs_trunc[i].expected_return_code) {
78 fprintf(stderr,"error: %d different from expected %d\n",ret,langs_trunc[i].expected_return_code);
79 return -1;
80 }
81 else if (ret>=0 && strcasecmp(ki.language,langs_trunc[i].expected_tag)) {
82 fprintf(stderr,"error: %s different from expected %s\n",ki.language,langs_trunc[i].expected_tag);
83 return -1;
84 }
85 }
86
87 for (i=0;i<sizeof(langs_cmp)/sizeof(langs_cmp[0]);++i) {
88 ret=kate_info_set_language(&ki,langs_cmp[i].tag1);
89 if (ret<0) {
90 fprintf(stderr,"error: kate_info_set_language failed: %d\n",ret);
91 return ret;
92 }
93 ret=kate_info_matches_language(&ki,langs_cmp[i].tag2);
94 if (ret!=langs_cmp[i].expected_return_code) {
95 fprintf(stderr,"error: %d different from expected %d\n",ret,langs_cmp[i].expected_return_code);
96 return -1;
97 }
98 }
99
100 ret=kate_info_clear(&ki);
101 if (ret<0) {
102 fprintf(stderr,"kate_info_clear failed: %d\n",ret);
103 return ret;
104 }
105
106 return 0;
107 }
108