1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2026-05-01 00:07:19 +02:00

Update libraries and make it build on windows.

Still gets some warnings because compilers have changed. But should work.
This commit is contained in:
Sandu Liviu Catalin
2025-06-25 22:34:23 +03:00
parent 520a5eacc5
commit f2b7499f85
3038 changed files with 251668 additions and 273857 deletions
+15 -1
View File
@@ -29,10 +29,18 @@ if(UNIX) # or if (NOT WIN32)
find_package(Threads)
endif()
if(WIN32)
# 4244, 4267 - libtap causes a significant number of conversion warning in
# our tests on Windows.
# 4996 - vsprintf used by libtap is unsafe.
add_definitions("/wd4244 /wd4267 /wd4996")
endif(WIN32)
foreach(TEST_TARGET_NAME ${TEST_TARGET_NAMES})
add_executable(${TEST_TARGET_NAME} ${TEST_TARGET_NAME}.c maxminddb_test_helper.c)
target_include_directories(${TEST_TARGET_NAME} PRIVATE ../src)
target_link_libraries(${TEST_TARGET_NAME} maxminddb tap)
target_compile_definitions(${TEST_TARGET_NAME} PRIVATE PACKAGE_VERSION="${PROJECT_VERSION}")
if(UNIX)
target_link_libraries(${TEST_TARGET_NAME} m)
@@ -42,5 +50,11 @@ foreach(TEST_TARGET_NAME ${TEST_TARGET_NAMES})
target_link_libraries(${TEST_TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
endif()
add_test(${TEST_TARGET_NAME} ${TEST_TARGET_NAME})
add_test( NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/t)
endforeach()
if(BUILD_FUZZING)
add_executable(fuzz_mmdb fuzz_mmdb.c)
target_include_directories(fuzz_mmdb PRIVATE ../src)
target_link_libraries(fuzz_mmdb maxminddb $ENV{LIB_FUZZING_ENGINE})
endif()
+6 -4
View File
@@ -2,9 +2,9 @@
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-broken-pointers-24.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
{
const char *ip = "1.1.1.16";
@@ -29,6 +29,9 @@ void run_tests(int mode, const char *mode_desc) {
"MMDB_get_entry_data_list returns MMDB_INVALID_DATA_ERROR for "
"bad pointer in data section");
// This is not necessary as on error we should not need to free
// anything. However test that it is safe to do so. See change in
// 1.12.2.
MMDB_free_entry_data_list(entry_data_list);
}
@@ -36,8 +39,7 @@ void run_tests(int mode, const char *mode_desc) {
const char *ip = "1.1.1.32";
int gai_error, mmdb_error;
MMDB_lookup_result_s UNUSED(result) =
MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
cmp_ok(mmdb_error,
"==",
+5 -5
View File
@@ -36,7 +36,7 @@ void test_one_result(MMDB_s *mmdb,
} else {
// When looking up IPv4 addresses in a mixed DB the result will be
// something like "::1.2.3.4", not just "1.2.3.4".
int maxlen = strlen(expect) + 3;
size_t maxlen = strlen(expect) + 3;
real_expect = malloc(maxlen);
if (!real_expect) {
BAIL_OUT("could not allocate memory");
@@ -77,12 +77,12 @@ void run_ipX_tests(const char *filename,
int missing_ips_length,
const char *pairs[][2],
int pairs_rows) {
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
int mode = Current_Mode;
const char *mode_desc = Current_Mode_Description;
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
char desc_suffix[500];
snprintf(desc_suffix, 500, "%s - %s", filename, mode_desc);
@@ -180,12 +180,12 @@ void all_record_sizes(int mode, const char *description) {
static void test_big_lookup(void) {
const char *const db_filename = "GeoIP2-Precision-Enterprise-Test.mmdb";
const char *const db_path = test_database_path(db_filename);
char *db_path = test_database_path(db_filename);
ok(db_path != NULL, "got database path");
MMDB_s *const mmdb = open_ok(db_path, MMDB_MODE_MMAP, "mmap mode");
ok(mmdb != NULL, "opened MMDB");
free((char *)db_path);
free(db_path);
int gai_err = 0, mmdb_err = 0;
const char *const ip_address = "81.2.69.160";
+15 -2
View File
@@ -28,7 +28,11 @@ int main(int argc, char *argv[])
{
const char *fname = "$test_db";
MMDB_s mmdb;
return MMDB_open(fname, MMDB_MODE_MMAP, &mmdb);
if (MMDB_open(fname, MMDB_MODE_MMAP, &mmdb) != MMDB_SUCCESS) {
return 1;
}
MMDB_close(&mmdb);
return 0;
}
EOF
@@ -45,8 +49,17 @@ my $include_dir = abs_path("$Bin/../include");
my $lib_dir = abs_path("$Bin/../src/.libs");
my $cxx = $ENV{CXX} || 'c++';
my @cxxflags = $ENV{CXXFLAGS} ? ( split ' ', $ENV{CXXFLAGS} ) : ();
_test_cmd(
[ $cxx, $file, "-I$include_dir", "-L$lib_dir", "-lmaxminddb", "-o$exe" ],
[
$cxx,
$file,
@cxxflags,
"-I$include_dir",
"-L$lib_dir",
"-lmaxminddb",
"-o$exe",
],
qr/^$/,
q{},
0,
+3 -1
View File
@@ -43,7 +43,9 @@ static void test_data_pool_new(void) {
}
static void test_data_pool_destroy(void) {
{ data_pool_destroy(NULL); }
{
data_pool_destroy(NULL);
}
{
MMDB_data_pool_s *const pool = data_pool_new(512);
+18 -19
View File
@@ -161,7 +161,7 @@ test_mapX_key_value_pair(MMDB_entry_data_list_s *entry_data_list) {
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"found a map key in 'map{mapX}'");
const char *mapX_key_name = dup_entry_string_or_bail(mapX_key->entry_data);
char *mapX_key_name = dup_entry_string_or_bail(mapX_key->entry_data);
if (strcmp(mapX_key_name, "utf8_stringX") == 0) {
MMDB_entry_data_list_s *mapX_value = entry_data_list =
@@ -170,18 +170,18 @@ test_mapX_key_value_pair(MMDB_entry_data_list_s *entry_data_list) {
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"'map{mapX}{utf8_stringX}' type is utf8_string");
const char *utf8_stringX_value =
char *utf8_stringX_value =
dup_entry_string_or_bail(mapX_value->entry_data);
ok(strcmp(utf8_stringX_value, "hello") == 0,
"map{mapX}{utf8_stringX} value is 'hello'");
free((void *)utf8_stringX_value);
free(utf8_stringX_value);
} else if (strcmp(mapX_key_name, "arrayX") == 0) {
entry_data_list = test_arrayX_value(entry_data_list);
} else {
ok(0, "unknown key found in map{mapX} - %s", mapX_key_name);
}
free((void *)mapX_key_name);
free(mapX_key_name);
return entry_data_list;
}
@@ -203,10 +203,9 @@ test_map_value(MMDB_entry_data_list_s *entry_data_list) {
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"found a map key in 'map'");
const char *map_key_1_name =
dup_entry_string_or_bail(map_key_1->entry_data);
char *map_key_1_name = dup_entry_string_or_bail(map_key_1->entry_data);
ok(strcmp(map_key_1_name, "mapX") == 0, "key name is mapX");
free((void *)map_key_1_name);
free(map_key_1_name);
MMDB_entry_data_list_s *mapX = entry_data_list = entry_data_list->next;
cmp_ok(mapX->entry_data.type,
@@ -312,7 +311,7 @@ test_utf8_string_value(MMDB_entry_data_list_s *entry_data_list) {
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"'utf8_string' key's value is a string");
const char *utf8_string = dup_entry_string_or_bail(value->entry_data);
char *utf8_string = dup_entry_string_or_bail(value->entry_data);
// This is hex for "unicode! ☯ - ♫" as bytes
char expect[19] = {0x75,
0x6e,
@@ -323,29 +322,29 @@ test_utf8_string_value(MMDB_entry_data_list_s *entry_data_list) {
0x65,
0x21,
0x20,
0xe2,
0x98,
0xaf,
(char)0xe2,
(char)0x98,
(char)0xaf,
0x20,
0x2d,
0x20,
0xe2,
0x99,
0xab,
(char)0xe2,
(char)0x99,
(char)0xab,
0x00};
is(utf8_string, expect, "got expected value for utf8_string key");
free((void *)utf8_string);
free(utf8_string);
return entry_data_list;
}
void run_tests(int mode, const char *description) {
const char *filename = "MaxMind-DB-test-decoder.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, description);
free((void *)path);
free(path);
char *ip = "1.1.1.1";
MMDB_lookup_result_s result =
@@ -385,7 +384,7 @@ void run_tests(int mode, const char *description) {
MMDB_DATA_TYPE_UTF8_STRING,
"found a map key");
const char *key_name = dup_entry_string_or_bail(key->entry_data);
char *key_name = dup_entry_string_or_bail(key->entry_data);
if (strcmp(key_name, "array") == 0) {
entry_data_list = test_array_value(entry_data_list);
} else if (strcmp(key_name, "boolean") == 0) {
@@ -414,7 +413,7 @@ void run_tests(int mode, const char *description) {
ok(0, "unknown key found in map - %s", key_name);
}
free((void *)key_name);
free(key_name);
}
MMDB_free_entry_data_list(first);
+13 -13
View File
@@ -14,7 +14,7 @@ void test_all_data_types(MMDB_lookup_result_s *result,
description,
"utf8_string",
NULL);
const char *string = mmdb_strndup(data.utf8_string, data.data_size);
char *string = mmdb_strndup(data.utf8_string, data.data_size);
// This is hex for "unicode! ☯ - ♫" as bytes
char expect[19] = {0x75,
0x6e,
@@ -25,19 +25,19 @@ void test_all_data_types(MMDB_lookup_result_s *result,
0x65,
0x21,
0x20,
0xe2,
0x98,
0xaf,
(char)0xe2,
(char)0x98,
(char)0xaf,
0x20,
0x2d,
0x20,
0xe2,
0x99,
0xab,
(char)0xe2,
(char)0x99,
(char)0xab,
0x00};
is(string, expect, "got expected utf8_string value");
free((char *)string);
free(string);
}
{
@@ -67,7 +67,7 @@ void test_all_data_types(MMDB_lookup_result_s *result,
MMDB_entry_data_s data =
data_ok(result, MMDB_DATA_TYPE_BYTES, description, "bytes", NULL);
uint8_t expect[] = {0x00, 0x00, 0x00, 0x2a};
ok(memcmp((uint8_t *)data.bytes, expect, 4) == 0,
ok(memcmp(data.bytes, expect, 4) == 0,
"bytes field has expected value");
}
@@ -204,9 +204,9 @@ void test_all_data_types(MMDB_lookup_result_s *result,
"mapX",
"utf8_stringX",
NULL);
const char *string = mmdb_strndup(data.utf8_string, data.data_size);
char *string = mmdb_strndup(data.utf8_string, data.data_size);
is(string, "hello", "map{mapX}{utf8_stringX} is 'hello'");
free((char *)string);
free(string);
snprintf(
description, 500, "map{mapX}{arrayX} for %s - %s", ip, mode_desc);
@@ -417,7 +417,7 @@ void test_all_data_types_as_zero(MMDB_lookup_result_s *result,
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-decoder.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
// All of the remaining tests require an open mmdb
@@ -426,7 +426,7 @@ void run_tests(int mode, const char *mode_desc) {
return;
}
free((void *)path);
free(path);
{
const char *ip = "not an ip";
+3 -2
View File
@@ -1,12 +1,13 @@
#define _XOPEN_SOURCE 700
#include "maxminddb_test_helper.h"
#ifdef HAVE_OPEN_MEMSTREAM
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-decoder.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const char *ip = "1.1.1.1";
MMDB_lookup_result_s result =
+8
View File
@@ -5,12 +5,20 @@ use warnings;
use FindBin qw( $Bin );
_skip_tests_if_not_linux();
_skip_tests_if_required_modules_are_not_present();
_skip_tests_if_nm_is_not_present();
_test_libs_external_symbols();
done_testing();
sub _skip_tests_if_not_linux {
return if $^O eq 'linux';
print "1..0 # skip all tests skipped - this test requires Linux.\n";
exit 0;
}
sub _skip_tests_if_required_modules_are_not_present {
eval <<'EOF';
use Test::More 0.88;
+34
View File
@@ -0,0 +1,34 @@
#include "maxminddb-compat-util.h"
#include "maxminddb.h"
#include <unistd.h>
#define kMinInputLength 2
#define kMaxInputLength 4048
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int status;
FILE *fp;
MMDB_s mmdb;
char filename[256];
if (size < kMinInputLength || size > kMaxInputLength)
return 0;
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
fp = fopen(filename, "wb");
if (!fp)
return 0;
fwrite(data, size, sizeof(uint8_t), fp);
fclose(fp);
status = MMDB_open(filename, MMDB_MODE_MMAP, &mmdb);
if (status == MMDB_SUCCESS)
MMDB_close(&mmdb);
unlink(filename);
return 0;
}
+2 -2
View File
@@ -47,9 +47,9 @@ void test_one_ip(MMDB_s *mmdb,
void run_tests(int mode, const char *mode_desc) {
const char *filename = "GeoIP2-City-Test.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
/* This exercises a bug where the entire top-level value is a pointer to
* another part of the data section. */
+4 -4
View File
@@ -77,9 +77,9 @@ int call_vget_value(MMDB_entry_s *entry, MMDB_entry_data_s *entry_data, ...) {
void test_simple_structure(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-decoder.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const char *ip = "1.1.1.1";
MMDB_lookup_result_s result =
@@ -242,9 +242,9 @@ void test_no_result(int status,
void test_nested_structure(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-nested.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const char *ip = "1.1.1.1";
MMDB_lookup_result_s result =
+2 -2
View File
@@ -18,9 +18,9 @@ void test_one_ip(MMDB_s *mmdb,
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-no-ipv4-search-tree.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
test_one_ip(mmdb, "1.1.1.1", filename, mode_desc);
test_one_ip(mmdb, "255.255.255.255", filename, mode_desc);
+3 -4
View File
@@ -2,14 +2,13 @@
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-ipv4-28.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const char *ip = "::abcd";
int gai_error, mmdb_error;
MMDB_lookup_result_s UNUSED(result) =
MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
cmp_ok(mmdb_error,
"==",
+23 -11
View File
@@ -1,14 +1,14 @@
#include "maxminddb_test_helper.h"
#if HAVE_CONFIG_H
#include <config.h>
#endif
#define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <stdarg.h>
#include <sys/types.h>
#include "maxminddb.h"
#include "maxminddb_test_helper.h"
#ifdef _WIN32
#include <io.h>
@@ -26,7 +26,15 @@ void for_all_record_sizes(const char *filename_fmt,
int size = sizes[i];
char filename[500];
#if defined(__clang__)
// This warning seems ok to ignore here in the tests.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
snprintf(filename, 500, filename_fmt, size);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
char description[14];
snprintf(description, 14, "%i bit record", size);
@@ -39,7 +47,7 @@ void for_all_modes(void (*tests)(int mode, const char *description)) {
tests(MMDB_MODE_MMAP, "mmap mode");
}
const char *test_database_path(const char *filename) {
char *test_database_path(const char *filename) {
char *test_db_dir;
#ifdef _WIN32
test_db_dir = "../t/maxmind-db/test-data";
@@ -59,12 +67,11 @@ const char *test_database_path(const char *filename) {
snprintf(path, 500, "%s/%s", test_db_dir, filename);
return (const char *)path;
return path;
}
const char *dup_entry_string_or_bail(MMDB_entry_data_s entry_data) {
const char *string =
mmdb_strndup(entry_data.utf8_string, entry_data.data_size);
char *dup_entry_string_or_bail(MMDB_entry_data_s entry_data) {
char *string = mmdb_strndup(entry_data.utf8_string, entry_data.data_size);
if (NULL == string) {
BAIL_OUT("mmdb_strndup failed");
}
@@ -73,7 +80,12 @@ const char *dup_entry_string_or_bail(MMDB_entry_data_s entry_data) {
}
MMDB_s *open_ok(const char *db_file, int mode, const char *mode_desc) {
if (0 != access(db_file, R_OK)) {
#ifdef _WIN32
int access_rv = _access(db_file, 04);
#else
int access_rv = access(db_file, R_OK);
#endif
if (access_rv != 0) {
BAIL_OUT("could not read the specified file - %s\nIf you are in a git "
"checkout try running 'git submodule update --init'",
db_file);
@@ -85,7 +97,7 @@ MMDB_s *open_ok(const char *db_file, int mode, const char *mode_desc) {
BAIL_OUT("could not allocate memory for our MMDB_s struct");
}
int status = MMDB_open(db_file, mode, mmdb);
int status = MMDB_open(db_file, (uint32_t)mode, mmdb);
int is_ok = ok(MMDB_SUCCESS == status,
"open %s status is success - %s",
@@ -211,9 +223,9 @@ MMDB_entry_data_s data_ok(MMDB_lookup_result_s *result,
"no error from call to MMDB_vget_value - %s",
description)) {
if (!cmp_ok(data.type,
if (!cmp_ok((int)data.type,
"==",
expect_type,
(int)expect_type,
"got the expected data type - %s",
description)) {
+8 -6
View File
@@ -1,6 +1,8 @@
/* Some test files may require something newer */
#if !defined(_GNU_SOURCE) && !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200112L
// The spec says this should be set prior to including any headers, but since
// this is test code, it should be fine to set it here. Setting it here avoids
// setting it in every test program.
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
#if HAVE_CONFIG_H
@@ -23,7 +25,7 @@
#include <netdb.h>
#endif
#if (_MSC_VER && _MSC_VER < 1900)
#if defined _MSC_VER && _MSC_VER < 1900
/* _snprintf has security issues, but I don't think it is worth
worrying about for the unit tests. */
#define snprintf _snprintf
@@ -45,8 +47,8 @@ extern void for_all_record_sizes(const char *filename_fmt,
const char *filename,
const char *description));
extern void for_all_modes(void (*tests)(int mode, const char *description));
extern const char *test_database_path(const char *filename);
extern const char *dup_entry_string_or_bail(MMDB_entry_data_s entry_data);
extern char *test_database_path(const char *filename);
extern char *dup_entry_string_or_bail(MMDB_entry_data_s entry_data);
extern MMDB_s *open_ok(const char *db_file, int mode, const char *mode_desc);
extern MMDB_lookup_result_s lookup_string_ok(MMDB_s *mmdb,
const char *ip,
+2 -2
View File
@@ -2,9 +2,9 @@
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-metadata-pointers.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
char *repeated_string = "Lots of pointers in metadata";
+17 -17
View File
@@ -3,8 +3,8 @@
void test_metadata(MMDB_s *mmdb, const char *mode_desc) {
cmp_ok(mmdb->metadata.node_count,
"==",
37,
"node_count is 37 - %s",
163,
"node_count is 163 - %s",
mode_desc);
cmp_ok(mmdb->metadata.record_size,
"==",
@@ -101,18 +101,18 @@ test_languages_value(MMDB_entry_data_list_s *entry_data_list) {
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"first array entry is a UTF8_STRING");
const char *lang0 = dup_entry_string_or_bail(idx0->entry_data);
char *lang0 = dup_entry_string_or_bail(idx0->entry_data);
is(lang0, "en", "first language is en");
free((void *)lang0);
free(lang0);
MMDB_entry_data_list_s *idx1 = entry_data_list = entry_data_list->next;
cmp_ok(idx1->entry_data.type,
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"second array entry is a UTF8_STRING");
const char *lang1 = dup_entry_string_or_bail(idx1->entry_data);
char *lang1 = dup_entry_string_or_bail(idx1->entry_data);
is(lang1, "zh", "second language is zh");
free((void *)lang1);
free(lang1);
return entry_data_list;
}
@@ -136,14 +136,14 @@ test_description_value(MMDB_entry_data_list_s *entry_data_list) {
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"found a map key in 'map'");
const char *key_name = dup_entry_string_or_bail(key->entry_data);
char *key_name = dup_entry_string_or_bail(key->entry_data);
MMDB_entry_data_list_s *value = entry_data_list = entry_data_list->next;
cmp_ok(value->entry_data.type,
"==",
MMDB_DATA_TYPE_UTF8_STRING,
"map value is a UTF8_STRING");
const char *description = dup_entry_string_or_bail(value->entry_data);
char *description = dup_entry_string_or_bail(value->entry_data);
if (strcmp(key_name, "en") == 0) {
is(description,
@@ -157,8 +157,8 @@ test_description_value(MMDB_entry_data_list_s *entry_data_list) {
ok(0, "unknown key found in description map - %s", key_name);
}
free((void *)key_name);
free((void *)description);
free(key_name);
free(description);
}
return entry_data_list;
@@ -193,11 +193,11 @@ void test_metadata_as_data_entry_list(MMDB_s *mmdb, const char *mode_desc) {
MMDB_DATA_TYPE_UTF8_STRING,
"found a map key");
const char *key_name = dup_entry_string_or_bail(key->entry_data);
char *key_name = dup_entry_string_or_bail(key->entry_data);
if (strcmp(key_name, "node_count") == 0) {
MMDB_entry_data_list_s *value = entry_data_list =
entry_data_list->next;
cmp_ok(value->entry_data.uint32, "==", 37, "node_count == 37");
cmp_ok(value->entry_data.uint32, "==", 163, "node_count == 163");
} else if (strcmp(key_name, "record_size") == 0) {
MMDB_entry_data_list_s *value = entry_data_list =
entry_data_list->next;
@@ -228,9 +228,9 @@ void test_metadata_as_data_entry_list(MMDB_s *mmdb, const char *mode_desc) {
} else if (strcmp(key_name, "database_type") == 0) {
MMDB_entry_data_list_s *value = entry_data_list =
entry_data_list->next;
const char *type = dup_entry_string_or_bail(value->entry_data);
char *type = dup_entry_string_or_bail(value->entry_data);
is(type, "Test", "type == Test");
free((void *)type);
free(type);
} else if (strcmp(key_name, "languages") == 0) {
entry_data_list = test_languages_value(entry_data_list);
} else if (strcmp(key_name, "description") == 0) {
@@ -239,7 +239,7 @@ void test_metadata_as_data_entry_list(MMDB_s *mmdb, const char *mode_desc) {
ok(0, "unknown key found in metadata map - %s", key_name);
}
free((void *)key_name);
free(key_name);
}
MMDB_free_entry_data_list(first);
@@ -247,7 +247,7 @@ void test_metadata_as_data_entry_list(MMDB_s *mmdb, const char *mode_desc) {
void run_tests(int mode, const char *mode_desc) {
const char *file = "MaxMind-DB-test-ipv4-24.mmdb";
const char *path = test_database_path(file);
char *path = test_database_path(file);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
// All of the remaining tests require an open mmdb
@@ -255,7 +255,7 @@ void run_tests(int mode, const char *mode_desc) {
diag("could not open %s - skipping remaining tests", path);
return;
}
free((void *)path);
free(path);
test_metadata(mmdb, mode_desc);
test_metadata_as_data_entry_list(mmdb, mode_desc);
+2 -2
View File
@@ -2,9 +2,9 @@
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-string-value-entries.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const char *ip = "1.1.1.1";
MMDB_lookup_result_s result =
+153 -138
View File
@@ -70,54 +70,59 @@ void run_read_node_tests(MMDB_s *mmdb,
void run_24_bit_record_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-mixed-24.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const uint32_t tests[7][5] = {
{0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_EMPTY},
{
80,
81,
MMDB_RECORD_TYPE_SEARCH_NODE,
197,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
96,
97,
MMDB_RECORD_TYPE_SEARCH_NODE,
242,
MMDB_RECORD_TYPE_EMPTY,
},
{
103,
242,
MMDB_RECORD_TYPE_EMPTY,
104,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
127,
242,
MMDB_RECORD_TYPE_EMPTY,
315,
MMDB_RECORD_TYPE_DATA,
},
{
132,
329,
MMDB_RECORD_TYPE_DATA,
242,
MMDB_RECORD_TYPE_EMPTY,
},
{
241,
96,
MMDB_RECORD_TYPE_SEARCH_NODE,
242,
MMDB_RECORD_TYPE_EMPTY,
}};
const uint32_t tests[7][5] = {{
0,
1,
MMDB_RECORD_TYPE_SEARCH_NODE,
435,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
80,
81,
MMDB_RECORD_TYPE_SEARCH_NODE,
323,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
96,
97,
MMDB_RECORD_TYPE_SEARCH_NODE,
148,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
103,
444,
MMDB_RECORD_TYPE_EMPTY,
104,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
127,
444,
MMDB_RECORD_TYPE_EMPTY,
514,
MMDB_RECORD_TYPE_DATA,
},
{
132,
527,
MMDB_RECORD_TYPE_DATA,
444,
MMDB_RECORD_TYPE_EMPTY,
},
{
241,
444,
MMDB_RECORD_TYPE_EMPTY,
242,
MMDB_RECORD_TYPE_SEARCH_NODE,
}};
run_read_node_tests(mmdb, tests, 7, 24);
MMDB_close(mmdb);
@@ -126,54 +131,59 @@ void run_24_bit_record_tests(int mode, const char *mode_desc) {
void run_28_bit_record_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-mixed-28.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const uint32_t tests[7][5] = {
{0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_EMPTY},
{
80,
81,
MMDB_RECORD_TYPE_SEARCH_NODE,
197,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
96,
97,
MMDB_RECORD_TYPE_SEARCH_NODE,
242,
MMDB_RECORD_TYPE_EMPTY,
},
{
103,
242,
MMDB_RECORD_TYPE_EMPTY,
104,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
127,
242,
MMDB_RECORD_TYPE_EMPTY,
315,
MMDB_RECORD_TYPE_DATA,
},
{
132,
329,
MMDB_RECORD_TYPE_DATA,
242,
MMDB_RECORD_TYPE_EMPTY,
},
{
241,
96,
MMDB_RECORD_TYPE_SEARCH_NODE,
242,
MMDB_RECORD_TYPE_EMPTY,
}};
const uint32_t tests[7][5] = {{
0,
1,
MMDB_RECORD_TYPE_SEARCH_NODE,
435,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
80,
81,
MMDB_RECORD_TYPE_SEARCH_NODE,
323,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
96,
97,
MMDB_RECORD_TYPE_SEARCH_NODE,
148,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
103,
444,
MMDB_RECORD_TYPE_EMPTY,
104,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
127,
444,
MMDB_RECORD_TYPE_EMPTY,
514,
MMDB_RECORD_TYPE_DATA,
},
{
132,
527,
MMDB_RECORD_TYPE_DATA,
444,
MMDB_RECORD_TYPE_EMPTY,
},
{
241,
444,
MMDB_RECORD_TYPE_EMPTY,
242,
MMDB_RECORD_TYPE_SEARCH_NODE,
}};
run_read_node_tests(mmdb, tests, 7, 28);
MMDB_close(mmdb);
@@ -182,54 +192,59 @@ void run_28_bit_record_tests(int mode, const char *mode_desc) {
void run_32_bit_record_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-mixed-32.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const uint32_t tests[7][5] = {
{0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_EMPTY},
{
80,
81,
MMDB_RECORD_TYPE_SEARCH_NODE,
197,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
96,
97,
MMDB_RECORD_TYPE_SEARCH_NODE,
242,
MMDB_RECORD_TYPE_EMPTY,
},
{
103,
242,
MMDB_RECORD_TYPE_EMPTY,
104,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
127,
242,
MMDB_RECORD_TYPE_EMPTY,
315,
MMDB_RECORD_TYPE_DATA,
},
{
132,
329,
MMDB_RECORD_TYPE_DATA,
242,
MMDB_RECORD_TYPE_EMPTY,
},
{
241,
96,
MMDB_RECORD_TYPE_SEARCH_NODE,
242,
MMDB_RECORD_TYPE_EMPTY,
}};
const uint32_t tests[7][5] = {{
0,
1,
MMDB_RECORD_TYPE_SEARCH_NODE,
435,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
80,
81,
MMDB_RECORD_TYPE_SEARCH_NODE,
323,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
96,
97,
MMDB_RECORD_TYPE_SEARCH_NODE,
148,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
103,
444,
MMDB_RECORD_TYPE_EMPTY,
104,
MMDB_RECORD_TYPE_SEARCH_NODE,
},
{
127,
444,
MMDB_RECORD_TYPE_EMPTY,
514,
MMDB_RECORD_TYPE_DATA,
},
{
132,
527,
MMDB_RECORD_TYPE_DATA,
444,
MMDB_RECORD_TYPE_EMPTY,
},
{
241,
444,
MMDB_RECORD_TYPE_EMPTY,
242,
MMDB_RECORD_TYPE_SEARCH_NODE,
}};
run_read_node_tests(mmdb, tests, 7, 32);
+9 -6
View File
@@ -128,10 +128,10 @@ void process_result(test_result_s *result,
void run_ipX_tests(MMDB_s *mmdb,
const char *pairs[][2],
int pairs_rows,
int mode,
const char *mode_desc) {
pthread_t threads[pairs_rows];
struct thread_arg thread_args[pairs_rows];
pthread_t *threads = malloc((unsigned long)pairs_rows * sizeof(pthread_t));
struct thread_arg *thread_args =
malloc((unsigned long)pairs_rows * sizeof(struct thread_arg));
for (int i = 0; i < pairs_rows; i += 1) {
thread_args[i].thread_id = i;
@@ -161,13 +161,16 @@ void run_ipX_tests(MMDB_s *mmdb,
free(test_result);
}
}
free(threads);
free(thread_args);
}
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-mixed-32.mmdb";
const char *path = test_database_path(filename);
char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
free(path);
const char *pairs[18][2] = {
{"1.1.1.1", "::1.1.1.1"},
@@ -190,7 +193,7 @@ void run_tests(int mode, const char *mode_desc) {
{"::2:0:59", "::2:0:58"},
};
run_ipX_tests(mmdb, pairs, 18, mode, mode_desc);
run_ipX_tests(mmdb, pairs, 18, mode_desc);
MMDB_close(mmdb);
free(mmdb);