ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
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/logging.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
174// Updater functions for test helpers (must be at file scope)
175static void test_set_test_pattern_updater(options_t *opts, void *ctx) {
176 opts->test_pattern = *(bool *)ctx;
177}
178
179static void test_set_webcam_flip_updater(options_t *opts, void *ctx) {
180 opts->webcam_flip = *(bool *)ctx;
181}
182
183static void test_set_width_updater(options_t *opts, void *ctx) {
184 opts->width = *(unsigned short int *)ctx;
185}
186
187static void test_set_height_updater(options_t *opts, void *ctx) {
188 opts->height = *(unsigned short int *)ctx;
189}
190
194static inline void test_set_test_pattern(bool value) {
195 options_update(test_set_test_pattern_updater, &value);
196}
197
201static inline void test_set_webcam_flip(bool value) {
202 options_update(test_set_webcam_flip_updater, &value);
203}
204
208static inline void test_set_width(unsigned short int value) {
209 options_update(test_set_width_updater, &value);
210}
211
215static inline void test_set_height(unsigned short int value) {
216 options_update(test_set_height_updater, &value);
217}
218
asciichat_error_t options_update(void(*updater)(options_t *, void *), void *context)
Update options using copy-on-write (thread-safe)
Definition rcu.c:237
const char * test_get_binary_path(void)
Get the path to the ascii-chat binary for integration tests.
📝 Logging API with multiple log levels and terminal output control
Consolidated options structure.
Definition options.h:439
unsigned short int width
Terminal width in characters.
Definition options.h:454
unsigned short int height
Terminal height in characters.
Definition options.h:455
bool test_pattern
Use test pattern instead of webcam.
Definition options.h:501
bool webcam_flip
Flip webcam image horizontally.
Definition options.h:500
Test environment detection utilities.
Test logging control utilities.