v2 / vlib / v / tests / builtin_arrays / array_fixed_c_test.c.v
39 lines · 35 sloc · 692 bytes · 94f0f6d93b6de115f748c151ea2e7c2ee1abe2b0
Raw
1#include "@VMODROOT/vlib/v/gen/c/testdata/multiple_c_cources/file3.c"
2
3@[typedef]
4struct C.CStruct {
5mut:
6 c char
7 i int
8 f f32
9}
10
11type C.PCStruct = &C.CStruct
12
13struct WrapperStruct {
14mut:
15 arr_fixed_c_type [2]C.PCStruct
16}
17
18fn test_main() {
19 s1 := &C.CStruct{
20 c: char(`A`)
21 f: 3.14
22 i: 42
23 }
24 s2 := &C.CStruct{
25 c: char(`B`)
26 f: 1.4142
27 i: 2
28 }
29 mut w := WrapperStruct{}
30 w.arr_fixed_c_type[0] = s1
31 w.arr_fixed_c_type[1] = s2
32 dump(w)
33 assert w.arr_fixed_c_type[0].c == char(`A`)
34 assert w.arr_fixed_c_type[1].c == char(`B`)
35 assert w.arr_fixed_c_type[0].f == 3.14
36 assert w.arr_fixed_c_type[1].f == 1.4142
37 assert w.arr_fixed_c_type[0].i == 42
38 assert w.arr_fixed_c_type[1].i == 2
39}
40