1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7//
8//  layout.m
9//  bocktest
10//
11//  Created by Blaine Garst on 3/21/08.
12//  Copyright 2008 __MyCompanyName__. All rights reserved.
13//
14
15// TEST_CONFIG SDK=macosx
16// TEST_CFLAGS -framework Foundation
17
18#include <Foundation/Foundation.h>
19#include <objc/runtime.h>
20#include "test.h"
21
22@interface TestObject : NSObject {
23    int (^getInt)(void);
24    int object;
25}
26@property(copy) int (^getInt)(void);
27@end
28
29@implementation TestObject
30@synthesize getInt;
31@end
32
33
34int main() {
35    [[NSAutoreleasePool alloc] init];
36    if (! [NSGarbageCollector defaultCollector]) {
37        succeed(__FILE__);
38    }
39
40    TestObject *to = [[TestObject alloc] init];
41    //to = [NSCalendarDate new];
42    const uint8_t *layout = (const uint8_t *)class_getIvarLayout(*(Class *)to);
43    if (!layout) {
44        fail("no layout for class TestObject!!!");
45    }
46    //printf("layout is:\n");
47    int cursor = 0;
48    // we're looking for slot 1
49    int seeking = 1;
50    while (*layout) {
51        int skip = (*layout) >> 4;
52        int process = (*layout) & 0xf;
53        //printf("(%x) skip %d, process %d\n", (*layout), skip, process);
54        cursor += skip;
55        if ((cursor <= seeking) && ((cursor + process) > seeking)) {
56            succeed(__FILE__);
57        }
58        cursor += process;
59        ++layout;
60    }
61
62    fail("didn't scan slot %d\n", seeking);
63}
64