Skip to content

Commit 5dd92b7

Browse files
committed
Integration tests: Test arrays
1 parent 4eaabba commit 5dd92b7

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

test/integration/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Add new test definition files to this list:
22
set(INTEGRATION_TEST_CONFIGS
33
anonymous.toml
4+
arrays.toml
45
container_enums.toml
56
cycles.toml
67
enums.toml

test/integration/arrays.toml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
definitions = '''
2+
struct Foo10 {
3+
int arr[10];
4+
};
5+
struct Foo0 {
6+
int arr[0];
7+
};
8+
struct MultiDim {
9+
int arr[2][3];
10+
};
11+
'''
12+
[cases]
13+
[cases.member_int10]
14+
param_types = ["const Foo10&"]
15+
setup = "return {};"
16+
expect_json = '''[{
17+
"staticSize":40,
18+
"dynamicSize":0,
19+
"members":[{
20+
"staticSize":40,
21+
"dynamicSize":0,
22+
"length":10,
23+
"capacity":10,
24+
"elementStaticSize":4
25+
}]}]'''
26+
[cases.member_int0]
27+
# WARNING: zero-length arrays are handled differently to non-empty arrays.
28+
# They end up not being treated as containers. This should probably change
29+
# in the future.
30+
param_types = ["const Foo0&"]
31+
setup = "return {};"
32+
expect_json = '''[{
33+
"staticSize":0,
34+
"dynamicSize":0,
35+
"members":[{
36+
"staticSize":0,
37+
"dynamicSize":0
38+
}]}]'''
39+
[cases.multidim]
40+
param_types = ["const MultiDim&"]
41+
setup = "return {};"
42+
expect_json = '''[{
43+
"staticSize":24,
44+
"dynamicSize":0,
45+
"members":[{
46+
"staticSize":24,
47+
"dynamicSize":0,
48+
"length":6,
49+
"capacity":6,
50+
"elementStaticSize":4
51+
}]}]'''
52+
[cases.direct_int10]
53+
skip = "Direct array arguments don't work"
54+
param_types = ["int[10]"]
55+
setup = "return {};"
56+
expect_json = '[{"staticSize":40, "dynamicSize":0, "length":10, "capacity":10, "elementStaticSize":4}]'
57+
[cases.direct_int0]
58+
skip = "Direct array arguments don't work"
59+
# WARNING: zero-length arrays are handled differently to non-empty arrays.
60+
# They end up not being treated as containers. This should probably change
61+
# in the future.
62+
param_types = ["int[0]"]
63+
setup = "return {};"
64+
expect_json = '[{"staticSize":0, "dynamicSize":0}]'
65+
[cases.ref_int10]
66+
skip = "CodeGen bug with array reference arguments"
67+
param_types = ["const int(&)[10]"]
68+
setup = "return {};"
69+
expect_json = '[{"staticSize":40, "dynamicSize":0, "length":10, "capacity":10, "elementStaticSize":4}]'
70+
[cases.ref_int0]
71+
skip = "CodeGen bug with array reference arguments"
72+
# WARNING: zero-length arrays are handled differently to non-empty arrays.
73+
# They end up not being treated as containers. This should probably change
74+
# in the future.
75+
param_types = ["const int(&)[0]"]
76+
setup = "return {};"
77+
expect_json = '[{"staticSize":0, "dynamicSize":0}]'

test/integration/gen_tests.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ def add_test_setup(f, config):
6161

6262
# fmt: on
6363

64+
def get_param_str(param, i):
65+
if "]" in param:
66+
# Array param
67+
68+
if ")" in param:
69+
# "int(&)[5]" -> "int (&a0)[5]"
70+
start, end = param.split(")")
71+
return f"{start}a{i}){end}"
72+
73+
# "int[5]" -> "int a0[5]"
74+
# "int[5][10]" -> "int a0[5][10]"
75+
type_name, array_size = param.split("[", 1)
76+
return f"{type_name} a{i}[{array_size}"
77+
78+
# Non-array param, e.g. "int&" -> "int& a0"
79+
return f"{param} a{i}"
80+
6481
def define_traceable_func(name, params, body):
6582
return (
6683
f"\n"
@@ -91,7 +108,7 @@ def define_traceable_func(name, params, body):
91108

92109
# generate oid and oil targets
93110
params_str = ", ".join(
94-
f"{param} a{i}" for i, param in enumerate(case["param_types"])
111+
get_param_str(param, i) for i, param in enumerate(case["param_types"])
95112
)
96113

97114
oid_func_body = "".join(

0 commit comments

Comments
 (0)