Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -184,10 +184,11 @@ 4B3D23E81337FCB000DD29B8 /* macros.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BBA36C511406AB700CBA3AC /* macros.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3D23E91337FCB000DD29B8 /* of_asprintf.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB50DCF12F863C700C9393F /* of_asprintf.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3D23EA1337FCB000DD29B8 /* threading.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B67998B1099E7C50041064A /* threading.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3D23EB1337FCB000DD29B8 /* unicode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B67998C1099E7C50041064A /* unicode.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3D23EE1337FFD000DD29B8 /* of_asprintf.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB50DD012F863C700C9393F /* of_asprintf.m */; }; + 4B3D5694139A617D0010A78F /* OFSerializationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3D5693139A617D0010A78F /* OFSerializationTests.m */; }; 4B55A0FF133ABEA900B58A93 /* OFThreadJoinFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A0F9133ABEA900B58A93 /* OFThreadJoinFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A100133ABEA900B58A93 /* OFThreadJoinFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A0FA133ABEA900B58A93 /* OFThreadJoinFailedException.m */; }; 4B55A101133ABEA900B58A93 /* OFThreadStartFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A0FB133ABEA900B58A93 /* OFThreadStartFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A102133ABEA900B58A93 /* OFThreadStartFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A0FC133ABEA900B58A93 /* OFThreadStartFailedException.m */; }; 4B55A103133ABEA900B58A93 /* OFThreadStillRunningException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A0FD133ABEA900B58A93 /* OFThreadStillRunningException.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -394,10 +395,11 @@ 4B3D236E1337FB5800DD29B8 /* base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = base64.m; path = src/base64.m; sourceTree = ""; }; 4B3D23701337FB7500DD29B8 /* OFHTTPRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHTTPRequestTests.m; path = tests/OFHTTPRequestTests.m; sourceTree = ""; }; 4B3D23761337FBC800DD29B8 /* ObjFW.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjFW.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4B3D23BB1337FC5800DD29B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; 4B3D23EF1338008000DD29B8 /* mach_alias_list */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mach_alias_list; path = src/mach_alias_list; sourceTree = SOURCE_ROOT; }; + 4B3D5693139A617D0010A78F /* OFSerializationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSerializationTests.m; path = tests/OFSerializationTests.m; sourceTree = ""; }; 4B4986DF1101F64500A2CFDA /* objc_properties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = objc_properties.m; path = src/objc_properties.m; sourceTree = ""; }; 4B4A61F212DF5EA20048F3F2 /* OFURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFURL.h; path = src/OFURL.h; sourceTree = SOURCE_ROOT; }; 4B4A61F312DF5EA20048F3F2 /* OFURL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFURL.m; path = src/OFURL.m; sourceTree = SOURCE_ROOT; }; 4B55A0F9133ABEA900B58A93 /* OFThreadJoinFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFThreadJoinFailedException.h; path = src/exceptions/OFThreadJoinFailedException.h; sourceTree = ""; }; 4B55A0FA133ABEA900B58A93 /* OFThreadJoinFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadJoinFailedException.m; path = src/exceptions/OFThreadJoinFailedException.m; sourceTree = ""; }; @@ -863,10 +865,11 @@ 4B6EF6721235358D0076B512 /* OFListTests.m */, 4B6EF6731235358D0076B512 /* OFMD5HashTests.m */, 4B6EF6741235358D0076B512 /* OFNumberTests.m */, 4B6EF6751235358D0076B512 /* OFObjectTests.m */, 4B6EF6761235358D0076B512 /* OFPluginTests.m */, + 4B3D5693139A617D0010A78F /* OFSerializationTests.m */, 4B6EF6771235358D0076B512 /* OFSHA1HashTests.m */, 4B6EF6781235358D0076B512 /* OFStreamTests.m */, 4B6EF6791235358D0076B512 /* OFStringTests.m */, 4B6EF67A1235358D0076B512 /* OFTCPSocketTests.m */, 4B6EF67B1235358D0076B512 /* OFThreadTests.m */, @@ -1301,10 +1304,11 @@ 4BF33B0E133807A20059CEF7 /* OFXMLElementBuilderTests.m in Sources */, 4BF33B0F133807A20059CEF7 /* OFXMLElementTests.m in Sources */, 4BF33B10133807A20059CEF7 /* OFXMLParserTests.m in Sources */, 4BF33B11133807A20059CEF7 /* PropertiesTests.m in Sources */, 4BF33B12133807A20059CEF7 /* TestsAppDelegate.m in Sources */, + 4B3D5694139A617D0010A78F /* OFSerializationTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -12,10 +12,11 @@ OFListTests.m \ OFMD5HashTests.m \ OFNumberTests.m \ OFObjectTests.m \ ${OFPLUGINTESTS_M} \ + OFSerializationTests.m \ OFSHA1HashTests.m \ OFStreamTests.m \ OFStringTests.m \ OFTCPSocketTests.m \ ${OFTHREADTESTS_M} \ ADDED tests/OFSerializationTests.m Index: tests/OFSerializationTests.m ================================================================== --- tests/OFSerializationTests.m +++ tests/OFSerializationTests.m @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFSerialization.h" +#import "OFString.h" +#import "OFArray.h" +#import "OFDictionary.h" +#import "OFList.h" +#import "OFNumber.h" +#import "OFDate.h" +#import "OFURL.h" +#import "OFAutoreleasePool.h" +#import "OFXMLElement.h" + +#import "TestsAppDelegate.h" + +static OFString *module = @"OFSerialization"; +static const OFString *expected = @"\n" + @"" + @"" + @"Qu"xbar\ntest" + @"1234" + @"asd" + @"1234" + @"5678" + @"Hello" + @"Blub" + @"B"la" + @"Hello" + @"Wo ld!\nHow are you?" + @"https://webkeks.org/" + @"x" + @"" + @"http://www.w3.org/2000/xmlns/" + @"xmlns" + @"http://www.w3.org/XML/1998/namespace" + @"xml" + @"" + @"y" + @"" + @"http://www.w3.org/2000/xmlns/" + @"xmlns" + @"http://www.w3.org/XML/1998/namespace" + @"xml" + @"" + @"list" + @""; + +@implementation TestsAppDelegate (SerializationTests) +- (void)serializationTests +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFMutableDictionary *d = [OFMutableDictionary dictionary]; + OFMutableArray *a = [OFMutableArray array]; + OFList *l = [OFList list]; + OFString *s; + + [a addObject: @"Qu\"xbar\ntest"]; + [a addObject: [OFNumber numberWithInt: 1234]]; + [a addObject: [OFMutableString stringWithString: @"asd"]]; + [a addObject: [OFDate dateWithTimeIntervalSince1970: 1234 + microseconds: 5678]]; + + [d setObject: @"Hello" + forKey: a]; + [d setObject: @"B\"la" + forKey: @"Blub"]; + + [l appendObject: @"Hello"]; + [l appendObject: @"Wo\rld!\nHow are you?"]; + [l appendObject: [OFURL URLWithString: @"https://webkeks.org/"]]; + [l appendObject: [OFXMLElement elementWithXMLString: @""]]; + + [d setObject: @"list" + forKey: l]; + + TEST(@"Serialization", + (s = [OFSerialization stringBySerializingObject: d]) && + [s isEqual: expected]) + + TEST(@"Deserialization", + [[OFSerialization objectByDeserializingString: s] isEqual: d]) + + [pool drain]; +} +@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -118,10 +118,14 @@ @end @interface TestsAppDelegate (PropertiesTests) - (void)propertiesTests; @end + +@interface TestsAppDelegate (SerializationTests) +- (void)serializationTests; +@end @interface TestsAppDelegate (OFSHA1HashTests) - (void)SHA1HashTests; @end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -139,10 +139,11 @@ [self HTTPRequestTests]; #endif [self XMLParserTests]; [self XMLElementTests]; [self XMLElementBuilderTests]; + [self serializationTests]; #ifdef OF_PLUGINS [self pluginTests]; #endif #ifdef OF_HAVE_PROPERTIES [self propertiesTests];