mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-12 21:56:54 +00:00
Integration tests: Test arrays
This commit is contained in:
parent
4eaabbab84
commit
5dd92b7f7f
@ -1,6 +1,7 @@
|
||||
# Add new test definition files to this list:
|
||||
set(INTEGRATION_TEST_CONFIGS
|
||||
anonymous.toml
|
||||
arrays.toml
|
||||
container_enums.toml
|
||||
cycles.toml
|
||||
enums.toml
|
||||
|
77
test/integration/arrays.toml
Normal file
77
test/integration/arrays.toml
Normal file
@ -0,0 +1,77 @@
|
||||
definitions = '''
|
||||
struct Foo10 {
|
||||
int arr[10];
|
||||
};
|
||||
struct Foo0 {
|
||||
int arr[0];
|
||||
};
|
||||
struct MultiDim {
|
||||
int arr[2][3];
|
||||
};
|
||||
'''
|
||||
[cases]
|
||||
[cases.member_int10]
|
||||
param_types = ["const Foo10&"]
|
||||
setup = "return {};"
|
||||
expect_json = '''[{
|
||||
"staticSize":40,
|
||||
"dynamicSize":0,
|
||||
"members":[{
|
||||
"staticSize":40,
|
||||
"dynamicSize":0,
|
||||
"length":10,
|
||||
"capacity":10,
|
||||
"elementStaticSize":4
|
||||
}]}]'''
|
||||
[cases.member_int0]
|
||||
# WARNING: zero-length arrays are handled differently to non-empty arrays.
|
||||
# They end up not being treated as containers. This should probably change
|
||||
# in the future.
|
||||
param_types = ["const Foo0&"]
|
||||
setup = "return {};"
|
||||
expect_json = '''[{
|
||||
"staticSize":0,
|
||||
"dynamicSize":0,
|
||||
"members":[{
|
||||
"staticSize":0,
|
||||
"dynamicSize":0
|
||||
}]}]'''
|
||||
[cases.multidim]
|
||||
param_types = ["const MultiDim&"]
|
||||
setup = "return {};"
|
||||
expect_json = '''[{
|
||||
"staticSize":24,
|
||||
"dynamicSize":0,
|
||||
"members":[{
|
||||
"staticSize":24,
|
||||
"dynamicSize":0,
|
||||
"length":6,
|
||||
"capacity":6,
|
||||
"elementStaticSize":4
|
||||
}]}]'''
|
||||
[cases.direct_int10]
|
||||
skip = "Direct array arguments don't work"
|
||||
param_types = ["int[10]"]
|
||||
setup = "return {};"
|
||||
expect_json = '[{"staticSize":40, "dynamicSize":0, "length":10, "capacity":10, "elementStaticSize":4}]'
|
||||
[cases.direct_int0]
|
||||
skip = "Direct array arguments don't work"
|
||||
# WARNING: zero-length arrays are handled differently to non-empty arrays.
|
||||
# They end up not being treated as containers. This should probably change
|
||||
# in the future.
|
||||
param_types = ["int[0]"]
|
||||
setup = "return {};"
|
||||
expect_json = '[{"staticSize":0, "dynamicSize":0}]'
|
||||
[cases.ref_int10]
|
||||
skip = "CodeGen bug with array reference arguments"
|
||||
param_types = ["const int(&)[10]"]
|
||||
setup = "return {};"
|
||||
expect_json = '[{"staticSize":40, "dynamicSize":0, "length":10, "capacity":10, "elementStaticSize":4}]'
|
||||
[cases.ref_int0]
|
||||
skip = "CodeGen bug with array reference arguments"
|
||||
# WARNING: zero-length arrays are handled differently to non-empty arrays.
|
||||
# They end up not being treated as containers. This should probably change
|
||||
# in the future.
|
||||
param_types = ["const int(&)[0]"]
|
||||
setup = "return {};"
|
||||
expect_json = '[{"staticSize":0, "dynamicSize":0}]'
|
@ -61,6 +61,23 @@ def add_test_setup(f, config):
|
||||
|
||||
# fmt: on
|
||||
|
||||
def get_param_str(param, i):
|
||||
if "]" in param:
|
||||
# Array param
|
||||
|
||||
if ")" in param:
|
||||
# "int(&)[5]" -> "int (&a0)[5]"
|
||||
start, end = param.split(")")
|
||||
return f"{start}a{i}){end}"
|
||||
|
||||
# "int[5]" -> "int a0[5]"
|
||||
# "int[5][10]" -> "int a0[5][10]"
|
||||
type_name, array_size = param.split("[", 1)
|
||||
return f"{type_name} a{i}[{array_size}"
|
||||
|
||||
# Non-array param, e.g. "int&" -> "int& a0"
|
||||
return f"{param} a{i}"
|
||||
|
||||
def define_traceable_func(name, params, body):
|
||||
return (
|
||||
f"\n"
|
||||
@ -91,7 +108,7 @@ def add_test_setup(f, config):
|
||||
|
||||
# generate oid and oil targets
|
||||
params_str = ", ".join(
|
||||
f"{param} a{i}" for i, param in enumerate(case["param_types"])
|
||||
get_param_str(param, i) for i, param in enumerate(case["param_types"])
|
||||
)
|
||||
|
||||
oid_func_body = "".join(
|
||||
|
Loading…
Reference in New Issue
Block a user