Files
shadowsocks-libev/tests/test_utils.c
T
Max LvandClaude Opus 4.6 1c404eccf4 Modernize build: switch to CMake, add unit tests, fix man pages
Remove autotools (configure.ac, Makefile.am, m4/, autogen.sh) and make
CMake the sole build system. Enhance CMake with proper Find modules for
MbedTLS, libsodium, PCRE, and c-ares with version/feature detection.
Add support for connmarktos, nftables, stack protector, and MinGW.

Add 10 unit test suites (CTest) covering base64, buffer, cache, crypto,
jconf, json, netutils, ppbloom, rule, and utils modules. Add a Python
stress test measuring bandwidth per cipher with memory leak detection.

Fix man page typos ("Resovle" -> "Resolve"), document missing TCP buffer
options, fix ss-manager duplicate --executable entry, add example section
to ss-tunnel, and document --workdir and --nftables-sets options.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 16:40:27 +08:00

77 lines
1.3 KiB
C

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <string.h>
#include <stdlib.h>
int verbose = 0;
#include "utils.h"
static void
test_ss_itoa(void)
{
char *s;
s = ss_itoa(0);
assert(s != NULL);
assert(strcmp(s, "0") == 0);
s = ss_itoa(42);
assert(s != NULL);
assert(strcmp(s, "42") == 0);
s = ss_itoa(-1);
assert(s != NULL);
assert(strcmp(s, "-1") == 0);
s = ss_itoa(12345);
assert(s != NULL);
assert(strcmp(s, "12345") == 0);
(void)s;
}
static void
test_ss_isnumeric(void)
{
assert(ss_isnumeric("12345") == 1);
assert(ss_isnumeric("0") == 1);
assert(ss_isnumeric("") == 0);
assert(ss_isnumeric("abc") == 0);
assert(ss_isnumeric("123abc") == 0);
assert(ss_isnumeric("12.34") == 0);
}
static void
test_ss_strndup(void)
{
char *s;
s = ss_strndup("hello world", 5);
assert(s != NULL);
assert(strcmp(s, "hello") == 0);
assert(strlen(s) == 5);
free(s);
s = ss_strndup("short", 10);
assert(s != NULL);
assert(strcmp(s, "short") == 0);
free(s);
s = ss_strndup("", 0);
assert(s != NULL);
assert(strcmp(s, "") == 0);
free(s);
}
int
main(void)
{
test_ss_itoa();
test_ss_isnumeric();
test_ss_strndup();
return 0;
}