ObjFW  Check-in [591b598230]

Overview
Comment:Add tests for OFSerialization.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 591b5982305877a05e8278600b4457417ee822a91c7c4000c726ee00d405a3f0
User & Date: js on 2011-06-04 16:37:01
Other Links: manifest | tags
Context
2011-06-04
17:50
Add a note about fast enumeration to OFDictionary. check-in: da4d353d45 user: js tags: trunk
16:37
Add tests for OFSerialization. check-in: 591b598230 user: js tags: trunk
16:30
Also escape \r in -[stringByXMLEscaping]. check-in: f5f074e27e user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [65c853b1de] to [db76976c3d].

182
183
184
185
186
187
188

189
190
191
192
193
194
195
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196







+







		4B3D23E61337FCB000DD29B8 /* atomic.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BBA36C411406AB700CBA3AC /* atomic.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B3D23E71337FCB000DD29B8 /* base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3D236D1337FB5800DD29B8 /* base64.h */; settings = {ATTRIBUTES = (Public, ); }; };
		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, ); }; };
		4B55A104133ABEA900B58A93 /* OFThreadStillRunningException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A0FE133ABEA900B58A93 /* OFThreadStillRunningException.m */; };
		4B55A109133AC05100B58A93 /* common.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A106133AC05100B58A93 /* common.h */; settings = {ATTRIBUTES = (Public, ); }; };
392
393
394
395
396
397
398

399
400
401
402
403
404
405
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407







+







		4B29BC60133AC9C90004B236 /* OFSymlinkFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSymlinkFailedException.m; path = src/exceptions/OFSymlinkFailedException.m; sourceTree = "<group>"; };
		4B3D236D1337FB5800DD29B8 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = base64.h; path = src/base64.h; sourceTree = "<group>"; };
		4B3D236E1337FB5800DD29B8 /* base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = base64.m; path = src/base64.m; sourceTree = "<group>"; };
		4B3D23701337FB7500DD29B8 /* OFHTTPRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHTTPRequestTests.m; path = tests/OFHTTPRequestTests.m; sourceTree = "<group>"; };
		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 = "<group>"; };
		4B4986DF1101F64500A2CFDA /* objc_properties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = objc_properties.m; path = src/objc_properties.m; sourceTree = "<group>"; };
		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 = "<group>"; };
		4B55A0FA133ABEA900B58A93 /* OFThreadJoinFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadJoinFailedException.m; path = src/exceptions/OFThreadJoinFailedException.m; sourceTree = "<group>"; };
		4B55A0FB133ABEA900B58A93 /* OFThreadStartFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFThreadStartFailedException.h; path = src/exceptions/OFThreadStartFailedException.h; sourceTree = "<group>"; };
		4B55A0FC133ABEA900B58A93 /* OFThreadStartFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadStartFailedException.m; path = src/exceptions/OFThreadStartFailedException.m; sourceTree = "<group>"; };
861
862
863
864
865
866
867

868
869
870
871
872
873
874
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877







+







				4B6EF6701235358D0076B512 /* OFDictionaryTests.m */,
				4B3D23701337FB7500DD29B8 /* OFHTTPRequestTests.m */,
				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 */,
				4BF0749512DFAFCA00A4ADD1 /* OFURLTests.m */,
				4B6EF67C1235358D0076B512 /* OFXMLElementBuilderTests.m */,
1299
1300
1301
1302
1303
1304
1305

1306
1307
1308
1309
1310
1311
1312
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316







+







				4BF33B0C133807A20059CEF7 /* OFThreadTests.m in Sources */,
				4BF33B0D133807A20059CEF7 /* OFURLTests.m in Sources */,
				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 */

/* Begin PBXTargetDependency section */
		4B23CA8F133811B20047A1D9 /* PBXTargetDependency */ = {

Modified tests/Makefile from [e7dc717883] to [26a376b8d1].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24







+







       OFDictionaryTests.m		\
       ${OFHTTPREQUESTTESTS_M}		\
       OFListTests.m			\
       OFMD5HashTests.m			\
       OFNumberTests.m			\
       OFObjectTests.m			\
       ${OFPLUGINTESTS_M}		\
       OFSerializationTests.m		\
       OFSHA1HashTests.m		\
       OFStreamTests.m			\
       OFStringTests.m			\
       OFTCPSocketTests.m		\
       ${OFTHREADTESTS_M}		\
       OFURLTests.m			\
       OFXMLElementTests.m		\

Added tests/OFSerializationTests.m version [b1cb4df2c6].






































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 = @"<?xml version='1.0' encoding='UTF-8'?>\n"
    @"<serialization xmlns='https://webkeks.org/objfw/serialization'>"
    @"<object class='OFMutableDictionary'><pair><key><object class='OFArray'>"
    @"<object class='OFString'>Qu&quot;xbar\ntest</object>"
    @"<object class='OFNumber' type='signed'>1234</object>"
    @"<object class='OFMutableString'>asd</object>"
    @"<object class='OFDate'><seconds>1234</seconds>"
    @"<microseconds>5678</microseconds></object></object></key><value>"
    @"<object class='OFString'>Hello</object></value></pair><pair><key>"
    @"<object class='OFString'>Blub</object></key><value>"
    @"<object class='OFString'>B&quot;la</object></value></pair><pair><key>"
    @"<object class='OFList'><object class='OFString'>Hello</object>"
    @"<object class='OFString'>Wo&#xD;ld!\nHow are you?</object>"
    @"<object class='OFURL'>https://webkeks.org/</object>"
    @"<object class='OFXMLElement'><name>x</name><namespaces>"
    @"<object class='OFMutableDictionary'><pair><key>"
    @"<object class='OFString'>http://www.w3.org/2000/xmlns/</object></key>"
    @"<value><object class='OFString'>xmlns</object></value></pair><pair><key>"
    @"<object class='OFString'>http://www.w3.org/XML/1998/namespace</object>"
    @"</key><value><object class='OFString'>xml</object></value></pair>"
    @"</object></namespaces><children><object class='OFMutableArray'>"
    @"<object class='OFXMLElement'><name>y</name><namespaces>"
    @"<object class='OFMutableDictionary'><pair><key><object class='OFString'>"
    @"http://www.w3.org/2000/xmlns/</object></key><value>"
    @"<object class='OFString'>xmlns</object></value></pair><pair><key>"
    @"<object class='OFString'>http://www.w3.org/XML/1998/namespace</object>"
    @"</key><value><object class='OFString'>xml</object></value></pair>"
    @"</object></namespaces></object></object></children></object></object>"
    @"</key><value><object class='OFString'>list</object></value></pair>"
    @"</object></serialization>";

@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: @"<x><y/></x>"]];

	[d setObject: @"list"
	      forKey: l];

	TEST(@"Serialization",
	    (s = [OFSerialization stringBySerializingObject: d]) &&
	    [s isEqual: expected])

	TEST(@"Deserialization",
	    [[OFSerialization objectByDeserializingString: s] isEqual: d])

	[pool drain];
}
@end

Modified tests/TestsAppDelegate.h from [04f3a2b803] to [71681b4674].

116
117
118
119
120
121
122




123
124
125
126
127
128
129
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133







+
+
+
+







@interface TestsAppDelegate (OFPluginTests)
- (void)pluginTests;
@end

@interface TestsAppDelegate (PropertiesTests)
- (void)propertiesTests;
@end

@interface TestsAppDelegate (SerializationTests)
- (void)serializationTests;
@end

@interface TestsAppDelegate (OFSHA1HashTests)
- (void)SHA1HashTests;
@end

@interface TestsAppDelegate (OFStreamTests)
- (void)streamTests;

Modified tests/TestsAppDelegate.m from [d504fe249a] to [ed60ad2524].

137
138
139
140
141
142
143

144
145
146
147
148
149
150
151
152
153
154
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155







+











	[self URLTests];
#ifdef OF_THREADS
	[self HTTPRequestTests];
#endif
	[self XMLParserTests];
	[self XMLElementTests];
	[self XMLElementBuilderTests];
	[self serializationTests];
#ifdef OF_PLUGINS
	[self pluginTests];
#endif
#ifdef OF_HAVE_PROPERTIES
	[self propertiesTests];
#endif

	if (fails > 0)
		[OFApplication terminateWithStatus: fails];
}
@end