ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
tests/common.c
Go to the documentation of this file.
1
7#include <stdbool.h>
8#include <stdlib.h>
9
10#ifndef _WIN32
11#include <unistd.h>
12#endif
13
14#include "../common.h"
15
16const char *test_get_binary_path(void) {
17 static char binary_path[256];
18 static bool initialized = false;
19
20 if (initialized) {
21 return binary_path;
22 }
23
24#ifdef _WIN32
25 // Windows: try several paths
26 const char *candidates[] = {
27 "./build/bin/ascii-chat.exe",
28 "./bin/ascii-chat.exe",
29 "ascii-chat.exe",
30 };
31 const char *fallback = "./build/bin/ascii-chat.exe";
32#else
33 // Check if we're in Docker (/.dockerenv file exists)
34 bool in_docker = (access("/.dockerenv", F_OK) == 0);
35 const char *build_dir = getenv("BUILD_DIR");
36
37 // Try BUILD_DIR first if set
38 if (build_dir) {
39 safe_snprintf(binary_path, sizeof(binary_path), "./%s/bin/ascii-chat", build_dir);
40 if (access(binary_path, X_OK) == 0) {
41 initialized = true;
42 return binary_path;
43 }
44 }
45
46 // Try several paths in order of preference
47 const char *candidates[] = {
48 // Relative paths from repo root
49 in_docker ? "./build_docker/bin/ascii-chat" : "./build/bin/ascii-chat",
50 // Relative paths from build directory (when ctest runs from there)
51 "./bin/ascii-chat",
52 // Absolute paths for Docker
53 in_docker ? "/app/build_docker/bin/ascii-chat" : NULL,
54 };
55 const char *fallback = in_docker ? "./build_docker/bin/ascii-chat" : "./build/bin/ascii-chat";
56#endif
57
58 // Try each candidate path
59 for (size_t i = 0; i < sizeof(candidates) / sizeof(candidates[0]); i++) {
60 if (candidates[i] && access(candidates[i], X_OK) == 0) {
61 safe_snprintf(binary_path, sizeof(binary_path), "%s", candidates[i]);
62 initialized = true;
63 return binary_path;
64 }
65 }
66
67 // Fallback to default (will likely fail but gives useful error)
68 safe_snprintf(binary_path, sizeof(binary_path), "%s", fallback);
69 initialized = true;
70 return binary_path;
71}
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Safe version of snprintf that ensures null termination.
const char * test_get_binary_path(void)
Get the path to the ascii-chat binary for integration tests.
bool initialized
Definition mmap.c:36