diff --git a/src/database.cpp b/src/database.cpp index f70c7c9..f462692 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -232,7 +232,7 @@ bool DatabasePrivate::getCurrectScheema() if (!typeId) qFatal("The class %s is not registered with qt meta object", qPrintable(name)); - +qDebug() << "Table found" << typeId; TableModel *sch = new TableModel(typeId, value); currentModel.append(sch); } diff --git a/test/common/consts.h b/test/common/consts.h index d550036..8a8a532 100644 --- a/test/common/consts.h +++ b/test/common/consts.h @@ -8,7 +8,7 @@ .arg(timer.elapsed() / 1000.) \ .arg(__func__) -#define DRIVER "QMYSQL" +#define DRIVER "QSQLITE" #define DATABASE QString(metaObject()->className()).toLower() + "_db" #define HOST "localhost" #define USERNAME "root" diff --git a/test/test.pro b/test/test.pro index 8a20269..4ca3c4f 100644 --- a/test/test.pro +++ b/test/test.pro @@ -8,5 +8,6 @@ SUBDIRS += \ #tst_join \ # tst_phrases tst_quuid \ - tst_generators + tst_generators \ + tst_upgrades diff --git a/test/tst_upgrades/.gitignore b/test/tst_upgrades/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/test/tst_upgrades/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/test/tst_upgrades/db1.cpp b/test/tst_upgrades/db1.cpp new file mode 100644 index 0000000..3171155 --- /dev/null +++ b/test/tst_upgrades/db1.cpp @@ -0,0 +1,9 @@ +#include "db1.h" + +#include "table1.h" + +DB1::DB1() : Nut::Database (), + m_sampleTable(new Nut::TableSet(this)) +{ + +} diff --git a/test/tst_upgrades/db1.h b/test/tst_upgrades/db1.h new file mode 100644 index 0000000..0a8d915 --- /dev/null +++ b/test/tst_upgrades/db1.h @@ -0,0 +1,21 @@ +#ifndef DB1_H +#define DB1_H + +#include +class Table1; + +class DB1 : public Nut::Database +{ + Q_OBJECT + + NUT_DB_VERSION(1) + + NUT_DECLARE_TABLE(Table1, sampleTable) + +public: + DB1(); +}; + +Q_DECLARE_METATYPE(DB1*) + +#endif // DB1_H diff --git a/test/tst_upgrades/db2.cpp b/test/tst_upgrades/db2.cpp new file mode 100644 index 0000000..de05611 --- /dev/null +++ b/test/tst_upgrades/db2.cpp @@ -0,0 +1,9 @@ +#include "db2.h" + +#include "table2.h" + +DB2::DB2() : Nut::Database (), + m_sampleTable(new Nut::TableSet(this)) +{ + +} diff --git a/test/tst_upgrades/db2.h b/test/tst_upgrades/db2.h new file mode 100644 index 0000000..4049861 --- /dev/null +++ b/test/tst_upgrades/db2.h @@ -0,0 +1,21 @@ +#ifndef DB2_H +#define DB2_H + +#include +class Table2; + +class DB2 : public Nut::Database +{ + Q_OBJECT + + NUT_DB_VERSION(1) + + NUT_DECLARE_TABLE(Table2, sampleTable) + +public: + DB2(); +}; + +Q_DECLARE_METATYPE(DB2*) + +#endif // DB2_H diff --git a/test/tst_upgrades/db3.cpp b/test/tst_upgrades/db3.cpp new file mode 100644 index 0000000..ab4c987 --- /dev/null +++ b/test/tst_upgrades/db3.cpp @@ -0,0 +1,9 @@ +#include "db3.h" + +#include "table3.h" + +DB3::DB3() : Nut::Database (), + m_sampleTable(new Nut::TableSet(this)) +{ + +} diff --git a/test/tst_upgrades/db3.h b/test/tst_upgrades/db3.h new file mode 100644 index 0000000..eae13ad --- /dev/null +++ b/test/tst_upgrades/db3.h @@ -0,0 +1,21 @@ +#ifndef DB3_H +#define DB3_H + +#include +class Table3; + +class DB3 : public Nut::Database +{ + Q_OBJECT + + NUT_DB_VERSION(1) + + NUT_DECLARE_TABLE(Table3, sampleTable) + +public: + DB3(); +}; + +Q_DECLARE_METATYPE(DB3*) + +#endif // DB3_H diff --git a/test/tst_upgrades/table1.cpp b/test/tst_upgrades/table1.cpp new file mode 100644 index 0000000..d74ed3b --- /dev/null +++ b/test/tst_upgrades/table1.cpp @@ -0,0 +1,7 @@ +#include "table1.h" + + +Table1::Table1(QObject *parent) : Nut::Table (parent) +{ + +} diff --git a/test/tst_upgrades/table1.h b/test/tst_upgrades/table1.h new file mode 100644 index 0000000..727b73a --- /dev/null +++ b/test/tst_upgrades/table1.h @@ -0,0 +1,20 @@ +#ifndef TABLE1_H +#define TABLE1_H + +#include "table.h" + +class Table1 : public Nut::Table +{ + Q_OBJECT + + NUT_PRIMARY_AUTO_INCREMENT(id) + NUT_DECLARE_FIELD(int, id, id, setId) + +public: + Q_INVOKABLE Table1(QObject *parent = Q_NULLPTR); + +}; + +Q_DECLARE_METATYPE(Table1*) + +#endif // TABLE1_H diff --git a/test/tst_upgrades/table2.cpp b/test/tst_upgrades/table2.cpp new file mode 100644 index 0000000..3118a19 --- /dev/null +++ b/test/tst_upgrades/table2.cpp @@ -0,0 +1,7 @@ +#include "table2.h" + + +Table2::Table2(QObject *parent) : Nut::Table (parent) +{ + +} diff --git a/test/tst_upgrades/table2.h b/test/tst_upgrades/table2.h new file mode 100644 index 0000000..1b4f06e --- /dev/null +++ b/test/tst_upgrades/table2.h @@ -0,0 +1,23 @@ +#ifndef TABLE2_H +#define TABLE2_H + +#include "table.h" + +class Table2 : public Nut::Table +{ + Q_OBJECT + + NUT_PRIMARY_AUTO_INCREMENT(id) + NUT_DECLARE_FIELD(int, id, id, setId) + + NUT_DECLARE_FIELD(QString, str, str, setStr) + NUT_DECLARE_FIELD(int, grade, grade, setGrade) + +public: + Q_INVOKABLE Table2(QObject *parent = Q_NULLPTR); + +}; + +Q_DECLARE_METATYPE(Table2*) + +#endif // TABLE2_H diff --git a/test/tst_upgrades/table3.cpp b/test/tst_upgrades/table3.cpp new file mode 100644 index 0000000..fa07443 --- /dev/null +++ b/test/tst_upgrades/table3.cpp @@ -0,0 +1,7 @@ +#include "table3.h" + + +Table3::Table3(QObject *parent) : Nut::Table (parent) +{ + +} diff --git a/test/tst_upgrades/table3.h b/test/tst_upgrades/table3.h new file mode 100644 index 0000000..0b68424 --- /dev/null +++ b/test/tst_upgrades/table3.h @@ -0,0 +1,20 @@ +#ifndef TABLE3_H +#define TABLE3_H + +#include "table.h" + +class Table3 : public Nut::Table +{ + Q_OBJECT + + NUT_PRIMARY_AUTO_INCREMENT(id) + NUT_DECLARE_FIELD(int, id, id, setId) + +public: + Q_INVOKABLE Table3(QObject *parent = Q_NULLPTR); + +}; + +Q_DECLARE_METATYPE(Table3*) + +#endif // TABLE3_H diff --git a/test/tst_upgrades/tst_upgrades.cpp b/test/tst_upgrades/tst_upgrades.cpp new file mode 100644 index 0000000..8d4cf68 --- /dev/null +++ b/test/tst_upgrades/tst_upgrades.cpp @@ -0,0 +1,69 @@ +#include + +#include "db1.h" +#include "db2.h" +#include "db3.h" + +#include "table1.h" +#include "table2.h" +#include "table3.h" + +#include "tst_upgrades.h" +#include "consts.h" + +void Upgrades::initDb(Nut::Database &db) +{ + db.setDriver(DRIVER); + db.setHostName(HOST); + db.setDatabaseName(DATABASE); + db.setUserName(USERNAME); + db.setPassword(PASSWORD); +} + +Upgrades::Upgrades() +{ + +} + +Upgrades::~Upgrades() +{ + +} + +void Upgrades::initTestCase() +{ + QFile::remove(DATABASE); + + REGISTER(DB1); + REGISTER(DB2); + REGISTER(DB3); + + REGISTER(Table1); + REGISTER(Table2); + REGISTER(Table3); +} + +void Upgrades::version1() +{ + DB1 db; + initDb(db); + QTEST_ASSERT(db.open()); +} + +void Upgrades::version2() +{ + DB2 db; + initDb(db); + QTEST_ASSERT(db.open()); +} + +void Upgrades::version3() +{ + DB3 db; + initDb(db); + QTEST_ASSERT(db.open()); +} + + +QTEST_APPLESS_MAIN(Upgrades) + diff --git a/test/tst_upgrades/tst_upgrades.h b/test/tst_upgrades/tst_upgrades.h new file mode 100644 index 0000000..fcdfbca --- /dev/null +++ b/test/tst_upgrades/tst_upgrades.h @@ -0,0 +1,28 @@ +#ifndef TST_UPGRADES_H +#define TST_UPGRADES_H + +#include + +namespace Nut { +class Database; +} +class Upgrades : public QObject +{ + Q_OBJECT + + void initDb(Nut::Database &db); + +public: + Upgrades(); + ~Upgrades(); + +private slots: + void initTestCase(); + + void version1(); + void version2(); + void version3(); + +}; + +#endif // TST_UPGRADES_H diff --git a/test/tst_upgrades/tst_upgrades.pro b/test/tst_upgrades/tst_upgrades.pro new file mode 100644 index 0000000..77ae72e --- /dev/null +++ b/test/tst_upgrades/tst_upgrades.pro @@ -0,0 +1,27 @@ +QT += qml quick testlib sql +QT -= gui + +TARGET = tst_upgrades +TEMPLATE = app + +CONFIG += warn_on qmltestcase c++11 +INCLUDEPATH += $$PWD/../../src $$PWD/../common +include(../../nut.pri) +IMPORTPATH += $$OUT_PWD/../src/imports + +SOURCES += tst_upgrades.cpp \ + db1.cpp \ + table1.cpp \ + db2.cpp \ + table2.cpp \ + db3.cpp \ + table3.cpp + +HEADERS += \ + tst_upgrades.h \ + db1.h \ + table1.h \ + db2.h \ + table2.h \ + db3.h \ + table3.h