ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
tests/common.h
Go to the documentation of this file.
1#pragma once
2
43
44/* Storage capacities in elements; text buffers include the terminating NUL. */
45#define TESTS_COMMON_VERSION_BUFFER_SIZE 256
46
47#include <stdint.h>
48#include <stdbool.h>
49
50// Standard C headers
51#include <stdio.h>
52#include <stdlib.h>
53#include <string.h>
54
55// System headers needed by tests
56#ifndef _WIN32
57#include <unistd.h> // For unlink(), access(), etc.
58#endif
59#include <sys/stat.h> // For stat(), struct stat
60
61// Now include Criterion which will pull in system headers
62#include <criterion/criterion.h>
63
64// Project headers - use relative paths from tests directory
65#include "../common.h"
66#include "../log/log.h"
67#include "../tests/logging.h"
68#include "test_env.h"
69
70// =============================================================================
71// Test Environment Detection
72// =============================================================================
73
104static inline bool test_is_in_headless_environment(void) {
105 // Check for CI environment
106 if (getenv("CI") != NULL) {
107 return true;
108 }
109
110 // Check for Docker
111 if (access("/.dockerenv", F_OK) == 0) {
112 return true;
113 }
114
115 // Check for WSL (look for "microsoft" or "WSL" in /proc/version)
116 FILE *version_file = fopen("/proc/version", "r");
117 if (version_file) {
118 char version_buf[TESTS_COMMON_VERSION_BUFFER_SIZE];
119 if (fgets(version_buf, sizeof(version_buf), version_file)) {
120 if (strstr(version_buf, "microsoft") || strstr(version_buf, "Microsoft") || strstr(version_buf, "WSL")) {
121 (void)fclose(version_file);
122 return true;
123 }
124 }
125 (void)fclose(version_file);
126 }
127
128 return false;
129}
130
131// =============================================================================
132// Test Binary Path Detection
133// =============================================================================
134
169const char *test_get_binary_path(void);
170
171// =============================================================================
172// Test Options Helpers (for RCU pattern)
173// =============================================================================
174
175#include "../options/rcu.h"
176
180static inline void test_set_test_pattern(bool value) {
181 options_set_bool("test_pattern", value);
182}
183
187static inline void test_set_flip_x(bool value) {
188 options_set_bool("flip_x", value);
189}
190
194static inline void test_set_flip_y(bool value) {
195 options_set_bool("flip_y", value);
196}
197
201static inline void test_set_width(unsigned short int value) {
202 options_set_int("width", (int)value);
203}
204
208static inline void test_set_height(unsigned short int value) {
209 options_set_int("height", (int)value);
210}
211
⚙️ Common definitions, error codes, macros, and types shared throughout the application
asciichat_error_t options_set_int(const char *name, int value)
Check if an option was explicitly set via command-line.
Definition rcu.c:894
asciichat_error_t options_set_bool(const char *name, bool value)
Definition rcu.c:902
const char * test_get_binary_path(void)
Get the path to the ascii-chat binary for integration tests.
#define TESTS_COMMON_VERSION_BUFFER_SIZE
📝 Logging API with multiple log levels and terminal output control
🔤 String Manipulation and Shell Escaping Utilities
Test environment detection utilities.