/[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 301 by siliconforks, Mon Oct 13 05:07:00 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);    assert(result == 0);
83    assert(num_characters == 4);    assert(num_characters == 4);
84    assert(characters[0] == 'e');    assert(characters[0] == 'e');
# Line 80  Line 87 
87    assert(characters[3] == 0xea);    assert(characters[3] == 0xea);
88    
89    free(characters);    free(characters);
90    #else
91      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
92    #endif
93    
94    uint8_t utf16be[] = {    uint8_t utf16be[] = {
95      0, 'e',      0, 'e',
# Line 90  Line 100 
100    
101    result = jscoverage_bytes_to_characters("UTF-16BE", utf16be, 8, &characters, &num_characters);    result = jscoverage_bytes_to_characters("UTF-16BE", utf16be, 8, &characters, &num_characters);
102    
103    #ifdef HAVE_ICONV
104    assert(result == 0);    assert(result == 0);
105    assert(num_characters == 4);    assert(num_characters == 4);
106    assert(characters[0] == 'e');    assert(characters[0] == 'e');
# Line 98  Line 109 
109    assert(characters[3] == 0xea);    assert(characters[3] == 0xea);
110    
111    free(characters);    free(characters);
112    #else
113      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
114    #endif
115    
116    uint8_t utf16be_with_bom[] = {    uint8_t utf16be_with_bom[] = {
117      0xfe, 0xff,      0xfe, 0xff,
# Line 109  Line 123 
123    
124    result = jscoverage_bytes_to_characters("UTF-16BE", utf16be_with_bom, 10, &characters, &num_characters);    result = jscoverage_bytes_to_characters("UTF-16BE", utf16be_with_bom, 10, &characters, &num_characters);
125    
126    #ifdef HAVE_ICONV
127    assert(result == 0);    assert(result == 0);
128    assert(num_characters == 4);    assert(num_characters == 4);
129    assert(characters[0] == 'e');    assert(characters[0] == 'e');
# Line 117  Line 132 
132    assert(characters[3] == 0xea);    assert(characters[3] == 0xea);
133    
134    free(characters);    free(characters);
135    #else
136      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
137    #endif
138    
139    uint8_t utf16le[] = {    uint8_t utf16le[] = {
140      'e', 0,      'e', 0,
# Line 127  Line 145 
145    
146    result = jscoverage_bytes_to_characters("UTF-16LE", utf16le, 8, &characters, &num_characters);    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 135  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[] = {    uint8_t utf16le_with_bom[] = {
162      0xff, 0xfe,      0xff, 0xfe,
# Line 146  Line 168 
168    
169    result = jscoverage_bytes_to_characters("UTF-16LE", utf16le_with_bom, 10, &characters, &num_characters);    result = jscoverage_bytes_to_characters("UTF-16LE", utf16le_with_bom, 10, &characters, &num_characters);
170    
171    #ifdef HAVE_ICONV
172    assert(result == 0);    assert(result == 0);
173    assert(num_characters == 4);    assert(num_characters == 4);
174    assert(characters[0] == 'e');    assert(characters[0] == 'e');
# Line 154  Line 177 
177    assert(characters[3] == 0xea);    assert(characters[3] == 0xea);
178    
179    free(characters);    free(characters);
180    #else
181      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
182    #endif
183    
184    /* bogus encoding */    /* bogus encoding */
185    uint8_t bogus[] = {'b', 'o', 'g', 'u', 's'};    uint8_t bogus[] = {'b', 'o', 'g', 'u', 's'};
# Line 162  Line 188 
188    
189    assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);    assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
190    
191    #ifdef HAVE_ICONV
192    /* malformed US-ASCII */    /* malformed US-ASCII */
193      /* NOTE: Windows simply discards the high bit */
194    uint8_t malformed_ascii[] = {    uint8_t malformed_ascii[] = {
195      'e',      'e',
196      0xe8,      0xe8,
# Line 173  Line 201 
201    result = jscoverage_bytes_to_characters("US-ASCII", malformed_ascii, 4, &characters, &num_characters);    result = jscoverage_bytes_to_characters("US-ASCII", malformed_ascii, 4, &characters, &num_characters);
202    
203    assert(result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE);    assert(result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE);
204    #endif
205    
206    /* malformed UTF-8 */    /* malformed UTF-8 */
207    uint8_t malformed_utf8[] = {    uint8_t malformed_utf8[] = {
# Line 184  Line 213 
213    
214    result = jscoverage_bytes_to_characters("UTF-8", malformed_utf8, 4, &characters, &num_characters);    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);    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.301  
changed lines
  Added in v.427

  ViewVC Help
Powered by ViewVC 1.1.24