Revision 9e2d71d6
Von Christian Ehringfeld vor etwa 10 Jahren hinzugefügt
| tests/models.cpp | ||
|---|---|---|
|
}
|
||
|
|
||
|
|
||
|
double Article::getPrice() const
|
||
|
{
|
||
|
return price;
|
||
|
}
|
||
|
|
||
|
void Article::setPrice(double value)
|
||
|
{
|
||
|
price = value;
|
||
|
}
|
||
|
|
||
|
QString Article::getName() const
|
||
|
{
|
||
|
return name;
|
||
|
}
|
||
|
|
||
|
void Article::setName(const QString &value)
|
||
|
{
|
||
|
name = value;
|
||
|
}
|
||
|
|
||
|
Article::~Article() {
|
||
|
|
||
|
}
|
||
|
|
||
|
Article::Article() {
|
||
|
this->price = 0.0;
|
||
|
}
|
||
|
|
||
|
Article::Article(double price, QString name) {
|
||
|
this->price = price;
|
||
|
this->name = name;
|
||
|
}
|
||
| tests/models.h | ||
|---|---|---|
|
#include <QList>
|
||
|
#include <QObject>
|
||
|
#include <QDebug>
|
||
|
#include "../../entitymanager/src/entity.h"
|
||
|
#include "entity.h"
|
||
|
|
||
|
using namespace CuteEntityManager;
|
||
|
class Group;
|
||
| ... | ... | |
|
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_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ getMaintainedGroups WRITE setMaintainedGroups)
|
||
|
Q_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ
|
||
|
getMaintainedGroups WRITE setMaintainedGroups)
|
||
|
|
||
|
public:
|
||
|
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
|
||
| ... | ... | |
|
QList<QSharedPointer<Group> > getMaintainedGroups() const;
|
||
|
void setMaintainedGroups(const QList<QSharedPointer<Group> > &value);
|
||
|
|
||
|
protected:
|
||
|
protected:
|
||
|
QString firstName;
|
||
|
QString familyName;
|
||
|
QString namePrefix;
|
||
| ... | ... | |
|
QList <QSharedPointer<Group>> maintainedGroups;
|
||
|
};
|
||
|
|
||
|
class Person;
|
||
|
class Relation;
|
||
|
class Group: public CuteEntityManager::Entity {
|
||
|
Q_OBJECT
|
||
| ... | ... | |
|
QString name;
|
||
|
};
|
||
|
|
||
|
class Article : public CuteEntityManager::Entity {
|
||
|
Q_OBJECT
|
||
|
Q_PROPERTY(double price READ getPrice WRITE setPrice)
|
||
|
Q_PROPERTY(QString name READ getName WRITE setName)
|
||
|
private:
|
||
|
double price;
|
||
|
QString name;
|
||
|
|
||
|
public:
|
||
|
virtual ~Article();
|
||
|
Q_INVOKABLE Article();
|
||
|
Article(double price, QString name);
|
||
|
double getPrice() const;
|
||
|
void setPrice(double value);
|
||
|
QString getName() const;
|
||
|
void setName(const QString &value);
|
||
|
};
|
||
|
|
||
|
#endif // MODELS_H
|
||
| tests/tables/tst_tables.cpp | ||
|---|---|---|
|
void initTestCase();
|
||
|
void cleanupTestCase();
|
||
|
void testStartup();
|
||
|
void testBasics();
|
||
|
// void init();
|
||
|
// void cleanup();
|
||
|
private:
|
||
| ... | ... | |
|
void Tables::initTestCase() {
|
||
|
CuteEntityManager::EntityInstanceFactory::registerClass<Group>();
|
||
|
CuteEntityManager::EntityInstanceFactory::registerClass<Person>();
|
||
|
CuteEntityManager::EntityInstanceFactory::registerClass<Article>();
|
||
|
this->e = new CuteEntityManager::EntityManager("QSQLITE",
|
||
|
":memory:", "", "", "", "", true, "foreign_keys = ON");
|
||
|
}
|
||
| ... | ... | |
|
QCOMPARE(migrations.at(0)->getVersion(), QString("test0.1"));
|
||
|
}
|
||
|
|
||
|
void Tables::testBasics() {
|
||
|
this->e->createTable("Article");
|
||
|
QVERIFY(this->e->getSchema()->getTableNames().contains("article"));
|
||
|
QSharedPointer<Article> article = QSharedPointer<Article>(new Article(10,
|
||
|
QString("TestItem")));
|
||
|
QSharedPointer<Entity> entity = article.objectCast<Entity>();
|
||
|
QVERIFY(this->e->create(entity));
|
||
|
article->setPrice(20);
|
||
|
article->setName("NewTestItem");
|
||
|
QVERIFY(this->e->save(entity));
|
||
|
QHash<QString, QVariant> attrs = QHash<QString, QVariant>();
|
||
|
attrs.insert("price", 20);
|
||
|
attrs.insert("name", "NewTestItem");
|
||
|
QSharedPointer<Article> article2 = this->e->findEntityByAttributes<Article>
|
||
|
(attrs);
|
||
|
QVERIFY(article2);
|
||
|
entity = article2.objectCast<Entity>();
|
||
|
QVERIFY(this->e->remove(entity));
|
||
|
QCOMPARE(this->e->count("article"), (quint8)0);
|
||
|
this->e->getDb()->exec(this->e->getQueryBuilder()->dropTable("article"));
|
||
|
QVERIFY(!this->e->getSchema()->getTableNames().contains("article"));
|
||
|
}
|
||
|
|
||
|
QTEST_APPLESS_MAIN(Tables)
|
||
|
|
||
|
#include "tst_tables.moc"
|
||
Auch abrufbar als: Unified diff
basic test