wip: upgrades test
This commit is contained in:
parent
8d0763c29c
commit
a0550b4e65
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@ SUBDIRS += \
|
|||
#tst_join \
|
||||
# tst_phrases
|
||||
tst_quuid \
|
||||
tst_generators
|
||||
tst_generators \
|
||||
tst_upgrades
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#include "db1.h"
|
||||
|
||||
#include "table1.h"
|
||||
|
||||
DB1::DB1() : Nut::Database (),
|
||||
m_sampleTable(new Nut::TableSet<Table1>(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef DB1_H
|
||||
#define DB1_H
|
||||
|
||||
#include <Database>
|
||||
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
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#include "db2.h"
|
||||
|
||||
#include "table2.h"
|
||||
|
||||
DB2::DB2() : Nut::Database (),
|
||||
m_sampleTable(new Nut::TableSet<Table2>(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef DB2_H
|
||||
#define DB2_H
|
||||
|
||||
#include <Database>
|
||||
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
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#include "db3.h"
|
||||
|
||||
#include "table3.h"
|
||||
|
||||
DB3::DB3() : Nut::Database (),
|
||||
m_sampleTable(new Nut::TableSet<Table3>(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef DB3_H
|
||||
#define DB3_H
|
||||
|
||||
#include <Database>
|
||||
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
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include "table1.h"
|
||||
|
||||
|
||||
Table1::Table1(QObject *parent) : Nut::Table (parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include "table2.h"
|
||||
|
||||
|
||||
Table2::Table2(QObject *parent) : Nut::Table (parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include "table3.h"
|
||||
|
||||
|
||||
Table3::Table3(QObject *parent) : Nut::Table (parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#include <QtTest>
|
||||
|
||||
#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)
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef TST_UPGRADES_H
|
||||
#define TST_UPGRADES_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue