1 |
/* |
2 |
encodings.c - test handling different character encodings |
3 |
Copyright (C) 2008 siliconforks.com |
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, |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
GNU General Public License for more details. |
14 |
|
15 |
You should have received a copy of the GNU General Public License along |
16 |
with this program; if not, write to the Free Software Foundation, Inc., |
17 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
*/ |
19 |
|
20 |
#include <assert.h> |
21 |
#include <string.h> |
22 |
|
23 |
#include "encoding.h" |
24 |
#include "stream.h" |
25 |
|
26 |
int main(void) { |
27 |
jschar * characters; |
28 |
size_t num_characters; |
29 |
int result; |
30 |
|
31 |
/* e, e grave, e acute, e circumflex */ |
32 |
uint8_t utf8[] = { |
33 |
'e', |
34 |
0xc3, |
35 |
0xa8, |
36 |
0xc3, |
37 |
0xa9, |
38 |
0xc3, |
39 |
0xaa, |
40 |
}; |
41 |
|
42 |
result = jscoverage_bytes_to_characters("UTF-8", utf8, 7, &characters, &num_characters); |
43 |
|
44 |
assert(result == 0); |
45 |
assert(num_characters == 4); |
46 |
assert(characters[0] == 'e'); |
47 |
assert(characters[1] == 0xe8); |
48 |
assert(characters[2] == 0xe9); |
49 |
assert(characters[3] == 0xea); |
50 |
|
51 |
free(characters); |
52 |
|
53 |
/* |
54 |
BOM is 0xfeff |
55 |
= 1111 1110 1111 1111 |
56 |
UTF: 1110xxxx 10xxxxxx 10xxxxxx |
57 |
= 11101111 10111011 10111111 |
58 |
= EF BB BF |
59 |
*/ |
60 |
uint8_t utf8_with_bom[] = { |
61 |
0xef, |
62 |
0xbb, |
63 |
0xbf, |
64 |
'e', |
65 |
0xc3, |
66 |
0xa8, |
67 |
0xc3, |
68 |
0xa9, |
69 |
0xc3, |
70 |
0xaa, |
71 |
}; |
72 |
|
73 |
result = jscoverage_bytes_to_characters("UTF-8", utf8_with_bom, 10, &characters, &num_characters); |
74 |
|
75 |
assert(result == 0); |
76 |
assert(num_characters == 4); |
77 |
assert(characters[0] == 'e'); |
78 |
assert(characters[1] == 0xe8); |
79 |
assert(characters[2] == 0xe9); |
80 |
assert(characters[3] == 0xea); |
81 |
|
82 |
free(characters); |
83 |
|
84 |
return 0; |
85 |
} |