feat: 添加Mock

添加Mock依赖

Log:
Change-Id: I9625b67a9ac0155fafd60aca3ec27b996c6005e8
This commit is contained in:
范朋程 2021-03-10 10:05:23 +08:00 committed by fanpengcheng
parent ffc0ed2da5
commit 7ba28a270c
22 changed files with 285 additions and 218 deletions

3
debian/control vendored
View File

@ -24,7 +24,8 @@ Build-Depends: debhelper (>= 8.0.0),
libdde-network-utils-dev,
libdbusmenu-qt5-dev,
libdtkgui-dev,
libgtest-dev
libgtest-dev,
libgmock-dev
Standards-Version: 3.9.8
Homepage: http://www.deepin.org/

View File

@ -27,7 +27,6 @@
#include "appswingeffectbuilder.h"
#include "appspreviewprovider.h"
#include "qgsettingsinterfaceimpl.h"
#include "qgsettingsinterfacemock.h"
#include <X11/X.h>
#include <X11/Xlib.h>
@ -55,14 +54,12 @@ static QGSettingsInterface *GSettingsByApp(QGSettingsInterface::Type type)
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.app");
return &settings;
}
case QGSettingsInterface::Type::MockType:
{
static QGSettingsInterfaceMock settings("com.deepin.dde.dock.module.app");
return &settings;
}
default:
{
qWarning("Unless you are doing unit testing, you should't see this message");
return nullptr;
}
}
}
static QGSettingsInterface *GSettingsByActiveApp(QGSettingsInterface::Type type)
@ -73,14 +70,12 @@ static QGSettingsInterface *GSettingsByActiveApp(QGSettingsInterface::Type type)
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.activeapp");
return &settings;
}
case QGSettingsInterface::Type::MockType:
{
static QGSettingsInterfaceMock settings("com.deepin.dde.dock.module.activeapp");
return &settings;
}
default:
{
qWarning("Unless you are doing unit testing, you should't see this message");
return nullptr;
}
}
}
static QGSettingsInterface *GSettingsByDockApp(QGSettingsInterface::Type type)
@ -91,14 +86,12 @@ static QGSettingsInterface *GSettingsByDockApp(QGSettingsInterface::Type type)
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.dockapp");
return &settings;
}
case QGSettingsInterface::Type::MockType:
{
static QGSettingsInterfaceMock settings("com.deepin.dde.dock.module.dockapp");
return &settings;
}
default:
{
qWarning("Unless you are doing unit testing, you should't see this message");
return nullptr;
}
}
}
AppItem::AppItem(const QDBusObjectPath &entry, QGSettingsInterface::Type type, QWidget *parent)
@ -161,9 +154,12 @@ AppItem::AppItem(const QDBusObjectPath &entry, QGSettingsInterface::Type type, Q
updateWindowInfos(m_itemEntryInter->windowInfos());
refreshIcon();
connect(m_qgAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
connect(m_qgDockedAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
connect(m_qgActiveAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
if (m_qgAppInterface && m_qgAppInterface->gsettings())
connect(m_qgAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
if (m_qgDockedAppInterface && m_qgDockedAppInterface->gsettings())
connect(m_qgDockedAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
if (m_qgActiveAppInterface && m_qgActiveAppInterface->gsettings())
connect(m_qgActiveAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &AppItem::onThemeTypeChanged);

View File

@ -1,79 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin 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 <QGSettings>
#include <QVariant>
#include "qgsettingsinterfacemock.h"
QGSettingsInterfaceMock::QGSettingsInterfaceMock(const QByteArray &schema_id, const QByteArray &path, QObject *parent)
{
}
QGSettingsInterfaceMock::~QGSettingsInterfaceMock()
{
}
QGSettingsInterface::Type QGSettingsInterfaceMock::type()
{
return Type::MockType;
}
QGSettings *QGSettingsInterfaceMock::gsettings()
{
return nullptr;
}
QVariant QGSettingsInterfaceMock::get(const QString &key) const
{
return QVariant();
}
void QGSettingsInterfaceMock::set(const QString &key, const QVariant &value)
{
}
bool QGSettingsInterfaceMock::trySet(const QString &key, const QVariant &value)
{
return false;
}
QStringList QGSettingsInterfaceMock::keys() const
{
return QStringList();
}
QVariantList QGSettingsInterfaceMock::choices(const QString &key) const
{
return QVariantList();
}
void QGSettingsInterfaceMock::reset(const QString &key)
{
}
bool QGSettingsInterfaceMock::isSchemaInstalled(const QByteArray &schema_id)
{
return false;
}

View File

@ -1,45 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin 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 QGSETTINGSINTERFACEMOCK_H
#define QGSETTINGSINTERFACEMOCK_H
#include <QObject>
#include "qgsettingsinterface.h"
class QGSettings;
class QGSettingsInterfaceMock : public QGSettingsInterface
{
public:
QGSettingsInterfaceMock(const QByteArray &schema_id, const QByteArray &path = QByteArray(), QObject *parent = nullptr);
~QGSettingsInterfaceMock() override;
virtual Type type() override;
virtual QGSettings *gsettings() override;
virtual QVariant get(const QString &key) const override;
virtual void set(const QString &key, const QVariant &value) override;
virtual bool trySet(const QString &key, const QVariant &value) override;
virtual QStringList keys() const override;
virtual QVariantList choices(const QString &key) const override;
virtual void reset(const QString &key) override;
static bool isSchemaInstalled(const QByteArray &schema_id);
};
#endif // QGSETTINGSINTERFACEMOCK_H

View File

@ -11,6 +11,9 @@ file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../widgets/*.h" "../widgets/*.cpp")
#
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
# gmockcmake
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tests/cmake/modules)
#
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
@ -21,6 +24,7 @@ find_package(DtkWidget REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5 COMPONENTS Test REQUIRED)
find_package(GTest REQUIRED)
find_package(GMock REQUIRED)
pkg_check_modules(QGSettings REQUIRED gsettings-qt)
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
@ -53,6 +57,7 @@ target_link_libraries(${BIN_NAME} PRIVATE
${QGSettings_LIBRARIES}
${Qt5Svg_LIBRARIES}
${GTEST_LIBRARIES}
${GMOCK_LIBRARIES}
-lpthread
-lm
)

View File

@ -0,0 +1,130 @@
# Locate the Google C++ Mocking Framework.
# (This file is almost an identical copy of the original FindGTest.cmake file,
# feel free to use it as it is or modify it for your own needs.)
#
#
# Defines the following variables:
#
# GMOCK_FOUND - Found the Google Testing framework
# GMOCK_INCLUDE_DIRS - Include directories
#
# Also defines the library variables below as normal
# variables. These contain debug/optimized keywords when
# a debugging library is found.
#
# GMOCK_BOTH_LIBRARIES - Both libgmock & libgmock-main
# GMOCK_LIBRARIES - libgmock
# GMOCK_MAIN_LIBRARIES - libgmock-main
#
# Accepts the following variables as input:
#
# GMOCK_ROOT - (as a CMake or environment variable)
# The root directory of the gmock install prefix
#
# GMOCK_MSVC_SEARCH - If compiling with MSVC, this variable can be set to
# "MD" or "MT" to enable searching a gmock build tree
# (defaults: "MD")
#
#-----------------------
# Example Usage:
#
# find_package(GMock REQUIRED)
# include_directories(${GMOCK_INCLUDE_DIRS})
#
# add_executable(foo foo.cc)
# target_link_libraries(foo ${GMOCK_BOTH_LIBRARIES})
#
#=============================================================================
# This file is released under the MIT licence:
#
# Copyright (c) 2011 Matej Svec
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#=============================================================================
function(_gmock_append_debugs _endvar _library)
if(${_library} AND ${_library}_DEBUG)
set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
else()
set(_output ${${_library}})
endif()
set(${_endvar} ${_output} PARENT_SCOPE)
endfunction()
function(_gmock_find_library _name)
find_library(${_name}
NAMES ${ARGN}
HINTS
$ENV{GMOCK_ROOT}
${GMOCK_ROOT}
PATH_SUFFIXES ${_gmock_libpath_suffixes}
)
mark_as_advanced(${_name})
endfunction()
if(NOT DEFINED GMOCK_MSVC_SEARCH)
set(GMOCK_MSVC_SEARCH MD)
endif()
set(_gmock_libpath_suffixes lib)
if(MSVC)
if(GMOCK_MSVC_SEARCH STREQUAL "MD")
list(APPEND _gmock_libpath_suffixes
msvc/gmock-md/Debug
msvc/gmock-md/Release)
elseif(GMOCK_MSVC_SEARCH STREQUAL "MT")
list(APPEND _gmock_libpath_suffixes
msvc/gmock/Debug
msvc/gmock/Release)
endif()
endif()
find_path(GMOCK_INCLUDE_DIR gmock/gmock.h
HINTS
$ENV{GMOCK_ROOT}/include
${GMOCK_ROOT}/include
)
mark_as_advanced(GMOCK_INCLUDE_DIR)
if(MSVC AND GMOCK_MSVC_SEARCH STREQUAL "MD")
# The provided /MD project files for Google Mock add -md suffixes to the
# library names.
_gmock_find_library(GMOCK_LIBRARY gmock-md gmock)
_gmock_find_library(GMOCK_LIBRARY_DEBUG gmock-mdd gmockd)
_gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main-md gmock_main)
_gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_main-mdd gmock_maind)
else()
_gmock_find_library(GMOCK_LIBRARY gmock)
_gmock_find_library(GMOCK_LIBRARY_DEBUG gmockd)
_gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main)
_gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind)
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY)
if(GMOCK_FOUND)
set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR})
_gmock_append_debugs(GMOCK_LIBRARIES GMOCK_LIBRARY)
_gmock_append_debugs(GMOCK_MAIN_LIBRARIES GMOCK_MAIN_LIBRARY)
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})
endif()

View File

@ -24,7 +24,7 @@
#include <gtest/gtest.h>
#include "appdrag.h"
#include "qgsettingsinterfacemock.h"
#include "mock/QGsettingsMock.h"
class Test_AppDrag : public ::testing::Test
{
@ -38,22 +38,26 @@ public:
void Test_AppDrag::SetUp()
{
QWidget *w = new QWidget;
drag = new AppDrag(new QGSettingsInterfaceMock("com.deepin.dde.dock.distancemultiple", "/com/deepin/dde/dock/distancemultiple/"),w);
}
void Test_AppDrag::TearDown()
{
delete drag;
drag = nullptr;
}
TEST_F(Test_AppDrag, drag_test)
{
QWidget *w = new QWidget;
QGSettingsMock mock;
ON_CALL(mock, get(::testing::_)) .WillByDefault(::testing::Invoke([](const QString& key){return 1.5; }));
drag = new AppDrag(&mock, w);
QPixmap pix(":/res/all_settings_on.png");
drag->setPixmap(pix);
ASSERT_TRUE(drag->appDragWidget());
drag->exec();
delete drag;
drag = nullptr;
}

View File

@ -25,7 +25,7 @@
#define private public
#include "appdragwidget.h"
#include "qgsettingsinterfacemock.h"
#include "mock/QGsettingsMock.h"
#undef private
class Test_AppDragWidget : public ::testing::Test
@ -33,24 +33,23 @@ class Test_AppDragWidget : public ::testing::Test
public:
virtual void SetUp() override;
virtual void TearDown() override;
public:
AppDragWidget *dragWidget = nullptr;
};
void Test_AppDragWidget::SetUp()
{
dragWidget = new AppDragWidget(new QGSettingsInterfaceMock("com.deepin.dde.dock.distancemultiple", "/com/deepin/dde/dock/distancemultiple/"));
{
}
void Test_AppDragWidget::TearDown()
{
delete dragWidget;
dragWidget = nullptr;
}
TEST_F(Test_AppDragWidget, cuntion_test)
{
QGSettingsMock mock;
ON_CALL(mock, get(::testing::_)) .WillByDefault(::testing::Invoke([](const QString& key){return 1.5; }));
AppDragWidget *dragWidget = new AppDragWidget(&mock);
QPixmap pix(":/res/all_settings_on.png");
dragWidget->setAppPixmap(pix);
dragWidget->setOriginPos(QPoint(-1, -1));
@ -62,18 +61,12 @@ TEST_F(Test_AppDragWidget, cuntion_test)
dragWidget->showRemoveTips();
dragWidget->showGoBackAnimation();
}
TEST_F(Test_AppDragWidget, event_test)
{
dragWidget->show();
dragWidget->hide();
QTest::mouseClick(dragWidget,Qt::LeftButton, Qt::NoModifier, QPoint(dragWidget->rect().center()));
}
TEST_F(Test_AppDragWidget, isRemoveAble_test)
{
// bottom
const QRect &rect = QRect(QPoint(0, 1040), QPoint(1920, 1080));
dragWidget->setDockInfo(Dock::Position::Bottom, rect);

View File

@ -71,7 +71,7 @@ TEST_F(Test_FloatingPreview, view_test)
// view->m_closeBtn3D->click();
view->hide();
ASSERT_EQ(shot->contentsMargins(), QMargins(0, 0, 0, 0));
ASSERT_TRUE(shot->contentsMargins() == QMargins(0, 0, 0, 0));
}
TEST_F(Test_FloatingPreview, empty_test)

View File

@ -26,7 +26,7 @@
#define private public
#include "appitem.h"
#include "qgsettingsinterfacemock.h"
#include "qgsettingsinterface.h"
#undef private
class Test_AppItem : public ::testing::Test
@ -59,7 +59,7 @@ TEST_F(Test_AppItem, coverage_test)
appItem->setDockInfo(Dock::Position::Top, QRect(QPoint(0,0), QPoint(1920, 40)));
ASSERT_EQ(appItem->accessibleName(), appItem->m_itemEntryInter->name());
ASSERT_TRUE(appItem->accessibleName() == appItem->m_itemEntryInter->name());
}
TEST_F(Test_AppItem, AppItem_show_test)
@ -68,7 +68,7 @@ TEST_F(Test_AppItem, AppItem_show_test)
QThread::msleep(450);
ASSERT_EQ(appItem->isVisible(), true);
ASSERT_TRUE(appItem->isVisible());
}
TEST_F(Test_AppItem, AppItem_hide_test)
@ -77,5 +77,5 @@ TEST_F(Test_AppItem, AppItem_hide_test)
QThread::msleep(450);
ASSERT_EQ(appItem->isVisible(), false);
ASSERT_TRUE(!appItem->isVisible());
}

View File

@ -23,8 +23,10 @@
#include <QThread>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "dockitem.h"
#include "mock/QGsettingsMock.h"
class Test_DockItem : public ::testing::Test
{

View File

@ -23,34 +23,43 @@
#include <QTest>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace ::testing;
#define private public
#include "launcheritem.h"
#undef private
#include "qgsettingsinterfacemock.h"
#include "mock/QGsettingsMock.h"
class Test_LauncherItem : public ::testing::Test
{
public:
virtual void SetUp() override;
virtual void TearDown() override;
public:
LauncherItem *launcherItem = nullptr;
};
void Test_LauncherItem::SetUp()
{
launcherItem = new LauncherItem(new QGSettingsInterfaceMock("com.deepin.dde.dock.module.launcher"));
}
void Test_LauncherItem::TearDown()
{
delete launcherItem;
launcherItem = nullptr;
}
TEST_F(Test_LauncherItem, launcher_test)
{
QGSettingsMock mock;
// EXPECT_CALL(mock, type()).WillRepeatedly(Return(QGSettingsMock::Type::MockType));
// EXPECT_CALL(mock, keys()).WillRepeatedly(Return(QStringList() << "enable" << "control"));
ON_CALL(mock, type()).WillByDefault(Return(QGSettingsMock::Type::MockType));
ON_CALL(mock, keys()).WillByDefault(Return(QStringList() << "enable" << "control"));
ON_CALL(mock, get(_)) .WillByDefault(::testing::Invoke([](const QString& key){return true; }));
LauncherItem *launcherItem = new LauncherItem(&mock);
ASSERT_EQ(launcherItem->itemType(), LauncherItem::Launcher);
launcherItem->refreshIcon();
launcherItem->show();
@ -60,6 +69,8 @@ TEST_F(Test_LauncherItem, launcher_test)
launcherItem->update();
QThread::msleep(10);
launcherItem->resize(100,100);
ASSERT_FALSE(launcherItem->popupTips());
ON_CALL(mock, get(_)) .WillByDefault(::testing::Invoke([](const QString& key){ return false; }));
ASSERT_TRUE(launcherItem->popupTips());
QTest::mouseClick(launcherItem, Qt::LeftButton, Qt::NoModifier, launcherItem->geometry().center());

View File

@ -47,7 +47,7 @@ void Test_PlaceholderItem::TearDown()
placeholderitem = nullptr;
}
TEST_F(Test_PlaceholderItem, launcher_test)
TEST_F(Test_PlaceholderItem, placeholder_test)
{
QCOMPARE(placeholderitem->itemType(), PlaceholderItem::Placeholder);
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2011 ~ 2018 Deepin 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 QGSETTINGSMOCK_H
#define QGSETTINGSMOCK_H
#include "qgsettingsinterface.h"
#include <gmock/gmock.h>
#include <QVariant>
#include <QString>
class QGSettingsMock : public QGSettingsInterface
{
public:
virtual ~QGSettingsMock() {}
MOCK_METHOD0(type, Type(void));
MOCK_METHOD0(gsettings, QGSettings *(void));
MOCK_CONST_METHOD1(get, QVariant(const QString &key));
MOCK_METHOD2(set, void(const QString &key, const QVariant &value));
MOCK_METHOD2(trySet, bool (const QString &key, const QVariant &value));
MOCK_CONST_METHOD0(keys, QStringList(void));
MOCK_CONST_METHOD1(choices, QVariantList(const QString &key));
MOCK_METHOD1(reset, void(const QString &key));
static bool isSchemaInstalled(const QByteArray &schema_id) {Q_UNUSED(schema_id); return true;}
};
#endif // QGSETTINGSMOCK_H

View File

@ -21,6 +21,7 @@
#include <QObject>
#include <QThread>
#include <QTest>
#include <gtest/gtest.h>
@ -73,43 +74,43 @@ TEST_F(Test_Monitor, monitor_test)
int h = 100;
monitor->setX(x);
ASSERT_EQ(monitor->x(), x);
QCOMPARE(monitor->x(), x);
monitor->setX(x);
monitor->setY(y);
ASSERT_EQ(monitor->y(), y);
QCOMPARE(monitor->y(), y);
monitor->setY(y);
monitor->setW(w);
ASSERT_EQ(monitor->w(), w);
QCOMPARE(monitor->w(), w);
monitor->setW(w);
monitor->setH(h);
ASSERT_EQ(monitor->h(), h);
QCOMPARE(monitor->h(), h);
monitor->setH(h);
ASSERT_EQ(monitor->left(), x);
ASSERT_EQ(monitor->right(), x + w);
ASSERT_EQ(monitor->top(), y);
ASSERT_EQ(monitor->bottom(), y + h);
QCOMPARE(monitor->left(), x);
QCOMPARE(monitor->right(), x + w);
QCOMPARE(monitor->top(), y);
QCOMPARE(monitor->bottom(), y + 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));
QCOMPARE(monitor->topLeft(), QPoint(x, y));
QCOMPARE(monitor->topRight(), QPoint(x + w, y));
QCOMPARE(monitor->bottomLeft(), QPoint(x, y + h));
QCOMPARE(monitor->bottomRight(), QPoint(x + w, y + h));
QCOMPARE(monitor->rect(), QRect(x, y, w, h));
QString name = "MonitorTestName";
monitor->setName(name);
ASSERT_EQ(monitor->name(), name);
QCOMPARE(monitor->name(), name);
QString path = "testPath";
monitor->setPath(path);
ASSERT_EQ(monitor->path(), path);
QCOMPARE(monitor->path(), path);
bool monitorEnable = true;
monitor->setMonitorEnable(monitorEnable);
ASSERT_EQ(monitor->enable(), monitorEnable);
QCOMPARE(monitor->enable(), monitorEnable);
monitor->setMonitorEnable(monitorEnable);
Monitor::DockPosition dockPosition;
@ -118,7 +119,7 @@ TEST_F(Test_Monitor, monitor_test)
dockPosition.topDock = true;
dockPosition.bottomDock = true;
monitor->setDockPosition(dockPosition);
ASSERT_EQ(monitor->dockPosition(), dockPosition);
QCOMPARE(monitor->dockPosition(), dockPosition);
}
TEST_F(Test_Monitor, dockPosition_test)

View File

@ -2,6 +2,7 @@
#include "touchsignalmanager.h"
#undef private
#include <QTest>
#include <QSignalSpy>
#include <gtest/gtest.h>
@ -23,23 +24,23 @@ void Ut_TouchSignalManager::TearDown()
TEST_F(Ut_TouchSignalManager, isDragIconPress_test)
{
ASSERT_EQ(TouchSignalManager::instance()->isDragIconPress(), false);
QCOMPARE(TouchSignalManager::instance()->isDragIconPress(), false);
TouchSignalManager::instance()->m_dragIconPressed = true;
ASSERT_EQ(TouchSignalManager::instance()->isDragIconPress(), true);
QCOMPARE(TouchSignalManager::instance()->isDragIconPress(), true);
TouchSignalManager::instance()->m_dragIconPressed = false;
ASSERT_EQ(TouchSignalManager::instance()->isDragIconPress(), false);
QCOMPARE(TouchSignalManager::instance()->isDragIconPress(), false);
}
TEST_F(Ut_TouchSignalManager, dealShortTouchPress_test)
{
QSignalSpy spy(TouchSignalManager::instance(), SIGNAL(shortTouchPress(int, double, double)));
TouchSignalManager::instance()->dealShortTouchPress(1, 0, 0);
ASSERT_EQ(spy.count(), 1);
ASSERT_EQ(TouchSignalManager::instance()->isDragIconPress(), true);
QCOMPARE(spy.count(), 1);
QCOMPARE(TouchSignalManager::instance()->isDragIconPress(), true);
const QList<QVariant> &arguments = spy.takeFirst();
ASSERT_EQ(arguments.size(), 3);
ASSERT_EQ(arguments.at(0), 1);
QCOMPARE(arguments.size(), 3);
QCOMPARE(arguments.at(0), 1);
ASSERT_TRUE(qAbs(arguments.at(1).toDouble()) < 0.00001);
ASSERT_TRUE(qAbs(arguments.at(2).toDouble()) < 0.00001);
}
@ -48,11 +49,11 @@ TEST_F(Ut_TouchSignalManager, dealTouchRelease_test)
{
QSignalSpy spy(TouchSignalManager::instance(), SIGNAL(touchRelease(double, double)));
TouchSignalManager::instance()->dealTouchRelease(0, 0);
ASSERT_EQ(spy.count(), 1);
ASSERT_EQ(TouchSignalManager::instance()->isDragIconPress(), false);
QCOMPARE(spy.count(), 1);
QCOMPARE(TouchSignalManager::instance()->isDragIconPress(), false);
const QList<QVariant> &arguments = spy.takeFirst();
ASSERT_EQ(arguments.size(), 2);
QCOMPARE(arguments.size(), 2);
ASSERT_TRUE(qAbs(arguments.at(0).toDouble()) < 0.00001);
ASSERT_TRUE(qAbs(arguments.at(1).toDouble()) < 0.00001);
}
@ -61,16 +62,16 @@ TEST_F(Ut_TouchSignalManager, dealTouchPress_test)
{
QSignalSpy spy(TouchSignalManager::instance(), SIGNAL(middleTouchPress(double, double)));
TouchSignalManager::instance()->dealTouchPress(1, 1000, 0, 0);
ASSERT_EQ(spy.count(), 1);
QCOMPARE(spy.count(), 1);
const QList<QVariant> &arguments = spy.takeFirst();
ASSERT_EQ(arguments.size(), 2);
QCOMPARE(arguments.size(), 2);
ASSERT_TRUE(qAbs(arguments.at(0).toDouble()) < 0.00001);
ASSERT_TRUE(qAbs(arguments.at(1).toDouble()) < 0.00001);
TouchSignalManager::instance()->dealTouchPress(1, 2000, 0, 0);
ASSERT_EQ(spy.count(), 0);
QCOMPARE(spy.count(), 0);
TouchSignalManager::instance()->dealTouchPress(1, 500, 0, 0);
ASSERT_EQ(spy.count(), 0);
QCOMPARE(spy.count(), 0);
TouchSignalManager::instance()->dealTouchPress(2, 0000, 0, 0);
ASSERT_EQ(spy.count(), 0);
QCOMPARE(spy.count(), 0);
}

View File

@ -1,5 +1,7 @@
#include "utils.h"
#include <QTest>
#include <gtest/gtest.h>
class Ut_Utils : public ::testing::Test
@ -23,11 +25,11 @@ TEST_F(Ut_Utils, comparePluginApi_test)
QString v2("1.0.1");
QString v3("1.0.0.0");
ASSERT_EQ(Utils::comparePluginApi(v1, v1), 0);
ASSERT_EQ(Utils::comparePluginApi(v1, v2), -1);
ASSERT_EQ(Utils::comparePluginApi(v2, v1), 1);
ASSERT_EQ(Utils::comparePluginApi(v1, v3), -1);
ASSERT_EQ(Utils::comparePluginApi(v3, v1), 1);
QCOMPARE(Utils::comparePluginApi(v1, v1), 0);
QCOMPARE(Utils::comparePluginApi(v1, v2), -1);
QCOMPARE(Utils::comparePluginApi(v2, v1), 1);
QCOMPARE(Utils::comparePluginApi(v1, v3), -1);
QCOMPARE(Utils::comparePluginApi(v3, v1), 1);
}
TEST_F(Ut_Utils, isSettingConfigured_test)
@ -39,13 +41,13 @@ TEST_F(Ut_Utils, isSettingConfigured_test)
TEST_F(Ut_Utils, screenAt_test)
{
Utils::screenAt(QPoint(0, 0));
ASSERT_EQ(Utils::screenAt(QPoint(-1, -1)), nullptr);
QCOMPARE(Utils::screenAt(QPoint(-1, -1)), nullptr);
}
TEST_F(Ut_Utils, screenAtByScaled_test)
{
Utils::screenAtByScaled(QPoint(0, 0));
ASSERT_EQ(Utils::screenAtByScaled(QPoint(-1, -1)), nullptr);
QCOMPARE(Utils::screenAtByScaled(QPoint(-1, -1)), nullptr);
}
TEST_F(Ut_Utils, renderSVG_test)
@ -54,7 +56,7 @@ TEST_F(Ut_Utils, renderSVG_test)
const QSize &size = pix.size();
ASSERT_TRUE(Utils::renderSVG("", size, 1.0).isNull());
ASSERT_EQ(Utils::renderSVG(":/res/all_settings_on.png", size, 1.0).size(), size);
ASSERT_EQ(Utils::renderSVG(":/res/all_settings_on.png", QSize(50, 50), 1.0).size(), QSize(50, 50));
ASSERT_EQ(Utils::renderSVG(":/res/all_settings_on.png", QSize(50, 50), 0.5).size(), QSize(25, 25));
QCOMPARE(Utils::renderSVG(":/res/all_settings_on.png", size, 1.0).size(), size);
QCOMPARE(Utils::renderSVG(":/res/all_settings_on.png", QSize(50, 50), 1.0).size(), QSize(50, 50));
QCOMPARE(Utils::renderSVG(":/res/all_settings_on.png", QSize(50, 50), 0.5).size(), QSize(25, 25));
}