dde-dock/tests/window/ut_mainwindow.cpp
yanghongwei 33c332cd45 test: 测试MainWindow的panelGeometryChanged
测试MainWindow的panelGeometryChanged

Log: 添加单元测试
Change-Id: I6481b3436d13a5a9c3ccf62d4430a8ed83a37a08
2021-05-10 11:12:57 +08:00

94 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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 <QObject>
#include <QThread>
#include <QTest>
#include <QSignalSpy>
#include <gtest/gtest.h>
#define private public
#include "mainwindow.h"
#undef private
using namespace ::testing;
class Test_MainWindow : public ::testing::Test
{
public:
virtual void SetUp() override;
virtual void TearDown() override;
public:
MainWindow *m_window = nullptr;
};
void Test_MainWindow::SetUp()
{
m_window = new MainWindow;
}
void Test_MainWindow::TearDown()
{
delete m_window;
m_window = nullptr;
}
TEST_F(Test_MainWindow, coverage_test)
{
ASSERT_TRUE(m_window);
m_window->getTrayVisableItemCount();
m_window->adjustShadowMask();
m_window->resetDragWindow();
m_window->onMainWindowSizeChanged(QPoint(10, 10));
m_window->touchRequestResizeDock();
m_window->sendNotifications();
m_window->callShow();
QTest::qWait(450);
//TODO 这里无论输入什么均返回true
// ASSERT_FALSE(m_window->appIsOnDock("testname"));
QEvent enterEvent(QEvent::Enter);
qApp->sendEvent(m_window, &enterEvent);
QTest::qWait(10);
QEvent dragEnterEvent(QEvent::Enter);
qApp->sendEvent(m_window->m_dragWidget, &dragEnterEvent);
QTest::qWait(10);
ASSERT_EQ(QApplication::overrideCursor()->shape(), m_window->m_dragWidget->cursor().shape());
QEvent dragLeaveEvent(QEvent::Leave);
qApp->sendEvent(m_window->m_dragWidget, &dragLeaveEvent);
QTest::qWait(10);
ASSERT_EQ(QApplication::overrideCursor()->shape(), Qt::ArrowCursor);
// 测试窗口大小变化时是否发出panelGeometryChanged信号
QEvent resizeEvent(QEvent::Resize);
QSignalSpy signal(m_window, &MainWindow::panelGeometryChanged);
qApp->sendEvent(m_window, &resizeEvent);
QTest::qWait(10);
ASSERT_EQ(signal.count(), 1);
}