1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-17 07:37:13 +02:00

Major plugin refactor and cleanup.

Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
This commit is contained in:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions

View File

@ -0,0 +1,136 @@
//
// AttributesParserTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "AttributesParserTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/CppParser/Attributes.h"
#include "Poco/CppParser/AttributesParser.h"
#include <sstream>
using Poco::CppParser::Attributes;
using Poco::CppParser::AttributesParser;
AttributesParserTest::AttributesParserTest(const std::string& name): CppUnit::TestCase(name)
{
}
AttributesParserTest::~AttributesParserTest()
{
}
void AttributesParserTest::testParser1()
{
Attributes attrs;
std::istringstream istr("");
AttributesParser parser(attrs, istr);
parser.parse();
assertTrue (attrs.begin() == attrs.end());
}
void AttributesParserTest::testParser2()
{
Attributes attrs;
std::istringstream istr("name=value");
AttributesParser parser(attrs, istr);
parser.parse();
assertTrue (attrs.getString("name") == "value");
}
void AttributesParserTest::testParser3()
{
Attributes attrs;
std::istringstream istr("name=value, name2=100");
AttributesParser parser(attrs, istr);
parser.parse();
assertTrue (attrs.getString("name") == "value");
assertTrue (attrs.getInt("name2") == 100);
}
void AttributesParserTest::testParser4()
{
Attributes attrs;
std::istringstream istr("name=value, name2=100, name3");
AttributesParser parser(attrs, istr);
parser.parse();
assertTrue (attrs.getString("name") == "value");
assertTrue (attrs.getInt("name2") == 100);
assertTrue (attrs.getBool("name3"));
}
void AttributesParserTest::testParser5()
{
Attributes attrs;
std::istringstream istr("name.a=value, name.b=100, name.c");
AttributesParser parser(attrs, istr);
parser.parse();
assertTrue (attrs.getString("name.a") == "value");
assertTrue (attrs.getInt("name.b") == 100);
assertTrue (attrs.getBool("name.c"));
}
void AttributesParserTest::testParser6()
{
Attributes attrs;
std::istringstream istr("name = {a=value, b=100, c}");
AttributesParser parser(attrs, istr);
parser.parse();
assertTrue (attrs.getString("name.a") == "value");
assertTrue (attrs.getInt("name.b") == 100);
assertTrue (attrs.getBool("name.c"));
}
void AttributesParserTest::testParser7()
{
Attributes attrs;
std::istringstream istr("name = {a=value, b=100, c}, name2=\"foo\"");
AttributesParser parser(attrs, istr);
parser.parse();
assertTrue (attrs.getString("name.a") == "value");
assertTrue (attrs.getInt("name.b") == 100);
assertTrue (attrs.getBool("name.c"));
assertTrue (attrs.getString("name2") == "foo");
}
void AttributesParserTest::setUp()
{
}
void AttributesParserTest::tearDown()
{
}
CppUnit::Test* AttributesParserTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AttributesParserTest");
CppUnit_addTest(pSuite, AttributesParserTest, testParser1);
CppUnit_addTest(pSuite, AttributesParserTest, testParser2);
CppUnit_addTest(pSuite, AttributesParserTest, testParser3);
CppUnit_addTest(pSuite, AttributesParserTest, testParser4);
CppUnit_addTest(pSuite, AttributesParserTest, testParser5);
CppUnit_addTest(pSuite, AttributesParserTest, testParser6);
CppUnit_addTest(pSuite, AttributesParserTest, testParser7);
return pSuite;
}

View File

@ -0,0 +1,44 @@
//
// AttributesParserTest.h
//
// Definition of the AttributesParserTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef AttributesParserTest_INCLUDED
#define AttributesParserTest_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "CppUnit/TestCase.h"
class AttributesParserTest: public CppUnit::TestCase
{
public:
AttributesParserTest(const std::string& name);
~AttributesParserTest();
void testParser1();
void testParser2();
void testParser3();
void testParser4();
void testParser5();
void testParser6();
void testParser7();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // AttributesParserTest_INCLUDED

View File

@ -0,0 +1,22 @@
//
// AttributesTestSuite.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "AttributesTestSuite.h"
#include "AttributesParserTest.h"
CppUnit::Test* AttributesTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CppParserTestSuite");
pSuite->addTest(AttributesParserTest::suite());
return pSuite;
}

View File

@ -0,0 +1,27 @@
//
// AttributesTestSuite.h
//
// Definition of the AttributesTestSuite class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef AttributesTestSuite_INCLUDED
#define AttributesTestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
class AttributesTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // AttributesTestSuite_INCLUDED

View File

@ -0,0 +1,202 @@
//
// CppParserTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "CppParserTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/CppParser/Utility.h"
#include "Poco/CppParser/Symbol.h"
#include "Poco/CppParser/CppToken.h"
#include <sstream>
#include <iostream>
using namespace Poco::CppParser;
std::string linker("cl");
std::string options("/I \"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\INCLUDE\", "
"/I \"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\PlatformSDK\\include\", "
"/I \"p:\\poco\\Foundation\\include\", "
"/I \"p:\\poco\\XML\\include\", "
"/I \"p:\\poco\\Util\\include\", "
"/I \"p:\\poco\\Net\\include\", "
"/D \"WIN32\", "
"/D \"_DEBUG\", "
"/D \"_WINDOWS\", "
"/D \"_MBCS\", "
"/C, /P, /TP");
std::string path("C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\BIN;C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\Tools;;C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\Tools\\bin");
CppParserTest::CppParserTest(const std::string& name): CppUnit::TestCase(name)
{
}
CppParserTest::~CppParserTest()
{
}
void CppParserTest::testParseDir()
{
//FIXME: implement some proper tests
return;
NameSpace::SymbolTable st;
std::vector<std::string> inc;
inc.push_back("./*.h");
std::vector<std::string> exc;
Utility::parseDir(inc, exc, st, linker, options, path);
NameSpace::SymbolTable::const_iterator it = st.begin();
NameSpace::SymbolTable::const_iterator itEnd = st.end();
for (; it != itEnd; ++it)
{
std::cout << it->first << ": ";
Symbol* pSym = it->second;
std::cout << pSym->name() << ", " << pSym->getDocumentation() << "\n";
}
}
void CppParserTest::testExtractName()
{
std::string decl("int _var");
std::string name = Symbol::extractName(decl);
assertTrue (name == "_var");
decl = "void func(int arg1, int arg2)";
name = Symbol::extractName(decl);
assertTrue (name == "func");
decl = "const std::vector<NS::MyType>* var";
name = Symbol::extractName(decl);
assertTrue (name == "var");
decl = "const std::vector<NS::MyType>* func(int arg) = 0";
name = Symbol::extractName(decl);
assertTrue (name == "func");
decl = "int (*func)(int, const std::string&)";
name = Symbol::extractName(decl);
assertTrue (name == "func");
decl = "int ( * func )(int, const std::string&)";
name = Symbol::extractName(decl);
assertTrue (name == "func");
decl = "template <typename A, typename B> B func(A a, B b)";
name = Symbol::extractName(decl);
assertTrue (name == "func");
decl = "template <typename A, typename B> class Class";
name = Symbol::extractName(decl);
assertTrue (name == "Class");
decl = "template <> class Class<int, std::string>";
name = Symbol::extractName(decl);
assertTrue (name == "Class");
decl = "template <> class Class <int, std::string>";
name = Symbol::extractName(decl);
assertTrue (name == "Class");
decl = "template <> class Class<int, MyTemplate<int> >";
name = Symbol::extractName(decl);
assertTrue (name == "Class");
}
void CppParserTest::testNumberLiterals()
{
testNumberLiteral("123");
testNumberLiteral("0123");
testNumberLiteral("0x123");
testNumberLiteral("0XABC");
testNumberLiteral("0b010101");
testNumberLiteral("0B101010");
testNumberLiteral("123L");
testNumberLiteral("0123L");
testNumberLiteral("0x123L");
testNumberLiteral("0XABCL");
testNumberLiteral("0b010101L");
testNumberLiteral("0B101010L");
testNumberLiteral("123LL");
testNumberLiteral("0123LL");
testNumberLiteral("0x123LL");
testNumberLiteral("0XABCLL");
testNumberLiteral("0b010101LL");
testNumberLiteral("0B101010LL");
testNumberLiteral("123U");
testNumberLiteral("0123U");
testNumberLiteral("0x123U");
testNumberLiteral("0XABCU");
testNumberLiteral("0b010101U");
testNumberLiteral("0B101010U");
testNumberLiteral("123UL");
testNumberLiteral("0123UL");
testNumberLiteral("0x123UL");
testNumberLiteral("0XABCUL");
testNumberLiteral("0b010101UL");
testNumberLiteral("0B101010UL");
testNumberLiteral("1.23");
testNumberLiteral(".123");
testNumberLiteral("1.23e+3");
testNumberLiteral("1.23E-3");
testNumberLiteral("0x1fp1");
testNumberLiteral("0x1f.e3p+12");
testNumberLiteral("0x1f.e3p-12");
testNumberLiteral("123'456");
testNumberLiteral("1'234'567");
testNumberLiteral("0x1234'5678");
testNumberLiteral("0xFFFF'FFFFULL");
}
void CppParserTest::testNumberLiteral(const std::string& literal)
{
NumberLiteralToken tok;
std::istringstream istr(literal);
assertTrue (tok.start(istr.get(), istr));
tok.finish(istr);
assertEquals (tok.tokenString(), literal);
}
void CppParserTest::setUp()
{
}
void CppParserTest::tearDown()
{
}
CppUnit::Test* CppParserTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CppParserTest");
CppUnit_addTest(pSuite, CppParserTest, testParseDir);
CppUnit_addTest(pSuite, CppParserTest, testExtractName);
CppUnit_addTest(pSuite, CppParserTest, testNumberLiterals);
return pSuite;
}

View File

@ -0,0 +1,43 @@
//
// CppParserTest.h
//
// Definition of the CppParserTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParserTest_INCLUDED
#define CppParserTest_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "CppUnit/TestCase.h"
class CppParserTest: public CppUnit::TestCase
{
public:
CppParserTest(const std::string& name);
~CppParserTest();
void testParseDir();
void testExtractName();
void testNumberLiterals();
void setUp();
void tearDown();
static CppUnit::Test* suite();
protected:
void testNumberLiteral(const std::string& literal);
private:
};
#endif // CppParserTest_INCLUDED

View File

@ -0,0 +1,24 @@
//
// CppParserTestSuite.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "CppParserTestSuite.h"
#include "AttributesTestSuite.h"
#include "CppParserTest.h"
CppUnit::Test* CppParserTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CppParserTestSuite");
pSuite->addTest(AttributesTestSuite::suite());
pSuite->addTest(CppParserTest::suite());
return pSuite;
}

View File

@ -0,0 +1,27 @@
//
// CppParserTestSuite.h
//
// Definition of the CppParserTestSuite class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParserTestSuite_INCLUDED
#define CppParserTestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
class CppParserTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // CppParserTestSuite_INCLUDED

View File

@ -0,0 +1,17 @@
//
// Driver.cpp
//
// Console-based test driver for Poco CppParser.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "CppUnit/TestRunner.h"
#include "CppParserTestSuite.h"
CppUnitMain(CppParserTestSuite)

View File

@ -0,0 +1,28 @@
//
// WinDriver.cpp
//
// Windows test driver for Poco CppParser.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "WinTestRunner/WinTestRunner.h"
#include "CppParserTestSuite.h"
class TestDriver: public CppUnit::WinTestRunnerApp
{
void TestMain()
{
CppUnit::WinTestRunner runner;
runner.addTest(CppParserTestSuite::suite());
runner.run();
}
};
TestDriver theDriver;