/[jscoverage]/trunk/tests/encodings.c
ViewVC logotype

Diff of /trunk/tests/encodings.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 205 by siliconforks, Fri Oct 3 02:22:22 2008 UTC revision 427 by siliconforks, Wed Feb 18 16:08:33 2009 UTC
# Line 1  Line 1 
1  /*  /*
2      encodings.c - test handling different character encodings      encodings.c - test handling different character encodings
3      Copyright (C) 2008 siliconforks.com      Copyright (C) 2008, 2009 siliconforks.com
4    
5      This program is free software; you can redistribute it and/or modify      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      it under the terms of the GNU General Public License as published by
# Line 17  Line 17 
17      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */  */
19    
20    #include <config.h>
21    
22  #include <assert.h>  #include <assert.h>
23  #include <string.h>  #include <string.h>
24    
# Line 41  Line 43 
43    
44    result = jscoverage_bytes_to_characters("UTF-8", utf8, 7, &characters, &num_characters);    result = jscoverage_bytes_to_characters("UTF-8", utf8, 7, &characters, &num_characters);
45    
46    #if HAVE_ICONV || HAVE_MULTIBYTETOWIDECHAR
47    assert(result == 0);    assert(result == 0);
48    assert(num_characters == 4);    assert(num_characters == 4);
49    assert(characters[0] == 'e');    assert(characters[0] == 'e');
# Line 49  Line 52 
52    assert(characters[3] == 0xea);    assert(characters[3] == 0xea);
53    
54    free(characters);    free(characters);
55    #else
56      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
57    #endif
58    
59    /*    /*
60    BOM is 0xfeff    BOM is 0xfeff
# Line 72  Line 78 
78    
79    result = jscoverage_bytes_to_characters("UTF-8", utf8_with_bom, 10, &characters, &num_characters);    result = jscoverage_bytes_to_characters("UTF-8", utf8_with_bom, 10, &characters, &num_characters);
80    
81    #if HAVE_ICONV || HAVE_MULTIBYTETOWIDECHAR
82      assert(result == 0);
83      assert(num_characters == 4);
84      assert(characters[0] == 'e');
85      assert(characters[1] == 0xe8);
86      assert(characters[2] == 0xe9);
87      assert(characters[3] == 0xea);
88    
89      free(characters);
90    #else
91      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
92    #endif
93    
94      uint8_t utf16be[] = {
95        0, 'e',
96        0, 0xe8,
97        0, 0xe9,
98        0, 0xea,
99      };
100    
101      result = jscoverage_bytes_to_characters("UTF-16BE", utf16be, 8, &characters, &num_characters);
102    
103    #ifdef HAVE_ICONV
104      assert(result == 0);
105      assert(num_characters == 4);
106      assert(characters[0] == 'e');
107      assert(characters[1] == 0xe8);
108      assert(characters[2] == 0xe9);
109      assert(characters[3] == 0xea);
110    
111      free(characters);
112    #else
113      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
114    #endif
115    
116      uint8_t utf16be_with_bom[] = {
117        0xfe, 0xff,
118        0, 'e',
119        0, 0xe8,
120        0, 0xe9,
121        0, 0xea,
122      };
123    
124      result = jscoverage_bytes_to_characters("UTF-16BE", utf16be_with_bom, 10, &characters, &num_characters);
125    
126    #ifdef HAVE_ICONV
127      assert(result == 0);
128      assert(num_characters == 4);
129      assert(characters[0] == 'e');
130      assert(characters[1] == 0xe8);
131      assert(characters[2] == 0xe9);
132      assert(characters[3] == 0xea);
133    
134      free(characters);
135    #else
136      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
137    #endif
138    
139      uint8_t utf16le[] = {
140        'e', 0,
141        0xe8, 0,
142        0xe9, 0,
143        0xea, 0,
144      };
145    
146      result = jscoverage_bytes_to_characters("UTF-16LE", utf16le, 8, &characters, &num_characters);
147    
148    #ifdef HAVE_ICONV
149    assert(result == 0);    assert(result == 0);
150    assert(num_characters == 4);    assert(num_characters == 4);
151    assert(characters[0] == 'e');    assert(characters[0] == 'e');
# Line 80  Line 154 
154    assert(characters[3] == 0xea);    assert(characters[3] == 0xea);
155    
156    free(characters);    free(characters);
157    #else
158      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
159    #endif
160    
161      uint8_t utf16le_with_bom[] = {
162        0xff, 0xfe,
163        'e', 0,
164        0xe8, 0,
165        0xe9, 0,
166        0xea, 0,
167      };
168    
169      result = jscoverage_bytes_to_characters("UTF-16LE", utf16le_with_bom, 10, &characters, &num_characters);
170    
171    #ifdef HAVE_ICONV
172      assert(result == 0);
173      assert(num_characters == 4);
174      assert(characters[0] == 'e');
175      assert(characters[1] == 0xe8);
176      assert(characters[2] == 0xe9);
177      assert(characters[3] == 0xea);
178    
179      free(characters);
180    #else
181      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
182    #endif
183    
184      /* bogus encoding */
185      uint8_t bogus[] = {'b', 'o', 'g', 'u', 's'};
186    
187      result = jscoverage_bytes_to_characters("BOGUS", bogus, 5, &characters, &num_characters);
188    
189      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
190    
191    #ifdef HAVE_ICONV
192      /* malformed US-ASCII */
193      /* NOTE: Windows simply discards the high bit */
194      uint8_t malformed_ascii[] = {
195        'e',
196        0xe8,
197        0xe9,
198        0xea,
199      };
200    
201      result = jscoverage_bytes_to_characters("US-ASCII", malformed_ascii, 4, &characters, &num_characters);
202    
203      assert(result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE);
204    #endif
205    
206      /* malformed UTF-8 */
207      uint8_t malformed_utf8[] = {
208        'e',
209        0xe8,
210        0xe9,
211        0xea,
212      };
213    
214      result = jscoverage_bytes_to_characters("UTF-8", malformed_utf8, 4, &characters, &num_characters);
215    
216    #if HAVE_ICONV || HAVE_MULTIBYTETOWIDECHAR
217      assert(result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE);
218    #else
219      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
220    #endif
221    
222    return 0;    return 0;
223  }  }

Legend:
Removed from v.205  
changed lines
  Added in v.427

  ViewVC Help
Powered by ViewVC 1.1.24