mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-20 21:43:41 +00:00
* 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
67 lines
1.4 KiB
C++
67 lines
1.4 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Ping-pong bloom filter (src/ppbloom.cpp): add and membership checks.
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
|
|
#include "ppbloom.h"
|
|
#include "test_helpers.hpp"
|
|
|
|
extern "C" {
|
|
int verbose = 0;
|
|
}
|
|
|
|
namespace {
|
|
|
|
void test_init_free()
|
|
{
|
|
SS_CHECK(ppbloom_init(1000, 0.01) == 0);
|
|
ppbloom_free();
|
|
}
|
|
|
|
void test_add_check()
|
|
{
|
|
ppbloom_init(1000, 0.01);
|
|
|
|
const char *item1 = "hello";
|
|
const char *item2 = "world";
|
|
const char *item3 = "missing";
|
|
|
|
// Not in the filter initially.
|
|
SS_CHECK(ppbloom_check(item1, std::strlen(item1)) == 0);
|
|
SS_CHECK(ppbloom_check(item2, std::strlen(item2)) == 0);
|
|
|
|
ppbloom_add(item1, std::strlen(item1));
|
|
ppbloom_add(item2, std::strlen(item2));
|
|
|
|
SS_CHECK(ppbloom_check(item1, std::strlen(item1)) == 1);
|
|
SS_CHECK(ppbloom_check(item2, std::strlen(item2)) == 1);
|
|
|
|
SS_CHECK(ppbloom_check(item3, std::strlen(item3)) == 0);
|
|
|
|
ppbloom_free();
|
|
}
|
|
|
|
void test_binary_data()
|
|
{
|
|
ppbloom_init(1000, 0.01);
|
|
|
|
const uint8_t data1[] = { 0x00, 0x01, 0x02, 0x03 };
|
|
const uint8_t data2[] = { 0xFF, 0xFE, 0xFD, 0xFC };
|
|
|
|
ppbloom_add(data1, sizeof(data1));
|
|
SS_CHECK(ppbloom_check(data1, sizeof(data1)) == 1);
|
|
SS_CHECK(ppbloom_check(data2, sizeof(data2)) == 0);
|
|
|
|
ppbloom_free();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main()
|
|
{
|
|
SS_RUN(test_init_free);
|
|
SS_RUN(test_add_check);
|
|
SS_RUN(test_binary_data);
|
|
return 0;
|
|
}
|