Files
shadowsocks-libev/tests/test_helpers.h
Max Lv 201e70c4bd Modernize C builds with offline dependencies and portable runtime helpers (#3050)
Bundle pinned offline dependencies, remove libcork/libipset and submodule requirements, and add portable runtime helpers with relocatable static/shared library installations.

Add Clang static build validation for Linux/musl, macOS and Windows, real TCP/UDP and SIP003 interoperability coverage, and recorded performance tradeoffs. All 21 hosted checks pass at the reviewed PR head 8d504e6218.
2026-09-11 13:42:11 +08:00

39 lines
920 B
C

#ifndef SS_TEST_HELPERS_H
#define SS_TEST_HELPERS_H
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "platform.h"
static inline void test_network_cleanup(void)
{
#ifdef _WIN32
WSACleanup();
#endif
}
static inline void test_network_init(void)
{
#ifdef _WIN32
WSADATA data;
assert(WSAStartup(MAKEWORD(2, 2), &data) == 0);
assert(atexit(test_network_cleanup) == 0);
#endif
}
static inline FILE *test_tempfile(char *path, size_t size)
{
#ifdef _WIN32
char directory[MAX_PATH];
DWORD length = GetTempPathA(sizeof(directory), directory);
assert(length != 0 && length < sizeof(directory));
assert(size >= MAX_PATH);
assert(GetTempFileNameA(directory, "ssc", 0, path) != 0);
return fopen(path, "w");
#else
assert(snprintf(path, size, "/tmp/ss-test.XXXXXX") < (int)size);
int fd = mkstemp(path);
assert(fd >= 0);
return fdopen(fd, "w");
#endif
}
#endif