Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 20e1ffec

Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt

  • ID 20e1ffecfd4791d41631a32ef710adad09e23a62
  • Vorgänger 4062c152
  • Nachfolger b3c9a8bf

test case updates

Unterschiede anzeigen:

tests/em/tst_em.cpp
void testValidate();
void testRelations();
void testRelationTableCreation();
void testInheritedRelations();
private:
CuteEntityManager::EntityManager *e;
......
QHash<QString, QVariant> attrs = QHash<QString, QVariant>();
attrs.insert("price", 20);
attrs.insert("name", "NewTestItem");
QSharedPointer<Article> article2 = this->e->findEntityByAttributes<Article>
(attrs);
QSharedPointer<Article> article2 = this->e->findEntityByAttributes<Article>(attrs);
QVERIFY(article2);
entity = article2.objectCast<Entity>();
QVERIFY(this->e->remove(entity));
......
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"));
......
void Em::testRelationTableCreation() {
this->createRelationTables();
auto tableNames = this->e->getSchema()->getTableNames();
QVERIFY(tableNames.contains("workergroup"));
QVERIFY(tableNames.contains("employee"));
QVERIFY(tableNames.contains("workergroup_workers"));
QVERIFY(!tableNames.contains("group_employee"));
QVERIFY(!tableNames.contains("employee_workergroups"));
QVERIFY(!tableNames.contains("employee_groups"));
QVERIFY(tableNames.contains("cuteentitymanager::databasemigration"));
auto tables = this->e->getSchema()->getTables();
/**
* @todo test columns
*/
QVERIFY(tables.contains("workergroup"));
QVERIFY(tables.contains("employee"));
QVERIFY(tables.contains("workergroup_workers"));
QVERIFY(!tables.contains("group_employee"));
QVERIFY(!tables.contains("employee_workergroups"));
QVERIFY(!tables.contains("employee_groups"));
QVERIFY(tables.contains("cuteentitymanager::databasemigration"));
auto migrations = this->e->findAll<CuteEntityManager::DatabaseMigration>();
QCOMPARE(migrations.size(), 2);
QCOMPARE(migrations.at(1)->getVersion(), QString("emTestB"));
this->deleteRelationTables();
}
void Em::testInheritedRelations() {
QSharedPointer<Employee> e1 = QSharedPointer<Employee>(new Employee(42, "Fenja", "Sey.",
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 1, 1), "Psychology"));
QSharedPointer<Employee> e2 = QSharedPointer<Employee>(new Employee(11, "Janine",
"Musterfrau",
Person::Gender::FEMALE, "janine.jpeg", "", "", QDate(2000, 1, 1), "Health", true));
QSharedPointer<WorkerGroup> wg = QSharedPointer<WorkerGroup>(new
WorkerGroup("Taskforce P&H", 42));
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));
}
void Em::createRelationTables() {
QStringList relationTables = QStringList() << "Employee" << "WorkerGroup";
QVERIFY2(this->e->startup("emTestB", relationTables), "Failure");
......
Person::Gender::FEMALE, "janine.jpeg", "", "", QDate(2000, 1, 1)));
QSharedPointer<Person> p3 = QSharedPointer<Person>(new Person("Fenja", "Sey.",
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 1, 1)));
QSharedPointer<Group> g = QSharedPointer<Group>(new Group());
g->setName("TestGroup");
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("TestGroup"));
g->setLeader(p1);
g->setPersons({p1});
auto gEnt = g.objectCast<Entity>();
tests/models.cpp
void WorkerGroup::setWorkers(const QList<QSharedPointer<Employee>> &value) {
workers = value;
}
void WorkerGroup::addWorker(const QSharedPointer<Employee> &value)
{
this->workers.append(value);
}
tests/models.h
Q_PROPERTY(bool manager READ isManager WRITE setManager)
public:
Employee() : Person() { }
Employee(quint64 persNumber, QString firstName, QString familyName,
Gender gender = Gender::UNKNOWNGENDER,
QString customPictureFileName = QString(), QString namePrefix = QString(),
QString nickName = QString(), QDate birthday = QDate(), QString department = QString(),
bool manager = false, QObject *parent = 0) : Person(firstName, familyName, gender,
customPictureFileName, namePrefix, nickName, birthday, parent) {
this->department = department;
this->manager = manager;
this->persNumber = persNumber;
}
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const
override;
QString getDepartment() const;
......
quint64 getPersNumber() const;
void setPersNumber(const quint64 &value);
private:
QString department;
quint64 persNumber;
......
setWorkers)
public:
WorkerGroup() : Entity() { }
WorkerGroup(QString name, quint32 efficiency, bool active=true) : Entity() {
this->name = name;
this->efficiency = efficiency;
this->active = active;
}
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const
override;
QString getName() const;
......
QList<QSharedPointer<Employee>> getWorkers() const;
void setWorkers(const QList<QSharedPointer<Employee>> &value);
void addWorker(const QSharedPointer<Employee> &value);
private:
QString name;
......
public:
Q_INVOKABLE Group();
const QHash<QString, CuteEntityManager::Relation> getRelations() const override;
Group(QString name) : Entity() {
this->name = name;
}
QString getName() const;
void setName(const QString &value);
QSharedPointer<Person> getLeader() const;

Auch abrufbar als: Unified diff