diff --git a/Makefile b/Makefile index b8f0149eb77..e6c676cadd8 100644 --- a/Makefile +++ b/Makefile @@ -682,10 +682,10 @@ cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h cli/threadexecutor.o: cli/threadexecutor.cpp cli/executor.h cli/threadexecutor.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/threadexecutor.cpp -test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h lib/xml.h test/fixture.h test/options.h test/redirect.h +test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/xml.h test/fixture.h test/helpers.h test/options.h test/redirect.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp -test/helpers.o: test/helpers.cpp cli/filelister.h externals/simplecpp/simplecpp.h lib/addoninfo.h lib/config.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/helpers.h +test/helpers.o: test/helpers.cpp cli/filelister.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/config.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/xml.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/helpers.cpp test/main.o: test/main.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h @@ -778,7 +778,7 @@ test/testio.o: test/testio.cpp lib/addoninfo.h lib/check.h lib/checkio.h lib/col test/testleakautovar.o: test/testleakautovar.cpp lib/addoninfo.h lib/check.h lib/checkleakautovar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testleakautovar.cpp -test/testlibrary.o: test/testlibrary.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h test/fixture.h test/helpers.h +test/testlibrary.o: test/testlibrary.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testlibrary.cpp test/testmathlib.o: test/testmathlib.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h @@ -787,7 +787,7 @@ test/testmathlib.o: test/testmathlib.cpp lib/addoninfo.h lib/check.h lib/color.h test/testmemleak.o: test/testmemleak.cpp lib/addoninfo.h lib/check.h lib/checkmemoryleak.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testmemleak.cpp -test/testnullpointer.o: test/testnullpointer.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checknullpointer.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h test/fixture.h test/helpers.h +test/testnullpointer.o: test/testnullpointer.cpp lib/addoninfo.h lib/check.h lib/checknullpointer.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testnullpointer.cpp test/testoptions.o: test/testoptions.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h diff --git a/lib/library.h b/lib/library.h index 05e456017f1..a8b9d61b9d8 100644 --- a/lib/library.h +++ b/lib/library.h @@ -50,11 +50,7 @@ namespace tinyxml2 { * @brief Library definitions handling */ class CPPCHECKLIB Library { - // TODO: get rid of this - friend class TestSymbolDatabase; // For testing only - friend class TestSingleExecutorBase; // For testing only - friend class TestThreadExecutorBase; // For testing only - friend class TestProcessExecutorBase; // For testing only + friend struct LibraryHelper; // for testing public: Library() = default; @@ -76,7 +72,6 @@ class CPPCHECKLIB Library { }; Error load(const char exename[], const char path[]); - Error load(const tinyxml2::XMLDocument &doc); struct AllocFunc { int groupId; @@ -466,6 +461,8 @@ class CPPCHECKLIB Library { bool hasAnyTypeCheck(const std::string& typeName) const; private: + Error load(const tinyxml2::XMLDocument &doc); + // load a xml node Error loadFunction(const tinyxml2::XMLElement * const node, const std::string &name, std::set &unknown_elements); diff --git a/test/fixture.cpp b/test/fixture.cpp index 484a5aebe17..a4deb169307 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -20,6 +20,7 @@ #include "cppcheck.h" #include "errortypes.h" +#include "helpers.h" #include "options.h" #include "redirect.h" @@ -454,7 +455,8 @@ TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::library(const char l if (REDUNDANT_CHECK && std::find(settings.libraries.cbegin(), settings.libraries.cend(), lib) != settings.libraries.cend()) throw std::runtime_error("redundant setting: libraries (" + std::string(lib) + ")"); // TODO: exename is not yet set - LOAD_LIB_2_EXE(settings.library, lib, fixture.exename.c_str()); + if (settings.library.load(fixture.exename.c_str(), lib).errorcode != Library::ErrorCode::OK) + throw std::runtime_error("library '" + std::string(lib) + "' not found"); // strip extension std::string lib_s(lib); const std::string ext(".cfg"); @@ -484,8 +486,8 @@ TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::libraryxml(const cha tinyxml2::XMLDocument doc; const tinyxml2::XMLError xml_error = doc.Parse(xmldata, len); if (tinyxml2::XML_SUCCESS != xml_error) - throw std::runtime_error(std::string("loading XML data failed - ") + tinyxml2::XMLDocument::ErrorIDToName(xml_error)); - const Library::ErrorCode lib_error = settings.library.load(doc).errorcode; + throw std::runtime_error(std::string("loading library XML data failed - ") + tinyxml2::XMLDocument::ErrorIDToName(xml_error)); + const Library::ErrorCode lib_error = LibraryHelper::loadxmldoc(settings.library, doc).errorcode; if (lib_error != Library::ErrorCode::OK) throw std::runtime_error("loading library XML failed - " + std::to_string(static_cast(lib_error))); return *this; diff --git a/test/fixture.h b/test/fixture.h index 391b5ba1963..96aadc7362e 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -308,8 +308,6 @@ class TestFixture : public ErrorLogger { #define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL) #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_ ## CLASSNAME; } -#define LOAD_LIB_2_EXE( LIB, NAME, EXE ) do { if (((LIB).load((EXE), NAME).errorcode != Library::ErrorCode::OK)) throw std::runtime_error("library '" + std::string(NAME) + "' not found"); } while (false) - #define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(Platform::toString(T), errstr, {exename}), errstr); } while (false) #endif // fixtureH diff --git a/test/helpers.cpp b/test/helpers.cpp index 85391067d4f..4e4effd76ac 100644 --- a/test/helpers.cpp +++ b/test/helpers.cpp @@ -20,6 +20,7 @@ #include "filelister.h" #include "filesettings.h" +#include "library.h" #include "path.h" #include "pathmatch.h" #include "preprocessor.h" @@ -43,6 +44,8 @@ #include +#include "xml.h" + class SuppressionList; const Settings SimpleTokenizer::s_settings; @@ -182,3 +185,23 @@ void PreprocessorHelper::preprocess(const char code[], std::vector std::list directives = preprocessor.createDirectives(tokens1); tokenizer.setDirectives(std::move(directives)); } + +bool LibraryHelper::loadxmldata(Library &lib, const char xmldata[], std::size_t len) +{ + tinyxml2::XMLDocument doc; + return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (lib.load(doc).errorcode == Library::ErrorCode::OK); +} + +bool LibraryHelper::loadxmldata(Library &lib, Library::Error& liberr, const char xmldata[], std::size_t len) +{ + tinyxml2::XMLDocument doc; + if (tinyxml2::XML_SUCCESS != doc.Parse(xmldata, len)) + return false; + liberr = lib.load(doc); + return true; +} + +Library::Error LibraryHelper::loadxmldoc(Library &lib, const tinyxml2::XMLDocument& doc) +{ + return lib.load(doc); +} diff --git a/test/helpers.h b/test/helpers.h index 2360b159f1a..30bc9003221 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -232,4 +232,11 @@ inline std::string filter_valueflow(const std::string& s) { return ostr; } +struct LibraryHelper +{ + static bool loadxmldata(Library &lib, const char xmldata[], std::size_t len); + static bool loadxmldata(Library &lib, Library::Error& liberr, const char xmldata[], std::size_t len); + static Library::Error loadxmldoc(Library &lib, const tinyxml2::XMLDocument& doc); +}; + #endif // helpersH diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index 66bf934e475..bdbe8670fc3 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -32,8 +32,6 @@ #include #include -#include "xml.h" - #define ASSERT_EQ(expected, actual) ASSERT(expected == actual) class TestLibrary : public TestFixture { @@ -72,12 +70,6 @@ class TestLibrary : public TestFixture { TEST_CASE(loadLibCombinations); } - static bool loadxmldata(Library &lib, const char xmldata[], std::size_t len) - { - tinyxml2::XMLDocument doc; - return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (lib.load(doc).errorcode == Library::ErrorCode::OK); - } - void isCompliantValidationExpression() const { ASSERT_EQUALS(true, Library::isCompliantValidationExpression("-1")); ASSERT_EQUALS(true, Library::isCompliantValidationExpression("1")); @@ -104,7 +96,7 @@ class TestLibrary : public TestFixture { // Reading an empty library file is considered to be OK constexpr char xmldata[] = "\n"; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT(library.functions().empty()); } @@ -121,7 +113,7 @@ class TestLibrary : public TestFixture { tokenList.front()->next()->astOperand1(tokenList.front()); Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(library.functions().size(), 1U); ASSERT(library.functions().at("foo").argumentChecks.empty()); ASSERT(library.isnotnoreturn(tokenList.front())); @@ -136,7 +128,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); { const char code[] = "fred.foo(123);"; // <- wrong scope, not library function const SimpleTokenList tokenList(code); @@ -166,7 +158,7 @@ class TestLibrary : public TestFixture { tokenList.createAst(); Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT(library.isNotLibraryFunction(tokenList.front())); } @@ -180,7 +172,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); { TokenList tokenList(&settings); @@ -234,7 +226,7 @@ class TestLibrary : public TestFixture { tokenList.front()->next()->varId(1); Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT(library.isNotLibraryFunction(tokenList.front()->next())); } @@ -251,7 +243,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(0, library.functions().at("foo").argumentChecks.at(1).notuninit); ASSERT_EQUALS(true, library.functions().at("foo").argumentChecks.at(2).notnull); ASSERT_EQUALS(true, library.functions().at("foo").argumentChecks.at(3).formatstr); @@ -270,7 +262,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(0, library.functions().at("foo").argumentChecks.at(-1).notuninit); } @@ -284,7 +276,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(0, library.functions().at("foo").argumentChecks.at(-1).notuninit); const char code[] = "foo(a,b,c,d,e);"; @@ -309,7 +301,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); const char code[] = "foo(a,b,c,d);"; SimpleTokenList tokenList(code); @@ -340,7 +332,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); const char code[] = "foo(a,b,c,d,e,f,g,h,i,j,k);"; SimpleTokenList tokenList(code); @@ -481,7 +473,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); const char code[] = "foo(a,b,c,d,e);"; SimpleTokenList tokenList(code); @@ -539,7 +531,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(library.functions().size(), 2U); ASSERT(library.functions().at("Foo::foo").argumentChecks.empty()); ASSERT(library.functions().at("bar").argumentChecks.empty()); @@ -566,7 +558,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(library.functions().size(), 1U); { @@ -593,7 +585,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); { SimpleTokenizer tokenizer(settings, *this); @@ -622,7 +614,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); const char code[] = "a(); b();"; const SimpleTokenList tokenList(code); @@ -655,7 +647,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT(library.functions().empty()); const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX"); @@ -682,8 +674,8 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT_EQUALS(true, loadxmldata(library, xmldata1, sizeof(xmldata1))); - ASSERT_EQUALS(true, loadxmldata(library, xmldata2, sizeof(xmldata2))); + ASSERT_EQUALS(true, LibraryHelper::loadxmldata(library, xmldata1, sizeof(xmldata1))); + ASSERT_EQUALS(true, LibraryHelper::loadxmldata(library, xmldata2, sizeof(xmldata2))); ASSERT_EQUALS(library.deallocId("free"), library.allocId("malloc")); ASSERT_EQUALS(library.deallocId("free"), library.allocId("foo")); @@ -698,7 +690,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT(library.functions().empty()); const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX"); @@ -717,7 +709,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT(library.functions().empty()); ASSERT(Library::isresource(library.allocId("CreateX"))); @@ -734,7 +726,7 @@ class TestLibrary : public TestFixture { " \n" ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); // s8 { const Library::PodType * const type = library.podtype("s8"); @@ -813,7 +805,7 @@ class TestLibrary : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); const Library::Container& A = library.containers().at("A"); const Library::Container& B = library.containers().at("B"); @@ -923,43 +915,39 @@ class TestLibrary : public TestFixture { } } +#define LOADLIBERROR(xmldata, errorcode) loadLibError(xmldata, errorcode, __FILE__, __LINE__) + void version() const { { constexpr char xmldata[] = "\n" "\n" ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); } { constexpr char xmldata[] = "\n" "\n" ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); } { constexpr char xmldata[] = "\n" "\n" ""; - Library library; - const Library::Error err = readLibrary(library, xmldata); - ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::UNSUPPORTED_FORMAT); + LOADLIBERROR(xmldata, Library::ErrorCode::UNSUPPORTED_FORMAT); } } - static Library::Error readLibrary(Library& library, const char* xmldata) { - tinyxml2::XMLDocument doc; - doc.Parse(xmldata); // TODO: check result - return library.load(doc); - } - - void loadLibError(const char xmldata[], Library::ErrorCode errorcode, const char* file, unsigned line) const { + template + void loadLibError(const char (&xmldata)[size], Library::ErrorCode errorcode, const char* file, unsigned line) const { Library library; - assertEquals(file, line, true, errorcode == readLibrary(library, xmldata).errorcode); + Library::Error liberr; + assertEquals(file, line, true, LibraryHelper::loadxmldata(library, liberr, xmldata, size-1)); + assertEquals(file, line, true, errorcode == liberr.errorcode); } -#define LOADLIBERROR(xmldata, errorcode) loadLibError(xmldata, errorcode, __FILE__, __LINE__) #define LOADLIB_ERROR_INVALID_RANGE(valid) LOADLIBERROR("\n" \ "\n" \ "\n" \ diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index c6a0ac7f247..432b50fab9c 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -34,8 +34,6 @@ #include #include -#include "xml.h" - class TestNullPointer : public TestFixture { public: TestNullPointer() : TestFixture("TestNullPointer") {} @@ -178,12 +176,6 @@ class TestNullPointer : public TestFixture { TEST_CASE(ctuTest); } - static bool loadxmldata(Library &lib, const char xmldata[], std::size_t len) - { - tinyxml2::XMLDocument doc; - return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (lib.load(doc).errorcode == Library::ErrorCode::OK); - } - #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) template void check_(const char* file, int line, const char (&code)[size], bool inconclusive = false, bool cpp = true) { @@ -4167,7 +4159,7 @@ class TestNullPointer : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); std::list null; CheckNullPointer::parseFunctionCall(*xtok, null, library); @@ -4186,7 +4178,7 @@ class TestNullPointer : public TestFixture { ""; Library library; - ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); + ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); std::list null; CheckNullPointer::parseFunctionCall(*xtok, null, library);