mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-08-07 00:21:48 +02:00
bin
cmake
module
Base
Core
Entity
Library
Misc
Vendor
AES256
B64
Hash
MDBC
MaxmindDB
bin
cmake
dev-bin
doc
include
projects
src
t
Makefile.am
bad_databases_t.c
bad_pointers_t.c
basic_lookup_t.c
compile_c++_t.pl
data-pool-t.c
data_entry_list_t.c
data_types_t.c
dump_t.c
external_symbols_t.pl
get_value_pointer_bug_t.c
get_value_t.c
ipv4_start_cache_t.c
ipv6_lookup_in_ipv4_t.c
maxminddb_test_helper.c
maxminddb_test_helper.h
metadata_pointers_t.c
metadata_t.c
mmdblookup_t.pl
no_map_get_value_t.c
read_node_t.c
threads_t.c
version_t.c
AUTHORS
CMakeLists.txt
Changes.md
LICENSE
Makefile.am
NOTICE
README.dev.md
README.md
appveyor.yml
bootstrap
common.mk
configure.ac
PUGIXML
SQLite
SimpleIni
TinyDir
Whirlpool
CMakeLists.txt
CMakeLists.txt
Core.cpp
Core.hpp
Logger.cpp
Logger.hpp
Main.cpp
Register.cpp
SqBase.hpp
sdk
sqrat
squirrel
vcmp
.gitignore
CMakeLists.txt
LICENSE
README.md
68 lines
1.5 KiB
C
68 lines
1.5 KiB
C
// This test currently does not work on Windows as nftw is
|
|
// not available.
|
|
#define _XOPEN_SOURCE 500
|
|
#include <ftw.h>
|
|
|
|
#include <libgen.h>
|
|
#include <unistd.h>
|
|
|
|
#include "maxminddb_test_helper.h"
|
|
|
|
int test_read(const char *path, const struct stat *UNUSED(
|
|
sbuf), int flags, struct FTW *UNUSED(ftw))
|
|
{
|
|
// Check if path is a regular file)
|
|
if (flags != FTW_F) {
|
|
return 0;
|
|
}
|
|
|
|
MMDB_s *mmdb = (MMDB_s *)calloc(1, sizeof(MMDB_s));
|
|
|
|
if (NULL == mmdb) {
|
|
BAIL_OUT("could not allocate memory for our MMDB_s struct");
|
|
}
|
|
|
|
int status = MMDB_open(path, MMDB_MODE_MMAP, mmdb);
|
|
|
|
if (status != MMDB_SUCCESS) {
|
|
ok(1, "received error when opening %s", path);
|
|
free(mmdb);
|
|
return 0;
|
|
}
|
|
|
|
int gai_error, mmdb_error;
|
|
MMDB_lookup_string(mmdb, "1.1.1.1", &gai_error, &mmdb_error);
|
|
if (gai_error != 0) {
|
|
BAIL_OUT("could not parse IP address");
|
|
}
|
|
|
|
cmp_ok(mmdb_error, "!=", MMDB_SUCCESS, "opening %s returned an error",
|
|
path);
|
|
|
|
MMDB_close(mmdb);
|
|
free(mmdb);
|
|
return 0;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char *test_db_dir;
|
|
#ifdef _WIN32
|
|
test_db_dir = "./t/maxmind-db/bad-data";
|
|
#else
|
|
char cwd[500];
|
|
char *UNUSED(tmp) = getcwd(cwd, 500);
|
|
|
|
if (strcmp(basename(cwd), "t") == 0) {
|
|
test_db_dir = "./maxmind-db/bad-data";
|
|
} else {
|
|
test_db_dir = "./t/maxmind-db/bad-data";
|
|
}
|
|
#endif
|
|
plan(NO_PLAN);
|
|
if (nftw(test_db_dir, test_read, 10, FTW_PHYS) != 0) {
|
|
BAIL_OUT("nftw failed");
|
|
}
|
|
done_testing();
|
|
}
|