~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Testing/nsinvocation.m

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
- (small) loopSmallPtr: (small*)v;
30
30
- (char*) loopString: (char*)v;
31
31
 
 
32
- (double) loopMulti: (float)f int: (float)v ch: (char)c;
 
33
 
32
34
- (char) retChar;
33
35
- (double) retDouble;
34
36
- (float) retFloat;
91
93
  return v;
92
94
}
93
95
 
 
96
- (double) loopMulti: (float)f int: (float)v ch: (char)c
 
97
{
 
98
  return v+1.0;
 
99
}
 
100
 
94
101
- (char) retChar
95
102
{
96
103
  return (char)99;
145
152
}
146
153
- (void) forwardInvocation: (NSInvocation*)inv;
147
154
- (id) initWithTarget: (id)target;
 
155
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector;
148
156
@end
149
157
 
150
158
@implementation MyProxy
164
172
  d = [NSArchiver archivedDataWithRootObject: i];
165
173
  i = [NSUnarchiver unarchiveObjectWithData: d];
166
174
  l = [[i methodSignature] methodReturnLength];
 
175
  if (l < sizeof(void *))
 
176
    l = sizeof(void *);
167
177
  b = (void *)objc_malloc(l);
168
178
  [i getReturnValue: b];
169
179
  [inv setReturnValue: b];
170
180
  objc_free(b);
171
181
}
 
182
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
 
183
{
 
184
  return [obj methodSignatureForSelector: aSelector];
 
185
}
172
186
@end
173
187
 
174
188
int
187
201
  float f;
188
202
  double        d;
189
203
  id            o;
190
 
  char* str;
 
204
  char          *str;
191
205
  NSInvocation  *inv;
192
206
  NSMethodSignature     *sig;
193
207
  Target                *t;
194
208
  id                    p;
195
209
  NSAutoreleasePool     *arp = [NSAutoreleasePool new];
196
210
 
 
211
printf("Starting\n");
197
212
  t = [Target new];
198
213
  p = [[MyProxy alloc] initWithTarget: t];
 
214
printf("Calling proxy\n");
 
215
[p loopInt: 1];
 
216
 
 
217
  printf("Testing NS_MESSAGE ... ");
 
218
  inv = NS_MESSAGE(t, loopInt: 5);
 
219
  [inv invoke];
 
220
  [inv getReturnValue: &i];
 
221
  if (i == 6)
 
222
    printf("OK\n");
 
223
  else
 
224
    printf("ERROR ... expecting 6 and got %d\n", i);
 
225
 
 
226
  printf("Testing NS_INVOCATION ... ");
 
227
  inv = NS_INVOCATION([Target class], loopInt: 7);
 
228
  [inv setTarget: t];
 
229
  [inv invoke];
 
230
  [inv getReturnValue: &i];
 
231
  if (i == 8)
 
232
    printf("OK\n");
 
233
  else
 
234
    printf("ERROR ... expecting 8 and got %d\n", i);
199
235
 
200
236
#define SETUP(X) \
201
237
  sig = [t methodSignatureForSelector: @selector(X)]; \
352
388
  d = [p loopDouble: 5.0];
353
389
  printf("forward: %.1f\n", d);
354
390
 
 
391
  SETUP(loopMulti:int:ch:);
 
392
  printf("Expect: 6.0, ");
 
393
  f = [p loopMulti: 3.0 int: 5.0  ch: 'a'];
 
394
  printf("forward: %.1f\n", f);
 
395
 
355
396
  SETUP(loopObject:);
356
397
  [inv setArgument: &p atIndex: 2];
357
398
  [inv invokeWithTarget: t];