1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2026-06-30 05:37:10 +02:00

Update POCO to 1.11.0

This commit is contained in:
Sandu Liviu Catalin
2021-08-22 18:07:06 +03:00
parent 151077c799
commit 7a3d92d1d1
450 changed files with 25219 additions and 6528 deletions
@@ -0,0 +1,333 @@
//
// ActiveRecordTest.cpp
//
// Copyright (c) 2020, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ActiveRecordTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/ActiveRecord/Context.h"
#include "Poco/ActiveRecord/Query.h"
#include "Poco/Data/SQLite/Connector.h"
#include "Poco/Data/Statement.h"
#include "Poco/UUIDGenerator.h"
#include "ORM/Employee.h"
#include "ORM/Role.h"
using namespace std::string_literals;
using namespace Poco::Data::Keywords;
using Poco::ActiveRecord::Context;
using Poco::ActiveRecord::Query;
using ORM::Employee;
using ORM::Role;
const std::string ActiveRecordTest::CONNECTOR("SQLite");
const std::string ActiveRecordTest::CONNECTION_STRING("ORM.sqlite");
ActiveRecordTest::ActiveRecordTest(const std::string& name): CppUnit::TestCase(name)
{
}
ActiveRecordTest::~ActiveRecordTest()
{
}
void ActiveRecordTest::testInsert()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
Role::Ptr pDeveloper = new Role;
pDeveloper->name("Developer").description("Developer role");
assertTrue (!pDeveloper->isValid());
pDeveloper->create(pContext);
assertTrue (pDeveloper->isValid());
int n = 0;
session << "SELECT COUNT(*) FROM roles", into(n), now;
assertTrue (n == 1);
assertTrue (pDeveloper->id() == 1);
Role::Ptr pSeniorDeveloper = new Role;
pSeniorDeveloper->name("Senior Developer").description("Senior developer role");
pSeniorDeveloper->create(pContext);
session << "SELECT COUNT(*) FROM roles", into(n), now;
assertTrue (n == 2);
assertTrue (pSeniorDeveloper->id() == 2);
}
void ActiveRecordTest::testFind()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Role::Ptr pRole = Role::find(pContext, 1);
assertTrue (!pRole.isNull());
assertTrue (pRole->name() == "Developer");
assertTrue (pRole->description() == "Developer role");
pRole = Role::find(pContext, 2);
assertTrue (!pRole.isNull());
assertTrue (pRole->name() == "Senior Developer");
assertTrue (pRole->description() == "Senior developer role");
pRole = Role::find(pContext, 3);
assertTrue (!pRole.isNull());
assertTrue (pRole->name() == "Manager");
assertTrue (pRole->description() == "Manager role");
pRole = Role::find(pContext, 4);
assertTrue (pRole.isNull());
}
void ActiveRecordTest::testUpdate()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Role::Ptr pRole = Role::find(pContext, 1);
assertTrue (!pRole.isNull());
pRole->name("Junior Developer").description("Junior developer role");
pRole->update();
pRole = Role::find(pContext, 1);
assertTrue (!pRole.isNull());
assertTrue (pRole->name() == "Junior Developer");
assertTrue (pRole->description() == "Junior developer role");
}
void ActiveRecordTest::testDelete()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Role::Ptr pRole = Role::find(pContext, 1);
assertTrue (!pRole.isNull());
pRole->remove();
pRole = Role::find(pContext, 1);
assertTrue (pRole.isNull());
}
void ActiveRecordTest::testRelations()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Employee::Ptr pManager = new Employee(Poco::UUIDGenerator().createOne());
pManager->name("Bill Lumbergh").ssn("23452343").roleID(3);
pManager->create(pContext);
Role::Ptr pManagerRole = pManager->role();
assertFalse (pManagerRole.isNull());
assertTrue (pManagerRole->id() == 3);
Employee::Ptr pEmployee = new Employee(Poco::UUIDGenerator().createOne());
pEmployee->name("Michael Bolton").ssn("123987123").roleID(2).manager(pManager);
pEmployee->create(pContext);
assertTrue (pEmployee->managerID() == pManager->id());
}
void ActiveRecordTest::testQuery()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Query<Role> query(pContext);
auto result = query.execute();
assertTrue (result.size() == 3);
}
void ActiveRecordTest::testQueryWhere()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Query<Role> query(pContext);
query.where("name = 'Senior Developer'");
auto result = query.execute();
assertTrue (result.size() == 1);
assertTrue (result[0]->name() == "Senior Developer");
}
void ActiveRecordTest::testQueryWhereBind()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Query<Role> query(pContext);
query.where("name = ?").bind("Senior Developer"s);
auto result = query.execute();
assertTrue (result.size() == 1);
assertTrue (result[0]->name() == "Senior Developer");
}
void ActiveRecordTest::testQueryFilter()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Query<Role> query(pContext);
query.filter(
[](const Role& role)
{
return role.name() == "Senior Developer";
}
);
auto result = query.execute();
assertTrue (result.size() == 1);
assertTrue (result[0]->name() == "Senior Developer");
}
void ActiveRecordTest::testQueryOrderBy()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Query<Role> query(pContext);
query.orderBy("id DESC");
auto result = query.execute();
assertTrue (result.size() == 3);
assertTrue (result[0]->name() == "Manager");
}
void ActiveRecordTest::testQueryPaging()
{
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
Context::Ptr pContext = new Context(session);
createRoles(pContext);
Query<Role> query(pContext);
auto result = query.orderBy("id").offset(0).limit(2).execute();
assertTrue (result.size() == 2);
assertTrue (result[0]->name() == "Developer");
assertTrue (result[1]->name() == "Senior Developer");
query.reset();
result = query.orderBy("id").offset(1).limit(2).execute();
assertTrue (result.size() == 2);
assertTrue (result[0]->name() == "Senior Developer");
assertTrue (result[1]->name() == "Manager");
}
void ActiveRecordTest::setUp()
{
Poco::Data::SQLite::Connector::registerConnector();
Poco::Data::Session session(CONNECTOR, CONNECTION_STRING);
session << "DROP TABLE IF EXISTS employees", now;
session << "DROP TABLE IF EXISTS roles", now;
session
<< "CREATE TABLE employees ("
<< " id CHAR(36),"
<< " name VARCHAR(64),"
<< " ssn VARCHAR(32),"
<< " role INTEGER,"
<< " manager CHAR(36)"
<< ")",
now;
session
<< "CREATE TABLE roles ("
<< " id INTEGER PRIMARY KEY AUTOINCREMENT,"
<< " name VARCHAR(64),"
<< " description VARCHAR(256)"
<< ")",
now;
}
void ActiveRecordTest::tearDown()
{
Poco::Data::SQLite::Connector::unregisterConnector();
}
void ActiveRecordTest::createRoles(Poco::ActiveRecord::Context::Ptr pContext)
{
Role::Ptr pDeveloper = new Role;
pDeveloper->name("Developer").description("Developer role");
pDeveloper->create(pContext);
Role::Ptr pSeniorDeveloper = new Role;
pSeniorDeveloper->name("Senior Developer").description("Senior developer role");
pSeniorDeveloper->create(pContext);
Role::Ptr pManager = new Role;
pManager->name("Manager").description("Manager role");
pManager->create(pContext);
}
CppUnit::Test* ActiveRecordTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ActiveRecordTest");
CppUnit_addTest(pSuite, ActiveRecordTest, testInsert);
CppUnit_addTest(pSuite, ActiveRecordTest, testFind);
CppUnit_addTest(pSuite, ActiveRecordTest, testUpdate);
CppUnit_addTest(pSuite, ActiveRecordTest, testDelete);
CppUnit_addTest(pSuite, ActiveRecordTest, testRelations);
CppUnit_addTest(pSuite, ActiveRecordTest, testQuery);
CppUnit_addTest(pSuite, ActiveRecordTest, testQueryWhere);
CppUnit_addTest(pSuite, ActiveRecordTest, testQueryWhereBind);
CppUnit_addTest(pSuite, ActiveRecordTest, testQueryOrderBy);
CppUnit_addTest(pSuite, ActiveRecordTest, testQueryFilter);
CppUnit_addTest(pSuite, ActiveRecordTest, testQueryPaging);
return pSuite;
}
@@ -0,0 +1,51 @@
//
// ActiveRecordTest.h
//
// Definition of the ActiveRecordTest class.
//
// Copyright (c) 2020, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ActiveRecordTest_INCLUDED
#define ActiveRecordTest_INCLUDED
#include "Poco/ActiveRecord/Context.h"
#include "CppUnit/TestCase.h"
class ActiveRecordTest: public CppUnit::TestCase
{
public:
ActiveRecordTest(const std::string& name);
~ActiveRecordTest();
void testInsert();
void testFind();
void testUpdate();
void testDelete();
void testRelations();
void testQuery();
void testQueryWhere();
void testQueryWhereBind();
void testQueryOrderBy();
void testQueryFilter();
void testQueryPaging();
void setUp();
void tearDown();
void createRoles(Poco::ActiveRecord::Context::Ptr pContext);
static CppUnit::Test* suite();
static const std::string CONNECTOR;
static const std::string CONNECTION_STRING;
};
#endif // ActiveRecordTest_INCLUDED
@@ -0,0 +1,22 @@
//
// ActiveRecordTestSuite.cpp
//
// Copyright (c) 2020, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ActiveRecordTestSuite.h"
#include "ActiveRecordTest.h"
CppUnit::Test* ActiveRecordTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ActiveRecordTestSuite");
pSuite->addTest(ActiveRecordTest::suite());
return pSuite;
}
@@ -0,0 +1,27 @@
//
// ActiveRecordTestSuite.h
//
// Definition of the ActiveRecordTestSuite class.
//
// Copyright (c) 2020, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ActiveRecordTestSuite_INCLUDED
#define ActiveRecordTestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
class ActiveRecordTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // ActiveRecordTestSuite_INCLUDED
+17
View File
@@ -0,0 +1,17 @@
//
// Driver.cpp
//
// Console-based test driver for Poco ActiveRecord.
//
// Copyright (c) 2020, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "CppUnit/TestRunner.h"
#include "ActiveRecordTestSuite.h"
CppUnitMain(ActiveRecordTestSuite)
+151
View File
@@ -0,0 +1,151 @@
//
// Employee.cpp
//
// This file has been generated from ORM.xml. Do not edit.
//
#include "ORM/Employee.h"
#include "Poco/UUIDGenerator.h"
using namespace std::string_literals;
using namespace Poco::Data::Keywords;
namespace ORM {
Employee::Employee(ID id):
Poco::ActiveRecord::ActiveRecord<Poco::UUID>(id)
{
}
Employee::Employee(const Employee& other):
Poco::ActiveRecord::ActiveRecord<Poco::UUID>(other),
_name(other._name),
_ssn(other._ssn),
_role(other._role),
_manager(other._manager)
{
}
Role::Ptr Employee::role() const
{
return Role::find(context(), _role);
}
Employee& Employee::role(Role::Ptr pObject)
{
if (pObject)
_role = pObject->id();
else
_role = Role::INVALID_ID;
return *this;
}
Employee::Ptr Employee::manager() const
{
return Employee::find(context(), _manager);
}
Employee& Employee::manager(Employee::Ptr pObject)
{
if (pObject)
_manager = pObject->id();
else
_manager = Employee::INVALID_ID;
return *this;
}
Employee::Ptr Employee::find(Poco::ActiveRecord::Context::Ptr pContext, const ID& id)
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(pContext->statementPlaceholderProvider());
Employee::Ptr pObject(new Employee);
pContext->session()
<< "SELECT id, name, ssn, role, manager"
<< " FROM employees"
<< " WHERE id = " << pSPP->next(),
into(pObject->mutableID()),
into(*pObject),
bind(id),
now;
return withContext(pObject, pContext);
}
void Employee::insert()
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(context()->statementPlaceholderProvider());
if (id().isNull())
{
mutableID() = Poco::UUIDGenerator().createRandom();
}
context()->session()
<< "INSERT INTO employees (id, name, ssn, role, manager)"
<< " VALUES (" << pSPP->next() << ", " << pSPP->next() << ", " << pSPP->next() << ", " << pSPP->next() << ", " << pSPP->next() << ")",
bind(id()),
use(*this),
now;
}
void Employee::update()
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(context()->statementPlaceholderProvider());
context()->session()
<< "UPDATE employees"
<< " SET name = " << pSPP->next() << ", ssn = " << pSPP->next() << ", role = " << pSPP->next() << ", manager = " << pSPP->next()
<< " WHERE id = " << pSPP->next(),
use(*this),
bind(id()),
now;
}
void Employee::remove()
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(context()->statementPlaceholderProvider());
context()->session()
<< "DELETE FROM employees"
<< " WHERE id = " << pSPP->next(),
bind(id()),
now;
}
const std::vector<std::string>& Employee::columns()
{
static const std::vector<std::string> cols =
{
"id"s,
"name"s,
"ssn"s,
"role"s,
"manager"s,
};
return cols;
}
const std::string& Employee::table()
{
static const std::string t = "employees";
return t;
}
} // namespace ORM
+109
View File
@@ -0,0 +1,109 @@
//
// Role.cpp
//
// This file has been generated from ORM.xml. Do not edit.
//
#include "ORM/Role.h"
using namespace std::string_literals;
using namespace Poco::Data::Keywords;
namespace ORM {
Role::Role(ID id):
Poco::ActiveRecord::ActiveRecord<Poco::Int16>(id)
{
}
Role::Role(const Role& other):
Poco::ActiveRecord::ActiveRecord<Poco::Int16>(other),
_name(other._name),
_description(other._description)
{
}
Role::Ptr Role::find(Poco::ActiveRecord::Context::Ptr pContext, const ID& id)
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(pContext->statementPlaceholderProvider());
Role::Ptr pObject(new Role);
pContext->session()
<< "SELECT id, name, description"
<< " FROM roles"
<< " WHERE id = " << pSPP->next(),
into(pObject->mutableID()),
into(*pObject),
bind(id),
now;
return withContext(pObject, pContext);
}
void Role::insert()
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(context()->statementPlaceholderProvider());
context()->session()
<< "INSERT INTO roles (id, name, description)"
<< " VALUES (NULL, " << pSPP->next() << ", " << pSPP->next() << ")",
use(*this),
now;
updateID(context()->session());
}
void Role::update()
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(context()->statementPlaceholderProvider());
context()->session()
<< "UPDATE roles"
<< " SET name = " << pSPP->next() << ", description = " << pSPP->next()
<< " WHERE id = " << pSPP->next(),
use(*this),
bind(id()),
now;
}
void Role::remove()
{
Poco::ActiveRecord::StatementPlaceholderProvider::Ptr pSPP(context()->statementPlaceholderProvider());
context()->session()
<< "DELETE FROM roles"
<< " WHERE id = " << pSPP->next(),
bind(id()),
now;
}
const std::vector<std::string>& Role::columns()
{
static const std::vector<std::string> cols =
{
"id"s,
"name"s,
"description"s,
};
return cols;
}
const std::string& Role::table()
{
static const std::string t = "roles";
return t;
}
} // namespace ORM
+30
View File
@@ -0,0 +1,30 @@
//
// WinCEDriver.cpp
//
// Console-based test driver for Windows CE.
//
// Copyright (c) 2020, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "CppUnit/TestRunner.h"
#include "ActiveRecordTestSuite.h"
#include <cstdlib>
int wmain(int argc, wchar_t* argv[])
{
std::vector<std::string> args;
for (int i = 0; i < argc; ++i)
{
char buffer[1024];
std::wcstombs(buffer, argv[i], sizeof(buffer));
args.push_back(std::string(buffer));
}
CppUnit::TestRunner runner;
runner.addTest("ActiveRecordTestSuite", ActiveRecordTestSuite::suite());
return runner.run(args) ? 0 : 1;
}
+28
View File
@@ -0,0 +1,28 @@
//
// WinDriver.cpp
//
// Windows test driver for Poco ActiveRecord.
//
// Copyright (c) 2020, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: Apache-2.0
//
#include "WinTestRunner/WinTestRunner.h"
#include "ActiveRecordTestSuite.h"
class TestDriver: public CppUnit::WinTestRunnerApp
{
void TestMain()
{
CppUnit::WinTestRunner runner;
runner.addTest(ActiveRecordTestSuite::suite());
runner.run();
}
};
TestDriver theDriver;