-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.m
145 lines (120 loc) · 2.53 KB
/
test.m
1
2
3
4
5
6
7
8
9
10
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
56
57
58
59
60
61
62
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
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
#import "JAValueToString.h"
#import <complex.h>
#import <CoreGraphics/CoreGraphics.h>
typedef int(*MyFunc)(CGRect r);
typedef int(^MyBlock)(CGRect r);
#if defined(__has_feature) && __has_feature(objc_arc)
#define USING_ARC 1
#define AUTORELEASE_ENTER @autoreleasepool {
#define AUTORELEASE_EXIT }
#else
#define USING_ARC 0
#define AUTORELEASE_ENTER { NSAutoreleasePool *autoreleasePool__ = [NSAutoreleasePool new];
#define AUTORELEASE_EXIT [autoreleasePool__ drain]; }
#endif
typedef union MyUnion
{
double b[6];
CGRect a;
} MyUnion;
typedef struct MyStruct
{
char c2;
complex double x;
unsigned char y;
_Bool flag;
#if !USING_ARC
NSString *s;
#endif
Class cls;
const char * const str;
int * a;
void *v;
CGRect *r;
CGRect r2;
short saf;
struct { int a; } anon;
struct { float a; } *anonp;
SEL ector;
int array[5];
MyUnion uni;
MyFunc fu;
#if !USING_ARC
MyBlock bl;
#endif
int fcc;
} MyStruct;
typedef struct MyStruct2
{
short a;
short c;
char b;
} MyStruct2;
int main (int argc, const char * argv[])
{
AUTORELEASE_ENTER
CGRect r = { 1, 2, 3, 4 };
int a = 42;
MyUnion u = { .a = r };
MyStruct testCase =
{
.c2 = 'A',
.x = 6 + 8 * _Complex_I,
.y = '7',
.flag = false,
#if !USING_ARC
.s = @"an NSString",
#endif
.cls = [NSArray class],
.str = "a C string",
.a = &a,
.v = &a,
.r = &r,
.r2 = r,
.saf = 123,
.ector = @selector(substringFromIndex:),
.uni = u,
.fcc = 'aFCC'
};
JA_DUMP(testCase);
/* Test case for size calculations.
The parser will find this to be 7 bytes long, but the "expected size"
from sizeof is rounded up to a multiple of the largest aligment of any
element. This case should be handled properly by JAValueToString().
*/
MyStruct2 alignmentTest = {0};
JA_DUMP(alignmentTest);
int integer = 768;
JA_DUMP(integer);
const char *string = "This am an string.";
JA_DUMP(string);
JA_DUMP("This, too, is a string.");
complex double complexDouble = 1 - 2 * _Complex_I;
JA_DUMP(complexDouble);
/* Previous failure case: calculation of alignment is dependent on the
highest-alignment field of the inner struct, i.e. c.
*/
struct NestedAlignmentTest
{
int16_t a;
struct
{
int16_t b;
int64_t c;
} s;
} nestedAlignmentTest = { 1, { 2, 3 } };
JA_DUMP(nestedAlignmentTest);
#if 0
// Known failure case: bitfields are not supported.
struct BitfieldTest
{
int bitfield: 4;
} bitfieldTestFAIL;
JA_DUMP(bitfieldTestFAIL);
#endif
int array[5] = { 1, 2, 3, 4, 5 };
JA_DUMP(array);
NSLog(@"Done.");
AUTORELEASE_EXIT
return 0;
}