mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-06 14:40:43 +00:00
* ChangeLog * config/pathtls.m4 * config/pathxml.m4 * configure * configure.ac * Documentation/ReleaseNotes.gsdoc * Headers/Foundation/NSCalendar.h * Headers/Foundation/NSDate.h * Headers/Foundation/NSException.h * Headers/Foundation/NSNetServices.h * Headers/Foundation/NSString.h * Headers/Foundation/NSXMLNode.h * Headers/GNUstepBase/config.h.in * NSTimeZones/NSTimeZones.tar * Source/GSFFIInvocation.m * Source/GSPrivate.h * Source/GSSocketStream.m * Source/GSString.m * Source/NSAffineTransform.m * Source/NSBundle.m * Source/NSConnection.m * Source/NSFileManager.m * Source/NSHost.m * Source/NSInvocation.m * Source/NSJSONSerialization.m * Source/NSKeyValueCoding.m * Source/NSNotificationCenter.m * Source/NSNumberFormatter.m * Source/NSURLRequest.m * Source/NSUserDefaults.m * Source/NSXMLNode.m: Corrected infinite loop. Return an NSXMLNode for NSXMLInvalidKind per Cocoa documentation. * Tests/base/NSJSONSerialization/json.m * Tests/base/NSObject/initialize.m * Tests/base/NSString/NSString_tests.h * Tests/base/NSURLRequest/basic.m * Version: Merge with trunk. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/nsxml_using_libxml2@34690 72102866-910b-0410-8b05-ffd578937521
67 lines
2 KiB
Objective-C
67 lines
2 KiB
Objective-C
#import <Foundation/Foundation.h>
|
|
#import "ObjectTesting.h"
|
|
|
|
int main(void)
|
|
{
|
|
[NSAutoreleasePool new];
|
|
// Simple test JSON, used for all of the examples
|
|
|
|
NSString *json = @"\
|
|
{\
|
|
\"Image\": {\
|
|
\"Width\": 800,\
|
|
\"Height\": 600,\
|
|
\"Title\": \"View from 15th Floor\",\
|
|
\"Thumbnail\": {\
|
|
\"Url\": \"http://www.example.com/image/481989943\",\
|
|
\"Height\": 125,\
|
|
\"Width\": \"100\"\
|
|
},\
|
|
},\
|
|
\"emptyString\":\"\",\"emptyArray\":[],\"emptyObject\":{},\
|
|
\"IDs\": [116, 943, 234, 38793],\
|
|
\"escapeTest\": \"\\\"\\u0001\"\
|
|
}";
|
|
NSStringEncoding encs[] = {\
|
|
NSUTF8StringEncoding,\
|
|
NSUTF16LittleEndianStringEncoding,\
|
|
NSUTF16BigEndianStringEncoding,\
|
|
NSUTF32LittleEndianStringEncoding,\
|
|
NSUTF32BigEndianStringEncoding};
|
|
NSInputStream *is;
|
|
NSData *data;
|
|
id obj;
|
|
int i;
|
|
|
|
for (i = 0; i < (sizeof(encs) / sizeof(NSStringEncoding)); i++)
|
|
{
|
|
NSError *e;
|
|
id tmp;
|
|
|
|
data = [json dataUsingEncoding: encs[i]];
|
|
tmp = [NSJSONSerialization JSONObjectWithData: data options: 0 error: &e];
|
|
if (i > 0)
|
|
{
|
|
PASS([tmp isEqual: obj],
|
|
"Decoding in different encodings give the same result");
|
|
}
|
|
obj = tmp;
|
|
}
|
|
|
|
PASS([obj count] == 6,
|
|
"Decoded dictionary had the right number of elements");
|
|
PASS([NSJSONSerialization isValidJSONObject: obj],
|
|
"Can serialise deserialised JSON");
|
|
|
|
data = [NSJSONSerialization dataWithJSONObject: obj
|
|
options: NSJSONWritingPrettyPrinted error: 0];
|
|
PASS_EQUAL([NSJSONSerialization JSONObjectWithData: data options: 0 error: 0],
|
|
obj, "Round trip worked with pretty printing");
|
|
data = [NSJSONSerialization dataWithJSONObject: obj options: 0 error: 0];
|
|
PASS_EQUAL([NSJSONSerialization JSONObjectWithData: data options: 0 error: 0],
|
|
obj, "Round trip worked with ugly printing");
|
|
is = [NSInputStream inputStreamWithData: data];
|
|
PASS_EQUAL([NSJSONSerialization JSONObjectWithStream: is options: 0 error: 0],
|
|
obj, "Round trip worked through stream");
|
|
return 0;
|
|
}
|