wip;uuid as primary key [skip ci]
This commit is contained in:
parent
4ea071836b
commit
af64d3f24f
|
|
@ -3,9 +3,9 @@ TEMPLATE = subdirs
|
|||
SUBDIRS += \
|
||||
tst_basic \
|
||||
tst_benckmark \
|
||||
tst_commands \
|
||||
tst_datatypes
|
||||
# tst_commands \
|
||||
tst_datatypes \
|
||||
#tst_join \
|
||||
# tst_phrases
|
||||
# tst_quuid
|
||||
tst_quuid
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "post.h"
|
||||
#include "comment.h"
|
||||
#include "user.h"
|
||||
#include "score.h"
|
||||
|
||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,13 +11,10 @@ class Test : public Nut::Table
|
|||
|
||||
NUT_PRIMARY_KEY(id)
|
||||
NUT_DECLARE_FIELD(QUuid, id, id, setId)
|
||||
|
||||
NUT_NOT_NULL(username)
|
||||
NUT_LEN(username, 50)
|
||||
NUT_DECLARE_FIELD(QString, username, username, setUsername)
|
||||
NUT_DECLARE_FIELD(QUuid, uuid, uuid, setUuid)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE Test(QObject *parentTableSet = 0);
|
||||
Q_INVOKABLE Test(QObject *parentTableSet = nullptr);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Test*)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
QT += qml quick testlib sql
|
||||
QT -= gui
|
||||
|
||||
TARGET = tst_nut
|
||||
TARGET = tst_uuid
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += warn_on qmltestcase c++11
|
||||
|
|
@ -9,12 +9,12 @@ INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
|||
include(../../nut.pri)
|
||||
IMPORTPATH += $$OUT_PWD/../src/imports
|
||||
SOURCES += \
|
||||
maintest.cpp \
|
||||
testdatabase.cpp \
|
||||
test.cpp
|
||||
test.cpp \
|
||||
tst_uuid.cpp
|
||||
|
||||
HEADERS += \
|
||||
maintest.h \
|
||||
../common/consts.h \
|
||||
testdatabase.h \
|
||||
test.h
|
||||
test.h \
|
||||
tst_uuid.h
|
||||
|
|
|
|||
|
|
@ -6,58 +6,65 @@
|
|||
|
||||
#include "consts.h"
|
||||
|
||||
#include "maintest.h"
|
||||
#include "tst_uuid.h"
|
||||
#include "query.h"
|
||||
#include "tableset.h"
|
||||
#include "tablemodel.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
||||
UuidTest::UuidTest(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void MainTest::initTestCase()
|
||||
void UuidTest::initTestCase()
|
||||
{
|
||||
qDebug() << "Test type id:" << qRegisterMetaType<Test*>();
|
||||
qDebug() << "DB type id:" << qRegisterMetaType<TestDatabase*>();
|
||||
|
||||
QFile::remove(DATABASE);
|
||||
|
||||
db.setDriver(DRIVER);
|
||||
db.setHostName(HOST);
|
||||
db.setDatabaseName("nut_tst_quuid");
|
||||
db.setDatabaseName(DATABASE);
|
||||
db.setUserName(USERNAME);
|
||||
db.setPassword(PASSWORD);
|
||||
|
||||
bool ok = db.open();
|
||||
|
||||
db.tests()->query()->remove();
|
||||
uuid = QUuid::createUuid();
|
||||
|
||||
QTEST_ASSERT(ok);
|
||||
}
|
||||
|
||||
void MainTest::add()
|
||||
void UuidTest::save()
|
||||
{
|
||||
TIC();
|
||||
QUuid uuid = QUuid::createUuid();
|
||||
Test t;
|
||||
t.setId(uuid);
|
||||
t.setUsername("test username");
|
||||
t.setId(QUuid::createUuid());
|
||||
t.setUuid(uuid);
|
||||
db.tests()->append(&t);
|
||||
db.saveChanges();
|
||||
int n = db.saveChanges();
|
||||
TOC();
|
||||
|
||||
Test *t2 = db.tests()->query()
|
||||
->where(Test::idField() == uuid)
|
||||
->first();
|
||||
|
||||
TOC();
|
||||
QTEST_ASSERT(t2->id() == uuid);
|
||||
QTEST_ASSERT(n == 1);
|
||||
}
|
||||
|
||||
void MainTest::cleanupTestCase()
|
||||
void UuidTest::restore()
|
||||
{
|
||||
TIC();
|
||||
auto test = db.tests()->query()->first();
|
||||
TOC();
|
||||
QTEST_ASSERT(!test->id().isNull());
|
||||
QTEST_ASSERT(test->uuid() == uuid);
|
||||
}
|
||||
|
||||
void UuidTest::cleanupTestCase()
|
||||
{
|
||||
qDeleteAll(Nut::TableModel::allModels());
|
||||
// Nut::DatabaseModel::deleteAllModels();
|
||||
}
|
||||
|
||||
QTEST_MAIN(MainTest)
|
||||
QTEST_MAIN(UuidTest)
|
||||
|
|
@ -4,21 +4,25 @@
|
|||
#include <QtCore/QObject>
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include <QUuid>
|
||||
|
||||
#include "testdatabase.h"
|
||||
class Test;
|
||||
class MainTest : public QObject
|
||||
class UuidTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
TestDatabase db;
|
||||
QUuid uuid;
|
||||
|
||||
public:
|
||||
explicit MainTest(QObject *parent = 0);
|
||||
explicit UuidTest(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void add();
|
||||
void save();
|
||||
void restore();
|
||||
|
||||
void cleanupTestCase();
|
||||
};
|
||||
Loading…
Reference in New Issue