SUBDIRS += \
src \
- tool
+ tool \
+ tests
--- /dev/null
+#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);
+}
+
--- /dev/null
+#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
--- /dev/null
+#include <QtTest/QtTest>
+
+#include "dutiltester.h"
+
+QTEST_MAIN(TestDUtil);
--- /dev/null
+/**
+ * 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();
+}
--- /dev/null
+/**
+ * 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();
+};
+
+
--- /dev/null
+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