]> git.saurik.com Git - apple/objc4.git/blob - test/methodListSize.m
objc4-756.2.tar.gz
[apple/objc4.git] / test / methodListSize.m
1 // TEST_CONFIG
2 // rdar://8052003 rdar://8077031
3
4 #include "test.h"
5
6 #include <malloc/malloc.h>
7 #include <objc/runtime.h>
8
9 // add SELCOUNT methods to each of CLASSCOUNT classes
10 #define CLASSCOUNT 100
11 #define SELCOUNT 200
12
13 int main()
14 {
15 int i, j;
16 malloc_statistics_t start, end;
17
18 Class root;
19 root = objc_allocateClassPair(NULL, "Root", 0);
20 objc_registerClassPair(root);
21
22 Class classes[CLASSCOUNT];
23 for (i = 0; i < CLASSCOUNT; i++) {
24 char *classname;
25 asprintf(&classname, "GrP_class_%d", i);
26 classes[i] = objc_allocateClassPair(root, classname, 0);
27 objc_registerClassPair(classes[i]);
28 free(classname);
29 }
30
31 SEL selectors[SELCOUNT];
32 for (i = 0; i < SELCOUNT; i++) {
33 char *selname;
34 asprintf(&selname, "GrP_sel_%d", i);
35 selectors[i] = sel_registerName(selname);
36 free(selname);
37 }
38
39 malloc_zone_statistics(NULL, &start);
40
41 for (i = 0; i < CLASSCOUNT; i++) {
42 for (j = 0; j < SELCOUNT; j++) {
43 class_addMethod(classes[i], selectors[j], (IMP)main, "");
44 }
45 }
46
47 malloc_zone_statistics(NULL, &end);
48
49 // expected: 3-word method struct plus two other words
50 ssize_t expected = (sizeof(void*) * (3+2)) * SELCOUNT * CLASSCOUNT;
51 ssize_t actual = end.size_in_use - start.size_in_use;
52 testassert(actual < expected * 3); // allow generous fudge factor
53
54 succeed(__FILE__);
55 }
56