Revision cca98131
Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt
tests/em/em.pro | ||
---|---|---|
|
||
|
||
SOURCES += tst_em.cpp \
|
||
tst_querybuildertest.cpp \
|
||
../models.cpp
|
||
../models.cpp \
|
||
main.cpp \
|
||
tst_querybuilder.cpp
|
||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
||
|
||
HEADERS += \
|
||
../models.h
|
||
../models.h \
|
||
tst_em.h \
|
||
tst_querybuilder.h
|
tests/em/main.cpp | ||
---|---|---|
#include <QtTest>
|
||
#include "tst_em.h"
|
||
#include "tst_querybuilder.h"
|
||
|
||
int main(int argc, char** argv) {
|
||
EmTest em;
|
||
QuerybuilderTest queryBuilderTest;
|
||
return QTest::qExec(&em, argc, argv) |
|
||
QTest::qExec(&queryBuilderTest, argc, argv);
|
||
}
|
tests/em/tst_em.cpp | ||
---|---|---|
#include <QString>
|
||
#include <QtTest>
|
||
#include <QSqlIndex>
|
||
#include "entitymanager.h"
|
||
#include "databasemigration.h"
|
||
#include "../models.h"
|
||
class Em : public QObject {
|
||
Q_OBJECT
|
||
#include "tst_em.h"
|
||
|
||
public:
|
||
Em();
|
||
|
||
private Q_SLOTS:
|
||
void initTestCase();
|
||
void cleanupTestCase();
|
||
void testCheckDuplicates();
|
||
void testBasics();
|
||
void init();
|
||
void cleanup();
|
||
void testFindById();
|
||
void testFindId();
|
||
void testHasChanged();
|
||
void testValidate();
|
||
void testRelations();
|
||
void testRelationTableCreation();
|
||
void testInheritedRelations();
|
||
void testDatabaseMigrationTable();
|
||
void testTableCreation();
|
||
|
||
private:
|
||
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::initTestCase() {
|
||
void EmTest::initTestCase() {
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Group>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Person>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Article>();
|
||
... | ... | |
":memory:", "", "", "", "", true, "foreign_keys = ON");
|
||
}
|
||
|
||
void Em::cleanupTestCase() {
|
||
void EmTest::cleanupTestCase() {
|
||
if (this->e) {
|
||
delete this->e;
|
||
this->e = nullptr;
|
||
}
|
||
}
|
||
|
||
void Em::testCheckDuplicates() {
|
||
void EmTest::testCheckDuplicates() {
|
||
QSharedPointer<Article> article = QSharedPointer<Article>(new Article(10,
|
||
QString("TestItem")));
|
||
QSharedPointer<Entity> entity = article.objectCast<Entity>();
|
||
... | ... | |
QVERIFY(!this->e->create(copy, true, true));
|
||
}
|
||
|
||
|
||
|
||
void Em::testBasics() {
|
||
void EmTest::testBasics() {
|
||
QSharedPointer<Article> article = QSharedPointer<Article>(new Article(10,
|
||
QString("TestItem")));
|
||
QSharedPointer<Entity> entity = article.objectCast<Entity>();
|
||
... | ... | |
QCOMPARE(this->e->count("article"), (quint8)0);
|
||
}
|
||
|
||
void Em::init() {
|
||
void EmTest::init() {
|
||
QStringList inits = QStringList() << "Person" << "Group" << "Article";
|
||
QVERIFY2(this->e->startup("emTestA", inits), "Failure");
|
||
auto migrations = this->e->findAll<CuteEntityManager::DatabaseMigration>();
|
||
... | ... | |
QCOMPARE(migrations.at(0)->getVersion(), QString("emTestA"));
|
||
}
|
||
|
||
void Em::testDatabaseMigrationTable() {
|
||
void EmTest::testDatabaseMigrationTable() {
|
||
auto tables = this->e->getSchema()->getTables();
|
||
QString tblName = "cuteentitymanager::databasemigration";
|
||
bool containsMigration = tables.contains(tblName);
|
||
... | ... | |
}
|
||
}
|
||
|
||
void Em::testTableCreation() {
|
||
void EmTest::testTableCreation() {
|
||
auto tables = this->e->getSchema()->getTables();
|
||
bool containsArticle = tables.contains("article");
|
||
QVERIFY(containsArticle);
|
||
... | ... | |
}
|
||
|
||
|
||
void Em::containsColumn(QHash<QString, QSharedPointer<QSqlField>> &columns, QString name,
|
||
QVariant::Type type, QString tableName, bool pk) {
|
||
void EmTest::containsColumn(QHash<QString, QSharedPointer<QSqlField>> &columns,
|
||
QString name,
|
||
QVariant::Type type, QString tableName, bool pk) {
|
||
bool containsColumn = columns.contains(name);
|
||
QVERIFY(containsColumn);
|
||
if(containsColumn) {
|
||
... | ... | |
}
|
||
|
||
|
||
void Em::cleanup() {
|
||
void EmTest::cleanup() {
|
||
auto qb = this->e->getQueryBuilder();
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("person_groups")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("group")));
|
||
... | ... | |
QVERIFY(this->e->removeAll("cuteentitymanager::databasemigration"));
|
||
}
|
||
|
||
void Em::testRelationTableCreation() {
|
||
void EmTest::testRelationTableCreation() {
|
||
this->createRelationTables();
|
||
auto tables = this->e->getSchema()->getTables();
|
||
QVERIFY(tables.contains("workergroup"));
|
||
... | ... | |
this->deleteRelationTables();
|
||
}
|
||
|
||
void Em::testInheritedRelations() {
|
||
void EmTest::testInheritedRelations() {
|
||
QSharedPointer<Employee> e1 = QSharedPointer<Employee>(new Employee(42, "Fenja", "S.",
|
||
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 10, 10), "Psychology"));
|
||
QSharedPointer<Employee> e2 = QSharedPointer<Employee>(new Employee(11, "Janine",
|
||
... | ... | |
}
|
||
}
|
||
|
||
void Em::createRelationTables() {
|
||
void EmTest::createRelationTables() {
|
||
QStringList relationTables = QStringList() << "Employee" << "WorkerGroup";
|
||
QVERIFY2(this->e->startup("emTestB", relationTables), "Failure");
|
||
}
|
||
|
||
void Em::deleteRelationTables() {
|
||
void EmTest::deleteRelationTables() {
|
||
auto qb = this->e->getQueryBuilder();
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("workergroup_workers")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("employee")));
|
||
... | ... | |
QCOMPARE(migrations.size(), 1);
|
||
}
|
||
|
||
void Em::testFindById() {
|
||
void EmTest::testFindById() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Patrick", "De",
|
||
Person::Gender::MALE, "patrick.jpeg", "", "Pat", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
... | ... | |
QVERIFY(this->e->findById(id, p->getClassname()));
|
||
}
|
||
|
||
void Em::testFindId() {
|
||
void EmTest::testFindId() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Essi", "Sa",
|
||
Person::Gender::MALE, "essi.jpeg", "", "Essi", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
... | ... | |
QVERIFY(foundId > -1 && foundId == ent->getId());
|
||
}
|
||
|
||
void Em::testHasChanged() {
|
||
void EmTest::testHasChanged() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Jelena", "Fl",
|
||
Person::Gender::MALE, "max.jpeg", "", "Maxi", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
... | ... | |
QVERIFY(this->e->hasChanged(ent));
|
||
}
|
||
|
||
void Em::testValidate() {
|
||
void EmTest::testValidate() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Patrick", "Pe",
|
||
Person::Gender::MALE, "patrick2.jpeg", "", "Maxi", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
... | ... | |
QVERIFY(!this->e->validate(ent) && ent->getErrors().size() == 2);
|
||
}
|
||
|
||
void Em::testRelations() {
|
||
void EmTest::testRelations() {
|
||
QSharedPointer<Person> p1 = QSharedPointer<Person>(new Person("Lucien", "We",
|
||
Person::Gender::MALE, "lucien.jpeg", "", "Luc", QDate(2000, 1, 1)));
|
||
QSharedPointer<Person> p2 = QSharedPointer<Person>(new Person("Janine", "Musterfrau",
|
||
... | ... | |
this->e->refresh(entityFp);
|
||
QVERIFY(firstPerson->getGroups().size() == 0 && g->getPersons().size() == 1);
|
||
}
|
||
|
||
QTEST_APPLESS_MAIN(Em)
|
||
|
||
#include "tst_em.moc"
|
tests/em/tst_em.h | ||
---|---|---|
#ifndef TST_EM
|
||
#define TST_EM
|
||
#include <QString>
|
||
#include <QtTest>
|
||
#include <QSqlIndex>
|
||
#include "entitymanager.h"
|
||
#include "databasemigration.h"
|
||
#include "../models.h"
|
||
|
||
class EmTest : public QObject {
|
||
Q_OBJECT
|
||
|
||
private Q_SLOTS:
|
||
void initTestCase();
|
||
void cleanupTestCase();
|
||
void testCheckDuplicates();
|
||
void testBasics();
|
||
void init();
|
||
void cleanup();
|
||
void testFindById();
|
||
void testFindId();
|
||
void testHasChanged();
|
||
void testValidate();
|
||
void testRelations();
|
||
void testRelationTableCreation();
|
||
void testInheritedRelations();
|
||
void testDatabaseMigrationTable();
|
||
void testTableCreation();
|
||
|
||
private:
|
||
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);
|
||
};
|
||
#endif // TST_EM
|
||
|
tests/em/tst_querybuilder.cpp | ||
---|---|---|
#include "tst_querybuilder.h"
|
||
|
||
void QuerybuilderTest::initTestCase() {
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Group>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Person>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Article>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Employee>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<WorkerGroup>();
|
||
this->e = new CuteEntityManager::EntityManager("QSQLITE",
|
||
":memory:", "", "", "", "", true, "foreign_keys = ON");
|
||
QStringList inits = QStringList() << "Person" << "Group" << "Employee" << "WorkerGroup";
|
||
QVERIFY2(this->e->startup("queryBuilderTest", inits), "Failure");
|
||
QSharedPointer<Person> p1 = QSharedPointer<Person>(new Person("Lucien", "We",
|
||
Person::Gender::MALE, "lucien.jpeg", "", "Luc", QDate(1995, 2, 4)));
|
||
QSharedPointer<Employee> p2 = QSharedPointer<Employee>(new Employee(11, "Janine",
|
||
"Musterfrau",
|
||
Person::Gender::FEMALE, "janine.jpeg", "", "", QDate(1992, 8, 5), "B"));
|
||
QSharedPointer<Employee> p3 = QSharedPointer<Employee>(new Employee(42, "Fenja", "Sey.",
|
||
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 11, 11), "A"));
|
||
QSharedPointer<Person> p4 = QSharedPointer<Person>(new Person("Fenja", "Neu",
|
||
Person::Gender::FEMALE, "fenja2.jpeg", "", "Fenni", QDate(1980, 5, 30)));
|
||
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("Group Psy"));
|
||
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("Group Health"));
|
||
g->setLeader(p1);
|
||
g->setPersons({p1, p2, p4});
|
||
g2->setLeader(p3);
|
||
g2->setPersons({p3});
|
||
QSharedPointer<WorkerGroup> wg = QSharedPointer<WorkerGroup>(new
|
||
WorkerGroup("Taskforce P&H", 50));
|
||
wg->addWorker(p2);
|
||
wg->addWorker(p3);
|
||
auto gEnt = g.objectCast<Entity>();
|
||
auto g2Ent = g2.objectCast<Entity>();
|
||
auto wgEnt = wg.objectCast<Entity>();
|
||
try {
|
||
QVERIFY(this->e->save(gEnt));
|
||
QVERIFY(this->e->save(wgEnt));
|
||
QVERIFY(this->e->save(g2Ent));
|
||
} catch(QString s) {
|
||
QFAIL(s.toUtf8().constData());
|
||
}
|
||
}
|
||
|
||
void QuerybuilderTest::cleanupTestCase() {
|
||
auto qb = this->e->getQueryBuilder();
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("workergroup_workers")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("employee")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("workergroup")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("person_groups")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("group")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("person")));
|
||
QVERIFY(this->e->removeAll("cuteentitymanager::databasemigration"));
|
||
if (this->e) {
|
||
delete this->e;
|
||
this->e = nullptr;
|
||
}
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributes() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["persNumber"] = 42;
|
||
QSharedPointer<Employee> p = e->findEntityByAttributes<Employee>(attributes, true);
|
||
QVERIFY(p);
|
||
QCOMPARE(p->getNickName(), QString("Lotta"));
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToOneRelation() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["firstName"] = QString("Lucien");
|
||
attributes["familyName"] = QString("We");
|
||
QSharedPointer<Person> p = e->findEntityByAttributes<Person>(attributes, true);
|
||
QVERIFY(p);
|
||
attributes.clear();
|
||
attributes["leader"] = QVariant(p);
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
QCOMPARE(group->getName(), QString("Group Psy"));
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToOneRelationAttribute() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["leader.firstName"] = QString("Fenja");
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToManyRelation() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["persNumber"] = 42;
|
||
QSharedPointer<Person> p = e->findEntityByAttributes<Person>(attributes, true);
|
||
QVERIFY(p);
|
||
QCOMPARE(p->getNickName(), QString("Lotta"));
|
||
attributes.clear();
|
||
attributes["persons"] = QVariant(p);
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
QCOMPARE(group->getName(), QString("Group Health"));
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToManyRelationWithList() {
|
||
QHash<QString, QVariant> attributes;
|
||
QList<QSharedPointer<Person>> persons = QList<QSharedPointer<Person>>();
|
||
attributes["firstName"] = QString("Lucien");
|
||
QSharedPointer<Person> p1 = e->findEntityByAttributes<Person>(attributes, true);
|
||
QVERIFY(p1);
|
||
QCOMPARE(p1->getFamilyName(), QString("We"));
|
||
persons.append(p1);
|
||
attributes["firstName"] = QString("Janine");
|
||
QSharedPointer<Person> p2 = e->findEntityByAttributes<Person>(attributes, true);
|
||
QVERIFY(p2);
|
||
QCOMPARE(p2->getFamilyName(), QString("Musterfrau"));
|
||
persons.append(p2);
|
||
attributes.clear();
|
||
QVariant var;
|
||
var.setValue<QList<QSharedPointer<Person>>>(persons);
|
||
attributes["persons"] = var;
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
QCOMPARE(group->getName(), QString("Group Psy"));
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToManyRelationAttribute() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["persons.firstName"] = QString("Janine");
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
QCOMPARE(group->getName(), QString("Group Psy"));
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilder() {
|
||
// Query q = Query();
|
||
// q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim"),
|
||
// JokerPosition::BEHIND));
|
||
// q.appendWhere(e->getQueryBuilder()->andOperator());
|
||
// q.appendWhere(e->getQueryBuilder()->arbitraryOperator("<", "birthday",
|
||
// QDate(2000, 10, 10)));
|
||
// //q.appendJoin(Join("person", "pupil.id = person.id"));
|
||
// q.setDistinct(true);
|
||
// q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
|
||
// q.setLimit(10);
|
||
// QList<QSharedPointer<Pupil>> list = e->find<Pupil>(q, true);
|
||
}
|
tests/em/tst_querybuilder.h | ||
---|---|---|
#ifndef TST_QUERYBUILDER
|
||
#define TST_QUERYBUILDER
|
||
#include <QString>
|
||
#include <QtTest>
|
||
#include "entitymanager.h"
|
||
#include "databasemigration.h"
|
||
#include "../models.h"
|
||
|
||
class QuerybuilderTest : public QObject {
|
||
Q_OBJECT
|
||
|
||
private Q_SLOTS:
|
||
void initTestCase();
|
||
void cleanupTestCase();
|
||
void testFindByAttributes();
|
||
void testFindByAttributesManyToOneRelation();
|
||
void testFindByAttributesManyToOneRelationAttribute();
|
||
void testFindByAttributesManyToManyRelation();
|
||
void testFindByAttributesManyToManyRelationWithList();
|
||
void testFindByAttributesManyToManyRelationAttribute();
|
||
void testQueryBuilder();
|
||
private:
|
||
CuteEntityManager::EntityManager *e;
|
||
};
|
||
#endif // TST_QUERYBUILDER
|
||
|
tests/em/tst_querybuildertest.cpp | ||
---|---|---|
#include <QString>
|
||
#include <QtTest>
|
||
#include "entitymanager.h"
|
||
#include "databasemigration.h"
|
||
#include "../models.h"
|
||
|
||
class QuerybuilderTest : public QObject {
|
||
Q_OBJECT
|
||
|
||
public:
|
||
QuerybuilderTest();
|
||
|
||
private Q_SLOTS:
|
||
void initTestCase();
|
||
void cleanupTestCase();
|
||
void testFindByAttributes();
|
||
void testFindByAttributesManyToOneRelation();
|
||
void testFindByAttributesManyToOneRelationAttribute();
|
||
void testFindByAttributesManyToManyRelation();
|
||
void testFindByAttributesManyToManyRelationAttribute();
|
||
void testFindByAttributesInheritance();
|
||
void testQueryBuilder();
|
||
void testQueryBuilderInheritance();
|
||
private:
|
||
CuteEntityManager::EntityManager *e;
|
||
};
|
||
|
||
QuerybuilderTest::QuerybuilderTest() {
|
||
}
|
||
|
||
void QuerybuilderTest::initTestCase() {
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Group>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Person>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Article>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Employee>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<WorkerGroup>();
|
||
this->e = new CuteEntityManager::EntityManager("QSQLITE",
|
||
":memory:", "", "", "", "", true, "foreign_keys = ON");
|
||
QStringList inits = QStringList() << "Person" << "Group" << "Employee" << "WorkerGroup";
|
||
QVERIFY2(this->e->startup("queryBuilderTest", inits), "Failure");
|
||
QSharedPointer<Person> p1 = QSharedPointer<Person>(new Person("Lucien", "We",
|
||
Person::Gender::MALE, "lucien.jpeg", "", "Luc", QDate(1995, 2, 4)));
|
||
QSharedPointer<Employee> p2 = QSharedPointer<Employee>(new Employee(11, "Janine",
|
||
"Musterfrau",
|
||
Person::Gender::FEMALE, "janine.jpeg", "", "", QDate(1992, 8, 5), "B"));
|
||
QSharedPointer<Employee> p3 = QSharedPointer<Employee>(new Employee(42, "Fenja", "Sey.",
|
||
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 11, 11), "A"));
|
||
QSharedPointer<Person> p4 = QSharedPointer<Person>(new Person("Fenja", "Neu",
|
||
Person::Gender::FEMALE, "fenja2.jpeg", "", "Fenni", QDate(1980, 5, 30)));
|
||
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("Group Psy"));
|
||
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("Group Health"));
|
||
g->setLeader(p1);
|
||
g->setPersons({p1, p2, p4});
|
||
g->setLeader(p3);
|
||
g->setPersons({p3});
|
||
QSharedPointer<WorkerGroup> wg = QSharedPointer<WorkerGroup>(new
|
||
WorkerGroup("Taskforce P&H", 50));
|
||
wg->addWorker(p2);
|
||
wg->addWorker(p3);
|
||
auto gEnt = g.objectCast<Entity>();
|
||
auto g2Ent = g2.objectCast<Entity>();
|
||
auto wgEnt = wg.objectCast<Entity>();
|
||
QVERIFY(this->e->save(gEnt));
|
||
QVERIFY(this->e->save(wgEnt));
|
||
QVERIFY(this->e->save(g2Ent));
|
||
}
|
||
|
||
void QuerybuilderTest::cleanupTestCase() {
|
||
auto qb = this->e->getQueryBuilder();
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("workergroup_workers")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("employee")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("workergroup")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("person_groups")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("group")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("person")));
|
||
QVERIFY(this->e->removeAll("cuteentitymanager::databasemigration"));
|
||
if (this->e) {
|
||
delete this->e;
|
||
this->e = nullptr;
|
||
}
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributes() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["persNumber"] = 42;
|
||
QSharedPointer<Employee> p = e->findEntityByAttributes<Employee>(attributes, true);
|
||
QVERIFY(p);
|
||
QCOMPARE(p->getNickName(), QString("Lotta"));
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToOneRelation() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["firstName"] = QString("Lucien");
|
||
attributes["familyName"] = QString("We");
|
||
QSharedPointer<Person> p = e->findEntityByAttributes<Person>(attributes, true);
|
||
QVERFIY(p);
|
||
attributes.clear();
|
||
attributes["leader"] = p;
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
QCOMPARE(group->getName(),QString("Group Psy"));
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToOneRelationAttribute() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["leader.firstName"] = QString("Fenja");
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToManyRelation() {
|
||
QHash<QString, QVariant> attributes;
|
||
QList<QSharedPointer<Person>> persons = QList<QSharedPointer<Person>>();
|
||
// attributes["persons"] = QVariant(persons);
|
||
// QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
// (attributes, true);
|
||
// QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToManyRelationAttribute() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["persons.firstName"] = QString("Fenja");
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesInheritance() {
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilder() {
|
||
// Query q = Query();
|
||
// q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim"),
|
||
// JokerPosition::BEHIND));
|
||
// q.appendWhere(e->getQueryBuilder()->andOperator());
|
||
// q.appendWhere(e->getQueryBuilder()->arbitraryOperator("<", "birthday",
|
||
// QDate(2000, 10, 10)));
|
||
// //q.appendJoin(Join("person", "pupil.id = person.id"));
|
||
// q.setDistinct(true);
|
||
// q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
|
||
// q.setLimit(10);
|
||
// QList<QSharedPointer<Pupil>> list = e->find<Pupil>(q, true);
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderInheritance() {
|
||
}
|
||
|
||
|
||
QTESTCASE_H
|
||
//QTEST_APPLESS_MAIN(QuerybuilderTest)
|
||
|
||
#include "tst_querybuildertest.moc"
|
tests/validators/main.cpp | ||
---|---|---|
#include <QtTest>
|
||
|
||
int main(int argc, char** argv) {
|
||
// EmTest em;
|
||
// QuerybuilderTest queryBuilderTest;
|
||
// return QTest::qExec(&em, argc, argv) |
|
||
// QTest::qExec(&queryBuilderTest, argc, argv);
|
||
return 0;
|
||
}
|
tests/validators/tst_validatorstest.cpp | ||
---|---|---|
QVERIFY2(true, "Failure");
|
||
}
|
||
|
||
QTEST_APPLESS_MAIN(ValidatorsTest)
|
||
|
||
#include "tst_validatorstest.moc"
|
tests/validators/validators.pro | ||
---|---|---|
TEMPLATE = app
|
||
|
||
|
||
SOURCES += tst_validatorstest.cpp
|
||
SOURCES += tst_validatorstest.cpp \
|
||
main.cpp
|
||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
Auch abrufbar als: Unified diff
test organisation