22#import < Foundation/NSAutoreleasePool.h>
33#import < Foundation/NSString.h>
44
5-
65static NSString *
76makeFormattedString (NSString *theFormat, ...)
87{
@@ -21,6 +20,7 @@ int main()
2120 uint8_t bytes[256 ];
2221 unichar u0 = ' a' ;
2322 unichar u1 = 0xfe66 ;
23+ unichar c;
2424 int i = 256 ;
2525 char buf[32 ];
2626 NSString *s;
@@ -142,7 +142,38 @@ int main()
142142 s = [[NSString alloc ] initWithBytes: " \\ u20ac"
143143 length: 6
144144 encoding: NSNonLossyASCIIStringEncoding];
145- PASS_EQUAL (s, @" €" , " lossy backslassh-u20ac is a euro" );
145+ PASS_EQUAL (s, @" €" , " lossy backslash-u20ac is a euro" );
146+ DESTROY (s);
147+
148+ uint8_t smiley[10 ] = {
149+ ' S' , ' M' , ' I' , ' L' , ' E' , ' Y' , 0xf0 , 0x9f , 0x98 , 0x8a
150+ };
151+ s = [[NSString alloc ] initWithBytes: smiley
152+ length: 10
153+ encoding: NSUTF8StringEncoding];
154+ PASS_EQUAL (s, @" SMILEY😊" , " text with smiley at end" );
155+ DESTROY (s);
156+
157+ // Second half of surrogate pair
158+ c = 0xde0a ;
159+ s = [[NSString alloc ] initWithBytes: &c
160+ length: 2
161+ encoding: NSUnicodeStringEncoding];
162+ PASS_EQUAL (s, nil , " native - second half of surrogate pair is invalid" );
163+ DESTROY (s);
164+
165+ c = GSSwapHostI16ToBig (0xde0a );
166+ s = [[NSString alloc ] initWithBytes: &c
167+ length: 2
168+ encoding: NSUTF16BigEndianStringEncoding];
169+ PASS_EQUAL (s, nil , " big endian second half of surrogate pair is invalid" );
170+ DESTROY (s);
171+
172+ c = GSSwapHostI16ToLittle (0xde0a );
173+ s = [[NSString alloc ] initWithBytes: &c
174+ length: 2
175+ encoding: NSUTF16LittleEndianStringEncoding];
176+ PASS_EQUAL (s, nil , " little endian second half of surrogate pair is invalid" );
146177 DESTROY (s);
147178
148179 s = makeFormattedString (@" %d .%d%s " , 10 , 20 , " hello" );
0 commit comments