/[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 310 by siliconforks, Mon Oct 13 07:19:42 2008 UTC
# 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 81  Line 83 
83    
84    free(characters);    free(characters);
85    
86    #ifdef HAVE_ICONV
87      uint8_t utf16be[] = {
88        0, 'e',
89        0, 0xe8,
90        0, 0xe9,
91        0, 0xea,
92      };
93    
94      result = jscoverage_bytes_to_characters("UTF-16BE", utf16be, 8, &characters, &num_characters);
95    
96      assert(result == 0);
97      assert(num_characters == 4);
98      assert(characters[0] == 'e');
99      assert(characters[1] == 0xe8);
100      assert(characters[2] == 0xe9);
101      assert(characters[3] == 0xea);
102    
103      free(characters);
104    
105      uint8_t utf16be_with_bom[] = {
106        0xfe, 0xff,
107        0, 'e',
108        0, 0xe8,
109        0, 0xe9,
110        0, 0xea,
111      };
112    
113      result = jscoverage_bytes_to_characters("UTF-16BE", utf16be_with_bom, 10, &characters, &num_characters);
114    
115      assert(result == 0);
116      assert(num_characters == 4);
117      assert(characters[0] == 'e');
118      assert(characters[1] == 0xe8);
119      assert(characters[2] == 0xe9);
120      assert(characters[3] == 0xea);
121    
122      free(characters);
123    
124      uint8_t utf16le[] = {
125        'e', 0,
126        0xe8, 0,
127        0xe9, 0,
128        0xea, 0,
129      };
130    
131      result = jscoverage_bytes_to_characters("UTF-16LE", utf16le, 8, &characters, &num_characters);
132    
133      assert(result == 0);
134      assert(num_characters == 4);
135      assert(characters[0] == 'e');
136      assert(characters[1] == 0xe8);
137      assert(characters[2] == 0xe9);
138      assert(characters[3] == 0xea);
139    
140      free(characters);
141    
142      uint8_t utf16le_with_bom[] = {
143        0xff, 0xfe,
144        'e', 0,
145        0xe8, 0,
146        0xe9, 0,
147        0xea, 0,
148      };
149    
150      result = jscoverage_bytes_to_characters("UTF-16LE", utf16le_with_bom, 10, &characters, &num_characters);
151    
152      assert(result == 0);
153      assert(num_characters == 4);
154      assert(characters[0] == 'e');
155      assert(characters[1] == 0xe8);
156      assert(characters[2] == 0xe9);
157      assert(characters[3] == 0xea);
158    
159      free(characters);
160    #endif
161    
162      /* bogus encoding */
163      uint8_t bogus[] = {'b', 'o', 'g', 'u', 's'};
164    
165      result = jscoverage_bytes_to_characters("BOGUS", bogus, 5, &characters, &num_characters);
166    
167      assert(result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED);
168    
169    #ifdef HAVE_ICONV
170      /* malformed US-ASCII */
171      /* NOTE: Windows simply discards the high bit */
172      uint8_t malformed_ascii[] = {
173        'e',
174        0xe8,
175        0xe9,
176        0xea,
177      };
178    
179      result = jscoverage_bytes_to_characters("US-ASCII", malformed_ascii, 4, &characters, &num_characters);
180    
181      assert(result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE);
182    #endif
183    
184      /* malformed UTF-8 */
185      uint8_t malformed_utf8[] = {
186        'e',
187        0xe8,
188        0xe9,
189        0xea,
190      };
191    
192      result = jscoverage_bytes_to_characters("UTF-8", malformed_utf8, 4, &characters, &num_characters);
193    
194      assert(result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE);
195    
196    return 0;    return 0;
197  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.24