Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 102 lines (87 sloc) 2.585 kb
c768616 @rbultje Updates for C99-to-C89/MSVC converter.
authored
1 /*
2 * Unit test for compound literal C99-to-C89 replacement.
3 */
4
5 typedef struct AVRational { int num, den; } AVRational;
6 struct AVRational2 { int num; int den; char **test[3]; };
7 typedef struct AVRational2 AVRational2;
8 typedef struct AVRational4 AVRational4;
9 typedef struct { int num, den; struct AVRational test; } AVRational3;
10
b316095 @dwbuiten Moidfy test1 to test designated initializers that begin with a gap
dwbuiten authored
11 static AVRational gap_test() {
12 AVRational gap = { .den = 4 };
13 gap.num = 1;
14 return gap;
15 }
16
c768616 @rbultje Updates for C99-to-C89/MSVC converter.
authored
17 static AVRational call_function_2(AVRational x)
18 {
19 AVRational y = (struct AVRational) { x.den, x.num };
75c0eee @rbultje Initial compound literal parsing work.
authored
20 int z = -1; // unused
21 y = (AVRational) { y.den, y.num };
22 if (z == 0)
23 return (AVRational) { 5, -5 };
24 else
25 return x.num > 0 ? (AVRational) { x.num, x.den } :
26 x.den > 0 ? (AVRational) { x.den, x.num } :
27 (AVRational) { 0, 0 };
c768616 @rbultje Updates for C99-to-C89/MSVC converter.
authored
28 }
29
7e65c7c @rbultje Make unit test slightly more complex.
authored
30 static int call_function_3(AVRational x)
31 {
32 return x.num ^ x.den;
33 }
34
c768616 @rbultje Updates for C99-to-C89/MSVC converter.
authored
35 static int call_function(AVRational x)
36 {
37 AVRational y = x.num > 0 ? call_function_2((AVRational) { x.num, x.den }) :
38 x.den > 0 ? call_function_2((AVRational) { x.den, x.num }) :
39 call_function_2((AVRational) { 0, 0 });
7e65c7c @rbultje Make unit test slightly more complex.
authored
40 int res;
41
42 if ((res = call_function_3((AVRational) { 5, -5 }) > 0)) {
b85e9ed @rbultje Count direct parent tree branches in traversal code.
authored
43 return ((AVRational) { -8, 8 }).den;
d5a8cbc @rbultje Add two more failing test cases based on avconv.c.
authored
44 } else if (1 && (res = call_function_3((AVRational) { 6, -6 }) > 0)) {
75c0eee @rbultje Initial compound literal parsing work.
authored
45 return call_function_3((AVRational) { -5, 5 });
d5a8cbc @rbultje Add two more failing test cases based on avconv.c.
authored
46 } else
47 return 0;
c768616 @rbultje Updates for C99-to-C89/MSVC converter.
authored
48 }
49
50 #define lut_vals(x) x, x+1, x+2, x+3
51 #define lut(x) { lut_vals(x), lut_vals(x+4) }
52 static const int l[][8] = {
53 lut(0),
54 lut(16),
55 lut(32),
56 lut(48)
57 };
58
d51eb2e @rbultje Add code to detect constant compound literals.
authored
59 typedef struct AVCodec {
60 int (*decode) (AVRational x);
61 const int *samplefmts;
62 } AVCodec;
63
64 static AVCodec decoder = {
65 .samplefmts = (const int[]) { 0, 1 },
66 .decode = call_function,
67 };
68
bfa7811 @rbultje Support designated initializers in compound literals.
authored
69 typedef struct AVFilterPad {
70 const char *name;
71 } AVFilterPad;
72
73 typedef struct AVFilter {
74 const char *name;
75 const AVFilterPad *inputs;
76 } AVFilter;
77
78 AVFilter filter = {
79 .name = "filter",
80 .inputs = (const AVFilterPad[]) {{.name="pad",},{.name=(void*)0,},},
81 };
82
c768616 @rbultje Updates for C99-to-C89/MSVC converter.
authored
83 int main(int argc, char *argv[])
84 {
85 int var;
86
93ba791 @rbultje Differentiate values in test1 slightly so it becomes easier to debug.
authored
87 #define X 3
02766cc @rbultje Handle switch/default statements correctly also.
authored
88 switch (call_function((AVRational){1, 1})) {
d5a8cbc @rbultje Add two more failing test cases based on avconv.c.
authored
89 case 0:
90 call_function((AVRational){2, 2});
91 break;
02766cc @rbultje Handle switch/default statements correctly also.
authored
92 default:
93 call_function((AVRational){3, 3});
94 break;
d5a8cbc @rbultje Add two more failing test cases based on avconv.c.
authored
95 }
d51eb2e @rbultje Add code to detect constant compound literals.
authored
96 var = ((const int[2]){1,2})[argc];
c768616 @rbultje Updates for C99-to-C89/MSVC converter.
authored
97 var = call_function((AVRational){1, 2});
98 if (var == 0) return call_function((AVRational){X, 2});
99 else return call_function((AVRational){2, X});
100 #undef X
101 }
Something went wrong with that request. Please try again.