rr_test_add_executable(
    robotraconteur_misc_tests
    SRC
    misc_tests.cpp
    DEPS
    robotraconteur_test_lfsr
    RobotRaconteurCore
    robotraconteur_test_cpp_common
    GTest::Main)

# Parses USB descriptors with the private USB transport parser, only compiled into the static core library on these
# platforms
if(NOT BUILD_SHARED_LIBS AND (WIN32 OR ("${CMAKE_SYSTEM}" MATCHES "Linux" AND NOT ANDROID)))
    rr_test_add_executable(robotraconteur_usb_descriptor_tests SRC usb_descriptor_tests.cpp DEPS RobotRaconteurCore
                           GTest::Main)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_sha1_leak_test
        SRC
        websocket_sha1_leak_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_sha1_leak_test
                               PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_sha1_leak_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_ping_test
        SRC
        websocket_ping_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_ping_test PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_ping_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_masked_empty_frame_test
        SRC
        websocket_masked_empty_frame_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_masked_empty_frame_test
                               PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_masked_empty_frame_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_handshake_trailing_data_test
        SRC
        websocket_handshake_trailing_data_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_handshake_trailing_data_test
                               PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_handshake_trailing_data_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_handler_nesting_test
        SRC
        websocket_handler_nesting_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_handler_nesting_test
                               PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_handler_nesting_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_client_short_write_test
        SRC
        websocket_client_short_write_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_client_short_write_test
                               PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_client_short_write_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_server_short_write_test
        SRC
        websocket_server_short_write_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_server_short_write_test
                               PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_server_short_write_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

if(NOT WIN32)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_websocket_header_end_test
        SRC
        websocket_header_end_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_websocket_header_end_test
                               PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
    target_compile_definitions(robotraconteur_websocket_header_end_test PRIVATE ROBOTRACONTEUR_USE_OPENSSL)
endif()

rr_test_add_executable(robotraconteur_tcp_accept_timeout_test SRC tcp_accept_timeout_test.cpp DEPS RobotRaconteurCore
                       GTest::Main)

rr_test_add_executable(robotraconteur_wall_timer_clock_offset_test SRC wall_timer_clock_offset_test.cpp DEPS
                       RobotRaconteurCore GTest::Main)
rr_test_add_executable(robotraconteur_rrarray_empty_test SRC rrarray_empty_test.cpp DEPS RobotRaconteurCore GTest::Main)

rr_test_add_executable(robotraconteur_pod_field_array_at_test SRC pod_field_array_at_test.cpp DEPS RobotRaconteurCore
                       GTest::Main)

rr_test_add_executable(robotraconteur_high_resolution_sleep_negative_test SRC high_resolution_sleep_negative_test.cpp
                       DEPS RobotRaconteurCore GTest::Main)

# Deletes the shared /tmp fallback user run dir, so it must not run alongside other tests
rr_test_add_executable(
    robotraconteur_tmp_user_run_dir_test
    SRC
    tmp_user_run_dir_test.cpp
    DEPS
    RobotRaconteurCore
    GTest::Main
    PROPERTIES
    RUN_SERIAL
    TRUE)

rr_test_add_executable(robotraconteur_tcp_erase_loser_test SRC tcp_erase_loser_test.cpp DEPS RobotRaconteurCore
                       GTest::Main)

# Waits past the 60 s discovery cache expiry
rr_test_add_executable(robotraconteur_intra_discovery_refresh_test SRC intra_discovery_refresh_test.cpp DEPS
                       RobotRaconteurCore GTest::Main)

# Uses the IPv4 loopback broadcast address, which reaches every socket bound to the discovery port only on Linux
if("${CMAKE_SYSTEM}" MATCHES "Linux" AND NOT ANDROID)
    rr_test_add_executable(robotraconteur_discovery_announce_only_test SRC discovery_announce_only_test.cpp DEPS
                           RobotRaconteurCore GTest::Main)
endif()

# Uses RLIMIT_NOFILE to make accept() fail
if("${CMAKE_SYSTEM}" MATCHES "Linux" AND NOT ANDROID)
    rr_test_add_executable(robotraconteur_tap_accept_error_test SRC tap_accept_error_test.cpp DEPS RobotRaconteurCore
                           GTest::Main)
endif()

# Uses the private OpenSSL TLS context class, only compiled into the core library with OpenSSL
if(NOT BUILD_SHARED_LIBS AND "${CMAKE_SYSTEM}" MATCHES "Linux" AND NOT ANDROID)
    find_package(OpenSSL REQUIRED)
    rr_test_add_executable(
        robotraconteur_tls_cert_load_test
        SRC
        tls_cert_load_test.cpp
        DEPS
        RobotRaconteurCore
        OpenSSL::SSL
        OpenSSL::Crypto
        GTest::Main)
    target_include_directories(robotraconteur_tls_cert_load_test PRIVATE ${CMAKE_SOURCE_DIR}/RobotRaconteurCore/src)
endif()

rr_test_add_executable(robotraconteur_stream_empty_message_test SRC stream_empty_message_test.cpp DEPS
                       RobotRaconteurCore GTest::Main)

rr_test_add_executable(robotraconteur_tcp_accept_filter_test SRC tcp_accept_filter_test.cpp DEPS RobotRaconteurCore
                       GTest::Main)
