Add tests

Change-Id: Ibcd2de8c0346bb0ad31555de392eaac7965bf3bc
This commit is contained in:
Iceyer 2017-08-03 11:28:43 +08:00
parent f4e20a5c93
commit 3925beaf37
Notes: Deepin Code Review 2017-08-03 12:00:59 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: Iceyer <me@iceyer.net>
Submitted-by: Iceyer <me@iceyer.net>
Submitted-at: Thu, 03 Aug 2017 12:00:59 +0800
Reviewed-on: https://cr.deepin.io/25222
Project: dtkcore
Branch: refs/heads/master
7 changed files with 176 additions and 1 deletions

View File

@ -4,4 +4,5 @@ CONFIG = ordered
SUBDIRS += \
src \
tool
tool \
tests

61
tests/dutiltester.cpp Normal file
View File

@ -0,0 +1,61 @@
#include "dutiltester.h"
#include <QCoreApplication>
#include <QtTest/QtTest>
#include <QStandardPaths>
#include <QThread>
#include "log/LogManager.h"
#include "filesystem/dpathbuf.h"
#include "singletontester.h"
DCORE_USE_NAMESPACE
TestDUtil::TestDUtil()
{
}
void TestDUtil::testLogPath()
{
qApp->setOrganizationName("deepin");
qApp->setApplicationName("deepin-test-dtk");
DPathBuf logPath(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
logPath = logPath / ".cache/deepin/deepin-test-dtk/deepin-test-dtk.log";
QCOMPARE(DLogManager::getlogFilePath(), logPath.toString());
}
void TestDUtil::testPathChange()
{
DPathBuf root("/");
auto usr = root / "./usr";
QCOMPARE(QDir(usr.toString()).absolutePath(), QDir::toNativeSeparators("/usr"));
root /= "root";
QCOMPARE(root.toString(), QDir::toNativeSeparators("/root"));
root /= "../usr";
QCOMPARE(root.toString(), usr.toString());
}
void TestDUtil::testDSingleton()
{
auto threadA = new QThread;
auto testerA = new MultiSingletonTester;
connect(threadA, &QThread::started, testerA, &MultiSingletonTester::run);
testerA->moveToThread(threadA);
auto threadB = new QThread;
auto testerB = new MultiSingletonTester;
testerB->moveToThread(threadB);
connect(threadB, &QThread::started, testerB, &MultiSingletonTester::run);
threadA->start();
threadB->start();
QThread::sleep(5);
}

18
tests/dutiltester.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef DUTILTESTER_H
#define DUTILTESTER_H
#include <QObject>
class TestDUtil: public QObject
{
Q_OBJECT
public:
TestDUtil();
private Q_SLOTS:
void testLogPath();
void testPathChange();
void testDSingleton();
};
#endif // DUTILTESTER_H

5
tests/main.cpp Normal file
View File

@ -0,0 +1,5 @@
#include <QtTest/QtTest>
#include "dutiltester.h"
QTEST_MAIN(TestDUtil);

34
tests/singletontester.cpp Normal file
View File

@ -0,0 +1,34 @@
/**
* Copyright (C) 2016 Deepin Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
**/
#include "singletontester.h"
#include <QDebug>
#include <QThread>
Singleton::Singleton(QObject *parent) : QObject(parent)
{
qDebug() << "Singleton Init Begin" << this;
QThread::sleep(3);
qDebug() << "Singleton Init End" << this;
}
void Singleton::test()
{
qDebug() << "test" << this;
}
MultiSingletonTester::MultiSingletonTester(QObject *parent) : QObject(parent)
{
}
void MultiSingletonTester::run()
{
Singleton::instance()->test();
}

35
tests/singletontester.h Normal file
View File

@ -0,0 +1,35 @@
/**
* Copyright (C) 2016 Deepin Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
**/
#pragma once
#include <QObject>
#include "base/dsingleton.h"
class Singleton : public QObject, public Dtk::Core::DSingleton<Singleton>
{
Q_OBJECT
friend class Dtk::Core::DSingleton<Singleton>;
public:
explicit Singleton(QObject *parent = 0);
void test();
};
class MultiSingletonTester : public QObject
{
Q_OBJECT
public:
explicit MultiSingletonTester(QObject *parent = 0);
void run();
};

21
tests/tests.pro Normal file
View File

@ -0,0 +1,21 @@
TEMPLATE = app
QT += testlib
QT -= gui
CONFIG += testcase c++11
TARGET = tests
SOURCES += \
main.cpp \
dutiltester.cpp \
singletontester.cpp
HEADERS += \
dutiltester.h \
singletontester.h
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../src/release/ -ldtkcore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../src/debug/ -ldtkcore
else:unix: LIBS += -L$$OUT_PWD/../src/ -ldtkcore
INCLUDEPATH += $$PWD/../src
DEPENDPATH += $$PWD/../src