3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Util/UTF8.hpp"
24 #include "Util/Macros.hpp"
25 #include "TestUtil.hpp"
29 static const char *const valid
[] = {
40 static const char *const invalid
[] = {
58 { "\xe7\x9b\xae", 1 },
67 { '\xfc', "\xc3\xbc", },
71 const char *input
, *output
;
75 { "foo\xc3\xbc", "foo\xc3\xbc", },
76 { "foo\xc3", "foo", },
77 { "foo\xe7\x9b\xae", "foo\xe7\x9b\xae", },
78 { "foo\xe7\x9b", "foo", },
79 { "foo\xe7", "foo", },
83 int main(int argc
, char **argv
)
85 plan_tests(ARRAY_SIZE(valid
) + ARRAY_SIZE(invalid
) +
88 ARRAY_SIZE(latin1_chars
));
93 for (auto i
: invalid
)
94 ok1(!ValidateUTF8(i
));
96 for (auto &l
: length
)
97 ok1(l
.length
== LengthUTF8(l
.value
));
101 for (auto &l
: latin1_chars
) {
102 *Latin1ToUTF8(l
.ch
, buffer
) = 0;
103 ok1(strcmp(l
.utf8
, buffer
) == 0);
106 for (auto &c
: crop
) {
107 strcpy(buffer
, c
.input
);
108 CropIncompleteUTF8(buffer
);
109 ok1(strcmp(c
.output
, buffer
) == 0);
112 return exit_status();