#!/usr/bin/env python
#
# Cppcheck - A tool for static C/C++ code analysis
# Copyright (C) 2007-2022 Cppcheck team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from donate_cpu_lib import *
def _test_library_includes(tmpdir, libs, content, libinc_obj=None):
if libinc_obj is None:
library_includes = LibraryIncludes()
else:
library_includes = libinc_obj
src_file = os.path.join(str(tmpdir), "file.cpp")
with open(src_file, 'w') as f:
f.write(content)
libs.sort()
libs_found = library_includes.get_libraries(str(tmpdir))
libs_found.sort()
assert libs == libs_found
def test_library_includes(tmpdir):
_test_library_includes(tmpdir, ['posix', 'gnu'], '')
_test_library_includes(tmpdir, ['posix', 'gnu'], '#include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'boost'], '#include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'python'], '#include "Python.h"')
_test_library_includes(tmpdir, ['posix', 'gnu', 'libcerror', 'lua', 'opengl', 'qt'], '#include \n#include \r#include "lua.h"\r\n#include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'microsoft_sal'], ' #include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'googletest'], '\t#include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'microsoft_atl'], ' \t #include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'cairo'], '\t #include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'gtk'], ' \t#include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd'], '#include \r\n')
_test_library_includes(tmpdir, ['posix', 'gnu', 'libcurl'], '#include \r')
_test_library_includes(tmpdir, ['posix', 'gnu', 'sqlite3'], '#include \n')
_test_library_includes(tmpdir, ['posix', 'gnu', 'openmp'], '# include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'mfc'], '#\tinclude ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'ruby'], '# \tinclude "ruby.h"')
_test_library_includes(tmpdir, ['posix', 'gnu', 'zlib'], '#\t include ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'pcre'], '#include')
_test_library_includes(tmpdir, ['posix', 'gnu', 'pcre'], '#include "pcre.h"')
_test_library_includes(tmpdir, ['posix', 'gnu', 'opengl'], '#include\t ')
_test_library_includes(tmpdir, ['posix', 'gnu', 'nspr'], '#include\t"prtypes.h"')
_test_library_includes(tmpdir, ['posix', 'gnu', 'lua'], '#include \t')
def test_match_multiple_time(tmpdir):
libinc = LibraryIncludes()
# there was a bug that we would only match each library once successfully
_test_library_includes(tmpdir, ['posix', 'gnu', 'zlib'], '#include ', libinc)
_test_library_includes(tmpdir, ['posix', 'gnu', 'zlib'], '#include ', libinc)