File: test_vector_traits.py

package info (click to toggle)
pygccxml 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,444 kB
  • sloc: xml: 29,841; python: 13,914; cpp: 2,671; makefile: 163; ansic: 59
file content (88 lines) | stat: -rw-r--r-- 2,761 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright 2014-2017 Insight Software Consortium.
# Copyright 2004-2009 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import pytest

from . import autoconfig

from pygccxml import parser
from pygccxml import declarations


TEST_FILES = [
    "vector_traits.hpp",
]


@pytest.fixture
def global_ns():
    COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
    INIT_OPTIMIZER = True
    config = autoconfig.cxx_parsers_cfg.config.clone()
    # TOOD: this breaks the tests, check why
    # config.castxml_epic_version = 1
    decls = parser.parse(TEST_FILES, config, COMPILATION_MODE)
    global_ns = declarations.get_global_namespace(decls)
    if INIT_OPTIMIZER:
        global_ns.init_optimizer()
    return global_ns


def validate_yes(value_type, container):
    traits = declarations.vector_traits
    assert traits.is_my_case(container) is True
    assert declarations.is_same(
            value_type,
            traits.element_type(container)) is True
    assert traits.is_sequence(container) is True


def test_global_ns(global_ns):
    value_type = global_ns.class_('_0_')
    container = global_ns.typedef('container', recursive=False)
    validate_yes(value_type, container)


def test_yes(global_ns):
    yes_ns = global_ns.namespace('yes')
    for struct in yes_ns.classes():
        if not struct.name.startswith('_'):
            continue
        if not struct.name.endswith('_'):
            continue
        validate_yes(
            struct.typedef('value_type'),
            struct.typedef('container'))


def test_no(global_ns):
    traits = declarations.vector_traits
    no_ns = global_ns.namespace('no')
    for struct in no_ns.classes():
        if not struct.name.startswith('_'):
            continue
        if not struct.name.endswith('_'):
            continue
        assert traits.is_my_case(struct.typedef('container')) is False


def test_declaration():
    cnt = (
        'std::vector<std::basic_string<char, std::char_traits<char>, ' +
        'std::allocator<char>>,std::allocator<std::basic_string<char, ' +
        'std::char_traits<char>, std::allocator<char>>>>' +
        '@::std::vector<std::basic_string<char, std::char_traits<char>, ' +
        'std::allocator<char>>, std::allocator<std::basic_string<char, ' +
        'std::char_traits<char>, std::allocator<char>>>>')
    traits = declarations.find_container_traits(cnt)
    assert declarations.vector_traits == traits


def test_element_type(global_ns):
    do_nothing = global_ns.free_function('do_nothing')
    v = declarations.remove_reference(
        declarations.remove_declarated(
            do_nothing.arguments[0].decl_type))
    declarations.vector_traits.element_type(v)