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

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

  ViewVC Help
Powered by ViewVC 1.1.24