Skip to content
Closed
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
109 changes: 87 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,101 @@
name: Build
name: CI

on:
push:
branches:
- master
paths:
- 'src/**'
branches: [ master ]
pull_request:
branches:
- master
paths:
- 'src/**'
branches: [ master ]

jobs:
build:
runs-on: macos-12
test-macos:
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: recursive

- name: Install dependencies
run: |
brew install cmake ninja
brew install sdl2

- name: Configure
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_HEADLESS_TESTS=ON

- name: Build
run: |
cd build
cmake --build . --config Release

- name: Run SDL tests in CI mode
run: |
cd build/bin
# macOS needs special handling for mouse automation in headless mode
# We'll use the CI mode flag we're adding to the test application
./RobotCPPSDLTest --ci-mode --run-tests

test-windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

# Alternative approach: clone vcpkg directly
- name: Setup vcpkg
run: |
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
shell: cmd

- name: Install SDL2
run: |
.\vcpkg\vcpkg.exe install sdl2:x64-windows
shell: cmd

- name: Create build directory
run: mkdir build
# Debug step to verify toolchain file existence
- name: Verify vcpkg toolchain
run: |
dir vcpkg\scripts\buildsystems
if (Test-Path "vcpkg\scripts\buildsystems\vcpkg.cmake") {
Write-Host "Toolchain file found!"
} else {
Write-Host "Toolchain file not found!"
}
shell: powershell

- name: Configure CMake
run: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=$(brew --prefix)/bin/ninja -G Ninja -S . -B build
- name: Configure
shell: powershell
run: |
mkdir build
cd build
# Use an absolute path that we know exists
$vcpkgToolchain = "$pwd\..\vcpkg\scripts\buildsystems\vcpkg.cmake"
Write-Host "Using toolchain file: $vcpkgToolchain"
cmake .. -DCMAKE_TOOLCHAIN_FILE="$vcpkgToolchain" -DCMAKE_BUILD_TYPE=Release -DBUILD_HEADLESS_TESTS=ON

- name: Link
run: ninja
working-directory: build
- name: Build
shell: powershell
run: |
cd build
cmake --build . --config Release

- name: Run SDL tests in CI mode
shell: powershell
run: |
if (Test-Path "build\bin\Release\RobotCPPSDLTest.exe") {
cd build\bin\Release
.\RobotCPPSDLTest.exe --ci-mode --run-tests
} elseif (Test-Path "build\tests\Release\RobotCPPSDLTest.exe") {
cd build\tests\Release
.\RobotCPPSDLTest.exe --ci-mode --run-tests
} else {
Write-Host "Searching for RobotCPPSDLTest.exe..."
Get-ChildItem -Path build -Recurse -Filter "RobotCPPSDLTest.exe" | ForEach-Object { $_.FullName }
exit 1
}
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "externals/lodepng"]
path = externals/lodepng
url = https://github.com/lvandeve/lodepng
[submodule "cmake/sdl2"]
path = cmake/sdl2
url = https://github.com/opeik/cmake-modern-findsdl2
[submodule "externals/googletest"]
path = externals/googletest
url = https://github.com/google/googletest
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ project(RobotCPP)
set(CMAKE_CXX_STANDARD 23)
set(LIB_NAME RobotCPP)

# Add option for headless tests
option(BUILD_HEADLESS_TESTS "Configure tests to run in headless/CI environments" OFF)

# Add GoogleTest
add_subdirectory(externals/googletest)
enable_testing()

# Find SDL2 for tests
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/sdl2/")
find_package(SDL2 REQUIRED)

set(COMMON_SOURCES
src/ActionRecorder.h
src/types.h
Expand All @@ -30,6 +41,19 @@ elseif (WIN32)
list(APPEND PLATFORM_SOURCES src/EventHookWindows.h)
endif ()

# If building headless tests, define a preprocessor flag
if (BUILD_HEADLESS_TESTS)
add_compile_definitions(ROBOT_HEADLESS_TESTS)
endif()

add_library(${LIB_NAME} STATIC ${COMMON_SOURCES} ${PLATFORM_SOURCES} ${SOURCES_LODEPNG})
target_include_directories(${LIB_NAME} PUBLIC src PRIVATE externals/lodepng)
target_link_libraries(${LIB_NAME} ${PLATFORM_LIBRARIES})

# Set output directory for all targets
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin)

# Add the tests directory
add_subdirectory(tests)
1 change: 1 addition & 0 deletions cmake/sdl2
Submodule sdl2 added at 77f77c
11 changes: 0 additions & 11 deletions example/CMakeLists.txt

This file was deleted.

39 changes: 0 additions & 39 deletions example/main.cpp

This file was deleted.

1 change: 1 addition & 0 deletions externals/googletest
Submodule googletest added at 0bdccf
48 changes: 48 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
set(TEST_NAME RobotCPPTest)
set(SDL_TEST_NAME RobotCPPSDLTest)

# We keep the gtest reference in the CMake setup as requested
# But we don't need to create the actual test executable
# Instead, just ensure gtest is available for other targets if needed
find_package(GTest QUIET)
if(NOT GTest_FOUND)
# GTest is already included via add_subdirectory in the main CMakeLists.txt
# We don't need to do anything here
endif()

# SDL2 Functional Tests - Only keeping mouse drag test
set(SDL_TEST_SOURCES
sdl/SDLTestApp.cpp
sdl/TestElements.h
sdl/MouseTests.h
)

add_executable(${SDL_TEST_NAME} ${SDL_TEST_SOURCES})
target_link_libraries(${SDL_TEST_NAME} PRIVATE
RobotCPP
SDL2::SDL2
)

# Set output directory to be consistent across build types
set_target_properties(${SDL_TEST_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin"
)

# Copy test assets
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin)

# Add a custom command to build the SDL test executable as part of ALL target
add_custom_target(build_sdl_tests ALL DEPENDS ${SDL_TEST_NAME})

# Add the SDL test as a test
add_test(NAME SDLFunctionalTests
COMMAND ${SDL_TEST_NAME} --headless --run-tests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Add another test configuration for interactive mode
add_test(NAME SDLInteractiveTests
COMMAND ${SDL_TEST_NAME}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_tests_properties(SDLInteractiveTests PROPERTIES DISABLED TRUE)
13 changes: 13 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Test Assets Directory

This directory contains assets required for testing the Robot CPP library.

## Structure

- `expected/` - Contains reference images for comparison in screen capture tests
- `temp/` - Temporary directory for test outputs (screenshots, logs, etc.)

## Usage

The SDL test application will save screenshots to this directory during tests.
When running tests, you can examine these screenshots to verify visual output.
40 changes: 40 additions & 0 deletions tests/assets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set(TEST_NAME RobotCPPTest)
set(SDL_TEST_NAME RobotCPPSDLTest)

# Unit Tests
set(TEST_SOURCES
unit/MouseTest.cpp
unit/KeyboardTest.cpp
unit/ScreenTest.cpp
)

add_executable(${TEST_NAME} ${TEST_SOURCES})
target_link_libraries(${TEST_NAME} PRIVATE
gtest
gmock
gtest_main
RobotCPP
)

add_test(NAME UnitTests COMMAND ${TEST_NAME})

# SDL2 Functional Tests
set(SDL_TEST_SOURCES
sdl/SDLTestApp.cpp
sdl/TestElements.h
sdl/MouseTests.h
sdl/KeyboardTests.h
sdl/ScreenTests.h
)

add_executable(${SDL_TEST_NAME} ${SDL_TEST_SOURCES})
target_link_libraries(${SDL_TEST_NAME} PRIVATE
RobotCPP
SDL2::SDL2
)

# Copy test assets
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/tests)

add_test(NAME FunctionalTests
COMMAND ${SDL_TEST_NAME} --headless --run-tests)
Loading
Loading