| 1 |
/* Contributed by Nicola Pero on Tue Mar 6 23:05:53 CET 2001 */ |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include "../../objc-obj-c++-shared/runtime.h" |
| 5 |
|
| 6 |
/* |
| 7 |
* Standard Tests For Methods of Classes and Objects - abort upon |
| 8 |
* failing; return normally if all is well. |
| 9 |
*/ |
| 10 |
|
| 11 |
/* Test that `class' has an instance method for the selector `selector' */ |
| 12 |
void test_that_class_has_instance_method (const char *class_name, |
| 13 |
SEL selector) |
| 14 |
{ |
| 15 |
Class class = objc_getClass (class_name); |
| 16 |
|
| 17 |
if (class_getInstanceMethod (class, selector) == NULL) |
| 18 |
{ |
| 19 |
printf ("test_class_has_instance_method failed\n"); |
| 20 |
abort (); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
/* Test that `class' has a class method for the selector `selector' */ |
| 25 |
void test_that_class_has_class_method (const char *class_name, |
| 26 |
SEL selector) |
| 27 |
{ |
| 28 |
Class class = objc_getClass (class_name); |
| 29 |
|
| 30 |
if (class_getClassMethod (class, selector) == NULL) |
| 31 |
{ |
| 32 |
printf ("test_class_has_class_method failed\n"); |
| 33 |
abort (); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
/* Test the accessor methods (called -state and -setState:) on the |
| 38 |
object `object'. */ |
| 39 |
#ifdef TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD |
| 40 |
void test_accessor_method (TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD object, |
| 41 |
int initial_state, |
| 42 |
int new_state_0, int expected_result_0, |
| 43 |
int new_state_1, int expected_result_1) |
| 44 |
{ |
| 45 |
if ([object state] != initial_state) |
| 46 |
{ |
| 47 |
printf ("test_accessor_method (initial state) failed\n"); |
| 48 |
abort (); |
| 49 |
} |
| 50 |
|
| 51 |
[object setState: new_state_0]; |
| 52 |
if ([object state] != expected_result_0) |
| 53 |
{ |
| 54 |
printf ("test_accessor_method (new_state_0) failed\n"); |
| 55 |
abort (); |
| 56 |
} |
| 57 |
|
| 58 |
[object setState: new_state_1]; |
| 59 |
if ([object state] != expected_result_1) |
| 60 |
{ |
| 61 |
printf ("test_accessor_method (new_state_1) failed\n"); |
| 62 |
abort (); |
| 63 |
} |
| 64 |
} |
| 65 |
#endif /* CLASS_WITH_ACCESSOR_METHOD */ |
| 66 |
|
| 67 |
|