
1 changed files with 221 additions and 0 deletions
@ -0,0 +1,221 @@ |
|||||
|
#!/usr/bin/env python3 |
||||
|
# -*- coding: utf-8 -*- |
||||
|
# This file is under GNU Affero General Public License 3.0 |
||||
|
# see LICENSE.txt |
||||
|
import pytest |
||||
|
|
||||
|
from gen_cid import utils |
||||
|
import gen_cid |
||||
|
|
||||
|
types_with_alias = [] |
||||
|
types_no_alias = [] |
||||
|
types_no_alias.append({"var": ["_P"], |
||||
|
"type_names": [ |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_E"], |
||||
|
"type_names": [ |
||||
|
"enum _E" |
||||
|
]}) |
||||
|
|
||||
|
types_with_alias.append({"var": ["E"], |
||||
|
"type_names": [ |
||||
|
"enum E" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_PS"], |
||||
|
"type_names": [ |
||||
|
"struct _PS" |
||||
|
]}) |
||||
|
|
||||
|
types_with_alias.append({"var": ["PS"], |
||||
|
"type_names": [ |
||||
|
"struct PS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_CS"], |
||||
|
"type_names": [ |
||||
|
"struct _CS", |
||||
|
"struct PS", |
||||
|
"struct _PS" |
||||
|
]}) |
||||
|
|
||||
|
types_with_alias.append({"var": ["CS"], |
||||
|
"type_names": [ |
||||
|
"struct CS", |
||||
|
"struct _PS", |
||||
|
"struct PS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_CCS"], |
||||
|
"type_names": [ |
||||
|
"struct _CCS", |
||||
|
"struct CS", |
||||
|
"struct _PS", |
||||
|
"struct PS" |
||||
|
]}) |
||||
|
|
||||
|
types_with_alias.append({"var": ["CCS"], |
||||
|
"type_names": [ |
||||
|
"struct CCS", |
||||
|
"struct CS", |
||||
|
"struct _PS", |
||||
|
"struct PS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_HS"], |
||||
|
"type_names": [ |
||||
|
"struct _HS", |
||||
|
"struct _NCS", |
||||
|
"struct CS", |
||||
|
"struct _PS", |
||||
|
"struct PS" |
||||
|
]}) |
||||
|
|
||||
|
types_with_alias.append({"var": ["HS"], |
||||
|
"type_names": [ |
||||
|
"struct HS", |
||||
|
"struct _NPS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NCS"], |
||||
|
"type_names": [ |
||||
|
"struct _NCS", |
||||
|
"struct CS", |
||||
|
"struct _PS", |
||||
|
"struct PS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NPS"], |
||||
|
"type_names": [ |
||||
|
"struct _NPS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_HHS"], |
||||
|
"type_names": [ |
||||
|
"struct _HHS", |
||||
|
"struct _NHS", |
||||
|
"struct _NNPS" |
||||
|
]}) |
||||
|
|
||||
|
types_with_alias.append({"var": ["HHS"], |
||||
|
"type_names": [ |
||||
|
"struct HHS", |
||||
|
"struct _NHS1", |
||||
|
"struct _NNCS", |
||||
|
"struct _CS", |
||||
|
"struct PS", |
||||
|
"struct _PS", |
||||
|
"enum _NENHS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NHS"], |
||||
|
"type_names": [ |
||||
|
"struct _NHS", |
||||
|
"struct _NNPS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NNPS"], |
||||
|
"type_names": [ |
||||
|
"struct _NNPS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NHS1"], |
||||
|
"type_names": [ |
||||
|
"struct _NHS1", |
||||
|
"struct _NNCS", |
||||
|
"struct _CS", |
||||
|
"struct PS", |
||||
|
"struct _PS", |
||||
|
"enum _NENHS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NNCS"], |
||||
|
"type_names": [ |
||||
|
"struct _NNCS", |
||||
|
"struct _CS", |
||||
|
"struct PS", |
||||
|
"struct _PS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NENHS"], |
||||
|
"type_names": [ |
||||
|
"enum _NENHS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_HS1"], |
||||
|
"type_names": [ |
||||
|
"struct _HS1", |
||||
|
"enum _NEHS" |
||||
|
]}) |
||||
|
|
||||
|
types_no_alias.append({"var": ["_NEHS"], |
||||
|
"type_names": [ |
||||
|
"enum _NEHS" |
||||
|
]}) |
||||
|
|
||||
|
|
||||
|
def resolve_vars_and_funcs_to_cid(vars, funcs): |
||||
|
header_filename = "examples/lib/test_cid/test_lib.h" |
||||
|
libclang_path = "/opt/local/libexec/llvm-9.0/lib/libclang.dylib" |
||||
|
cidtools = gen_cid.CIDTools(libclang_path, header_filename, "test_cid") |
||||
|
header = cidtools.extract(vars,funcs) |
||||
|
|
||||
|
return header["cid"] |
||||
|
|
||||
|
|
||||
|
def check_expected_types_resolved(vars, funcs, type_names_expected): |
||||
|
print("RESOLVING: ", vars, funcs) |
||||
|
cid = resolve_vars_and_funcs_to_cid(vars, funcs) |
||||
|
|
||||
|
# Check on unresolved vars |
||||
|
assert len(cid["vars_notfound"]) == 0, "vars not found" |
||||
|
|
||||
|
# Check on unresolved functions |
||||
|
assert len(cid["functions_notfound"]) == 0, "vars not found" |
||||
|
|
||||
|
# Check on unresolved typerefs |
||||
|
assert len(cid["typerefs_notfound"]) == 0, "vars not found" |
||||
|
|
||||
|
type_names = cid["type_names"] |
||||
|
# test for no dup types |
||||
|
for tn in type_names: |
||||
|
assert type_names.count(tn) == 1, "duplicate type" |
||||
|
|
||||
|
type_names.sort() |
||||
|
type_names_expected.sort() |
||||
|
|
||||
|
# test expected types match in no specific order |
||||
|
# print("GOT: ", type_names) |
||||
|
# print("EXPECTED: ", type_names_expected) |
||||
|
assert type_names == type_names_expected |
||||
|
|
||||
|
|
||||
|
@pytest.mark.skip |
||||
|
@pytest.mark.parametrize('vars', [["var_TP"]]) |
||||
|
@pytest.mark.parametrize('funcs', [""]) |
||||
|
def test_manual(vars, funcs): |
||||
|
resolve_vars_and_funcs_to_cid(vars, funcs) |
||||
|
|
||||
|
|
||||
|
# @pytest.mark.skip |
||||
|
@pytest.mark.parametrize('variation', ["var_", "var_A", "var_T", "var_TA", "var_TT", "var_TTA"]) |
||||
|
@pytest.mark.parametrize('data', types_with_alias) |
||||
|
def test_single_var_with_alias(data, variation): |
||||
|
var_list = [] |
||||
|
for var in data["var"]: |
||||
|
var_name = variation + var |
||||
|
var_list.append(var_name) |
||||
|
|
||||
|
check_expected_types_resolved(var_list, [], data["type_names"]) |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize('variation', ["var_", "var_T", "var_TT"]) |
||||
|
@pytest.mark.parametrize('data', types_no_alias) |
||||
|
def test_single_var_no_alias(data, variation): |
||||
|
var_list = [] |
||||
|
for var in data["var"]: |
||||
|
var_name = variation + var |
||||
|
var_list.append(var_name) |
||||
|
|
||||
|
check_expected_types_resolved(var_list, [], data["type_names"]) |
Loading…
Reference in new issue