Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: test/cctest/test-strings.cc

Issue 1539013: Change String::WriteUtf8() to return characters written. (Closed)
Patch Set: Fix style issues Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 // Check that we can traverse very deep stacks of ConsStrings using 3 // Check that we can traverse very deep stacks of ConsStrings using
4 // StringInputBuffer. Check that Get(int) works on very deep stacks 4 // StringInputBuffer. Check that Get(int) works on very deep stacks
5 // of ConsStrings. These operations may not be very fast, but they 5 // of ConsStrings. These operations may not be very fast, but they
6 // should be possible without getting errors due to too deep recursion. 6 // should be possible without getting errors due to too deep recursion.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "v8.h" 10 #include "v8.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // U+0064 -> 64 316 // U+0064 -> 64
317 // U+12E4 -> E1 8B A4 317 // U+12E4 -> E1 8B A4
318 // U+0030 -> 30 318 // U+0030 -> 30
319 // U+3045 -> E3 81 85 319 // U+3045 -> E3 81 85
320 const uint16_t mixed_string[] = {0x02E4, 0x0064, 0x12E4, 0x0030, 0x3045}; 320 const uint16_t mixed_string[] = {0x02E4, 0x0064, 0x12E4, 0x0030, 0x3045};
321 // The characters we expect to be output 321 // The characters we expect to be output
322 const unsigned char as_utf8[11] = {0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, 322 const unsigned char as_utf8[11] = {0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30,
323 0xE3, 0x81, 0x85, 0x00}; 323 0xE3, 0x81, 0x85, 0x00};
324 // The number of bytes expected to be written for each length 324 // The number of bytes expected to be written for each length
325 const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11}; 325 const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11};
326 const int char_lengths[12] = {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5};
326 v8::Handle<v8::String> mixed = v8::String::New(mixed_string, 5); 327 v8::Handle<v8::String> mixed = v8::String::New(mixed_string, 5);
327 CHECK_EQ(10, mixed->Utf8Length()); 328 CHECK_EQ(10, mixed->Utf8Length());
328 // Try encoding the string with all capacities 329 // Try encoding the string with all capacities
329 char buffer[11]; 330 char buffer[11];
330 const char kNoChar = static_cast<char>(-1); 331 const char kNoChar = static_cast<char>(-1);
331 for (int i = 0; i <= 11; i++) { 332 for (int i = 0; i <= 11; i++) {
332 // Clear the buffer before reusing it 333 // Clear the buffer before reusing it
333 for (int j = 0; j < 11; j++) 334 for (int j = 0; j < 11; j++)
334 buffer[j] = kNoChar; 335 buffer[j] = kNoChar;
335 int written = mixed->WriteUtf8(buffer, i); 336 int chars_written;
337 int written = mixed->WriteUtf8(buffer, i, &chars_written);
336 CHECK_EQ(lengths[i], written); 338 CHECK_EQ(lengths[i], written);
339 CHECK_EQ(char_lengths[i], chars_written);
337 // Check that the contents are correct 340 // Check that the contents are correct
338 for (int j = 0; j < lengths[i]; j++) 341 for (int j = 0; j < lengths[i]; j++)
339 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); 342 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j]));
340 // Check that the rest of the buffer hasn't been touched 343 // Check that the rest of the buffer hasn't been touched
341 for (int j = lengths[i]; j < 11; j++) 344 for (int j = lengths[i]; j < 11; j++)
342 CHECK_EQ(kNoChar, buffer[j]); 345 CHECK_EQ(kNoChar, buffer[j]);
343 } 346 }
344 } 347 }
345 348
346 349
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 " if (non_ascii[i] !=" 426 " if (non_ascii[i] !="
424 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" 427 " (non_ascii[j] + external_non_ascii[i - j])) return 12;"
425 " }" 428 " }"
426 " }" 429 " }"
427 " return 0;" 430 " return 0;"
428 "};" 431 "};"
429 "test()"; 432 "test()";
430 CHECK_EQ(0, 433 CHECK_EQ(0,
431 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value()); 434 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value());
432 } 435 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698