Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/src/windowstatethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ void windowStateThread::run()
{
qDebug() << "Starting window state monitoring loop";
while (!isInterruptionRequested()) {
#ifdef UNITTEST
// 单元测试环境下跳过 workspaceWindows(),
// 因为 DForeignWindow::fromWinId() 在工作线程中调用会违反 Qt 线程安全规则
break;
#endif
//获取当前工作区域内所有的窗口
auto list = workspaceWindows();
qDebug() << "Found" << list.size() << "windows in workspace";
Expand All @@ -38,9 +43,6 @@ void windowStateThread::run()
}
//线程休眠1秒
std::this_thread::sleep_for(std::chrono::seconds(1));
#ifdef UNITTEST
break;
#endif
}
qInfo() << "Window state monitoring thread ended";
}
Expand Down
85 changes: 56 additions & 29 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

# 定义需要的cmake版本
cmake_minimum_required(VERSION 3.16)

# 设置工程名字
project(deepin-camera-test VERSION 1.0.0)
set(CMD_NAME deepin-camera-test)
set(TARGET_NAME deepin-camera-test)
# 定义需要的cmake版本
cmake_minimum_required(VERSION 3.0)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
Expand Down Expand Up @@ -37,25 +38,36 @@ set(PROJECT_INCLUDE
./stub
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/include/libusb-1.0
/usr/include/libusb-1.0
${CMAKE_INSTALL_PREFIX}/include/SDL2
${PROJECT_SOURCE_DIR}/../deepin-camera
${PROJECT_SOURCE_DIR}/googletest/include
)
# 设置Qt模块
set(QtModule Core Gui Widgets DBus Concurrent LinguistTools Multimedia PrintSupport Svg)
# 设置Qt6模块
set(QtModule Core Gui Widgets DBus Concurrent LinguistTools Multimedia PrintSupport Svg SvgWidgets OpenGLWidgets Xml Test)

# 查找Qt相关的库链接
find_package(Qt5 REQUIRED ${QtModule})
# 查找Qt6相关的库链接
find_package(Qt6 REQUIRED ${QtModule})
find_package(PkgConfig REQUIRED)

file (GLOB_RECURSE CXXSOURCES
./*.cpp
../src/src/basepub/*.cpp
../src/src/*.cpp
../src/src/qtsingleapplication/*.cpp
./stub/*.cpp
)

# 收集 src/src/*.cpp (排除 videosurface.cpp)
file(GLOB_RECURSE SRC_CXXSOURCES ../src/src/*.cpp)

# 将 src/src/*.cpp (排除 videosurface.cpp) 加入编译
foreach(src_file ${SRC_CXXSOURCES})
get_filename_component(src_name ${src_file} NAME)
if(NOT src_name STREQUAL "videosurface.cpp")
list(APPEND CXXSOURCES ${src_file})
endif()
endforeach()

file (GLOB_RECURSE CSOURCES
../src/src/*.c
../libcam/*.c
Expand All @@ -82,40 +94,55 @@ add_executable( ${TARGET_NAME} ${CXXSOURCES} ${CSOURCES} ${RESOURCES}


pkg_check_modules(3rd_lib REQUIRED
dtkgui
dtkwidget gstreamer-1.0 gstreamer-app-1.0
dtk6gui
dtk6widget
gstreamer-1.0
gstreamer-app-1.0
pciaccess
# libv4l2
# libudev
# libusb-1.0
# libavcodec
# libavutil
# libavformat
# libswscale
# libpng
# sdl2
# libpulse
# libswresample
# libffmpegthumbnailer
libva
libavcodec
libavutil
libavformat
libswscale
libswresample
libudev
)
# 添加第三方库的所有文件夹路径到工程中来(注意 *_INCLUDE_DIRS)

target_include_directories(${TARGET_NAME} PUBLIC ${3rd_lib_INCLUDE_DIRS} ${PROJECT_INCLUDE} ${GLOB_RECURSE})
# 将第三方库链接进来(注意 *_LIBRARIES)
target_link_libraries(${PROJECT_NAME} ${3rd_lib_LIBRARIES}
target_link_libraries(${TARGET_NAME} PRIVATE
${3rd_lib_LIBRARIES}
gtest
pthread
Qt5Test
Qt6::Test
dl
# portaudio
# asound
# z
va
va-x11

imagevisualresult
imagevisualresult6
)

# 将工程与Qt模块链接起来
qt5_use_modules(${PROJECT_NAME} ${QtModule})
# 将工程与Qt6模块链接起来
target_link_libraries(${TARGET_NAME} PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
Qt6::DBus
Qt6::Concurrent
Qt6::Multimedia
Qt6::PrintSupport
Qt6::Svg
Qt6::SvgWidgets
Qt6::OpenGLWidgets
)

# 链接DTK6库
target_link_libraries(${TARGET_NAME} PRIVATE
dtk6core
dtk6gui
dtk6widget
)

include_directories(${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR})
Expand Down
21 changes: 15 additions & 6 deletions tests/CameraTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@
#include "src/Settings.h"
#include "src/mainwindow.h"
#include "src/photorecordbtn.h"
#include "src/majorimageprocessingthread.h"

Check warning on line 24 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "src/majorimageprocessingthread.h" not found.

Check warning on line 24 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "src/majorimageprocessingthread.h" not found.
#include "src/capplication.h"

Check warning on line 25 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "src/capplication.h" not found.

Check warning on line 25 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "src/capplication.h" not found.
#include "src/camera.h"

Check warning on line 26 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "src/camera.h" not found.

Check warning on line 26 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "src/camera.h" not found.
#include "src/videosurface.h"
#include "src/basepub/datamanager.h"

Check warning on line 27 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "src/basepub/datamanager.h" not found.

Check warning on line 27 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "src/basepub/datamanager.h" not found.
#include "ac-deepin-camera-define.h"

Check warning on line 28 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ac-deepin-camera-define.h" not found.

Check warning on line 28 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "ac-deepin-camera-define.h" not found.
#include "stub/stub_function.h"
#include "addr_pri.h"

Check warning on line 30 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "addr_pri.h" not found.

Check warning on line 30 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "addr_pri.h" not found.


#include <QtTest/qtest.h>
#include <QVideoSurfaceFormat>
#include <QTest>

Check warning on line 33 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 33 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtMultimedia/QVideoFrame>

Check warning on line 34 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtMultimedia/QVideoFrame> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 34 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QtMultimedia/QVideoFrame> not found. Please note: Cppcheck does not need standard library headers to get proper results.

ACCESS_PRIVATE_FUN(CMainWindow, void(), initCameraConnection);

ACCESS_PRIVATE_FIELD(CMainWindow, bool, m_bRecording);
#if QT_VERSION_MAJOR <= 5
ACCESS_PRIVATE_FIELD(Camera, QString, m_curDevName);
ACCESS_PRIVATE_FIELD(Camera, VideoSurface*, m_videoSurface);
#endif

CameraTest::CameraTest()

Check warning on line 44 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Member variable 'CameraTest::m_devnumMonitor' is not initialized in the constructor. Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.

Check warning on line 44 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Member variable 'CameraTest::m_mainwindow' is not initialized in the constructor. Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.

Check warning on line 44 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Member variable 'CameraTest::m_devnumMonitor' is not initialized in the constructor. Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.

Check warning on line 44 in tests/CameraTest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Member variable 'CameraTest::m_mainwindow' is not initialized in the constructor. Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.
{
DataManager::instance()->setEncodeEnv(QCamera_Env);
}
Expand Down Expand Up @@ -81,6 +82,7 @@
*/
TEST_F(CameraTest, refreshCamera)
{
#if QT_VERSION_MAJOR <= 5
// 重启摄像头
Stub_Function::resetSub(ADDR(Camera, getSupportResolutionsSize), ADDR(Stub_Function, getSupportResolutionsSize));
Stub_Function::resetSub(ADDR(QCamera, status), ADDR(Stub_Function, cameraStatus));
Expand All @@ -94,6 +96,12 @@
access_private_field::Cameram_curDevName(*Camera::instance()) = "/dev/video4";
m_devnumMonitor->existDevice();
access_private_field::Cameram_curDevName(*Camera::instance()) = "";
#else
// Qt6 下仅测试设备监控功能
Stub_Function::resetSub(ADDR(DataManager, getdevStatus), ADDR(Stub_Function, getNoDevStatus));
m_devnumMonitor->existDevice();
Stub_Function::clearSub(ADDR(DataManager, getdevStatus));
#endif
}

/**
Expand Down Expand Up @@ -145,8 +153,9 @@
QTest::qWait(500);
}

#if QT_VERSION_MAJOR <= 5
/**
* @brief videoSurface功能
* @brief videoSurface功能 (Qt5 only)
*/
TEST_F(CameraTest, videoSurfaceFunction)
{
Expand All @@ -158,7 +167,7 @@
}

/**
* @brief 发送一帧图片
* @brief 发送一帧图片 (Qt5 only)
*/
TEST_F(CameraTest, presentImage)
{
Expand All @@ -175,5 +184,5 @@
m_processThread->m_bTake = false;
Stub_Function::clearSub(ADDR(QVideoFrame, map));
}

#endif

2 changes: 1 addition & 1 deletion tests/ClosedialogTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <QTimer>
#include <QtTest/QTest>
#include <QTest>

#include "ClosedialogTest.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/DevNumTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "src/mainwindow.h"
#include "src/capplication.h"
#include "stub/stub_function.h"
#include <QtTest/qtest.h>
#include <QTest>

DevNumberTest::DevNumberTest()
{
Expand Down
3 changes: 1 addition & 2 deletions tests/GStreamerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
#include "addr_pri.h"


#include <QtTest/qtest.h>
#include <QVideoSurfaceFormat>
#include <QTest>

ACCESS_PRIVATE_FUN(CMainWindow, void(), initCameraConnection);

Expand Down
2 changes: 1 addition & 1 deletion tests/ImageItemTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "datamanager.h"
#include "stub/addr_pri.h"
#include "src/imageitem.h"
#include <QtTest/QTest>
#include <QTest>
#include <QShortcut>


Expand Down
8 changes: 4 additions & 4 deletions tests/MainwindowTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <QVariantMap>
#include <QStandardPaths>

#include <DWindowMaxButton>
#include <DWindowMinButton>
#include <DWindowCloseButton>
#include <DPrintPreviewDialog>
#include <dtk6/DWidget/DWindowMaxButton>
#include <dtk6/DWidget/DWindowMinButton>
#include <dtk6/DWidget/DWindowCloseButton>
#include <dtk6/DWidget/DPrintPreviewDialog>

#include "MainwindowTest.h"
#include "DButtonBox"
Expand Down
18 changes: 10 additions & 8 deletions tests/MainwindowTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>

#include <QtTest/QTest>
#include <QTest>
#include <QSharedMemory>

#include <DApplication>
#include <DMainWindow>
#include <DWidgetUtil>
#include <DWindowOptionButton>
#include <DMenu>
#include <DLog>
#include <DApplicationSettings>
#include <dtk6/DWidget/DApplication>
#include <dtk6/DWidget/DMainWindow>
#include <dtk6/DWidget/DWidgetUtil>
#include <dtk6/DWidget/DWindowOptionButton>
#include <dtk6/DWidget/DMenu>
#include <dtk6/DCore/DLog>
#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
#include <dtk6/DWidget/dapplicationsettings>
#endif

#include "src/mainwindow.h"
#include "src/capplication.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/MajorImageProcessingThreadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "src/majorimageprocessingthread.h"
#include "src/capplication.h"
#include "stub/stub_function.h"
#include <QtTest/qtest.h>
#include <QTest>
extern "C"
{
#include "v4l2_devices.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/PhotoRecordBtnTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "ac-deepin-camera-define.h"
#include "stub/addr_pri.h"
#include "datamanager.h"
#include <QtTest/qtest.h>
#include <QTest>


PhotoRecordBtnTest::PhotoRecordBtnTest()
Expand Down
2 changes: 1 addition & 1 deletion tests/RollingBoxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "ac-deepin-camera-define.h"
#include "stub/addr_pri.h"
#include "datamanager.h"
#include <QtTest/qtest.h>
#include <QTest>

RollingBoxTest::RollingBoxTest()
{
Expand Down
7 changes: 6 additions & 1 deletion tests/TakePhotoSettingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "src/accessibility/ac-deepin-camera-define.h"
#include "addr_pri.h"

#include <QtTest/QTest>
#include <QTest>

using namespace Dtk::Core;

Expand Down Expand Up @@ -306,7 +306,12 @@ TEST_F(TakePhotoSettingTest, exposureSlider)

QTest::qWait(500);
QPoint p(slider->rect().topLeft() + QPoint(10, 20));
#if QT_VERSION_MAJOR <= 5
QWheelEvent wheelEvent(p, 40, Qt::MiddleButton, Qt::NoModifier);
#else
// Qt6: QWheelEvent(pos, globalPos, pixelDelta, angleDelta, buttons, modifiers, phase, inverted)
QWheelEvent wheelEvent(QPointF(p), QPointF(slider->mapToGlobal(p)), QPoint(0, 40), QPoint(0, 40), Qt::NoButton, Qt::NoModifier, Qt::ScrollBegin, false);
#endif
QApplication::sendEvent(slider, &wheelEvent);

QTest::qWait(500);
Expand Down
4 changes: 2 additions & 2 deletions tests/VideoWidgetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "ac-deepin-camera-define.h"
#include "stub/addr_pri.h"
#include "datamanager.h"
#include <QtTest/QTest>
#include <QTest>


ACCESS_PRIVATE_FUN(videowidget, void(), showNocam);
Expand All @@ -36,7 +36,7 @@ ACCESS_PRIVATE_FUN(videowidget, void(), stopEverything);
ACCESS_PRIVATE_FUN(videowidget, void(), onReachMaxDelayedFrames);
ACCESS_PRIVATE_FUN(videowidget, void(), flash);
ACCESS_PRIVATE_FUN(videowidget, void(QGraphicsView *view), forbidScrollBar);
ACCESS_PRIVATE_FUN(videowidget, void(PRIVIEW_ENUM_STATE state), showCountDownLabel);
ACCESS_PRIVATE_FUN(videowidget, void(PREVIEW_ENUM_STATE state), showCountDownLabel);
ACCESS_PRIVATE_FUN(videowidget, void(const QString &resolution), slotresolutionchanged);

ACCESS_PRIVATE_FIELD(videowidget, QGraphicsTextItem *, m_pCamErrItem);
Expand Down
Loading
Loading