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
91 changes: 31 additions & 60 deletions tests/test_copy_constructor2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,41 @@

import os
import bz2
import unittest

from . import autoconfig
from . import parser_test_case

from pygccxml import parser
from pygccxml import declarations


class Test(parser_test_case.parser_test_case_t):

def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.global_ns = None
self.xml_path = None

def setUp(self):
if not self.global_ns:

# Extract the xml file from the bz2 archive
bz2_path = os.path.join(
autoconfig.data_directory,
'ogre.1.7.xml.bz2')
self.xml_path = os.path.join(
autoconfig.data_directory,
'ogre.1.7.xml')
with open(self.xml_path, 'wb') as new_file:
# bz2.BZ2File can not be used in a with statement in python 2.6
bz2_file = bz2.BZ2File(bz2_path, 'rb')
for data in iter(lambda: bz2_file.read(100 * 1024), b''):
new_file.write(data)
bz2_file.close()

reader = parser.source_reader_t(autoconfig.cxx_parsers_cfg.config)
self.global_ns = declarations.get_global_namespace(
reader.read_xml_file(
self.xml_path))
self.global_ns.init_optimizer()

def tearDown(self):
# Delete the extracted xml file
os.remove(self.xml_path)

def test_copy_constructor2(self):
for x in self.global_ns.typedefs('SettingsMultiMap'):
self.assertTrue(not declarations.is_noncopyable(x))

for x in self.global_ns.typedefs('SettingsIterator'):
self.assertTrue(not declarations.is_noncopyable(x))

for x in self.global_ns.typedefs('SectionIterator'):
self.assertTrue(not declarations.is_noncopyable(x))


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()
def test_copy_constructor2():
# Extract the xml file from the bz2 archive
bz2_path = os.path.join(
autoconfig.data_directory,
'ogre.1.7.xml.bz2')
xml_path = os.path.join(
autoconfig.data_directory,
'ogre.1.7.xml')
with open(xml_path, 'wb') as new_file:
# bz2.BZ2File can not be used in a with statement in python 2.6
bz2_file = bz2.BZ2File(bz2_path, 'rb')
for data in iter(lambda: bz2_file.read(100 * 1024), b''):
new_file.write(data)
bz2_file.close()

reader = parser.source_reader_t(autoconfig.cxx_parsers_cfg.config)
global_ns = declarations.get_global_namespace(
reader.read_xml_file(xml_path)
)
global_ns.init_optimizer()

for x in global_ns.typedefs('SettingsMultiMap'):
assert declarations.is_noncopyable(x) is False

for x in global_ns.typedefs('SettingsIterator'):
assert declarations.is_noncopyable(x) is False

for x in global_ns.typedefs('SectionIterator'):
assert declarations.is_noncopyable(x) is False

os.remove(xml_path)
68 changes: 25 additions & 43 deletions tests/test_cpp_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,44 @@
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import pytest

import platform
import unittest

from . import parser_test_case
from . import autoconfig

from pygccxml import parser


class Test(parser_test_case.parser_test_case_t):

def test(self):
"""
Test different compilation standards by setting cflags.

"""

parser.parse(["cpp_standards.hpp"], self.config)

if platform.system() != 'Windows':
self.config.cflags = "-std=c++98"
parser.parse(["cpp_standards.hpp"], self.config)

self.config.cflags = "-std=c++03"
parser.parse(["cpp_standards.hpp"], self.config)
def test_cpp_standards():
"""
Test different compilation standards by setting cflags.

self.config.cflags = "-std=c++11"
parser.parse(["cpp_standards.hpp"], self.config)
"""

# This is broken with llvm 3.6.2 (the one from homebrew)
# It should work with never llvms but I keep the test disabled
# See https://llvm.org/bugs/show_bug.cgi?id=24872
# self.config.cflags = "-std=c++14"
# parser.parse(["cpp_standards.hpp"], self.config)
config = autoconfig.cxx_parsers_cfg.config.clone()

# Same as above
# self.config.cflags = "-std=c++1z"
# parser.parse(["cpp_standards.hpp"], self.config)
parser.parse(["cpp_standards.hpp"], config)

# Pass down a flag that does not exist.
# This should raise an exception.
self.config.cflags = "-std=c++00"
self.assertRaises(
RuntimeError,
lambda: parser.parse(["cpp_standards.hpp"], self.config))
if platform.system() != 'Windows':
config.cflags = "-std=c++98"
parser.parse(["cpp_standards.hpp"], config)

config.cflags = "-std=c++03"
parser.parse(["cpp_standards.hpp"], config)

def create_suite():
suite = unittest.TestSuite()
suite.addTest(
unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test))
return suite
config.cflags = "-std=c++11"

parser.parse(["cpp_standards.hpp"], config)

def run_suite():
unittest.TextTestRunner(verbosity=2).run(create_suite())
config.cflags = "-std=c++14"
parser.parse(["cpp_standards.hpp"], config)

config.cflags = "-std=c++1z"
parser.parse(["cpp_standards.hpp"], config)

if __name__ == "__main__":
run_suite()
# Pass down a flag that does not exist.
# This should raise an exception.
config.cflags = "-std=c++00"
with pytest.raises(RuntimeError):
parser.parse(["cpp_standards.hpp"], config)
116 changes: 49 additions & 67 deletions tests/test_decl_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,58 @@
# See http://www.boost.org/LICENSE_1_0.txt

import sys
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):

def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.__files = [
'core_ns_join_1.hpp',
'core_ns_join_2.hpp',
'core_ns_join_3.hpp',
'core_membership.hpp',
'core_class_hierarchy.hpp',
'core_types.hpp',
'core_diamand_hierarchy_base.hpp',
'core_diamand_hierarchy_derived1.hpp',
'core_diamand_hierarchy_derived2.hpp',
'core_diamand_hierarchy_final_derived.hpp',
'core_overloads_1.hpp',
'core_overloads_2.hpp',
'typedefs_base.hpp']

# for i, f in enumerate(self.__files):
# f = parser.create_cached_source_fc(
# os.path.join( autoconfig.data_directory, f)
# , os.path.join( autoconfig.data_directory, f + '.xml') )
# self.__files[i] = f
prj_reader = parser.project_reader_t(self.config)
self.decls = prj_reader.read_files(
self.__files,
compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE)

def test_printer(self):

# Redirect sys.stdout to a class with a writer doing nothing
# This greatly reduces the size of the test output and makes
# test log files readable.
# Note: flush needs to be defined; because if not this will
# result in an AttributeError on call.
class DontPrint(object):
def write(*args):
pass

def flush(*args):
pass
sys.stdout = DontPrint()

declarations.print_declarations(self.decls)

def test__str__(self):
decls = declarations.make_flatten(self.decls)
for decl in decls:
str(decl)


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()
TEST_FILES = [
'core_ns_join_1.hpp',
'core_ns_join_2.hpp',
'core_ns_join_3.hpp',
'core_membership.hpp',
'core_class_hierarchy.hpp',
'core_types.hpp',
'core_diamand_hierarchy_base.hpp',
'core_diamand_hierarchy_derived1.hpp',
'core_diamand_hierarchy_derived2.hpp',
'core_diamand_hierarchy_final_derived.hpp',
'core_overloads_1.hpp',
'core_overloads_2.hpp',
'typedefs_base.hpp',
]


@pytest.fixture
def decls():
COMPILATION_MODE = parser.COMPILATION_MODE.FILE_BY_FILE
config = autoconfig.cxx_parsers_cfg.config.clone()
config.castxml_epic_version = 1
decls = parser.parse(TEST_FILES, config, COMPILATION_MODE)
return decls


def test_printer(decls):
# Redirect sys.stdout to a class with a writer doing nothing
# This greatly reduces the size of the test output and makes
# test log files readable.
# Note: flush needs to be defined; because if not this will
# result in an AttributeError on call.
class DontPrint(object):
def write(*args):
pass

def flush(*args):
pass
sys.stdout = DontPrint()

declarations.print_declarations(decls)


def test__str__(decls):
decls = declarations.make_flatten(decls)
for decl in decls:
str(decl)
74 changes: 29 additions & 45 deletions tests/test_declaration_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,38 @@
# See http://www.boost.org/LICENSE_1_0.txt

import os
import unittest

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):

def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.__files = [
'core_ns_join_1.hpp',
'core_ns_join_2.hpp',
'core_ns_join_3.hpp',
'core_membership.hpp',
'core_class_hierarchy.hpp',
'core_types.hpp',
'core_diamand_hierarchy_base.hpp',
'core_diamand_hierarchy_derived1.hpp',
'core_diamand_hierarchy_derived2.hpp',
'core_diamand_hierarchy_final_derived.hpp',
'core_overloads_1.hpp',
'core_overloads_2.hpp']

def test(self):
prj_reader = parser.project_reader_t(self.config)
decls = prj_reader.read_files(
self.__files,
compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE)
files = declarations.declaration_files(decls)
result = set()
for fn in files:
result.add(os.path.split(fn)[1])
self.assertTrue(set(self.__files).issubset(result))


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()
TEST_FILES = [
'core_ns_join_1.hpp',
'core_ns_join_2.hpp',
'core_ns_join_3.hpp',
'core_membership.hpp',
'core_class_hierarchy.hpp',
'core_types.hpp',
'core_diamand_hierarchy_base.hpp',
'core_diamand_hierarchy_derived1.hpp',
'core_diamand_hierarchy_derived2.hpp',
'core_diamand_hierarchy_final_derived.hpp',
'core_overloads_1.hpp',
'core_overloads_2.hpp',
'typedefs_base.hpp',
]


def test_declaration_files():
config = autoconfig.cxx_parsers_cfg.config.clone()
prj_reader = parser.project_reader_t(config)
decls = prj_reader.read_files(
TEST_FILES,
compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE)
files = declarations.declaration_files(decls)
result = set()
for fn in files:
result.add(os.path.split(fn)[1])
assert set(TEST_FILES).issubset(result) is True
Loading
Loading