Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f3d12d3
feat: minimal tests
developer239 Mar 10, 2025
1a681a1
feat: minimal working interactive
developer239 Mar 10, 2025
918a66a
feat: minimal working interactive
developer239 Mar 10, 2025
8463cb1
test: even simpler tests
developer239 Mar 10, 2025
bf80365
test: simple working test
developer239 Mar 10, 2025
d3c28eb
fix: ci
developer239 Mar 10, 2025
c0872ca
fix: windows ci
developer239 Mar 10, 2025
2390012
fix: windows ci
developer239 Mar 10, 2025
98e166c
fix: windows ci
developer239 Mar 10, 2025
d659355
test: remove CI mode
developer239 Mar 11, 2025
904b933
test: remove headless mode
developer239 Mar 11, 2025
07a01f5
refactor: use modern C++ practices
developer239 Mar 11, 2025
318ba51
refactor: gtest friendly structure
developer239 Mar 11, 2025
5871fa1
refactor: leaner mouse drag test implementation
developer239 Mar 11, 2025
92c00a6
chore: polish code
developer239 Mar 11, 2025
3eb791e
ci: new test action
developer239 Mar 11, 2025
e8a378b
fix: window ci
developer239 Mar 11, 2025
028acc5
fix: window ci
developer239 Mar 11, 2025
0823bc2
ci: enable macos tests again
developer239 Mar 11, 2025
899a368
test: remove interactive test
developer239 Mar 11, 2025
42bcfcf
test: write more mouse tests
developer239 Mar 11, 2025
14b940c
refactor: polish test code
developer239 Mar 11, 2025
879b573
ci: split CI actions
developer239 Mar 11, 2025
3fe750f
fix: don't include test framework in build
developer239 Mar 11, 2025
aecbc71
ci: add macos build action
developer239 Mar 11, 2025
28876c1
docs: add badge
developer239 Mar 11, 2025
c765b0f
fix: build action
developer239 Mar 11, 2025
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
19 changes: 11 additions & 8 deletions .github/workflows/ci.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ name: Build

on:
push:
branches:
- master
branches: [ master ]
paths:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'CMakeLists.txt'
pull_request:
branches:
- master
branches: [ master ]
paths:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'CMakeLists.txt'

jobs:
build:
runs-on: macos-12
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: |
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: MacOS Tests (mouse)

on:
push:
branches: [ master ]
paths:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'CMakeLists.txt'
pull_request:
branches: [ master ]
paths:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'CMakeLists.txt'

jobs:
test-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install dependencies
run: brew install cmake sdl2

- name: Configure
run: cmake -B build -DBUILD_ROBOT_TESTS=ON

- name: Build
run: cmake --build build

- name: Test
run: |
# macOS can run GUI apps in headless mode
build/bin/RobotCPPSDLTest --gtest_filter=-*InteractiveMode --ci-mode true
103 changes: 103 additions & 0 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Windows Tests (mouse)

on:
push:
branches: [ master ]
paths:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'CMakeLists.txt'
pull_request:
branches: [ master ]
paths:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'CMakeLists.txt'

jobs:
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install vcpkg and SDL2
run: |
# Clone vcpkg
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg

# Bootstrap vcpkg
.\bootstrap-vcpkg.bat

# Install SDL2
.\vcpkg install sdl2:x64-windows

# Integrate with Visual Studio
.\vcpkg integrate install

cd ..

- name: Configure with vcpkg
run: |
cmake -B build -DCMAKE_TOOLCHAIN_FILE="$PWD/vcpkg/scripts/buildsystems/vcpkg.cmake" -DBUILD_ROBOT_TESTS=ON

- name: Build
run: cmake --build build --config Release

- name: Test
run: |
# Check and display directory structure
Write-Host "Checking directory structure..."

# Check vcpkg directories
Write-Host "Vcpkg directories:"
Get-ChildItem -Path "vcpkg\installed\x64-windows\bin" -ErrorAction SilentlyContinue

# Check build output directories
Write-Host "Build output directories:"
Get-ChildItem -Path "build\bin" -ErrorAction SilentlyContinue
Get-ChildItem -Path "build\bin\Release" -ErrorAction SilentlyContinue

# Find SDL2.dll
Write-Host "Finding SDL2.dll..."
Get-ChildItem -Path "vcpkg" -Recurse -Filter "SDL2.dll" -ErrorAction SilentlyContinue |
ForEach-Object { Write-Host $_.FullName }

# Create Release directory if it doesn't exist
if (-not (Test-Path "build\bin\Release")) {
Write-Host "Creating missing directory: build\bin\Release"
New-Item -Path "build\bin\Release" -ItemType Directory -Force
}

# Try to find the executable
Write-Host "Finding test executable..."
Get-ChildItem -Path "build" -Recurse -Filter "*.exe" -ErrorAction SilentlyContinue |
ForEach-Object { Write-Host $_.FullName }

# Try to run the executable wherever it is
$executable = Get-ChildItem -Path "build" -Recurse -Filter "RobotCPPSDLTest.exe" -ErrorAction SilentlyContinue |
Select-Object -First 1

if ($executable) {
Write-Host "Found executable at: $($executable.FullName)"

# Try to find and copy SDL2.dll
$sdl2Dll = Get-ChildItem -Path "vcpkg" -Recurse -Filter "SDL2.dll" -ErrorAction SilentlyContinue |
Select-Object -First 1

if ($sdl2Dll) {
Write-Host "Found SDL2.dll at: $($sdl2Dll.FullName)"
Copy-Item -Path $sdl2Dll.FullName -Destination $executable.DirectoryName -Force
}

# Run the executable
Write-Host "Running: $($executable.FullName) --gtest_filter=-*InteractiveMode --ci-mode true"
& $executable.FullName --gtest_filter=-*InteractiveMode --ci-mode true
} else {
Write-Host "Executable not found!"
exit 1
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
# Build files
/cmake-build-debug
/example/cmake-build-debug


/build
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
47 changes: 44 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,36 @@ cmake_minimum_required(VERSION 3.21)
project(RobotCPP)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Library name
set(LIB_NAME RobotCPP)

# Option to build tests (OFF by default)
option(BUILD_ROBOT_TESTS "Build the RobotCPP tests" OFF)

# Only find dependencies and add GoogleTest if tests are enabled
if(BUILD_ROBOT_TESTS)
# 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)
endif()

# Compiler-specific options
if(MSVC)
# MSVC flags
add_compile_options(/W4 /MP)
else()
# GCC/Clang flags
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Common source files
set(COMMON_SOURCES
src/ActionRecorder.h
src/types.h
Expand All @@ -17,19 +45,32 @@ set(COMMON_SOURCES
src/Screen.cpp
src/Screen.h)

# External dependencies
set(SOURCES_LODEPNG
externals/lodepng/lodepng.cpp
externals/lodepng/lodepng.h)

if (APPLE)
# Platform-specific components
if(APPLE)
list(APPEND PLATFORM_SOURCES src/EventHookMacOS.h)
find_library(CARBON_LIBRARY Carbon)
mark_as_advanced(CARBON_LIBRARY)
list(APPEND PLATFORM_LIBRARIES ${CARBON_LIBRARY})
elseif (WIN32)
elseif(WIN32)
list(APPEND PLATFORM_SOURCES src/EventHookWindows.h)
endif ()
endif()

# Define the main library
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 only if tests are enabled
if(BUILD_ROBOT_TESTS)
add_subdirectory(tests)
endif()
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Robot CPP

![master](https://github.com/developer239/robot-cpp/actions/workflows/ci.yml/badge.svg)
![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white)
![macOS](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0)
![Build](https://github.com/developer239/robot-cpp/actions/workflows/build.yml/badge.svg)
[![MacOS Tests](https://github.com/developer239/robot-cpp/actions/workflows/test-macos.yml/badge.svg)](https://github.com/developer239/robot-cpp/actions/workflows/test-macos.yml)
[![Windows Tests](https://github.com/developer239/robot-cpp/actions/workflows/test-windows.yml/badge.svg)](https://github.com/developer239/robot-cpp/actions/workflows/test-windows.yml)

This library is inspired by older unmaintained libraries like [octalmage/robotjs](https://github.com/octalmage/robotjs)
and [Robot/robot-js](https://github.com/Robot/robot-js). The goal is to provide cross-platform controls for various
Expand Down
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
45 changes: 45 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
set(SDL_TEST_NAME RobotCPPSDLTest)

# Find test dependencies
find_package(GTest QUIET)
if(NOT GTest_FOUND)
# GTest is already included via add_subdirectory in the main CMakeLists.txt
endif()

# Define test sources
set(SDL_TEST_SOURCES
sdl/SDLTestMain.cpp
sdl/MouseTests.cpp
sdl/TestElements.h
sdl/TestContext.h
sdl/TestConfig.h
sdl/RobotSDLTestFixture.h
)

# Create test executable
add_executable(${SDL_TEST_NAME} ${SDL_TEST_SOURCES})

# Link dependencies
target_link_libraries(${SDL_TEST_NAME} PRIVATE
RobotCPP
SDL2::SDL2
gtest
gtest_main
)

# Set output directory for test targets
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"
)

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

# Add automated tests
add_test(
NAME SDLFunctionalTests
COMMAND ${SDL_TEST_NAME} --run-tests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
Loading
Loading