Overview
| Comment: | Migrate OFNotificationCenterTests to ObjFWTest |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | objfwtest |
| Files: | files | file ages | folders |
| SHA3-256: |
1f32e5e17c6f1a3505efee1ebe8512b9 |
| User & Date: | js on 2024-02-17 19:56:00 |
| Other Links: | branch diff | manifest | tags |
Context
|
2024-02-17
| ||
| 20:39 | Fix OFStringTests on Windows (check-in: cb8e4b80ad user: js tags: objfwtest) | |
| 19:56 | Migrate OFNotificationCenterTests to ObjFWTest (check-in: 1f32e5e17c user: js tags: objfwtest) | |
| 19:42 | Migrate OFXMLElementBuilderTests to ObjFWTest (check-in: c4600793bc user: js tags: objfwtest) | |
Changes
Modified new_tests/Makefile from [5cdba355af] to [ba61598ebe].
| ︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
OFLocaleTests.m \
OFMatrix4x4Tests.m \
OFMethodSignatureTests.m \
OFMutableArrayTests.m \
OFMutableSetTests.m \
OFMutableStringTests.m \
OFMutableUTF8StringTests.m \
OFNumberTests.m \
OFObjectTests.m \
OFPBKDF2Tests.m \
OFPropertyListTests.m \
OFScryptTests.m \
OFSetTests.m \
OFStringTests.m \
| > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
OFLocaleTests.m \
OFMatrix4x4Tests.m \
OFMethodSignatureTests.m \
OFMutableArrayTests.m \
OFMutableSetTests.m \
OFMutableStringTests.m \
OFMutableUTF8StringTests.m \
OFNotificationCenterTests.m \
OFNumberTests.m \
OFObjectTests.m \
OFPBKDF2Tests.m \
OFPropertyListTests.m \
OFScryptTests.m \
OFSetTests.m \
OFStringTests.m \
|
| ︙ | ︙ |
Renamed and modified tests/OFNotificationCenterTests.m [088812ee19] to new_tests/OFNotificationCenterTests.m [0385b37634].
| ︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | > < | > > > | | | < | < | < | < | < | < | | | | | | | | | | < | | > | > < | | > | > < | | > | > < | | | > > | > | > | > < | | | | | | | | < | | > | | < | 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 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 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 |
* 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 "ObjFW.h"
#import "ObjFWTest.h"
static const OFNotificationName notificationName =
@"OFNotificationCenterTestName";
static const OFNotificationName otherNotificationName =
@"OFNotificationCenterTestOtherName";
@interface OFNotificationCenterTests: OTTestCase
@end
@interface OFNotificationCenterTestClass: OFObject
{
@public
id _expectedObject;
int _received;
}
- (void)handleNotification: (OFNotification *)notification;
@end
@implementation OFNotificationCenterTestClass
- (void)handleNotification: (OFNotification *)notification
{
OFEnsure([notification.name isEqual: notificationName]);
OFEnsure(_expectedObject == nil ||
notification.object == _expectedObject);
_received++;
}
@end
@implementation OFNotificationCenterTests
- (void)testNotificationCenter
{
OFNotificationCenter *center = [OFNotificationCenter defaultCenter];
OFNotificationCenterTestClass *test1, *test2, *test3, *test4;
OFNotification *notification;
test1 = [[[OFNotificationCenterTestClass alloc] init] autorelease];
test1->_expectedObject = self;
test2 = [[[OFNotificationCenterTestClass alloc] init] autorelease];
test3 = [[[OFNotificationCenterTestClass alloc] init] autorelease];
test3->_expectedObject = self;
test4 = [[[OFNotificationCenterTestClass alloc] init] autorelease];
/* First one intentionally added twice to test deduplication. */
[center addObserver: test1
selector: @selector(handleNotification:)
name: notificationName
object: self];
[center addObserver: test1
selector: @selector(handleNotification:)
name: notificationName
object: self];
[center addObserver: test2
selector: @selector(handleNotification:)
name: notificationName
object: nil];
[center addObserver: test3
selector: @selector(handleNotification:)
name: otherNotificationName
object: self];
[center addObserver: test4
selector: @selector(handleNotification:)
name: otherNotificationName
object: nil];
notification = [OFNotification notificationWithName: notificationName
object: nil];
[center postNotification: notification];
OTAssertEqual(test1->_received, 0);
OTAssertEqual(test2->_received, 1);
OTAssertEqual(test3->_received, 0);
OTAssertEqual(test4->_received, 0);
notification = [OFNotification notificationWithName: notificationName
object: self];
[center postNotification: notification];
OTAssertEqual(test1->_received, 1);
OTAssertEqual(test2->_received, 2);
OTAssertEqual(test3->_received, 0);
OTAssertEqual(test4->_received, 0);
notification = [OFNotification notificationWithName: notificationName
object: @"foo"];
[center postNotification: notification];
OTAssertEqual(test1->_received, 1);
OTAssertEqual(test2->_received, 3);
OTAssertEqual(test3->_received, 0);
OTAssertEqual(test4->_received, 0);
#ifdef OF_HAVE_BLOCKS
__block bool received = false;
id handle;
notification = [OFNotification notificationWithName: notificationName
object: self];
handle = [center addObserverForName: notificationName
object: self
usingBlock: ^ (OFNotification *notification_) {
OTAssertEqual(notification_, notification);
OTAssertFalse(received);
received = true;
}];
[center postNotification: notification];
OTAssertTrue(received);
OTAssertEqual(test1->_received, 2);
OTAssertEqual(test2->_received, 4);
OTAssertEqual(test3->_received, 0);
OTAssertEqual(test4->_received, 0);
/* Act like the block test didn't happen. */
[center removeObserver: handle];
test1->_received--;
test2->_received--;
#endif
[center removeObserver: test1
selector: @selector(handleNotification:)
name: notificationName
object: self];
[center removeObserver: test2
selector: @selector(handleNotification:)
name: notificationName
object: nil];
[center removeObserver: test3
selector: @selector(handleNotification:)
name: otherNotificationName
object: self];
[center removeObserver: test4
selector: @selector(handleNotification:)
name: otherNotificationName
object: nil];
notification = [OFNotification notificationWithName: notificationName
object: self];
[center postNotification: notification];
OTAssertEqual(test1->_received, 1);
OTAssertEqual(test2->_received, 3);
OTAssertEqual(test3->_received, 0);
OTAssertEqual(test4->_received, 0);
}
@end
|
Modified tests/Makefile from [58390fbc39] to [6326adde66].
| ︙ | ︙ | |||
13 14 15 16 17 18 19 |
PROG_NOINST = tests${PROG_SUFFIX}
STATIC_LIB_NOINST = ${TESTS_STATIC_LIB}
SRCS = OFDataTests.m \
OFDictionaryTests.m \
OFListTests.m \
OFMemoryStreamTests.m \
| < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
PROG_NOINST = tests${PROG_SUFFIX}
STATIC_LIB_NOINST = ${TESTS_STATIC_LIB}
SRCS = OFDataTests.m \
OFDictionaryTests.m \
OFListTests.m \
OFMemoryStreamTests.m \
OFStreamTests.m \
OFValueTests.m \
OFXMLNodeTests.m \
OFXMLParserTests.m \
TestsAppDelegate.m \
${USE_SRCS_FILES} \
${USE_SRCS_SOCKETS} \
|
| ︙ | ︙ |
Modified tests/TestsAppDelegate.h from [ea3f6e5ee1] to [016922afeb].
| ︙ | ︙ | |||
87 88 89 90 91 92 93 | - (void)listTests; @end @interface TestsAppDelegate (OFMemoryStreamTests) - (void)memoryStreamTests; @end | < < < < | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | - (void)listTests; @end @interface TestsAppDelegate (OFMemoryStreamTests) - (void)memoryStreamTests; @end @interface TestsAppDelegate (OFStreamTests) - (void)streamTests; @end @interface TestsAppDelegate (OFValueTests) - (void)valueTests; @end |
| ︙ | ︙ |
Modified tests/TestsAppDelegate.m from [88c74ae116] to [5c2ea3ac4e].
| ︙ | ︙ | |||
372 373 374 375 376 377 378 | [self dataTests]; [self dictionaryTests]; [self listTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; | < | 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | [self dataTests]; [self dictionaryTests]; [self listTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; #ifdef OF_HAVE_SOCKETS [self kernelEventObserverTests]; #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self HTTPClientTests]; #endif #ifdef OF_HAVE_SOCKETS |
| ︙ | ︙ |