File: test_attributes.py

package info (click to toggle)
pygccxml 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,444 kB
  • sloc: xml: 29,841; python: 13,914; cpp: 2,671; makefile: 163; ansic: 59
file content (66 lines) | stat: -rw-r--r-- 1,975 bytes parent folder | download
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
# 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 = [
    # TODO: once gccxml is removed; rename this to something like
    # annotate_tester
    "attributes_castxml.hpp",
]


@pytest.fixture
def global_ns():
    COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
    INIT_OPTIMIZER = True
    config = autoconfig.cxx_parsers_cfg.config.clone()
    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 test_attributes(global_ns):
    numeric = global_ns.class_('numeric_t')
    do_nothing = numeric.member_function('do_nothing')
    arg = do_nothing.arguments[0]
    assert "annotate(sealed)" == numeric.attributes
    assert "annotate(no throw)" == do_nothing.attributes
    assert "annotate(out)" == arg.attributes
    assert numeric.member_operators(name="=")[0].attributes is None


def test_attributes_thiscall():
    """
    Test attributes with the "f2" flag

    """

    COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
    config = autoconfig.cxx_parsers_cfg.config.clone()

    config.flags = ["f2"]
    config.castxml_epic_version = 1

    decls = parser.parse(TEST_FILES, config, COMPILATION_MODE)
    global_ns = declarations.get_global_namespace(decls)
    global_ns.init_optimizer()

    numeric = global_ns.class_('numeric_t')
    do_nothing = numeric.member_function('do_nothing')
    arg = do_nothing.arguments[0]

    assert "annotate(sealed)" == numeric.attributes
    assert "annotate(out)" == arg.attributes

    assert "annotate(no throw)" == do_nothing.attributes
    assert numeric.member_operators(name="=")[0].attributes is None