<commit_before>#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdarg.h>
#include "MMDB.h"
#include "MMDB_test_helper.h"

void for_all_modes(void (*tests) (int mode, const char *description))
{
    tests(MMDB_MODE_STANDARD, "standard mode");
    tests(MMDB_MODE_MEMORY_CACHE, "memory cache mode");
}

static const char *test_db_dir = "../maxmind-db/test-data";

const char *test_database_path(const char *filename)
{
    char *path = malloc(500);
    assert(path != NULL);

    snprintf(path, 500, "%s/%s", test_db_dir, filename);

    return (const char *)path;
}

MMDB_s *open_ok(const char *db_file, int mode, const char *mode_desc)
{
    MMDB_s *mmdb = (MMDB_s *)calloc(1, sizeof(MMDB_s));
    uint16_t status;
    int ok;

    if (NULL == mmdb) {
        BAIL_OUT("could not allocate memory for our MMDB_s struct");
    }

    status = MMDB_open(db_file, mode, mmdb);

    ok = ok(MMDB_SUCCESS == status, "open %s status is success - %s",
            db_file, mode_desc);

    if (!ok) {
        diag("open status code = %d", status);
        return NULL;
    }

    ok = ok(NULL != mmdb, "returned mmdb struct is not null for %s - %s",
            db_file, mode_desc);

    if (!ok) {
        return NULL;
    }

    return mmdb;
}

MMDB_lookup_result_s *lookup_ok(MMDB_s *mmdb, const char *ip,
                                const char *file, const char *mode_desc)
{
    int gai_error, mmdb_error;
    MMDB_lookup_result_s *root;
    int ok;

    root = MMDB_lookup(mmdb, ip, &gai_error, &mmdb_error);

    ok = ok(0 == gai_error,
            "no getaddrinfo error in call to MMDB_lookup for %s - %s - %s",
            ip, file, mode_desc);

    if (!ok) {
        diag("error from call to getaddrinfo for %s - %s",
             ip, gai_strerror(gai_error));
    }

    ok = ok(0 == mmdb_error,
            "no MMDB error in call to MMDB_lookup for %s - %s - %s",
            ip, file, mode_desc);

    if (!ok) {
        diag("MMDB error - %d", mmdb_error);<commit_msg>Rename variable from ok to is_ok so it's not the same as the ok() function<commit_after>#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdarg.h>
#include "MMDB.h"
#include "MMDB_test_helper.h"

void for_all_modes(void (*tests) (int mode, const char *description))
{
    tests(MMDB_MODE_STANDARD, "standard mode");
    tests(MMDB_MODE_MEMORY_CACHE, "memory cache mode");
}

static const char *test_db_dir = "../maxmind-db/test-data";

const char *test_database_path(const char *filename)
{
    char *path = malloc(500);
    assert(path != NULL);

    snprintf(path, 500, "%s/%s", test_db_dir, filename);

    return (const char *)path;
}

MMDB_s *open_ok(const char *db_file, int mode, const char *mode_desc)
{
    MMDB_s *mmdb = (MMDB_s *)calloc(1, sizeof(MMDB_s));
    uint16_t status;
    int ok;

    if (NULL == mmdb) {
        BAIL_OUT("could not allocate memory for our MMDB_s struct");
    }

    status = MMDB_open(db_file, mode, mmdb);

    ok = ok(MMDB_SUCCESS == status, "open %s status is success - %s",
            db_file, mode_desc);

    if (!ok) {
        diag("open status code = %d", status);
        return NULL;
    }

    ok = ok(NULL != mmdb, "returned mmdb struct is not null for %s - %s",
            db_file, mode_desc);

    if (!ok) {
        return NULL;
    }

    return mmdb;
}

MMDB_lookup_result_s *lookup_ok(MMDB_s *mmdb, const char *ip,
                                const char *file, const char *mode_desc)
{
    int gai_error, mmdb_error;
    MMDB_lookup_result_s *root;
    int is_ok;

    root = MMDB_lookup(mmdb, ip, &gai_error, &mmdb_error);

    is_ok = ok(0 == gai_error,
            "no getaddrinfo error in call to MMDB_lookup for %s - %s - %s",
            ip, file, mode_desc);

    if (!is_ok) {
        diag("error from call to getaddrinfo for %s - %s",
             ip, gai_strerror(gai_error));
    }

    is_ok = ok(0 == mmdb_error,
            "no MMDB error in call to MMDB_lookup for %s - %s - %s",
            ip, file, mode_desc);

    if (!is_ok) {
        diag("MMDB error - %d", mmdb_error);
{'fraction_non_alphanumeric': 0.13389830508474576, 'fraction_numerical': 0.005326876513317191, 'mean_word_length': 2.633245382585752, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6137618', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1533, 'n_words': 417}