mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-21 14:33:55 +00:00
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.
This commit is contained in:
+31
-39
@@ -1,27 +1,24 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int verbose = 0;
|
||||
// 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"
|
||||
|
||||
static void
|
||||
test_init_free(void)
|
||||
extern "C" {
|
||||
int verbose = 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void test_init_free()
|
||||
{
|
||||
int ret = ppbloom_init(1000, 0.01);
|
||||
assert(ret == 0);
|
||||
(void)ret;
|
||||
SS_CHECK(ppbloom_init(1000, 0.01) == 0);
|
||||
ppbloom_free();
|
||||
}
|
||||
|
||||
static void
|
||||
test_add_check(void)
|
||||
void test_add_check()
|
||||
{
|
||||
ppbloom_init(1000, 0.01);
|
||||
|
||||
@@ -29,27 +26,22 @@ test_add_check(void)
|
||||
const char *item2 = "world";
|
||||
const char *item3 = "missing";
|
||||
|
||||
/* Not in filter initially */
|
||||
assert(ppbloom_check(item1, strlen(item1)) == 0);
|
||||
assert(ppbloom_check(item2, strlen(item2)) == 0);
|
||||
// Not in the filter initially.
|
||||
SS_CHECK(ppbloom_check(item1, std::strlen(item1)) == 0);
|
||||
SS_CHECK(ppbloom_check(item2, std::strlen(item2)) == 0);
|
||||
|
||||
/* Add items */
|
||||
ppbloom_add(item1, strlen(item1));
|
||||
ppbloom_add(item2, strlen(item2));
|
||||
ppbloom_add(item1, std::strlen(item1));
|
||||
ppbloom_add(item2, std::strlen(item2));
|
||||
|
||||
/* Should be found */
|
||||
assert(ppbloom_check(item1, strlen(item1)) == 1);
|
||||
assert(ppbloom_check(item2, strlen(item2)) == 1);
|
||||
SS_CHECK(ppbloom_check(item1, std::strlen(item1)) == 1);
|
||||
SS_CHECK(ppbloom_check(item2, std::strlen(item2)) == 1);
|
||||
|
||||
/* Should not be found */
|
||||
assert(ppbloom_check(item3, strlen(item3)) == 0);
|
||||
(void)item3;
|
||||
SS_CHECK(ppbloom_check(item3, std::strlen(item3)) == 0);
|
||||
|
||||
ppbloom_free();
|
||||
}
|
||||
|
||||
static void
|
||||
test_binary_data(void)
|
||||
void test_binary_data()
|
||||
{
|
||||
ppbloom_init(1000, 0.01);
|
||||
|
||||
@@ -57,18 +49,18 @@ test_binary_data(void)
|
||||
const uint8_t data2[] = { 0xFF, 0xFE, 0xFD, 0xFC };
|
||||
|
||||
ppbloom_add(data1, sizeof(data1));
|
||||
assert(ppbloom_check(data1, sizeof(data1)) == 1);
|
||||
assert(ppbloom_check(data2, sizeof(data2)) == 0);
|
||||
(void)data2;
|
||||
SS_CHECK(ppbloom_check(data1, sizeof(data1)) == 1);
|
||||
SS_CHECK(ppbloom_check(data2, sizeof(data2)) == 0);
|
||||
|
||||
ppbloom_free();
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
test_init_free();
|
||||
test_add_check();
|
||||
test_binary_data();
|
||||
SS_RUN(test_init_free);
|
||||
SS_RUN(test_add_check);
|
||||
SS_RUN(test_binary_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user