Differences From Artifact [7f9159fd57]:
- File
tests/OFStringTests.m
— part of check-in
[9d3cd5e5fe]
at
2013-01-07 22:07:58
on branch trunk
— OFString: Zero-terminate UTF-16 strings.
This partly reverts e8502c7.
The rationale behind this is that, on some OSes, native APIs (on e.g.
Windows) take UTF-16 strings that are zero-terminated.However, forcing zero-termination for every string so that -[characters]
returns a zero-terminated UTF-32 string does not make sense. Therefore,
in the future, -[UTF32String] will be added, which will include
zero-termination. OFString subclasses can then just return their
internal representation if it includes a terminating zero or create a
copy that has a terminating zero if not. (user: js, size: 22619) [annotate] [blame] [check-ins using]
To Artifact [1701ed672c]:
- File tests/OFStringTests.m — part of check-in [7cddd5f891] at 2013-01-08 12:33:53 on branch trunk — OFString: Add methods for UTF-32. (user: js, size: 22869) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
36 37 38 39 40 41 42 | static OFString *module = @"OFString"; static OFString* whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; static of_unichar_t ucstr[] = { | | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | static OFString *module = @"OFString"; static OFString* whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; static of_unichar_t ucstr[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A, 0 }; static of_unichar_t sucstr[] = { 0xFFFE0000, 0x66000000, 0xF6000000, 0xF6000000, 0x62000000, 0xE4000000, 0x72000000, 0x3AF00100, 0 }; static uint16_t utf16str[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0 }; static uint16_t sutf16str[] = { 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, 0 |
︙ | ︙ | |||
153 154 155 156 157 158 159 | TEST(@"+[stringWithUTF8String:length:]", (s[0] = [OFMutableString stringWithUTF8String: "\xEF\xBB\xBF" "foobar" length: 6]) && [s[0] isEqual: @"foo"]) | < < < < < < < < < < > > > > > > | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | TEST(@"+[stringWithUTF8String:length:]", (s[0] = [OFMutableString stringWithUTF8String: "\xEF\xBB\xBF" "foobar" length: 6]) && [s[0] isEqual: @"foo"]) TEST(@"+[stringWithUTF16String:]", (is = [OFString stringWithUTF16String: utf16str]) && [is isEqual: @"fööbär🀺"] && (is = [OFString stringWithUTF16String: sutf16str]) && [is isEqual: @"fööbär🀺"]) TEST(@"+[stringWithUTF32String::]", (is = [OFString stringWithUTF32String: ucstr]) && [is isEqual: @"fööbär🀺"] && (is = [OFString stringWithUTF32String: sucstr]) && [is isEqual: @"fööbär🀺"]) TEST(@"+[stringWithContentsOfFile:encoding]", (is = [OFString stringWithContentsOfFile: @"testfile.txt" encoding: OF_STRING_ENCODING_ISO_8859_1]) && [is isEqual: @"testäöü"]) TEST(@"+[stringWithContentsOfURL:encoding]", (is = [OFString |
︙ | ︙ | |||
404 405 406 407 408 409 410 | EXPECT_EXCEPTION(@"Detect out of range in -[hexadecimalValue]", OFOutOfRangeException, [@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" hexadecimalValue]) TEST(@"-[characters]", (ua = [@"fööbär🀺" characters]) && | | | < | | > > > > > > > > > > | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | EXPECT_EXCEPTION(@"Detect out of range in -[hexadecimalValue]", OFOutOfRangeException, [@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" hexadecimalValue]) TEST(@"-[characters]", (ua = [@"fööbär🀺" characters]) && !memcmp(ua, ucstr + 1, sizeof(ucstr) - 8)) TEST(@"-[UTF16String]", (u16a = [@"fööbär🀺" UTF16String]) && !memcmp(u16a, utf16str + 1, of_string_utf16_length(utf16str) * 2) && (u16a = [@"fööbär🀺" #ifdef OF_BIG_ENDIAN UTF16StringWithByteOrder: OF_BYTE_ORDER_LITTLE_ENDIAN]) && #else UTF16StringWithByteOrder: OF_BYTE_ORDER_BIG_ENDIAN]) && #endif !memcmp(u16a, sutf16str + 1, of_string_utf16_length(sutf16str) * 2)) TEST(@"-[UTF16StringLength]", [@"fööbär🀺" UTF16StringLength] == 8) TEST(@"-[UTF32String]", (ua = [@"fööbär🀺" UTF32String]) && !memcmp(ua, ucstr + 1, of_string_utf32_length(ucstr) * 4) && (ua = [@"fööbär🀺" #ifdef OF_BIG_ENDIAN UTF32StringWithByteOrder: OF_BYTE_ORDER_LITTLE_ENDIAN]) && #else UTF32StringWithByteOrder: OF_BYTE_ORDER_BIG_ENDIAN]) && #endif !memcmp(ua, sucstr + 1, of_string_utf32_length(sucstr) * 4)) TEST(@"-[MD5Hash]", [[@"asdfoobar" MD5Hash] isEqual: @"184dce2ec49b5422c7cfd8728864db4c"]) TEST(@"-[SHA1Hash]", [[@"asdfoobar" SHA1Hash] isEqual: @"f5f81ac0a8b5cbfdc4585ec1ad32e7b3a12b9b49"]) |
︙ | ︙ |