validation and marshaling of structs/unions
[m6w6/ext-psi] / tests / parser / validate001.phpt
1 --TEST--
2 validate types
3 --SKIPIF--
4 <?php
5 extension_loaded("psi") or die("skip - need ext/psi");
6 ?>
7 --FILE--
8 ===TEST===
9 <?php
10 function validate($check, $psi) {
11 $file = __DIR__."/001.psi";
12 file_put_contents($file, $psi);
13 if ($check !== psi_validate($file)) {
14 printf("Assertion failed!\nExpected: %s\n\n%s\n\n",
15 $check ? "true" : "false", $psi);
16 }
17 }
18
19 validate(false, "typedef void foo;");
20 validate(true, "typedef void *bar;");
21 validate(false, "typedef long int;");
22 validate(true, "typedef long foo;");
23 validate(false, "typedef struct foo bar;");
24 validate(true, "typedef struct {int a;} foo;");
25 validate(false, "struct a; \ntypedef struct a a_t;");
26 validate(true, "struct a::(8,8); \ntypedef struct a a_t;");
27 validate(true, "typedef struct a a_t; \nstruct a::(8,8);");
28
29 validate(true,
30 <<<PSI
31 enum {
32 A,
33 B,
34 C
35 }
36 PSI
37 );
38 validate(false,
39 <<<PSI
40 enum {
41 A,
42 B = A + 2,
43 C = X
44 }
45 PSI
46 );
47
48 validate(true,
49 <<<PSI
50 struct a {
51 int i;
52 }
53 struct b {
54 long l;
55 }
56 typedef struct b b;
57 union v {
58 struct a a;
59 b b;
60 struct {
61 double d;
62 } s;
63 union {
64 long l;
65 double d;
66 } u;
67 }
68 PSI
69 );
70
71 validate(true, "typedef int foo(int bar);");
72 validate(true, "typedef int (foo)(int bar);");
73 validate(true, "typedef int (*foo)(int bar);");
74 validate(true, "typedef int *(*foo)(int bar);");
75 validate(false, "typedef int *(*foo)(int *(*bar)(int baz));");
76 validate(true, "typedef int *(*bar)(int baz); \ntypedef int *(*foo)(bar bar);");
77 validate(true, "typedef int bar(int baz); \ntypedef int *(*foo)(bar bar);");
78
79 ?>
80 ===DONE===
81 --CLEAN--
82 <?php
83 @unlink(__DIR__."/001.psi");
84 ?>
85 --EXPECTF--
86 ===TEST===
87
88 Warning: PSI syntax error: Unexpected token ';' at pos 17 in %s001.psi on line 1
89
90 Warning: PSI syntax error: Unexpected token 'int' at pos 14 in %s001.psi on line 1
91
92 Warning: Type 'bar' cannot be aliased to struct 'foo' in %s001.psi on line 1
93
94 Warning: Cannot compute size of empty struct 'a' in %s001.psi on line 1
95
96 Warning: Unknown variable 'X' in numeric expression in %s001.psi on line 4
97
98 Warning: PSI syntax error: Unexpected token '(' at pos 26 in %s001.psi on line 1
99 ===DONE===