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
14 changes: 14 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ the build directory.

The project uses gtest as a test framework.

Sunshine tests must include `tests/tests_common.h` using the appropriate relative path, rather than including
`<gtest/gtest.h>` directly. The common header provides GoogleTest through the shared test support and makes
`TEST` use `BaseTest`, including its output capture and shared setup/teardown.

Group test headers first under `// test includes`, followed by `// standard includes`, `// lib includes`, and
`// local includes`, with a blank line between groups. Put shared test helpers in the test group, and omit empty
groups. Keep platform-specific headers and their group comments inside the appropriate preprocessor guards.
When a test depends on a particular include order, preserve that order and explain the dependency in a comment;
do not move the common header ahead of headers whose first-include behavior is being tested.

Add or update regression tests for new or modified source-code methods and behavior.
Target 100% coverage on changed source code.

Expand Down Expand Up @@ -70,6 +80,10 @@ plan in the issue. This limit applies only to creating issues; investigate or fi

## Code Review Rules

Check new and modified tests for the common-header and include-group conventions above. Request
`tests_common.h` instead of direct GoogleTest includes, and ensure shared test helpers are in the test include
group. Verify any documented include-order dependency before asking the author to reorder headers.

Report concrete issues introduced by the change that the contributor can address. For each finding, explain the
triggering condition, impact, and a practical fix; point to the relevant code or test. Keep workflow status separate
from code findings.
Expand Down
5 changes: 4 additions & 1 deletion tests/tests_common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* @file tests/tests_common.h
* @brief Common declarations.
* @brief Common GoogleTest support, BaseTest fixtures, and Sunshine test helpers.
*
* Include this header from Sunshine tests instead of including GoogleTest directly. The shared test support
* makes TEST use BaseTest so tests receive common setup, teardown, and output capture.
*/
#pragma once

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/platform/linux/test_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

#ifdef __linux__

// test includes
#include "../../../tests_common.h"

// standard includes
#include <chrono>
#include <vector>

// lib includes
#include <gtest/gtest.h>
#include <pulse/pulseaudio.h>

// local includes
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/platform/linux/test_dynamic_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/
#ifdef __linux__

// test includes
#include "../../../tests_common.h"

// standard includes
#include <bit>

// platform includes
#include <dlfcn.h>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/platform/linux/misc.h"

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/platform/linux/test_kms_plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#ifdef __linux__

// test includes
#include "../../../tests_common.h"

// standard includes
#include <chrono>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/platform/linux/kms_plane.h"

Expand Down
6 changes: 5 additions & 1 deletion tests/unit/platform/linux/test_kmsgrab_cursor_formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
* @file tests/unit/platform/linux/test_kmsgrab_cursor_formats.cpp
* @brief Test KMS cursor format conversion and validation.
*/
// test includes
#include "../../../tests_common.h"

// standard includes
#include <array>
#include <cstdint>
#include <gtest/gtest.h>

#ifdef SUNSHINE_BUILD_DRM
// lib includes
#include <drm_fourcc.h>

namespace platf::kms {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/platform/linux/test_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

#ifdef __linux__

// test includes
#include "../../../tests_common.h"

// standard includes
#include <array>
#include <cstdlib>
#include <optional>
#include <string>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/logging.h"
#include "src/platform/linux/misc.h"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/platform/linux/test_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @brief Test Wayland output mode selection.
*/
#ifdef SUNSHINE_BUILD_WAYLAND
// test includes
#include "../../../tests_common.h"

// standard includes
#include <array>
#include <cerrno>
Expand All @@ -25,9 +28,6 @@
#include <unistd.h>
#include <xf86drm.h>

// test includes
#include "../../../tests_common.h"

// local includes
#include <src/platform/linux/wayland.h>
#ifdef SUNSHINE_BUILD_CUDA
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/platform/windows/test_nvprefs_undo_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// standard includes
#include <type_traits>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/platform/windows/nvprefs/undo_data.h"
#include "src/platform/windows/nvprefs/undo_file.h"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_constructor_contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @brief Tests for explicit conversions, ownership transfers, and member initialization.
*/

// test includes
#include "../tests_common.h"

// standard includes
#include <array>
#include <functional>
Expand All @@ -12,9 +15,6 @@
#include <utility>
#include <vector>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/crypto.h"
#include "src/move_by_copy.h"
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* @brief Test src/crypto.*.
*/
// test includes
#include "../certificate_test_utils.h"
#include "../tests_common.h"

// lib includes
#include <openssl/x509.h>

// local includes
#include "../certificate_test_utils.h"

#include <src/crypto.h>

TEST(CryptoTest, GeneratedCredentialsExposeSubjectAndVerifySignatures) {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_nvenc_dynamic_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/
#ifdef _WIN32

// test includes
#include "../tests_common.h"

// standard includes
#include <array>
#include <bit>
Expand All @@ -12,9 +15,6 @@
#include <string_view>
#include <utility>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/nvenc/nvenc_dynamic_factory.h"

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_nvenc_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/

#ifdef _WIN32
// test includes
#include "../tests_common.h"

// standard includes
#include <array>
#include <bit>
Expand All @@ -13,9 +16,6 @@
#include <tuple>
#include <utility>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/nvenc/nvenc_base.h"
#include "src/nvenc/nvenc_d3d11.h"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_nvenc_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @brief Tests for runtime NVENC SDK version selection.
*/

// test includes
#include "../tests_common.h"

// standard includes
#include <array>
#include <cstdint>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/nvenc/nvenc_version.h"

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_nvhttp_client_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @brief Test exact paired-client certificate authorization and persistence.
*/

// test includes
#include "../certificate_test_utils.h"
#include "../tests_common.h"

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @brief Verify RTSP response handlers through their common dispatcher signature.
*/

// test includes
#include "../tests_common.h"

// standard includes
#include <array>
#include <string>
Expand All @@ -14,9 +17,6 @@ extern "C" {
#include <moonlight-common-c/src/Rtsp.h>
}

// test includes
#include "../tests_common.h"

// local includes
#include <src/rtsp.h>

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @brief Regression coverage for synchronized-value lock lifetimes.
*/

// test includes
#include "../tests_common.h"

// standard includes
#include <array>
#include <stdexcept>
#include <system_error>
#include <thread>

// lib includes
#include <gtest/gtest.h>

// local includes
#include <src/sync.h>

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_system_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

// test includes
#include "../tests_common.h"
#if defined(SUNSHINE_TRAY) && SUNSHINE_TRAY >= 1
#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32)
#include "third-party/tray/tests/notification_utils.h"
#include "third-party/tray/tests/screenshot_utils.h"
#endif
#endif

// standard includes
#include <atomic>
Expand All @@ -25,21 +31,15 @@
#if defined(_WIN32) || defined(__APPLE__)
#include <libvirtualhid/license.hpp>
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32)
#include <lizardbyte/common/env.h>
#endif

// local includes
#include <src/config.h>
#include <src/system_tray.h>
#include <src/thread_safe.h>

#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32)
// lib includes
#include <lizardbyte/common/env.h>

// test includes
#include "third-party/tray/tests/notification_utils.h"
#include "third-party/tray/tests/screenshot_utils.h"
#endif

namespace {
using namespace std::chrono_literals;

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_task_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* @brief Regression coverage for delayed task lookup over the complete queue.
*/

// lib includes
#include <gtest/gtest.h>
// test includes
#include "../tests_common.h"

// local includes
#include <src/task_pool.h>
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_thread_safe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @brief Tests for thread-safe utility types.
*/

// test includes
#include "../tests_common.h"

// standard includes
#include <cstdint>
#include <type_traits>

// lib includes
#include <gtest/gtest.h>

// local includes
#include "src/thread_safe.h"

Expand Down
Loading