Revision 21826301
Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt
tests/em/tst_em.cpp | ||
---|---|---|
if(containsPerson) {
|
||
auto schema = tables.value("person");
|
||
auto columns = schema->getColumns();
|
||
QCOMPARE(columns.size(), 8);
|
||
QCOMPARE(columns.size(), 6);
|
||
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", QVariant::String);
|
||
this->containsColumn(columns, "nickName", QVariant::String);
|
||
this->containsColumn(columns, "gender", QVariant::Int);
|
||
... | ... | |
}
|
||
}
|
||
|
||
|
||
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->executeQuery(qb->dropTable("person")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("article")));
|
||
// QVERIFY(this->e->executeQuery(qb->dropTable("workergroup_workers")));
|
||
// QVERIFY(this->e->executeQuery(qb->dropTable("workergroup")));
|
||
// QVERIFY(this->e->executeQuery(qb->dropTable("employee")));
|
||
auto tableNames = this->e->getSchema()->getTableNames();
|
||
QVERIFY(!tableNames.contains("person"));
|
||
QVERIFY(!tableNames.contains("group"));
|
||
... | ... | |
auto schema = tables.value("employee");
|
||
auto columns = schema->getColumns();
|
||
QCOMPARE(columns.size(), 4);
|
||
this->containsColumn(columns, "id", QVariant::Int, "employee", true);
|
||
this->containsColumn(columns, "id", QVariant::Int, "employee", false);
|
||
this->containsColumn(columns, "persNumber", QVariant::String);
|
||
this->containsColumn(columns, "manager", QVariant::Int);
|
||
this->containsColumn(columns, "department", QVariant::String);
|
||
... | ... | |
|
||
void EmTest::testInheritedRelations() {
|
||
QSharedPointer<Employee> e1 = QSharedPointer<Employee>(new Employee(42, "Fenja", "S.",
|
||
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 10, 10), "Psychology"));
|
||
Person::Gender::FEMALE, "Lotta", QDate(1990, 10, 10), "Psychology"));
|
||
QSharedPointer<Employee> e2 = QSharedPointer<Employee>(new Employee(11, "Janine",
|
||
"Musterfrau",
|
||
Person::Gender::FEMALE, "janine.jpeg", "", "", QDate(2000, 1, 1), "Health", true));
|
||
Person::Gender::FEMALE, "", QDate(2000, 1, 1), "Health", true));
|
||
QSharedPointer<WorkerGroup> wg = QSharedPointer<WorkerGroup>(new
|
||
WorkerGroup("Taskforce P&H", 42));
|
||
wg->addWorker(e1);
|
||
... | ... | |
|
||
void EmTest::testFindById() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Patrick", "De",
|
||
Person::Gender::MALE, "patrick.jpeg", "", "Pat", QDate(2000, 1, 1)));
|
||
Person::Gender::MALE, "Pat", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
QVERIFY(this->e->create(ent));
|
||
auto id = p->getId();
|
||
... | ... | |
|
||
void EmTest::testFindId() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Essi", "Sa",
|
||
Person::Gender::MALE, "essi.jpeg", "", "Essi", QDate(2000, 1, 1)));
|
||
Person::Gender::MALE, "Essi", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
QVERIFY(this->e->create(ent));
|
||
auto entity = QSharedPointer<Entity>(p->copy());
|
||
... | ... | |
|
||
void EmTest::testHasChanged() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Jelena", "Fl",
|
||
Person::Gender::MALE, "max.jpeg", "", "Maxi", QDate(2000, 1, 1)));
|
||
Person::Gender::MALE, "Maxi", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
QVERIFY(this->e->create(ent));
|
||
p->setFirstName("Laura");
|
||
... | ... | |
|
||
void EmTest::testValidate() {
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Patrick", "Pe",
|
||
Person::Gender::MALE, "patrick2.jpeg", "", "Maxi", QDate(2000, 1, 1)));
|
||
Person::Gender::MALE, "Maxi", QDate(2000, 1, 1)));
|
||
auto ent = p.objectCast<Entity>();
|
||
QVERIFY(this->e->validate(ent));
|
||
p->setFirstName("M");
|
||
... | ... | |
|
||
void EmTest::testRelations() {
|
||
QSharedPointer<Person> p1 = QSharedPointer<Person>(new Person("Lucien", "We",
|
||
Person::Gender::MALE, "lucien.jpeg", "", "Luc", QDate(2000, 1, 1)));
|
||
Person::Gender::MALE, "Luc", QDate(2000, 1, 1)));
|
||
QSharedPointer<Person> p2 = QSharedPointer<Person>(new Person("Janine", "Musterfrau",
|
||
Person::Gender::FEMALE, "janine.jpeg", "", "", QDate(2000, 1, 1)));
|
||
Person::Gender::FEMALE, "", QDate(2000, 1, 1)));
|
||
QSharedPointer<Person> p3 = QSharedPointer<Person>(new Person("Fenja", "Sey.",
|
||
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 11, 11)));
|
||
Person::Gender::FEMALE, "Lotta", QDate(1990, 11, 11)));
|
||
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("TestGroup"));
|
||
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("TestGroup2"));
|
||
g->setLeader(p1);
|
tests/em/tst_querybuilder.cpp | ||
---|---|---|
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",
|
||
... | ... | |
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)));
|
||
Person::Gender::MALE, "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"));
|
||
Person::Gender::FEMALE, "", 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"));
|
||
Person::Gender::FEMALE, "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)));
|
||
Person::Gender::FEMALE, "Fenni", QDate(1980, 5, 30)));
|
||
QSharedPointer<Employee> p5 = QSharedPointer<Employee>(new Employee(90, "Milan", "Mes.",
|
||
Person::Gender::MALE, "milan.jpeg", "", "", QDate(1994, 3, 27), "D"));
|
||
Person::Gender::MALE, "", QDate(1994, 3, 27), "D"));
|
||
QSharedPointer<Person> p6 = QSharedPointer<Person>(new Person("Kristina", "Zero",
|
||
Person::Gender::FEMALE, "kristina.jpeg", "", "", QDate(1996, 5, 17)));
|
||
Person::Gender::FEMALE, "", QDate(1996, 5, 17)));
|
||
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("Group Psy"));
|
||
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("Group Health"));
|
||
QSharedPointer<Group> g3 = QSharedPointer<Group>(new Group("Group ABC"));
|
tests/models.cpp | ||
---|---|---|
}
|
||
|
||
Person::Person(QString firstName, QString familyName, Gender gender,
|
||
QString customPictureFileName, QString namePrefix, QString nickName,
|
||
QString nickName,
|
||
QDate birthday, QObject *parent): Entity(parent) {
|
||
setFirstName(firstName);
|
||
setFamilyName(familyName);
|
||
setNamePrefix(namePrefix);
|
||
setNickName(nickName);
|
||
setBirthday(birthday);
|
||
setGender(gender);
|
||
setCustomPictureFileName(customPictureFileName);
|
||
}
|
||
|
||
const QHash<QString, CuteEntityManager::Relation> Person::getRelations() const {
|
||
... | ... | |
if (nameOrder == NameOrder::FAMILY_FIRST_NAME_ORDER) {
|
||
name += this->getFamilyName();
|
||
name += ", ";
|
||
if (!this->getNamePrefix().isEmpty()) {
|
||
name += this->getNamePrefix();
|
||
name += " ";
|
||
}
|
||
name += this->getFirstName();
|
||
} else {
|
||
name += this->getFirstName();
|
||
name += " ";
|
||
name += this->getFamilyName();
|
||
if (!this->getNamePrefix().isEmpty()) {
|
||
name += ", ";
|
||
name += this->getNamePrefix();
|
||
}
|
||
}
|
||
return name;
|
||
}
|
||
... | ... | |
void Person::setFamilyName(const QString &value) {
|
||
familyName = value;
|
||
}
|
||
QString Person::getNamePrefix() const {
|
||
return namePrefix;
|
||
}
|
||
|
||
void Person::setNamePrefix(const QString &value) {
|
||
namePrefix = value;
|
||
}
|
||
|
||
QString Person::getNickName() const {
|
||
return nickName;
|
||
... | ... | |
gender = value;
|
||
}
|
||
|
||
QString Person::getCustomPictureFileName() const {
|
||
return customPictureFileName;
|
||
}
|
||
|
||
void Person::setCustomPictureFileName(const QString &value) {
|
||
customPictureFileName = value;
|
||
}
|
||
|
||
QList<QSharedPointer<Group>> Person::getGroups() const {
|
||
return groups;
|
||
}
|
||
... | ... | |
workers = value;
|
||
}
|
||
|
||
void WorkerGroup::addWorker(const QSharedPointer<Employee> &value)
|
||
{
|
||
void WorkerGroup::addWorker(const QSharedPointer<Employee> &value) {
|
||
this->workers.append(value);
|
||
}
|
tests/models.h | ||
---|---|---|
Q_OBJECT
|
||
Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName)
|
||
Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName)
|
||
Q_PROPERTY(QString namePrefix READ getNamePrefix WRITE setNamePrefix)
|
||
Q_PROPERTY(QString nickName READ getNickName WRITE setNickName)
|
||
Q_PROPERTY(QString customPictureFileName READ getCustomPictureFileName WRITE
|
||
setCustomPictureFileName)
|
||
Q_PROPERTY(QDate birthday READ getBirthday WRITE setBirthday)
|
||
Q_PROPERTY(Gender gender READ getGender WRITE setGender)
|
||
Q_PROPERTY(QList<QSharedPointer<Group>> groups READ getGroups WRITE setGroups)
|
||
... | ... | |
Q_INVOKABLE explicit Person(QObject *parent = 0);
|
||
Person(QString firstName, QString familyName,
|
||
Gender gender = Gender::UNKNOWNGENDER,
|
||
QString customPictureFileName = QString(), QString namePrefix = QString(),
|
||
QString nickName = QString(), QDate birthday = QDate(), QObject *parent = 0);
|
||
|
||
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const
|
||
... | ... | |
QString getFamilyName() const;
|
||
void setFamilyName(const QString &value);
|
||
|
||
QString getNamePrefix() const;
|
||
void setNamePrefix(const QString &value);
|
||
|
||
QString getNickName() const;
|
||
void setNickName(const QString &value);
|
||
|
||
... | ... | |
Gender getGender() const;
|
||
void setGender(const Gender &value);
|
||
|
||
QString getCustomPictureFileName() const;
|
||
void setCustomPictureFileName(const QString &value);
|
||
|
||
QList<QSharedPointer<Group>> getGroups() const;
|
||
void setGroups(const QList<QSharedPointer<Group>> &value);
|
||
|
||
... | ... | |
protected:
|
||
QString firstName;
|
||
QString familyName;
|
||
QString namePrefix;
|
||
QString nickName;
|
||
QDate birthday;
|
||
Gender gender;
|
||
QString customPictureFileName;
|
||
QList <QSharedPointer<Group>> groups;
|
||
QList <QSharedPointer<Group>> maintainedGroups;
|
||
};
|
||
... | ... | |
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) {
|
||
nickName, birthday, parent) {
|
||
this->department = department;
|
||
this->manager = manager;
|
||
this->persNumber = persNumber;
|
Auch abrufbar als: Unified diff
cleanup tests