diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a459c836..74452f5bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt new file mode 100644 index 000000000..1ce7815c7 --- /dev/null +++ b/unittest/CMakeLists.txt @@ -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} +) diff --git a/unittest/dock_unit_test.cpp b/unittest/dock_unit_test.cpp new file mode 100644 index 000000000..d9de6b3b3 --- /dev/null +++ b/unittest/dock_unit_test.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd. + * + * Author: fanpengcheng + * + * Maintainer: fanpengcheng + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#include + +#include "dock_unit_test.h" + +DockUnitTest::DockUnitTest() +{ + qDBusRegisterMetaType(); +} + +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(); + QVariant vFirst = dbvFirst.variant(); + QDBusArgument dbusArgs = vFirst.value(); + + 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(); + QVariant vFirst = dbvFirst.variant(); + QDBusArgument dbusArgs = vFirst.value(); + + dbusArgs >> dockRect; + qDebug() << dockRect; + } + + QCOMPARE(daemonDockRect, dockRect); +} + +QTEST_APPLESS_MAIN(DockUnitTest) + +#include "dock_unit_test.moc" diff --git a/unittest/dock_unit_test.h b/unittest/dock_unit_test.h new file mode 100644 index 000000000..89ae9f5c8 --- /dev/null +++ b/unittest/dock_unit_test.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd. + * + * Author: fanpengcheng + * + * Maintainer: fanpengcheng + * + * 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 . + */ +#ifndef DOCK_UNIT_TEST_H +#define DOCK_UNIT_TEST_H +#include + +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