mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-11-02 16:03:45 +00:00
C++20 port 16/16: config parsing on arenas, unit tests in C++ (#3080)
* Rename test_jconf.c to test_jconf_cpp.cpp * Parse the config file on arenas read_jconf now reads the file and builds the JSON tree in a scratch arena that is released before it returns, and copies the parsed strings into one process-lifetime arena instead of a malloc per string. parse_addr and the config parser share one address splitter. Port test_jconf to C++ and cover every field copied out of the parse tree, a re-read, and the densest file the size limit accepts. * tests: rename remaining C unit tests to .cpp (no content changes) * tests: port remaining C unit tests to the C++ test harness Convert acl, acl_literal, aead2022, base64, buffer, cache (legacy reference), crypto, ipset, ipset_reference, json, netutils, ppbloom, process, ref, ssurl and utils tests to test_helpers.hpp. ctest names are unchanged; every assertion is kept. Build the ported sources with the strict C++ warning set. * Run clang-tidy on every ported test The test regex skipped file names with digits (test_aead2022_cpp.cpp, test_base64_cpp.cpp); include them, fix the two optional accesses it then reports, and build test_jconf with the strict warning set. * docs: per-connection RSS on Linux against the C relay * test_jconf: check read_jconf results before using them
This commit is contained in:
@@ -1,103 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int verbose = 0;
|
||||
|
||||
#include "crypto.h"
|
||||
|
||||
/* Provide nonce_cache symbol needed by crypto.cpp */
|
||||
struct cache *nonce_cache = NULL;
|
||||
|
||||
static void
|
||||
test_balloc(void)
|
||||
{
|
||||
buffer_t buf;
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
|
||||
int ret = balloc(&buf, 100);
|
||||
assert(ret == 100);
|
||||
(void)ret;
|
||||
assert(buf.data != NULL);
|
||||
assert(buf.capacity >= 100);
|
||||
assert(buf.len == 0);
|
||||
assert(buf.idx == 0);
|
||||
|
||||
bfree(&buf);
|
||||
assert(buf.data == NULL);
|
||||
assert(buf.capacity == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_brealloc(void)
|
||||
{
|
||||
buffer_t buf;
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
|
||||
balloc(&buf, 50);
|
||||
buf.len = 10;
|
||||
|
||||
/* Grow the buffer */
|
||||
int ret = brealloc(&buf, 10, 200);
|
||||
assert(ret == 200);
|
||||
(void)ret;
|
||||
assert(buf.capacity >= 200);
|
||||
assert(buf.len == 10);
|
||||
|
||||
bfree(&buf);
|
||||
}
|
||||
|
||||
static void
|
||||
test_bprepend(void)
|
||||
{
|
||||
buffer_t dst, src;
|
||||
memset(&dst, 0, sizeof(dst));
|
||||
memset(&src, 0, sizeof(src));
|
||||
|
||||
balloc(&dst, 100);
|
||||
balloc(&src, 100);
|
||||
|
||||
/* Put some data in src */
|
||||
memcpy(src.data, "HEADER", 6);
|
||||
src.len = 6;
|
||||
|
||||
/* Put some data in dst */
|
||||
memcpy(dst.data, "BODY", 4);
|
||||
dst.len = 4;
|
||||
|
||||
int ret = bprepend(&dst, &src, 200);
|
||||
assert(ret == 10);
|
||||
(void)ret;
|
||||
assert(dst.len == 10);
|
||||
assert(memcmp(dst.data, "HEADERBODY", 10) == 0);
|
||||
|
||||
bfree(&dst);
|
||||
bfree(&src);
|
||||
}
|
||||
|
||||
static void
|
||||
test_balloc_zero(void)
|
||||
{
|
||||
buffer_t buf;
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
|
||||
int ret = balloc(&buf, 0);
|
||||
assert(ret == 0);
|
||||
(void)ret;
|
||||
/* A zero-capacity buffer should still succeed */
|
||||
bfree(&buf);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
test_balloc();
|
||||
test_brealloc();
|
||||
test_bprepend();
|
||||
test_balloc_zero();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user