ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
tests/common.h
Go to the documentation of this file.
1#pragma once
2
44#include <stdint.h>
45#include <stdbool.h>
46
47// Standard C headers
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51
52// System headers needed by tests
53#ifndef _WIN32
54#include <unistd.h> // For unlink(), access(), etc.
55#endif
56#include <sys/stat.h> // For stat(), struct stat
57
58// Now include Criterion which will pull in system headers
59#include <criterion/criterion.h>
60
61// Project headers - use relative paths from tests directory
62#include "../common.h"
63#include "../log/log.h"
64#include "../tests/logging.h"
65#include "test_env.h"
66
67// =============================================================================
68// Test Environment Detection
69// =============================================================================
70
101static inline bool test_is_in_headless_environment(void) {
102 // Check for CI environment
103 if (getenv("CI") != NULL) {
104 return true;
105 }
106
107 // Check for Docker
108 if (access("/.dockerenv", F_OK) == 0) {
109 return true;
110 }
111
112 // Check for WSL (look for "microsoft" or "WSL" in /proc/version)
113 FILE *version_file = fopen("/proc/version", "r");
114 if (version_file) {
115 char version_buf[256];
116 if (fgets(version_buf, sizeof(version_buf), version_file)) {
117 if (strstr(version_buf, "microsoft") || strstr(version_buf, "Microsoft") || strstr(version_buf, "WSL")) {
118 (void)fclose(version_file);
119 return true;
120 }
121 }
122 (void)fclose(version_file);
123 }
124
125 return false;
126}
127
128// =============================================================================
129// Test Binary Path Detection
130// =============================================================================
131
166const char *test_get_binary_path(void);
167
168// =============================================================================
169// Test Options Helpers (for RCU pattern)
170// =============================================================================
171
172#include "../options/rcu.h"
173
177static inline void test_set_test_pattern(bool value) {
178 options_set_bool("test_pattern", value);
179}
180
184static inline void test_set_flip_x(bool value) {
185 options_set_bool("flip_x", value);
186}
187
191static inline void test_set_flip_y(bool value) {
192 options_set_bool("flip_y", value);
193}
194
198static inline void test_set_width(unsigned short int value) {
199 options_set_int("width", (int)value);
200}
201
205static inline void test_set_height(unsigned short int value) {
206 options_set_int("height", (int)value);
207}
208
asciichat_error_t options_set_int(const char *field_name, int value)
Check if an option was explicitly set via command-line.
Definition rcu.c:761
asciichat_error_t options_set_bool(const char *field_name, bool value)
Definition rcu.c:969
const char * test_get_binary_path(void)
Get the path to the ascii-chat binary for integration tests.
ClangTool/LibTooling compatibility shim for stdbool.h.
Test environment detection utilities.