fix QDate[Time].toString()
This commit is contained in:
parent
1fb87d6a03
commit
65496ff71a
|
|
@ -9,8 +9,7 @@ SUBDIRS += \
|
|||
tst_generators \
|
||||
tst_upgrades \
|
||||
tst_json \
|
||||
tst_datetime \
|
||||
tst_sametype
|
||||
tst_datetime
|
||||
|
||||
cmake.CONFIG += no_run-tests_target
|
||||
prepareRecursiveTarget(run-tests)
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
# 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
|
||||
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#include "db.h"
|
||||
#include "sampletable.h"
|
||||
|
||||
DB::DB() : Nut::Database()
|
||||
, m_users1(new Nut::TableSet<SampleTable>(this))
|
||||
, m_users2(new Nut::TableSet<SampleTable>(this))
|
||||
, m_users3(new Nut::TableSet<SampleTable>(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef DB1_H
|
||||
#define DB1_H
|
||||
|
||||
#include "database.h"
|
||||
|
||||
class SampleTable;
|
||||
class DB : public Nut::Database
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
NUT_DB_VERSION(1)
|
||||
|
||||
NUT_DECLARE_TABLE(SampleTable, users1)
|
||||
NUT_DECLARE_TABLE(SampleTable, users2)
|
||||
NUT_DECLARE_TABLE(SampleTable, users3)
|
||||
|
||||
public:
|
||||
DB();
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(DB*)
|
||||
|
||||
#endif // DB1_H
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
#include "sampletable.h"
|
||||
|
||||
|
||||
SampleTable::SampleTable(QObject *parent) : Nut::Table (parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef TABLE1_H
|
||||
#define TABLE1_H
|
||||
|
||||
#include "table.h"
|
||||
|
||||
class SampleTable : public Nut::Table
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
NUT_PRIMARY_AUTO_INCREMENT(id)
|
||||
NUT_DECLARE_FIELD(int, id, id, setId)
|
||||
|
||||
NUT_DECLARE_FIELD(QString, name, name, setName)
|
||||
NUT_DECLARE_FIELD(QString, password, password, setPassword)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE SampleTable(QObject *parent = Q_NULLPTR);
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(SampleTable*)
|
||||
|
||||
#endif // TABLE1_H
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
QT += testlib sql
|
||||
|
||||
TARGET = tst_upgrades
|
||||
TEMPLATE = app
|
||||
CONFIG += warn_on c++11
|
||||
|
||||
include(../common/nut-lib.pri)
|
||||
|
||||
SOURCES += \
|
||||
db.cpp \
|
||||
sampletable.cpp \
|
||||
tst_sametypes.cpp
|
||||
|
||||
HEADERS += \
|
||||
db.h \
|
||||
sampletable.h \
|
||||
tst_sametypes.h
|
||||
|
||||
|
|
@ -1,148 +0,0 @@
|
|||
#include <QtTest>
|
||||
|
||||
#include "db.h"
|
||||
#include "sampletable.h"
|
||||
#include "query.h"
|
||||
|
||||
#include "tst_sametypes.h"
|
||||
#include "consts.h"
|
||||
|
||||
SameTypes::SameTypes()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SameTypes::~SameTypes()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SameTypes::initTestCase()
|
||||
{
|
||||
REGISTER(DB);
|
||||
REGISTER(SampleTable);
|
||||
|
||||
db.setDriver(DRIVER);
|
||||
db.setHostName(HOST);
|
||||
db.setDatabaseName(DATABASE);
|
||||
db.setUserName(USERNAME);
|
||||
db.setPassword(PASSWORD);
|
||||
|
||||
db.open();
|
||||
}
|
||||
|
||||
void SameTypes::insert()
|
||||
{
|
||||
insertOnList(1, "1");
|
||||
insertOnList(2, "2");
|
||||
insertOnList(3, "3");
|
||||
}
|
||||
|
||||
void SameTypes::counts()
|
||||
{
|
||||
for (int i = 1; i < 4; ++i) {
|
||||
auto t = query(i);
|
||||
|
||||
QTEST_ASSERT(t != nullptr);
|
||||
QCOMPARE(t->toList().count(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
void SameTypes::read()
|
||||
{
|
||||
QCOMPARE(readPassword(1), "1");
|
||||
QCOMPARE(readPassword(2), "2");
|
||||
QCOMPARE(readPassword(3), "3");
|
||||
}
|
||||
|
||||
void SameTypes::insertOnList(char no, const QString &password)
|
||||
{
|
||||
Nut::TableSet<SampleTable> *tableSet;
|
||||
|
||||
switch (no) {
|
||||
case 1:
|
||||
tableSet = db.users1();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
tableSet = db.users2();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
tableSet = db.users3();
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
auto q = tableSet->query();
|
||||
int n = q->insert((SampleTable::nameField() = "user")
|
||||
& (SampleTable::passwordField() = password))
|
||||
.toInt(&ok);
|
||||
|
||||
qDebug() << q->sqlCommand();
|
||||
QTEST_ASSERT(ok);
|
||||
|
||||
QTEST_ASSERT(n != 0);
|
||||
}
|
||||
|
||||
QString SameTypes::readPassword(char no)
|
||||
{
|
||||
Nut::TableSet<SampleTable> *tableSet;
|
||||
|
||||
switch (no) {
|
||||
case 1:
|
||||
tableSet = db.users1();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
tableSet = db.users2();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
tableSet = db.users3();
|
||||
break;
|
||||
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool ok;
|
||||
auto q = tableSet->query();
|
||||
QStringList passwordList = q->where(SampleTable::nameField() == "user")
|
||||
->select(SampleTable::passwordField());
|
||||
|
||||
|
||||
qDebug() << q->sqlCommand();
|
||||
QTEST_ASSERT(passwordList.size() == 1);
|
||||
|
||||
return passwordList.first();
|
||||
}
|
||||
|
||||
Nut::Query<SampleTable> *SameTypes::query(int n)
|
||||
{
|
||||
switch (n) {
|
||||
case 1:
|
||||
return db.users1()->query();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
return db.users2()->query();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
return db.users3()->query();
|
||||
break;
|
||||
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
QTEST_APPLESS_MAIN(SameTypes)
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef TST_UPGRADES_H
|
||||
#define TST_UPGRADES_H
|
||||
|
||||
#include <QObject>
|
||||
#include "db.h"
|
||||
|
||||
|
||||
namespace Nut {
|
||||
class Database;
|
||||
template<class T>
|
||||
class Query;
|
||||
}
|
||||
class SameTypes : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
DB db;
|
||||
|
||||
void insertOnList(char no, const QString &password);
|
||||
QString readPassword(char no);
|
||||
Nut::Query<SampleTable> *query(int n);
|
||||
|
||||
public:
|
||||
SameTypes();
|
||||
~SameTypes();
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
|
||||
void insert();
|
||||
void counts();
|
||||
void read();
|
||||
|
||||
};
|
||||
|
||||
#endif // TST_UPGRADES_H
|
||||
Loading…
Reference in New Issue