Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b3c9a8bf

Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt

  • ID b3c9a8bf42a3cb955b68a667c8ecd7996a5a2a0d
  • Vorgänger 20e1ffec
  • Nachfolger d8f2b16b

testcases

Unterschiede anzeigen:

src/entitymanager.cpp
void EntityManager::missingManyToManyTable(const QString &tblName,
const QSharedPointer<Entity> &e, const Relation &r) {
this->logger->logMsg("MANY_TO_MANY Table " + tblName + " is missing.\n" +
"Entity " + EntityHelper::getClassName(e.data()) +
" is affected.\n" + "Relation of property: " + r.getPropertyName(),
MsgType::CRITICAL);
QString text = "MANY_TO_MANY Table " + tblName + " is missing.\n" +
"Entity " + EntityHelper::getClassName(e.data()) +
" is affected.\n" + "Relation of property: " + r.getPropertyName();
#ifdef QT_DEBUG
throw QString(text);
#else
this->logger->logMsg(text, MsgType::CRITICAL);
#endif
}
void EntityManager::manyToMany(const QSharedPointer<Entity> &entity,
......
QSharedPointer<Entity> e;
for (int var = 0; var < listMap.size(); ++var) {
auto id = listMap.at(var).value(builder->generateManyToManyColumnName(secEntityPtr));
if (refresh || !(this->cache.contains(id.toLongLong(), secClassName) && (e = this->cache.get(id.toLongLong(), secClassName)))) {
if (refresh || !(this->cache.contains(id.toLongLong(), secClassName) &&
(e = this->cache.get(id.toLongLong(), secClassName)))) {
e = this->findById(id.toLongLong(), secClassName);
}
if (e) {
tests/em/tst_em.cpp
#include <QString>
#include <QtTest>
#include <QSqlIndex>
#include "entitymanager.h"
#include "databasemigration.h"
#include "../models.h"
......
CuteEntityManager::EntityManager *e;
void createRelationTables();
void deleteRelationTables();
void containsColumn(QHash<QString, QSharedPointer<QSqlField>> &columns, QString name,
QVariant::Type type = QVariant::UserType, QString tableName = "", bool pk = false);
};
Em::Em() {
......
void Em::init() {
QStringList inits = QStringList() << "Person" << "Group" << "Article";
QVERIFY2(this->e->startup("emTestA", inits), "Failure");
auto tableNames = this->e->getSchema()->getTableNames();
/**
* @todo test columns
*/
QVERIFY(tableNames.contains("article"));
QVERIFY(tableNames.contains("person"));
QVERIFY(tableNames.contains("group"));
QVERIFY(tableNames.contains("person_groups"));
QVERIFY(!tableNames.contains("group_persons"));
QVERIFY(tableNames.contains("cuteentitymanager::databasemigration"));
auto tables = this->e->getSchema()->getTables();
bool containsArticle = tables.contains("article");
QVERIFY(containsArticle);
if(containsArticle) {
auto schema = tables.value("article");
auto columns = schema->getColumns();
QCOMPARE(columns.size(), 3);
this->containsColumn(columns, "id", QVariant::Int, "article", true);
this->containsColumn(columns, "name", QVariant::String);
this->containsColumn(columns, "price", QVariant::Double);
}
bool containsPerson = tables.contains("person");
QVERIFY(containsPerson);
if(containsPerson) {
auto schema = tables.value("person");
auto columns = schema->getColumns();
QCOMPARE(columns.size(), 8);
this->containsColumn(columns, "id", QVariant::Int, "person", true);
this->containsColumn(columns, "namePrefix", QVariant::String);
this->containsColumn(columns, "firstName", QVariant::String);
this->containsColumn(columns, "familyName", QVariant::String);
this->containsColumn(columns, "customPictureFileName", QVariant::String);
this->containsColumn(columns, "birthday");
this->containsColumn(columns, "nickName", QVariant::String);
this->containsColumn(columns, "gender", QVariant::Int);
}
bool containsGroup = tables.contains("group");
QVERIFY(containsGroup);
if(containsGroup) {
auto schema = tables.value("group");
auto columns = schema->getColumns();
QCOMPARE(columns.size(), 3);
this->containsColumn(columns, "id", QVariant::Int, "group", true);
this->containsColumn(columns, "name", QVariant::String);
this->containsColumn(columns, "leader_id");
}
QVERIFY(tables.contains("person_groups"));
QVERIFY(!tables.contains("group_persons"));
QVERIFY(tables.contains("cuteentitymanager::databasemigration"));
auto migrations = this->e->findAll<CuteEntityManager::DatabaseMigration>();
QCOMPARE(migrations.size(), 1);
QCOMPARE(migrations.at(0)->getVersion(), QString("emTestA"));
}
void Em::containsColumn(QHash<QString, QSharedPointer<QSqlField>> &columns, QString name,
QVariant::Type type, QString tableName, bool pk) {
bool containsColumn = columns.contains(name);
QVERIFY(containsColumn);
if(containsColumn) {
auto column = columns.value(name);
if(type != QVariant::UserType) {
QCOMPARE(column->type(), type);
}
if(pk) {
QCOMPARE(this->e->getDb()->getDatabase().primaryIndex(tableName).fieldName(0), name);
}
}
}
void Em::cleanup() {
auto qb = this->e->getQueryBuilder();
QVERIFY(this->e->executeQuery(qb->dropTable("person_groups")));
......
wg->addWorker(e1);
wg->addWorker(e2);
auto entityWorkerGroup = wg.objectCast<Entity>();
QVERIFY(this->e->create(entityWorkerGroup));
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("EmployeeGroup"));
g->setPersons({e1, e2});
auto entityGroup = g.objectCast<Entity>();
QVERIFY(this->e->create(entityGroup));
try {
QVERIFY(this->e->create(entityWorkerGroup));
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("EmployeeGroup"));
g->setPersons({e1, e2});
auto entityGroup = g.objectCast<Entity>();
QVERIFY(this->e->create(entityGroup));
} catch(QString e) {
QFAIL(e.toUtf8().constData());
}
}
void Em::createRelationTables() {

Auch abrufbar als: Unified diff