mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 添加针对源代码的单元测试,添加触发自动测试代码
因为单元测试需要直接测试源代码,而主程序代码中include的单元使用了相对路径 单元测试的CMakeLists和主程序的CMakeLists路径不同,编译单元测试时会提示找不到文件 因此设置搜索路径,并修改各单元引用头文件的路径。在单元测试的CMakeLists中添加需要依赖 Log: 添加针对源代码的单元测试,添加触发自动测试代码 Change-Id: I0e0bc92c28d6cee42fc52064fc360c58f7c02826
This commit is contained in:
parent
9520f11e05
commit
2ef1176873
@ -47,6 +47,47 @@ endif()
|
||||
|
||||
file(GLOB INTERFACES "interfaces/*.h")
|
||||
|
||||
#因为单元测试需要直接测试源代码,而主程序代码中include的单元使用了相对路径
|
||||
#单元测试的CMakeLists和主程序的CMakeLists路径不同,编译单元测试时会提示找不到文件
|
||||
#因此设置搜索路径
|
||||
include_directories(
|
||||
frame/controller
|
||||
frame/dbus
|
||||
frame/dbus/sni
|
||||
frame/item
|
||||
frame/item/components
|
||||
frame/item/resources
|
||||
frame/panel
|
||||
frame/qss
|
||||
frame/util
|
||||
frame/window
|
||||
frame/xcb
|
||||
)
|
||||
|
||||
aux_source_directory(frame/controller CONTROLLER)
|
||||
aux_source_directory(frame/dbus DBUS)
|
||||
aux_source_directory(frame/dbus/sni SNI)
|
||||
aux_source_directory(frame/item ITEM)
|
||||
aux_source_directory(frame/item/components COMPONENTS)
|
||||
aux_source_directory(frame/item/resources RESOURCES)
|
||||
aux_source_directory(frame/panel PANEL)
|
||||
aux_source_directory(frame/qss QSSPATH)
|
||||
aux_source_directory(frame/util UTIL)
|
||||
aux_source_directory(frame/window WINDOW)
|
||||
aux_source_directory(frame/xcb XCB)
|
||||
|
||||
file(GLOB SRC_PATH
|
||||
${CONTROLLER}
|
||||
${DBUS}
|
||||
${SNI}
|
||||
${ITEM}
|
||||
${COMPONENTS}
|
||||
${PANEL}
|
||||
${UTIL}
|
||||
${WINDOW}
|
||||
${XCB}
|
||||
)
|
||||
|
||||
add_subdirectory("frame")
|
||||
add_subdirectory("plugins")
|
||||
add_subdirectory("unittest")
|
||||
|
@ -23,16 +23,19 @@ pkg_check_modules(QGSettings REQUIRED gsettings-qt)
|
||||
pkg_check_modules(DtkGUI REQUIRED dtkgui)
|
||||
|
||||
# driver-manager
|
||||
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES} item/item.qrc frame.qrc)
|
||||
target_include_directories(${BIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
|
||||
${XCB_EWMH_INCLUDE_DIRS}
|
||||
${DFrameworkDBus_INCLUDE_DIRS}
|
||||
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
|
||||
${PROJECT_BINARY_DIR}
|
||||
${QGSettings_INCLUDE_DIRS}
|
||||
${DtkGUI_INCLUDE_DIRS}
|
||||
${Qt5Svg_INCLUDE_DIRS}
|
||||
../interfaces)
|
||||
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES} ${SRC_PATH} item/item.qrc frame.qrc)
|
||||
|
||||
target_include_directories(${BIN_NAME} PUBLIC
|
||||
${DtkWidget_INCLUDE_DIRS}
|
||||
${XCB_EWMH_INCLUDE_DIRS}
|
||||
${DFrameworkDBus_INCLUDE_DIRS}
|
||||
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
|
||||
${PROJECT_BINARY_DIR}
|
||||
${QGSettings_INCLUDE_DIRS}
|
||||
${DtkGUI_INCLUDE_DIRS}
|
||||
${Qt5Svg_INCLUDE_DIRS}
|
||||
../interfaces
|
||||
)
|
||||
|
||||
target_link_libraries(${BIN_NAME} PRIVATE
|
||||
${XCB_EWMH_LIBRARIES}
|
||||
|
@ -20,10 +20,10 @@
|
||||
*/
|
||||
|
||||
#include "dockitemmanager.h"
|
||||
#include "item/appitem.h"
|
||||
#include "item/launcheritem.h"
|
||||
#include "item/pluginsitem.h"
|
||||
#include "item/traypluginitem.h"
|
||||
#include "appitem.h"
|
||||
#include "launcheritem.h"
|
||||
#include "pluginsitem.h"
|
||||
#include "traypluginitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGSettings>
|
||||
|
@ -24,9 +24,9 @@
|
||||
|
||||
#include "dockpluginscontroller.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "item/dockitem.h"
|
||||
#include "item/appitem.h"
|
||||
#include "item/placeholderitem.h"
|
||||
#include "dockitem.h"
|
||||
#include "appitem.h"
|
||||
#include "placeholderitem.h"
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "dockpluginscontroller.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "item/traypluginitem.h"
|
||||
#include "traypluginitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
@ -22,9 +22,9 @@
|
||||
#ifndef DOCKPLUGINSCONTROLLER_H
|
||||
#define DOCKPLUGINSCONTROLLER_H
|
||||
|
||||
#include "item/pluginsitem.h"
|
||||
#include "pluginsitem.h"
|
||||
#include "pluginproxyinterface.h"
|
||||
#include "util/abstractpluginscontroller.h"
|
||||
#include "abstractpluginscontroller.h"
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
|
||||
@ -42,7 +42,7 @@ class DockPluginsController : public AbstractPluginsController
|
||||
friend class DockItemManager;
|
||||
|
||||
public:
|
||||
explicit DockPluginsController(QObject *parent = 0);
|
||||
explicit DockPluginsController(QObject *parent = nullptr);
|
||||
|
||||
// implements PluginProxyInterface
|
||||
void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey) override;
|
||||
|
@ -23,12 +23,11 @@
|
||||
#define DBUSDOCKADAPTORS_H
|
||||
|
||||
#include <QtDBus/QtDBus>
|
||||
#include "window/mainwindow.h"
|
||||
class MainWindow;
|
||||
#include "mainwindow.h"
|
||||
|
||||
/*
|
||||
* Adaptor class for interface com.deepin.dde.Dock
|
||||
*/
|
||||
|
||||
class DBusDockAdaptors: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -21,12 +21,11 @@
|
||||
*/
|
||||
|
||||
#include "appitem.h"
|
||||
|
||||
#include "util/themeappicon.h"
|
||||
#include "util/imagefactory.h"
|
||||
#include "xcb/xcb_misc.h"
|
||||
#include "components/appswingeffectbuilder.h"
|
||||
#include "components/appspreviewprovider.h"
|
||||
#include "themeappicon.h"
|
||||
#include "imagefactory.h"
|
||||
#include "xcb_misc.h"
|
||||
#include "appswingeffectbuilder.h"
|
||||
#include "appspreviewprovider.h"
|
||||
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
@ -24,9 +24,9 @@
|
||||
#define APPITEM_H
|
||||
|
||||
#include "dockitem.h"
|
||||
#include "components/previewcontainer.h"
|
||||
#include "components/appdrag.h"
|
||||
#include "dbus/dbusclientmanager.h"
|
||||
#include "previewcontainer.h"
|
||||
#include "appdrag.h"
|
||||
#include "dbusclientmanager.h"
|
||||
#include "../widgets/tipswidget.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <qwidget.h>
|
||||
#include "../widgets/tipswidget.h"
|
||||
#include "util/dockpopupwindow.h"
|
||||
#include "dockpopupwindow.h"
|
||||
|
||||
class AppGraphicsObject;
|
||||
class AppDragWidget : public QGraphicsView
|
||||
|
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "hoverhighlighteffect.h"
|
||||
#include "util/imagefactory.h"
|
||||
#include "imagefactory.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
@ -23,8 +23,8 @@
|
||||
#define DOCKITEM_H
|
||||
|
||||
#include "constants.h"
|
||||
#include "util/dockpopupwindow.h"
|
||||
#include "components/hoverhighlighteffect.h"
|
||||
#include "dockpopupwindow.h"
|
||||
#include "hoverhighlighteffect.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QPointer>
|
||||
|
@ -20,8 +20,8 @@
|
||||
*/
|
||||
|
||||
#include "launcheritem.h"
|
||||
#include "util/themeappicon.h"
|
||||
#include "util/imagefactory.h"
|
||||
#include "themeappicon.h"
|
||||
#include "imagefactory.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QProcess>
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include "pluginsitem.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
|
||||
#include "util/utils.h"
|
||||
#include "util/imagefactory.h"
|
||||
#include "utils.h"
|
||||
#include "imagefactory.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QBoxLayout>
|
||||
|
@ -20,14 +20,14 @@
|
||||
*/
|
||||
|
||||
#include "mainpanelcontrol.h"
|
||||
#include "../item/dockitem.h"
|
||||
#include "../item/placeholderitem.h"
|
||||
#include "../item/components/appdrag.h"
|
||||
#include "../item/appitem.h"
|
||||
#include "../item/pluginsitem.h"
|
||||
#include "../item/traypluginitem.h"
|
||||
#include "../controller/dockitemmanager.h"
|
||||
#include "util/touchsignalmanager.h"
|
||||
#include "dockitem.h"
|
||||
#include "placeholderitem.h"
|
||||
#include "components/appdrag.h"
|
||||
#include "appitem.h"
|
||||
#include "pluginsitem.h"
|
||||
#include "traypluginitem.h"
|
||||
#include "dockitemmanager.h"
|
||||
#include "touchsignalmanager.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QTimer>
|
||||
|
@ -19,7 +19,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "menuworker.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
#include "dockitemmanager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "multiscreenworker.h"
|
||||
#include "window/mainwindow.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QScreen>
|
||||
|
@ -21,12 +21,12 @@
|
||||
|
||||
#ifndef MULTISCREENWORKER_H
|
||||
#define MULTISCREENWORKER_H
|
||||
|
||||
#include "constants.h"
|
||||
#include "monitor.h"
|
||||
#include "utils.h"
|
||||
#include "item/dockitem.h"
|
||||
|
||||
#include "xcb/xcb_misc.h"
|
||||
#include "dockitem.h"
|
||||
#include "xcb_misc.h"
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
#include <com_deepin_daemon_display.h>
|
||||
|
@ -21,10 +21,10 @@
|
||||
*/
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "panel/mainpanelcontrol.h"
|
||||
#include "controller/dockitemmanager.h"
|
||||
#include "util/utils.h"
|
||||
#include "util/menuworker.h"
|
||||
#include "mainpanelcontrol.h"
|
||||
#include "dockitemmanager.h"
|
||||
#include "utils.h"
|
||||
#include "menuworker.h"
|
||||
|
||||
#include <DStyle>
|
||||
#include <DPlatformWindowHandle>
|
||||
|
@ -23,11 +23,11 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include "xcb/xcb_misc.h"
|
||||
#include "dbus/sni/statusnotifierwatcher_interface.h"
|
||||
#include "panel/mainpanelcontrol.h"
|
||||
#include "util/multiscreenworker.h"
|
||||
#include "util/touchsignalmanager.h"
|
||||
#include "xcb_misc.h"
|
||||
#include "statusnotifierwatcher_interface.h"
|
||||
#include "mainpanelcontrol.h"
|
||||
#include "multiscreenworker.h"
|
||||
#include "touchsignalmanager.h"
|
||||
|
||||
#include <DPlatformWindowHandle>
|
||||
#include <DWindowManagerHelper>
|
||||
|
@ -6,33 +6,61 @@ set(BIN_NAME dde_dock_unit_test)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
# 源文件
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp")
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../widgets/*.h" "../widgets/*.cpp")
|
||||
|
||||
# 用于测试覆盖率的编译条件
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
|
||||
|
||||
# 查找依赖库
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Widgets Test DBus REQUIRED)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
find_package(Qt5Concurrent REQUIRED)
|
||||
find_package(Qt5X11Extras REQUIRED)
|
||||
find_package(Qt5DBus REQUIRED)
|
||||
find_package(DtkWidget REQUIRED)
|
||||
find_package(Qt5Svg REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Test REQUIRED)
|
||||
find_package(GTest REQUIRED)
|
||||
|
||||
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
|
||||
pkg_check_modules(QGSettings REQUIRED gsettings-qt)
|
||||
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
|
||||
pkg_check_modules(XCB_EWMH REQUIRED xcb-ewmh x11)
|
||||
|
||||
# 添加执行文件信息
|
||||
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES})
|
||||
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES} ${SRC_PATH} ../frame/item/item.qrc ../frame/frame.qrc)
|
||||
|
||||
# 包含路径
|
||||
target_include_directories(${BIN_NAME} PUBLIC ${DFrameworkDBus_INCLUDE_DIRS} ../../interfaces)
|
||||
|
||||
target_include_directories(${BIN_NAME} PUBLIC
|
||||
${DtkWidget_INCLUDE_DIRS}
|
||||
${XCB_EWMH_INCLUDE_DIRS}
|
||||
${DFrameworkDBus_INCLUDE_DIRS}
|
||||
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
|
||||
${QGSettings_INCLUDE_DIRS}
|
||||
../interfaces
|
||||
)
|
||||
|
||||
# 链接库
|
||||
target_link_libraries(${BIN_NAME} PRIVATE
|
||||
${Qt5Test_LIBRARIES}
|
||||
${Qt5DBus_LIBRARIES}
|
||||
${XCB_EWMH_LIBRARIES}
|
||||
${DFrameworkDBus_LIBRARIES}
|
||||
${QGSettings_LIBRARIES}
|
||||
${DtkWidget_LIBRARIES}
|
||||
${Qt5Widgets_LIBRARIES}
|
||||
${Qt5Concurrent_LIBRARIES}
|
||||
${Qt5X11Extras_LIBRARIES}
|
||||
${Qt5DBus_LIBRARIES}
|
||||
${QGSettings_LIBRARIES}
|
||||
${Qt5Svg_LIBRARIES}
|
||||
${GTEST_LIBRARIES}
|
||||
-lpthread
|
||||
-lm
|
||||
)
|
||||
|
||||
add_custom_target(check)
|
||||
|
||||
add_custom_command(TARGET check
|
||||
COMMAND ./${BIN_NAME}
|
||||
)
|
||||
|
||||
add_dependencies(check ${BIN_NAME})
|
||||
|
@ -1,404 +0,0 @@
|
||||
/*
|
||||
* 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 <QGSettings/QGSettings>
|
||||
#include <QThread>
|
||||
#include <QProcess>
|
||||
|
||||
#include <com_deepin_daemon_display.h>
|
||||
|
||||
#include "dock_unit_test.h"
|
||||
|
||||
#define SLEEP1 QThread::sleep(1);
|
||||
|
||||
DockUnitTest::DockUnitTest()
|
||||
{
|
||||
qDBusRegisterMetaType<ScreenRect>();
|
||||
}
|
||||
|
||||
DockUnitTest::~DockUnitTest()
|
||||
{
|
||||
}
|
||||
|
||||
void DockUnitTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DockUnitTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
const DockRect DockUnitTest::dockGeometry()
|
||||
{
|
||||
DockRect dockRect;
|
||||
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;
|
||||
|
||||
return dockRect;
|
||||
}
|
||||
|
||||
const DockRect DockUnitTest::frontendWindowRect()
|
||||
{
|
||||
DBusDock dockInter("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
||||
return dockInter.frontendWindowRect();
|
||||
}
|
||||
|
||||
void DockUnitTest::setPosition(Dock::Position pos)
|
||||
{
|
||||
DBusDock daemonDockInter("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
||||
daemonDockInter.setPosition(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DockUnitTest::dock_defaultGsettings_check
|
||||
* 验证任务栏的默认配置值是否正确,用于检查新安装系统或新创建用户的默认配置文件的正确性。
|
||||
* 后续如果还有类似验证,应一并放到这里:
|
||||
* 1.任务栏默认显示模式。
|
||||
* 2.任务栏默认显示状态。
|
||||
* 3.任务栏默认位置。
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_defaultGsettings_check)
|
||||
{
|
||||
QGSettings setting("com.deepin.dde.dock", "/com/deepin/dde/dock/");
|
||||
|
||||
if (setting.keys().contains("displayMode")) {
|
||||
QString currentDisplayMode = setting.get("display-mode").toString();
|
||||
QString defaultDisplayMode = "efficient";
|
||||
ASSERT_EQ(currentDisplayMode, defaultDisplayMode);
|
||||
}
|
||||
if (setting.keys().contains("hideMode")) {
|
||||
QString currentHideMode = setting.get("hide-mode").toString();
|
||||
QString defaultHideMode = "keep-showing";
|
||||
ASSERT_EQ(currentHideMode, defaultHideMode);
|
||||
}
|
||||
if (setting.keys().contains("position")) {
|
||||
QString currentPosition = setting.get("position").toString();
|
||||
QString defaultPosition = "bottom";
|
||||
ASSERT_EQ(currentPosition, defaultPosition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DockUnitTest::dock_geometry_test 比较任务栏自身的位置和通知给后端的位置是否吻合
|
||||
*/
|
||||
TEST_F(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;
|
||||
}
|
||||
|
||||
ASSERT_EQ(daemonDockRect, dockRect);
|
||||
}
|
||||
/**
|
||||
* @brief DockUnitTest::dock_position_check 比较Dbus和QGSettings获取的坐标信息是否一致
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_position_check)
|
||||
{
|
||||
DBusDock *dockInter = new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
||||
int nPos = dockInter->position();
|
||||
QString postion = "";
|
||||
qDebug() << nPos;
|
||||
|
||||
switch (nPos) {
|
||||
case 0 :
|
||||
postion = "top";
|
||||
break;
|
||||
case 1:
|
||||
postion = "right";
|
||||
break;
|
||||
case 2:
|
||||
postion = "bottom";
|
||||
break;
|
||||
case 3:
|
||||
postion = "left";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
QGSettings *setting = new QGSettings("com.deepin.dde.dock");
|
||||
if (setting->keys().contains("position")) {
|
||||
qDebug() << setting->get("position");
|
||||
ASSERT_EQ(postion, setting->get("position").toString());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief DockUnitTest::dock_displayMode_check 比较Dbus和QGSettings获取的显示模式是否一致
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_displayMode_check)
|
||||
{
|
||||
DBusDock *dockInter = new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
||||
int nMode = dockInter->displayMode();
|
||||
QString displayMode = "";
|
||||
qDebug() << nMode;
|
||||
|
||||
switch (nMode) {
|
||||
case 0 :
|
||||
displayMode = "fashion";
|
||||
break;
|
||||
case 1:
|
||||
displayMode = "efficient";
|
||||
break;
|
||||
case 2:
|
||||
displayMode = "classic";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
QGSettings *setting = new QGSettings("com.deepin.dde.dock");
|
||||
if (setting->keys().contains("displayMode")) {
|
||||
qDebug() << setting->get("displayMode");
|
||||
ASSERT_EQ(displayMode, setting->get("displayMode").toString());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DockUnitTest, dock_appItemCount_check)
|
||||
{
|
||||
DBusDock *dockInter = new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
||||
qDebug() << dockInter->entries().size();
|
||||
for (auto inter : dockInter->entries()) {
|
||||
qDebug() << inter.path();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DockUnitTest::dock_frontWindowRect_check
|
||||
* 原理:将任务栏设置为一直显示模式,然后切换四个位置,查看其frontendWindowRect与实际位置是否一致.
|
||||
* 前提条件: 开启系统缩放(大于1即可)
|
||||
* Tips: 任务栏在副屏时,frontendWindowRect对应的是上一次在主屏设置过的值.
|
||||
* 可测出问题:任务栏在5.3.0.2版本时,开启缩放后,启动器打开时位置和任务栏有重叠,5.3.0.5版本修复了这个问题
|
||||
* 对应Bug: https://pms.uniontech.com/zentao/bug-view-42095.html
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_frontWindowRect_check)
|
||||
{
|
||||
setPosition(Dock::Position::Top);
|
||||
SLEEP1;
|
||||
ASSERT_EQ(dockGeometry(), frontendWindowRect());
|
||||
|
||||
setPosition(Dock::Position::Right);
|
||||
SLEEP1;
|
||||
ASSERT_EQ(dockGeometry(), frontendWindowRect());
|
||||
|
||||
setPosition(Dock::Position::Bottom);
|
||||
SLEEP1;
|
||||
ASSERT_EQ(dockGeometry(), frontendWindowRect());
|
||||
|
||||
setPosition(Dock::Position::Left);
|
||||
SLEEP1;
|
||||
ASSERT_EQ(dockGeometry(), frontendWindowRect());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DockUnitTest::dock_multi_process
|
||||
* 检查dde-dock是否在没进程存在时能否正常启动,在已有dde-dock进程存在时能否正常退出
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_multi_process)
|
||||
{
|
||||
QProcess *dockProc = new QProcess();
|
||||
dockProc->start("dde-dock");
|
||||
connect(dockProc, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||
ASSERT_EQ(exitCode, 255);
|
||||
ASSERT_EQ(exitStatus, QProcess::ExitStatus::NormalExit);
|
||||
});
|
||||
connect(dockProc, &QProcess::errorOccurred, this, [=](QProcess::ProcessError error) {
|
||||
qDebug() << "dde-dock error occurred: " << error;
|
||||
QFAIL("control center error occurred");
|
||||
});
|
||||
dockProc->waitForFinished();
|
||||
|
||||
delete dockProc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DockUnitTest::dock_defaultVolume_Check 判断音量实际值是否与默认值是否相等
|
||||
* @param defaultVolume 默认音量
|
||||
* 运行此用例时需满足用户未手动修改过声音值这一条件,才能保证得到的是默认值,测试才能通过
|
||||
* 所以最好在新创建的用户,或者是新装的系统时进行测试
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_defaultVolume_Check)
|
||||
{
|
||||
float volume = 0;
|
||||
QDBusInterface audioInterface("com.deepin.daemon.Audio", "/com/deepin/daemon/Audio", "com.deepin.daemon.Audio", QDBusConnection::sessionBus(), this);
|
||||
QDBusObjectPath defaultPath = audioInterface.property("DefaultSink").value<QDBusObjectPath>();
|
||||
if (defaultPath.path() == "/") { //路径为空
|
||||
qDebug() << "defaultPath" << defaultPath.path();
|
||||
return;
|
||||
} else {
|
||||
QDBusInterface sinkInterface("com.deepin.daemon.Audio", defaultPath.path(), "com.deepin.daemon.Audio.Sink", QDBusConnection::sessionBus(), this);
|
||||
volume = sinkInterface.property("Volume").toFloat() * 100.0f;
|
||||
}
|
||||
ASSERT_EQ(volume, 50.0f);
|
||||
}
|
||||
/**
|
||||
* @brief DockUnitTest::dock_coreDump_check
|
||||
* 间隔一段时间判断dock是不是同一个pid,判断是否一直在崩溃
|
||||
*
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_coreDump_check)
|
||||
{
|
||||
auto process = new QProcess();
|
||||
process->start("pidof -s dde-dock");
|
||||
process->waitForFinished();
|
||||
QByteArray pid = process->readAllStandardOutput();
|
||||
process->close();
|
||||
|
||||
QThread::sleep(1);
|
||||
|
||||
process->start("pidof -s dde-dock");
|
||||
process->waitForFinished();
|
||||
QByteArray pid2 = process->readAllStandardOutput();
|
||||
process->close();
|
||||
|
||||
ASSERT_EQ(pid, pid2);
|
||||
|
||||
delete process;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DockUnitTest::dock_appIconSize_check
|
||||
* 判断dbus和gsettings获取的任务栏图标大小是否一致
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_appIconSize_check)
|
||||
{
|
||||
DBusDock *dockInter = new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
||||
QGSettings *setting = new QGSettings("com.deepin.dde.dock");
|
||||
unsigned int iconSize = dockInter->iconSize();
|
||||
qDebug() << "Please check the size of icons:" << iconSize;
|
||||
ASSERT_EQ(iconSize, setting->get("icon-size").toUInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief dock_appDockUndock_check
|
||||
* 取靠近启动器的应用区域的第一个应用,先 undock ,然后 dock 进行检测
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_appDockUndock_check)
|
||||
{
|
||||
const QString service_name = "com.deepin.dde.daemon.Dock";
|
||||
const QString dock_path = "/com/deepin/dde/daemon/Dock";
|
||||
|
||||
DBusDock dockInter(service_name, dock_path, QDBusConnection::sessionBus(), this);
|
||||
|
||||
// get all desktopfiles and entries
|
||||
QStringList appDesktopFiles=dockInter.GetDockedAppsDesktopFiles();
|
||||
QList<QDBusObjectPath> appEntries = dockInter.entries();
|
||||
|
||||
if (appEntries.size() == 0) {
|
||||
qDebug() << "at least one app on the dock !";
|
||||
return;
|
||||
}
|
||||
|
||||
int appIndex = 0; // location in the dock (start with 0)
|
||||
const QString appDockPath = appEntries[appIndex].path();
|
||||
|
||||
// get DesktopFile
|
||||
QDBusInterface appPropertyInter(service_name, appDockPath, "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus(), this);
|
||||
QDBusInterface appSlotInter(service_name, appDockPath, "com.deepin.dde.daemon.Dock.Entry", QDBusConnection::sessionBus(), this);
|
||||
|
||||
QDBusReply<QVariant> replyDesktopFile = appPropertyInter.call("Get", "com.deepin.dde.daemon.Dock.Entry", "DesktopFile");
|
||||
QString desktopFile = QVariant(replyDesktopFile).toString(); // desktopFile
|
||||
|
||||
// ForceQuit
|
||||
QDBusReply<void> replyQuit = appSlotInter.call("ForceQuit");
|
||||
|
||||
// Undock app
|
||||
appSlotInter.call("RequestUndock");
|
||||
QThread::sleep(1);
|
||||
|
||||
// check if app still dock
|
||||
appDesktopFiles=dockInter.GetDockedAppsDesktopFiles();
|
||||
ASSERT_EQ(appDesktopFiles.contains(desktopFile), false);
|
||||
|
||||
// dock app
|
||||
dockInter.RequestDock(desktopFile, appIndex);
|
||||
QThread::msleep(100); // must
|
||||
|
||||
// check if app is docked
|
||||
ASSERT_EQ(dockInter.IsDocked(desktopFile), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DockUnitTest::checkDockStateAfterSwitchMode
|
||||
* 检查智能模式时,切换任务栏显示模式,任务栏状态
|
||||
* 可以检测桌面无窗口,切换为智能隐藏模式后任务栏隐藏问题 41907
|
||||
*/
|
||||
TEST_F(DockUnitTest, dock_switchModeState_check)
|
||||
{
|
||||
QProcess process;
|
||||
process.start("/usr/lib/deepin-daemon/desktop-toggle");
|
||||
bool ret = process.waitForFinished(2000);
|
||||
if (!ret) {
|
||||
qDebug() << "show desktop failed, check stop";
|
||||
return;
|
||||
}
|
||||
|
||||
DBusDock daemonDockInter("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this);
|
||||
daemonDockInter.setSync(true);
|
||||
daemonDockInter.setHideMode(Dock::HideMode::SmartHide);
|
||||
daemonDockInter.setDisplayMode(Dock::DisplayMode::Fashion);
|
||||
daemonDockInter.setDisplayMode(Dock::DisplayMode::Efficient);
|
||||
|
||||
QThread::sleep(2);
|
||||
int state = daemonDockInter.hideState();
|
||||
|
||||
ASSERT_EQ(state, Dock::HideState::Show);
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
#include <com_deepin_dde_daemon_dock.h>
|
||||
|
||||
#include "../interfaces/constants.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using DBusDock = com::deepin::dde::daemon::Dock;
|
||||
|
||||
class DockUnitTest : public QObject, public ::testing::Test
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DockUnitTest();
|
||||
virtual ~DockUnitTest();
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
|
||||
public:
|
||||
const DockRect dockGeometry(); // 获取任务栏实际位置
|
||||
const DockRect frontendWindowRect(); // 后端记录的任务栏前端界面位置(和实际位置不一定对应)
|
||||
void setPosition(Dock::Position pos);
|
||||
};
|
||||
|
||||
#endif // DOCK_UNIT_TEST_H
|
@ -1,11 +1,18 @@
|
||||
#include <QApplication>
|
||||
#include <gtest/gtest.h>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <DLog>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// gerrit编译时没有显示器,需要指定环境变量
|
||||
qputenv("QT_QPA_PLATFORM", "offscreen");
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
qApp->setProperty("CANSHOW", true);
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
71
unittest/test_dockitem.cpp
Normal file
71
unittest/test_dockitem.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
|
||||
*
|
||||
* Author: chenjun <chenjun@uniontech.com>
|
||||
*
|
||||
* Maintainer: chenjun <chenjun@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 <QObject>
|
||||
#include <QThread>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "dockitem.h"
|
||||
|
||||
class Test_DockItem : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
public:
|
||||
DockItem *dockItem = nullptr;
|
||||
};
|
||||
|
||||
void Test_DockItem::SetUp()
|
||||
{
|
||||
dockItem = new DockItem();
|
||||
}
|
||||
|
||||
void Test_DockItem::TearDown()
|
||||
{
|
||||
delete dockItem;
|
||||
dockItem = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(Test_DockItem, dockitem_test)
|
||||
{
|
||||
ASSERT_NE(dockItem, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(Test_DockItem, dockitem_show_test)
|
||||
{
|
||||
dockItem->show();
|
||||
|
||||
QThread::msleep(450);
|
||||
|
||||
ASSERT_EQ(dockItem->isVisible(), true);
|
||||
}
|
||||
|
||||
TEST_F(Test_DockItem, dockitem_hide_test)
|
||||
{
|
||||
dockItem->hide();
|
||||
|
||||
QThread::msleep(450);
|
||||
|
||||
ASSERT_EQ(dockItem->isVisible(), false);
|
||||
}
|
112
unittest/test_monitor.cpp
Normal file
112
unittest/test_monitor.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
|
||||
*
|
||||
* Author: chenjun <chenjun@uniontech.com>
|
||||
*
|
||||
* Maintainer: chenjun <chenjun@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 <QObject>
|
||||
#include <QThread>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "monitor.h"
|
||||
|
||||
//因为GTest不能断言自定义结构数据,需要重载<<和==操作符
|
||||
std::ostream & operator<<(std::ostream & os, const Monitor::DockPosition & dockPosition) {
|
||||
return os << "leftDock = "
|
||||
<< dockPosition.leftDock
|
||||
<< " rightDock = "
|
||||
<< dockPosition.rightDock
|
||||
<< "topDock = "
|
||||
<< dockPosition.topDock
|
||||
<< " bottomDock = "
|
||||
<< dockPosition.bottomDock;
|
||||
}
|
||||
|
||||
bool operator==(const Monitor::DockPosition & p1, const Monitor::DockPosition & p2) {
|
||||
return p1.leftDock == p2.leftDock && p1.rightDock == p2.rightDock && p1.topDock == p2.topDock && p1.bottomDock == p2.bottomDock;
|
||||
}
|
||||
|
||||
class Test_Monitor : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
public:
|
||||
Monitor *monitor = nullptr;
|
||||
};
|
||||
|
||||
void Test_Monitor::SetUp()
|
||||
{
|
||||
monitor = new Monitor();
|
||||
}
|
||||
|
||||
void Test_Monitor::TearDown()
|
||||
{
|
||||
delete monitor;
|
||||
monitor = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(Test_Monitor, dockitem_test)
|
||||
{
|
||||
ASSERT_NE(monitor, nullptr);
|
||||
|
||||
int x = 10;
|
||||
int y = 10;
|
||||
int w = 100;
|
||||
int h = 100;
|
||||
|
||||
monitor->setX(x);
|
||||
ASSERT_EQ(monitor->x(), x);
|
||||
|
||||
monitor->setY(y);
|
||||
ASSERT_EQ(monitor->y(), y);
|
||||
|
||||
monitor->setW(w);
|
||||
ASSERT_EQ(monitor->w(), w);
|
||||
|
||||
monitor->setH(h);
|
||||
ASSERT_EQ(monitor->h(), h);
|
||||
|
||||
ASSERT_EQ(monitor->topLeft(), QPoint(x, y));
|
||||
ASSERT_EQ(monitor->topRight(), QPoint(x + w, y));
|
||||
ASSERT_EQ(monitor->bottomLeft(), QPoint(x, y + h));
|
||||
ASSERT_EQ(monitor->bottomRight(), QPoint(x + w, y + h));
|
||||
ASSERT_EQ(monitor->rect(), QRect(x, y, w, h));
|
||||
|
||||
QString name = "MonitorTestName";
|
||||
monitor->setName(name);
|
||||
ASSERT_EQ(monitor->name(), name);
|
||||
|
||||
QString path = "testPath";
|
||||
monitor->setPath(path);
|
||||
ASSERT_EQ(monitor->path(), path);
|
||||
|
||||
bool monitorEnable = true;
|
||||
monitor->setMonitorEnable(monitorEnable);
|
||||
ASSERT_EQ(monitor->enable(), monitorEnable);
|
||||
|
||||
Monitor::DockPosition dockPosition;
|
||||
dockPosition.leftDock = true;
|
||||
dockPosition.rightDock = true;
|
||||
dockPosition.topDock = true;
|
||||
dockPosition.bottomDock = true;
|
||||
monitor->setDockPosition(dockPosition);
|
||||
ASSERT_EQ(monitor->dockPosition(), dockPosition);
|
||||
}
|
71
unittest/test_statebutton.cpp
Normal file
71
unittest/test_statebutton.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
|
||||
*
|
||||
* Author: chenjun <chenjun@uniontech.com>
|
||||
*
|
||||
* Maintainer: chenjun <chenjun@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 <QObject>
|
||||
#include <QThread>
|
||||
#include <QApplication>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "statebutton.h"
|
||||
|
||||
class Test_StateButton : public QObject, public ::testing::Test
|
||||
{
|
||||
public:
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
public:
|
||||
StateButton *stateButton = nullptr;
|
||||
};
|
||||
|
||||
void Test_StateButton::SetUp()
|
||||
{
|
||||
stateButton = new StateButton();
|
||||
}
|
||||
|
||||
void Test_StateButton::TearDown()
|
||||
{
|
||||
delete stateButton;
|
||||
stateButton = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(Test_StateButton, statebutton_test)
|
||||
{
|
||||
ASSERT_NE(stateButton, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(Test_StateButton, statebutton_clicked_test)
|
||||
{
|
||||
bool clicked = false;
|
||||
|
||||
connect(stateButton, &StateButton::click, this, [ = ]() mutable {
|
||||
clicked = true;
|
||||
});
|
||||
|
||||
Qt::MouseButton button = Qt::LeftButton;
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonPress, stateButton->rect().center(), button, Qt::NoButton, Qt::NoModifier);
|
||||
bool ret = QApplication::sendEvent(stateButton, &mouseEvent);
|
||||
|
||||
ASSERT_NE(ret, clicked);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user