ObjFW  Check-in [d4a1b1966d]

Overview
Comment:Add tests for OFKernelEventObserver
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d4a1b1966db881529a428266b488ac48ae430a43b55f2f905d0554113f3cf923
User & Date: js on 2015-04-20 20:46:09
Other Links: manifest | tags
Context
2015-04-20
20:48
Remove a few now unnecessary imports check-in: 0dbf08158c user: js tags: trunk
20:46
Add tests for OFKernelEventObserver check-in: d4a1b1966d user: js tags: trunk
2015-04-14
19:46
Add a few more const check-in: 5d729d9ba0 user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [f5dc643e0a] to [e2719fbf29].

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







+







		4B187E58163EA3DA0049A832 /* OFDictionary_NSDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B187E36163EA3DA0049A832 /* OFDictionary_NSDictionary.m */; };
		4B187E59163EA3DA0049A832 /* OFDictionary+NSObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B187E37163EA3DA0049A832 /* OFDictionary+NSObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B187E5B163EA3DA0049A832 /* OFDictionary+NSObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B187E38163EA3DA0049A832 /* OFDictionary+NSObject.m */; };
		4B187E5C163EA3DA0049A832 /* OFString+NSObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B187E39163EA3DA0049A832 /* OFString+NSObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B187E5E163EA3DA0049A832 /* OFString+NSObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B187E3A163EA3DA0049A832 /* OFString+NSObject.m */; };
		4B187E61163EA4530049A832 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B187E60163EA4530049A832 /* Foundation.framework */; };
		4B187E62163EA46D0049A832 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; };
		4B22BE201AE594A000CD320A /* OFKernelEventObserverTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B22BE1F1AE594A000CD320A /* OFKernelEventObserverTests.m */; };
		4B23CA92133811DC0047A1D9 /* TestPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF684123535B60076B512 /* TestPlugin.m */; };
		4B23CA93133811E20047A1D9 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; };
		4B23CA941338121C0047A1D9 /* TestPlugin.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B23CA8A133811610047A1D9 /* TestPlugin.bundle */; };
		4B24592A19B5397C0059F271 /* OFSHA224Hash.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B24592619B5397C0059F271 /* OFSHA224Hash.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B24592B19B5397C0059F271 /* OFSHA224Hash.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B24592719B5397C0059F271 /* OFSHA224Hash.m */; };
		4B24592C19B5397C0059F271 /* OFSHA224Or256Hash.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B24592819B5397C0059F271 /* OFSHA224Or256Hash.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B24592D19B5397C0059F271 /* OFSHA224Or256Hash.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B24592919B5397C0059F271 /* OFSHA224Or256Hash.m */; };
630
631
632
633
634
635
636

637
638
639
640
641
642
643
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645







+







		4B187E37163EA3DA0049A832 /* OFDictionary+NSObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFDictionary+NSObject.h"; path = "src/bridge/OFDictionary+NSObject.h"; sourceTree = "<group>"; };
		4B187E38163EA3DA0049A832 /* OFDictionary+NSObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFDictionary+NSObject.m"; path = "src/bridge/OFDictionary+NSObject.m"; sourceTree = "<group>"; };
		4B187E39163EA3DA0049A832 /* OFString+NSObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+NSObject.h"; path = "src/bridge/OFString+NSObject.h"; sourceTree = "<group>"; };
		4B187E3A163EA3DA0049A832 /* OFString+NSObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFString+NSObject.m"; path = "src/bridge/OFString+NSObject.m"; sourceTree = "<group>"; };
		4B187E60163EA4530049A832 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
		4B19023A1338D6A2000374C9 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = src/Makefile; sourceTree = SOURCE_ROOT; };
		4B19023D1338D6D5000374C9 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = tests/Makefile; sourceTree = "<group>"; };
		4B22BE1F1AE594A000CD320A /* OFKernelEventObserverTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFKernelEventObserverTests.m; path = tests/OFKernelEventObserverTests.m; sourceTree = "<group>"; };
		4B23CA8A133811610047A1D9 /* TestPlugin.bundle */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = TestPlugin.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
		4B24592619B5397C0059F271 /* OFSHA224Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSHA224Hash.h; path = src/OFSHA224Hash.h; sourceTree = "<group>"; };
		4B24592719B5397C0059F271 /* OFSHA224Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA224Hash.m; path = src/OFSHA224Hash.m; sourceTree = "<group>"; };
		4B24592819B5397C0059F271 /* OFSHA224Or256Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSHA224Or256Hash.h; path = src/OFSHA224Or256Hash.h; sourceTree = "<group>"; };
		4B24592919B5397C0059F271 /* OFSHA224Or256Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA224Or256Hash.m; path = src/OFSHA224Or256Hash.m; sourceTree = "<group>"; };
		4B24592E19B53BC80059F271 /* OFSHA224HashTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA224HashTests.m; path = tests/OFSHA224HashTests.m; sourceTree = "<group>"; };
		4B24592F19B53BC80059F271 /* OFSHA256HashTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA256HashTests.m; path = tests/OFSHA256HashTests.m; sourceTree = "<group>"; };
1508
1509
1510
1511
1512
1513
1514

1515
1516
1517
1518
1519
1520
1521
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524







+







				4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */,
				4B6EF66F1235358D0076B512 /* OFDataArrayTests.m */,
				4BE5F0E512DF4259005C7A0C /* OFDateTests.m */,
				4B6EF6701235358D0076B512 /* OFDictionaryTests.m */,
				4BB4B54916776094002A2DCE /* OFHTTPClientTests.m */,
				4B5B02C018B2897500CE6AE4 /* OFINIFileTests.m */,
				4BAA60C714D09699006F068D /* OFJSONTests.m */,
				4B22BE1F1AE594A000CD320A /* OFKernelEventObserverTests.m */,
				4B6EF6721235358D0076B512 /* OFListTests.m */,
				4B6EF6731235358D0076B512 /* OFMD5HashTests.m */,
				4B6EF6741235358D0076B512 /* OFNumberTests.m */,
				4B6EF6751235358D0076B512 /* OFObjectTests.m */,
				4B6EF6761235358D0076B512 /* OFPluginTests.m */,
				4BEC83BB19B7CBDE00E4BB08 /* OFRIPEMD160HashTests.m */,
				4B3D5693139A617D0010A78F /* OFSerializationTests.m */,
2169
2170
2171
2172
2173
2174
2175

2176
2177
2178
2179
2180
2181
2182
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186







+







				4BF33AFD133807A20059CEF7 /* OFBlockTests.m in Sources */,
				4BF33AFE133807A20059CEF7 /* OFDataArrayTests.m in Sources */,
				4BF33AFF133807A20059CEF7 /* OFDateTests.m in Sources */,
				4BF33B00133807A20059CEF7 /* OFDictionaryTests.m in Sources */,
				4BB4B54A16776094002A2DCE /* OFHTTPClientTests.m in Sources */,
				4B5B02C118B2897500CE6AE4 /* OFINIFileTests.m in Sources */,
				4BAA60C814D09699006F068D /* OFJSONTests.m in Sources */,
				4B22BE201AE594A000CD320A /* OFKernelEventObserverTests.m in Sources */,
				4BF33B03133807A20059CEF7 /* OFListTests.m in Sources */,
				4BF33B04133807A20059CEF7 /* OFMD5HashTests.m in Sources */,
				4BF33B05133807A20059CEF7 /* OFNumberTests.m in Sources */,
				4BF33B06133807A20059CEF7 /* OFObjectTests.m in Sources */,
				4BF33B07133807A20059CEF7 /* OFPluginTests.m in Sources */,
				4BEC83BC19B7CBDE00E4BB08 /* OFRIPEMD160HashTests.m in Sources */,
				4B3D5694139A617D0010A78F /* OFSerializationTests.m in Sources */,

Modified tests/Makefile from [1b4c53721a] to [f063a68138].

38
39
40
41
42
43
44

45

46
47
48
49
50
51
52
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







+
-
+







	     OFSerializationTests.m	\
	     OFSHA1HashTests.m		\
	     OFSHA224HashTests.m	\
	     OFSHA256HashTests.m	\
	     OFSHA384HashTests.m	\
	     OFSHA512HashTests.m
SRCS_PLUGINS = OFPluginTests.m
SRCS_SOCKETS = OFKernelEventObserverTests.m	\
SRCS_SOCKETS = OFTCPSocketTests.m	\
	       OFTCPSocketTests.m		\
	       OFUDPSocketTests.m
SRCS_THREADS = OFThreadTests.m

IOS_USER ?= mobile
IOS_TMP ?= /tmp/objfw-test

include ../buildsys.mk

Added tests/OFKernelEventObserverTests.m version [c4a91b451f].









































































































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
102
103
104
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
 *   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 "OFKernelEventObserver.h"
#import "OFString.h"
#import "OFTCPSocket.h"
#import "OFAutoreleasePool.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFKernelEventObserverSocket";
static OFKernelEventObserver *observer;
static int events = 0;
static id expectedObject;
static bool readData = false;

@interface ObserverDelegate: OFObject <OFKernelEventObserverDelegate>
- (void)objectIsReadyForReading: (id)object;
@end

@implementation ObserverDelegate
- (void)objectIsReadyForReading: (id)object
{
	events++;

	OF_ENSURE(object == expectedObject);

	if ([object isListening]) {
		OFTCPSocket *client = [object accept];

		[observer addObjectForReading: client];
		[client writeBuffer: "0"
			     length: 1];

		return;
	} else if (readData) {
		char buf;

		[object readIntoBuffer: &buf
				length: 1];

		OF_ENSURE(buf == '0');
	}
}
@end

@implementation TestsAppDelegate (OFKernelEventObserverTests)
- (void)kernelEventObserverTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	ObserverDelegate *delegate =
	    [[[ObserverDelegate alloc] init] autorelease];
	OFTCPSocket *sock1 = [OFTCPSocket socket];
	OFTCPSocket *sock2 = [OFTCPSocket socket];
	uint16_t port;

	port = [sock1 bindToHost: @"127.0.0.1"
			    port: 0];
	[sock1 listen];

	TEST(@"+[observer]",
	    (observer = [OFKernelEventObserver observer]) &&
	    R([observer setDelegate: delegate]))

	TEST(@"-[addObjectForReading:]",
	    R([observer addObjectForReading: sock1]))

	[sock2 connectToHost: @"127.0.0.1"
			port: port];
	TEST(@"-[observe] waiting for connection",
	    (expectedObject = sock1) &&
	    [observer observeForTimeInterval: 0.01] == 1)

	TEST(@"-[observe] waiting for data",
	    (expectedObject = sock2) &&
	    R([observer addObjectForReading: sock2]) &&
	    [observer observeForTimeInterval: 0.01] == 1)

	TEST(@"-[observe] keeping event until read",
	    R(readData = true) && [observer observeForTimeInterval: 0.01] == 1)

	TEST(@"-[observer] time out due to no events",
	    R(readData = false) && [observer observeForTimeInterval: 0.01] == 0)

	TEST(@"-[observe] correct number of events", events == 3)

	[pool drain];
}
@end

Modified tests/TestsAppDelegate.h from [b160a0aca4] to [7884d34f10].

103
104
105
106
107
108
109




110
111
112
113
114
115
116
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120







+
+
+
+







@interface TestsAppDelegate (OFINIFileTests)
- (void)INIFileTests;
@end

@interface TestsAppDelegate (OFJSONTests)
- (void)JSONTests;
@end

@interface TestsAppDelegate (OFKernelEventObserverTests)
- (void)kernelEventObserverTests;
@end

@interface TestsAppDelegate (OFListTests)
- (void)listTests;
@end

@interface TestsAppDelegate (OFMD5HashTests)
- (void)MD5HashTests;
172
173
174
175
176
177
178
179
180


181
182
183
184


185
186
187
188
189
190
191
176
177
178
179
180
181
182


183
184
185
186


187
188
189
190
191
192
193
194
195







-
-
+
+


-
-
+
+







- (void)stringTests;
@end

@interface TestsAppDelegate (OFTCPSocketTests)
- (void)TCPSocketTests;
@end

@interface TestsAppDelegate (OFUDPSocketTests)
- (void)UDPSocketTests;
@interface TestsAppDelegate (OFThreadTests)
- (void)threadTests;
@end

@interface TestsAppDelegate (OFThreadTests)
- (void)threadTests;
@interface TestsAppDelegate (OFUDPSocketTests)
- (void)UDPSocketTests;
@end

@interface TestsAppDelegate (OFURLTests)
- (void)URLTests;
@end

@interface TestsAppDelegate (OFXMLElementBuilderTests)

Modified tests/TestsAppDelegate.m from [bb5273585c] to [57375072ae].

347
348
349
350
351
352
353

354
355
356
357
358
359
360
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361







+







	[self SHA384HashTests];
	[self SHA512HashTests];
	[self INIFileTests];
#endif
#ifdef OF_HAVE_SOCKETS
	[self TCPSocketTests];
	[self UDPSocketTests];
	[self kernelEventObserverTests];
#endif
#ifdef OF_HAVE_THREADS
	[self threadTests];
#endif
	[self URLTests];
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
	[self HTTPClientTests];