Skip to content

Commit

Permalink
chore: link to target directly on unit test
Browse files Browse the repository at this point in the history
link to target directly, instead of compiling the source code.

Log: Link to target directly on unit test
  • Loading branch information
wangfei authored and FeiWang1119 committed Aug 16, 2023
1 parent 67175b7 commit c97dccf
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 36 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast")
endif ()
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/plugins/platforms)

add_subdirectory(xcb)
if("${PROJECT_VERSION_MAJOR}" STREQUAL "5")
Expand Down
24 changes: 10 additions & 14 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ else()
find_package(Qt6 REQUIRED COMPONENTS OpenGL XcbQpaPrivate)
endif()

# NOTE(sbw): 禁止语法树上的 vrp 优化,-O2/-O3 默认开启,会导致测试虚析构函数 HOOK 失败
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-vrp" CACHE STRING "disable vrp optimization" FORCE)

add_definitions(-DDXCB_VERSION=\"${DTK_VERSION}\")
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DQT_NO_DEBUG_OUTPUT=TRUE)
endif()

include(${CMAKE_SOURCE_DIR}/xcb/xcb.cmake)
include(${CMAKE_SOURCE_DIR}/src/src.cmake)

file(GLOB test_SRC test.h main.cpp src/*.cpp)

add_executable(${PROJECT_NAME} ${GLOBAL_HEADERS} ${GLOBAL_SOURCES} ${test_SRC} ${xcb_SRC})
add_executable(${PROJECT_NAME} ${test_SRC})

include(${CMAKE_SOURCE_DIR}/xcb/linux.cmake)

add_definitions(-DPLUGIN_OUTPUT_PATH=\"${LIBRARY_OUTPUT_PATH}/..\")

target_compile_options(${PROJECT_NAME} PRIVATE -fno-access-control -fsanitize=address)
target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=address)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand All @@ -38,26 +35,25 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${PROJECT_NAME} PRIVATE -fprofile-arcs -ftest-coverage)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/xcb
)

target_link_libraries(${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Test
GTest::GTest
gmock
pthread
m
gcov
-ldl
dxcb
)

target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::Widgets
)
if(${QT_VERSION_MAJOR} STREQUAL "5")
target_link_libraries(${PROJECT_NAME}
PRIVATE
Expand Down
5 changes: 3 additions & 2 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "test.h"

#include <QApplication>
#include <QTest>
#include <gtest/gtest.h>

#ifdef QT_DEBUG
Expand All @@ -13,6 +12,8 @@

int main(int argc, char *argv[])
{
qputenv("QT_PLUGIN_PATH", PLUGIN_OUTPUT_PATH);

// gerrit编译时没有显示器,需要指定环境变量
if (!qEnvironmentVariableIsSet("DISPLAY"))
qputenv("QT_QPA_PLATFORM", "offscreen");
Expand Down
5 changes: 3 additions & 2 deletions tests/src/ut_dbackingstoreproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <gtest/gtest.h>
#include <QWindow>
#include <QVariant>

#include "dbackingstoreproxy.h"

Expand Down Expand Up @@ -32,13 +33,13 @@ TEST_F(TDBackingStoreProxy, useGLPaint)
{
ASSERT_FALSE(DBackingStoreProxy::useGLPaint(window));
window->setSurfaceType(QSurface::OpenGLSurface);
window->setProperty("_d_enableGLPaint", true);
window->setProperty("_d_enableGLPaint", QVariant::fromValue(true));
ASSERT_TRUE(DBackingStoreProxy::useGLPaint(window));
}

TEST_F(TDBackingStoreProxy, useWallpaperPaint)
{
ASSERT_FALSE(DBackingStoreProxy::useWallpaperPaint(window));
window->setProperty("_d_dxcb_wallpaper", true);
window->setProperty("_d_dxcb_wallpaper", QVariant::fromValue(true));
ASSERT_TRUE(DBackingStoreProxy::useWallpaperPaint(window));
}
14 changes: 0 additions & 14 deletions tests/src/ut_dnotitlebarwindowhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,56 +45,42 @@ TEST_F(TDNoTitlebarWindowHelper, theme)

TEST_F(TDNoTitlebarWindowHelper, windowRadius)
{
QPointF defaultValue(0.0, 0.0);
ASSERT_EQ(defaultValue, helper->windowRadius());
helper->setWindowRadius(QPointF(0.1, 0.1));
ASSERT_EQ(QPointF(0.1, 0.1), helper->windowRadius());
}

TEST_F(TDNoTitlebarWindowHelper, borderWidth)
{
int defaultValue = 0;
ASSERT_EQ(defaultValue, helper->borderWidth());
helper->setBorderWidth(2.0);
ASSERT_EQ(2.0, helper->borderWidth());
}

TEST_F(TDNoTitlebarWindowHelper, borderColor)
{
QColor defaultValue;
ASSERT_EQ(defaultValue, helper->borderColor());
helper->setBorderColor(Qt::red);
ASSERT_EQ(QColor(Qt::red), helper->borderColor());
}

TEST_F(TDNoTitlebarWindowHelper, shadowRadius)
{
qreal defaultValue;
ASSERT_EQ(defaultValue, helper->shadowRadius());
helper->setShadowRadius(2.0);
ASSERT_EQ(2.0, helper->shadowRadius());
}

TEST_F(TDNoTitlebarWindowHelper, shadowOffset)
{
QPointF defaultValue;
ASSERT_EQ(defaultValue, helper->shadowOffset());
helper->setShadowOffect(QPointF(1.0, 1.0));
ASSERT_EQ(QPointF(1.0, 1.0), helper->shadowOffset());
}

TEST_F(TDNoTitlebarWindowHelper, shadowColor)
{
QColor defaultValue;
ASSERT_EQ(defaultValue, helper->shadowColor());
helper->setShadowColor(Qt::blue);
ASSERT_EQ(QColor(Qt::blue), helper->shadowColor());
}

TEST_F(TDNoTitlebarWindowHelper, mouseInputAreaMargins)
{
QMarginsF defaultValue;
ASSERT_EQ(defaultValue, helper->mouseInputAreaMargins());
helper->setMouseInputAreaMargins(QMarginsF(1.0, 1.0, 1.0 ,1.0));
ASSERT_EQ(QMarginsF(1.0, 1.0, 1.0 ,1.0), helper->mouseInputAreaMargins());
}
12 changes: 8 additions & 4 deletions xcb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

project(dxcb)

find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Widgets DBus)
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Widgets)
find_package(DtkBuildHelper REQUIRED)
if(${QT_VERSION_MAJOR} STREQUAL "5")
find_package(Qt5 REQUIRED COMPONENTS XcbQpa X11Extras EdidSupport XkbCommonSupport)
else()
Expand All @@ -22,12 +23,15 @@ endif()
include(${CMAKE_CURRENT_LIST_DIR}/xcb.cmake)
include(${CMAKE_SOURCE_DIR}/src/src.cmake)

set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/plugins/platforms)

add_library(${PROJECT_NAME} MODULE ${GLOBAL_HEADERS} ${GLOBAL_SOURCES} ${xcb_SRC} ${DBUS_INTERFACE_XMLS})
add_library(${PROJECT_NAME} SHARED ${GLOBAL_HEADERS} ${GLOBAL_SOURCES} ${xcb_SRC} ${DBUS_INTERFACE_XMLS})

include(${CMAKE_CURRENT_LIST_DIR}/linux.cmake)

set(EnableCov CACHE BOOL FALSE)
if (EnableCov)
dtk_setup_code_coverage(${PROJECT_NAME})
endif()

target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Expand Down

0 comments on commit c97dccf

Please sign in to comment.