1
2
3
4
5
6
7
8
9
10
|
1
2
3
4
5
6
7
8
9
10
|
-
-
+
+
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
* Jonathan Schleifer <js@webkeks.org>
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
* Jonathan Schleifer <js@heap.zone>
*
* 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.
*
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
+
|
@interface ObserverTest: OFObject
{
@public
TestsAppDelegate *_testsAppDelegate;
OFKernelEventObserver *_observer;
OFTCPSocket *_server, *_client, *_accepted;
size_t _events;
int _fails;
}
- (void)run;
@end
@implementation ObserverTest
- initWithTestsAppDelegate: (TestsAppDelegate*)testsAppDelegate
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
-
+
+
+
-
+
+
+
-
+
+
+
-
+
+
+
-
+
+
+
|
[_observer observeForTimeInterval: 0.01];
}
if (!deadlineExceeded)
[_testsAppDelegate
outputSuccess: @"-[observe] not exceeding deadline"
inModule: module];
else
else {
[_testsAppDelegate
outputFailure: @"-[observe] not exceeding deadline"
inModule: module];
_fails++;
}
if (_events == EXPECTED_EVENTS)
[_testsAppDelegate
outputSuccess: @"-[observe] handling all events"
inModule: module];
else
else {
[_testsAppDelegate
outputFailure: @"-[observe] handling all events"
inModule: module];
_fails++;
}
}
- (void)objectIsReadyForReading: (id)object
{
char buf;
switch (_events++) {
case 0:
if (object == _server)
[_testsAppDelegate
outputSuccess: @"-[observe] with listening socket"
inModule: module];
else
else {
[_testsAppDelegate
outputFailure: @"-[observe] with listening socket"
inModule: module];
_fails++;
}
_accepted = [[object accept] retain];
[_observer addObjectForReading: _accepted];
[_testsAppDelegate
outputTesting: @"-[observe] with data ready to read"
inModule: module];
break;
case 1:
if (object == _accepted &&
[object readIntoBuffer: &buf
length: 1] == 1 && buf == '0')
[_testsAppDelegate
outputSuccess: @"-[observe] with data ready to read"
inModule: module];
else
else {
[_testsAppDelegate
outputFailure: @"-[observe] with data ready to read"
inModule: module];
_fails++;
}
[_client close];
[_testsAppDelegate
outputTesting: @"-[observe] with closed connection"
inModule: module];
break;
case 2:
if (object == _accepted &&
[object readIntoBuffer: &buf
length: 1] == 0)
[_testsAppDelegate
outputSuccess: @"-[observe] with closed connection"
inModule: module];
else
else {
[_testsAppDelegate
outputFailure: @"-[observe] with closed connection"
inModule: module];
_fails++;
}
break;
default:
OF_ENSURE(0);
}
}
@end
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
+
|
(test->_observer = [OFKernelEventObserver observer]))
[test->_observer setDelegate: test];
TEST(@"-[addObjectForReading:]",
R([test->_observer addObjectForReading: test->_server]))
[test run];
_fails += test->_fails;
}
- (void)kernelEventObserverTests
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
#if defined(HAVE_SYS_SELECT_H) || defined(_WIN32)
|