Differences From Artifact [24325e2282]:
- File tests/OFKernelEventObserverTests.m — part of check-in [374e1a1bfa] at 2021-01-02 22:04:26 on branch trunk — Update copyright (user: js, size: 5134) [annotate] [blame] [check-ins using] [more...]
To Artifact [f4ab45b387]:
- File
tests/OFKernelEventObserverTests.m
— part of check-in
[14f1e22d79]
at
2021-05-08 23:22:59
on branch trunk
— tests: Align more with ObjFW style
ObjFW's style changed over the years, but the tests were never adjusted
to it. (user: js, size: 5130) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
26 27 28 29 30 31 32 | #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif #import "TestsAppDelegate.h" | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif #import "TestsAppDelegate.h" static const size_t numExpectedEvents = 3; static OFString *module; @interface ObserverTest: OFObject <OFKernelEventObserverDelegate> { @public TestsAppDelegate *_testsAppDelegate; |
︙ | ︙ | |||
54 55 56 57 58 59 60 | @try { uint16_t port; _testsAppDelegate = testsAppDelegate; _server = [[OFTCPSocket alloc] init]; | | < | < < | < | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | @try { uint16_t port; _testsAppDelegate = testsAppDelegate; _server = [[OFTCPSocket alloc] init]; port = [_server bindToHost: @"127.0.0.1" port: 0]; [_server listen]; _client = [[OFTCPSocket alloc] init]; [_client connectToHost: @"127.0.0.1" port: port]; [_client writeBuffer: "0" length: 1]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
90 91 92 93 94 95 96 | OFDate *deadline; bool deadlineExceeded = false; [_testsAppDelegate outputTesting: @"-[observe] with listening socket" inModule: module]; deadline = [OFDate dateWithTimeIntervalSinceNow: 1]; | | | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 | OFDate *deadline; bool deadlineExceeded = false; [_testsAppDelegate outputTesting: @"-[observe] with listening socket" inModule: module]; deadline = [OFDate dateWithTimeIntervalSinceNow: 1]; while (_events < numExpectedEvents) { if (deadline.timeIntervalSinceNow < 0) { deadlineExceeded = true; break; } [_observer observeForTimeInterval: 0.01]; } if (!deadlineExceeded) [_testsAppDelegate outputSuccess: @"-[observe] not exceeding deadline" inModule: module]; else { [_testsAppDelegate outputFailure: @"-[observe] not exceeding deadline" inModule: module]; _fails++; } if (_events == numExpectedEvents) [_testsAppDelegate outputSuccess: @"-[observe] handling all events" inModule: module]; else { [_testsAppDelegate outputFailure: @"-[observe] handling all events" inModule: module]; _fails++; } } - (void)objectIsReadyForReading: (id)object { char buffer; switch (_events++) { case 0: if (object == _server) [_testsAppDelegate outputSuccess: @"-[observe] with listening socket" inModule: module]; |
︙ | ︙ | |||
149 150 151 152 153 154 155 | [_testsAppDelegate outputTesting: @"-[observe] with data ready to read" inModule: module]; break; case 1: if (object == _accepted && | | | | < | | 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 | [_testsAppDelegate outputTesting: @"-[observe] with data ready to read" inModule: module]; break; case 1: if (object == _accepted && [object readIntoBuffer: &buffer length: 1] == 1 && buffer == '0') [_testsAppDelegate outputSuccess: @"-[observe] with data ready to read" inModule: module]; 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: &buffer length: 1] == 0) [_testsAppDelegate outputSuccess: @"-[observe] with closed connection" inModule: module]; else { [_testsAppDelegate outputFailure: @"-[observe] with closed connection" inModule: module]; _fails++; } break; default: OFEnsure(0); } } @end @implementation TestsAppDelegate (OFKernelEventObserverTests) - (void)kernelEventObserverTestsWithClass: (Class)class { |
︙ | ︙ |