Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 0 additions & 103 deletions tests/parser_test_case.py

This file was deleted.

89 changes: 36 additions & 53 deletions tests/test_algorithms_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,58 @@
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import unittest
import pytest

from . import parser_test_case
from . import autoconfig

from pygccxml import parser
from pygccxml import declarations


class Test(parser_test_case.parser_test_case_t):
# tester source reader
COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE

def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.header = 'core_membership.hpp'
self.global_ns = None

def setUp(self):
decls = parser.parse([self.header], self.config)
self.xml_generator_from_xml_file = \
self.config.xml_generator_from_xml_file
self.global_ns = declarations.get_global_namespace(decls)

def test_name_based(self):
cls = self.global_ns.class_(name='class_for_nested_enums_t')
TEST_FILES = ['core_membership.hpp']

cls_full_name = declarations.full_name(cls)
self.assertTrue(cls.cache.full_name == cls_full_name)

cls_declaration_path = declarations.declaration_path(cls)
self.assertTrue(cls.cache.declaration_path == cls_declaration_path)

enum = cls.enumeration('ENestedPublic')

enum_full_name = declarations.full_name(enum)
self.assertTrue(enum.cache.full_name == enum_full_name)
@pytest.fixture
def global_ns():
COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
config = autoconfig.cxx_parsers_cfg.config.clone()
decls = parser.parse(TEST_FILES, config, COMPILATION_MODE)
global_ns = declarations.get_global_namespace(decls)
global_ns.init_optimizer()
return global_ns

enum_declaration_path = declarations.declaration_path(enum)
self.assertTrue(enum.cache.declaration_path == enum_declaration_path)

# now we change class name, all internal decls cache should be cleared
cls.name = "new_name"
self.assertTrue(not cls.cache.full_name)
self.assertTrue(not cls.cache.declaration_path)
def test_name_based(global_ns):
cls = global_ns.class_(name='class_for_nested_enums_t')

self.assertTrue(not enum.cache.full_name)
self.assertTrue(not enum.cache.declaration_path)
cls_full_name = declarations.full_name(cls)
assert cls.cache.full_name == cls_full_name

def test_access_type(self):
cls = self.global_ns.class_(name='class_for_nested_enums_t')
enum = cls.enumeration('ENestedPublic')
self.assertTrue(enum.cache.access_type == 'public')
enum.cache.reset_access_type()
self.assertTrue(not enum.cache.access_type)
self.assertTrue('public' == cls.find_out_member_access_type(enum))
self.assertTrue(enum.cache.access_type == 'public')
cls_declaration_path = declarations.declaration_path(cls)
assert cls.cache.declaration_path == cls_declaration_path

enum = cls.enumeration('ENestedPublic')

def create_suite():
suite = unittest.TestSuite()
suite.addTest(
unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test))
enum_full_name = declarations.full_name(enum)
assert enum.cache.full_name == enum_full_name

return suite
enum_declaration_path = declarations.declaration_path(enum)
assert enum.cache.declaration_path == enum_declaration_path

# now we change class name, all internal decls cache should be cleared
cls.name = "new_name"
assert not cls.cache.full_name
assert not cls.cache.declaration_path

def run_suite():
unittest.TextTestRunner(verbosity=2).run(create_suite())
assert not enum.cache.full_name
assert not enum.cache.declaration_path


if __name__ == "__main__":
run_suite()
def test_access_type(global_ns):
cls = global_ns.class_(name='class_for_nested_enums_t')
enum = cls.enumeration('ENestedPublic')
assert enum.cache.access_type == 'public'
enum.cache.reset_access_type()
assert not enum.cache.access_type
assert 'public' == cls.find_out_member_access_type(enum)
assert enum.cache.access_type == 'public'
63 changes: 25 additions & 38 deletions tests/test_argument_without_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,41 @@
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import unittest
import pytest

from . import parser_test_case
from . import autoconfig

from pygccxml import parser
from pygccxml import declarations

TEST_FILES = ['test_argument_without_name.hpp']

class Test(parser_test_case.parser_test_case_t):

def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.header = "test_argument_without_name.hpp"
self.config.cflags = "-std=c++11"
@pytest.fixture
def global_ns():
COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
config = autoconfig.cxx_parsers_cfg.config.clone()
config.cflags = "-std=c++11"
decls = parser.parse(TEST_FILES, config, COMPILATION_MODE)
global_ns = declarations.get_global_namespace(decls)
global_ns.init_optimizer()
return global_ns

def test_argument_without_name(self):

"""
Test passing an object without name to a templated function.
def test_argument_without_name(global_ns):
"""
Test passing an object without name to a templated function.

The test was failing when building the declaration string.
The declaration string will be 'void (*)( & )'. If the passed
object had a name the result would then be 'void (*)(Name & )'.
The test was failing when building the declaration string.
The declaration string will be 'void (*)( & )'. If the passed
object had a name the result would then be 'void (*)(Name & )'.

See bug #55
See bug #55

"""
"""

decls = parser.parse([self.header], self.config)
global_ns = declarations.get_global_namespace(decls)

criteria = declarations.calldef_matcher(name="function")
free_funcs = declarations.matcher.find(criteria, global_ns)
for free_func in free_funcs:
decl_string = free_func.create_decl_string(with_defaults=False)
self.assertEqual(decl_string, "void (*)( & )")


def create_suite():
suite = unittest.TestSuite()
suite.addTest(
unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test))
return suite


def run_suite():
unittest.TextTestRunner(verbosity=2).run(create_suite())


if __name__ == "__main__":
run_suite()
criteria = declarations.calldef_matcher(name="function")
free_funcs = declarations.matcher.find(criteria, global_ns)
for free_func in free_funcs:
decl_string = free_func.create_decl_string(with_defaults=False)
assert decl_string == "void (*)( & )"
Loading
Loading