Differences From Artifact [d9a0d74b25]:
- File
tests/ForwardingTests.m
— part of check-in
[c5ef582958]
at
2013-03-04 17:20:15
on branch trunk
— Replace BOOL with bool.
The only places where BOOL is left are those where they are required by
the ABI. (user: js, size: 2030) [annotate] [blame] [check-ins using]
To Artifact [821ca2e4ae]:
- File tests/ForwardingTests.m — part of check-in [249eda6023] at 2013-07-11 11:55:33 on branch trunk — Add tests for -[forwardingTargetForSelector:]. (user: js, size: 3839) [annotate] [blame] [check-ins using]
︙ | |||
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 | 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 | + + + + + + + + + + + + + + + | * 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" #include <string.h> #import "OFString.h" #import "OFAutoreleasePool.h" #import "macros.h" #import "TestsAppDelegate.h" static OFString *module = @"Forwarding"; static size_t forwardings = 0; static bool success = false; static id target = nil; struct stret_test { char s[27]; }; @interface ForwardingTest: OFObject @end @interface ForwardingTest (Test) + (void)test; - (void)test; - (OFString*)forwardingTargetTest: (OFConstantString*)fmt, ...; - (long double)forwardingTargetFPRetTest; - (struct stret_test)forwardingTargetStRetTest; @end @interface ForwardingTarget: OFObject @end static void test(id self, SEL _cmd) { success = true; } |
︙ | |||
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 | 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 162 163 164 165 166 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | withImplementation: (IMP)test typeEncoding: "v@:"]; return true; } return false; } - (id)forwardingTargetForSelector: (SEL)selector { if (sel_isEqual(selector, @selector(forwardingTargetTest:)) || sel_isEqual(selector, @selector(forwardingTargetFPRetTest)) || sel_isEqual(selector, @selector(forwardingTargetStRetTest))) return target; return nil; } @end @implementation ForwardingTarget - (OFString*)forwardingTargetTest: (OFConstantString*)fmt, ... { va_list args; OFString *ret; OF_ENSURE(self == target); va_start(args, fmt); ret = [[[OFString alloc] initWithFormat: fmt arguments: args] autorelease]; va_end(args); return ret; } - (long double)forwardingTargetFPRetTest { OF_ENSURE(self == target); return 12345678.00006103515625; } - (struct stret_test)forwardingTargetStRetTest { struct stret_test ret; OF_ENSURE(self == target); memcpy(ret.s, "abcdefghijklmnopqrstuvwxyz", 27); return ret; } @end @implementation TestsAppDelegate (ForwardingTests) - (void)forwardingTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; TEST(@"Forwarding a message and adding a class method", R([ForwardingTest test]) && success && R([ForwardingTest test]) && forwardings == 1); ForwardingTest *t = [[[ForwardingTest alloc] init] autorelease]; success = false; forwardings = 0; TEST(@"Forwarding a message and adding an instance method", R([t test]) && success && R([t test]) && forwardings == 1); #ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR target = [[[ForwardingTarget alloc] init] autorelease]; TEST(@"-[forwardingTargetForSelector:]", [([t forwardingTargetTest: @"%@ %@ %@ %@ %@ %@ %@ %@ %@", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"]) isEqual: @"1 2 3 4 5 6 7 8 9"]) TEST(@"-[forwardingTargetForSelector:] with fp return", [t forwardingTargetFPRetTest] == 12345678.00006103515625) # ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET TEST(@"-[forwardingTargetForSelector:] with struct return", !memcmp([t forwardingTargetStRetTest].s, "abcdefghijklmnopqrstuvwxyz", 27)) # endif #endif [pool drain]; } @end |