feat: 添加单元测试框架

加入单元测试框架,后期由开发逐渐丰富测试用例

Log: 添加测试用例框架
This commit is contained in:
范朋程 2020-07-15 20:12:25 +08:00
parent a7863c5b4f
commit 6c537c668b
4 changed files with 152 additions and 0 deletions

View File

@ -42,6 +42,7 @@ file(GLOB INTERFACES "interfaces/*.h")
add_subdirectory("frame")
add_subdirectory("plugins")
add_subdirectory("unittest")
# Install settings
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

28
unittest/CMakeLists.txt Normal file
View File

@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.7)
set(BIN_NAME dde_dock_unit_test)
# moc
set(CMAKE_AUTOMOC ON)
#
file(GLOB_RECURSE SRCS "*.h" "*.cpp")
#
find_package(PkgConfig REQUIRED)
find_package(Qt5 COMPONENTS Test DBus REQUIRED)
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
#
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES})
#
target_include_directories(${BIN_NAME} PUBLIC ${DFrameworkDBus_INCLUDE_DIRS})
#
target_link_libraries(${BIN_NAME} PRIVATE
${Qt5Test_LIBRARIES}
${Qt5DBus_LIBRARIES}
${DFrameworkDBus_LIBRARIES}
)

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
*
* Author: fanpengcheng <fanpengcheng@uniontech.com>
*
* Maintainer: fanpengcheng <fanpengcheng@uniontech.com>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtTest>
#include <QDBusInterface>
#include <QDBusMetaType>
#include <QDBusMessage>
#include <QDBusArgument>
#include <com_deepin_daemon_display.h>
#include "dock_unit_test.h"
DockUnitTest::DockUnitTest()
{
qDBusRegisterMetaType<ScreenRect>();
}
DockUnitTest::~DockUnitTest()
{
}
/**
* @brief DockUnitTest::dock_geometry_test
*/
void DockUnitTest::dock_geometry_check()
{
ScreenRect daemonDockRect, dockRect;
{
QDBusInterface inter("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", "org.freedesktop.DBus.Properties");
QString interface = "com.deepin.dde.daemon.Dock";
QString arg = "FrontendWindowRect";
QDBusMessage msg = inter.call("Get", interface, arg);
QVariant var = msg.arguments().first();
QDBusVariant dbvFirst = var.value<QDBusVariant>();
QVariant vFirst = dbvFirst.variant();
QDBusArgument dbusArgs = vFirst.value<QDBusArgument>();
dbusArgs >> daemonDockRect;
qDebug() << daemonDockRect;
}
{
QDBusInterface inter("com.deepin.dde.Dock", "/com/deepin/dde/Dock", "org.freedesktop.DBus.Properties");
QString interface = "com.deepin.dde.Dock";
QString arg = "geometry";
QDBusMessage msg = inter.call("Get", interface, arg);
QVariant var = msg.arguments().first();
QDBusVariant dbvFirst = var.value<QDBusVariant>();
QVariant vFirst = dbvFirst.variant();
QDBusArgument dbusArgs = vFirst.value<QDBusArgument>();
dbusArgs >> dockRect;
qDebug() << dockRect;
}
QCOMPARE(daemonDockRect, dockRect);
}
QTEST_APPLESS_MAIN(DockUnitTest)
#include "dock_unit_test.moc"

40
unittest/dock_unit_test.h Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
*
* Author: fanpengcheng <fanpengcheng@uniontech.com>
*
* Maintainer: fanpengcheng <fanpengcheng@uniontech.com>
*
* 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DOCK_UNIT_TEST_H
#define DOCK_UNIT_TEST_H
#include <QObject>
class DockUnitTest : public QObject
{
Q_OBJECT
public:
DockUnitTest();
~DockUnitTest();
private slots:
void dock_geometry_check(); // 显示区域
// void dock_position_check(); // 位置检查
// void dock_displayMode_check(); // 显示模式检查
// void dock_appItemCount_check(); // 应用显示数量检查
};
#endif // DOCK_UNIT_TEST_H