"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "t/read_node_t.c" between
libmaxminddb-1.5.0.tar.gz and libmaxminddb-1.5.2.tar.gz

About: libmaxminddb is a library that provides functions for working with MaxMind DB files (free GeoLite 2 or commercial GeoIP2).

read_node_t.c  (libmaxminddb-1.5.0):read_node_t.c  (libmaxminddb-1.5.2)
#include "maxminddb_test_helper.h" #include "maxminddb_test_helper.h"
void test_entry_data(MMDB_s *mmdb, MMDB_entry_s *entry, uint32_t node_number, void test_entry_data(MMDB_s *mmdb,
char * node_record) MMDB_entry_s *entry,
{ uint32_t node_number,
char *node_record) {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
int status = int status = MMDB_get_value(entry, &entry_data, "ip", NULL);
MMDB_get_value(entry, &entry_data, "ip", cmp_ok(status, "==", MMDB_SUCCESS, "successful data lookup for node");
NULL); cmp_ok(entry_data.type,
cmp_ok(status, "==", MMDB_SUCCESS, "==",
"successful data lookup for node"); MMDB_DATA_TYPE_UTF8_STRING,
cmp_ok( "returned entry type is UTF8_STRING for %s record of node %i",
entry_data.type, "==", MMDB_DATA_TYPE_UTF8_STRING, node_record,
"returned entry type is UTF8_STRING for %s record of node %i", node_number);
node_record, node_number);
} }
void run_read_node_tests(MMDB_s *mmdb, const uint32_t tests[][5], void run_read_node_tests(MMDB_s *mmdb,
const uint32_t tests[][5],
int test_count, int test_count,
uint8_t record_size) uint8_t record_size) {
{
for (int i = 0; i < test_count; i++) { for (int i = 0; i < test_count; i++) {
uint32_t node_number = tests[i][0]; uint32_t node_number = tests[i][0];
MMDB_search_node_s node; MMDB_search_node_s node;
int status = MMDB_read_node(mmdb, node_number, &node); int status = MMDB_read_node(mmdb, node_number, &node);
if (MMDB_SUCCESS == status) { if (MMDB_SUCCESS == status) {
cmp_ok(node.left_record, "==", tests[i][1], cmp_ok(node.left_record,
"==",
tests[i][1],
"left record for node %i is %i - %i bit DB", "left record for node %i is %i - %i bit DB",
node_number, tests[i][1], record_size); node_number,
cmp_ok(node.left_record_type, "==", tests[i][2], tests[i][1],
"left record type for node %i is %i", node_number, record_size);
cmp_ok(node.left_record_type,
"==",
tests[i][2],
"left record type for node %i is %i",
node_number,
tests[i][2]); tests[i][2]);
if (node.left_record_type == MMDB_RECORD_TYPE_DATA) { if (node.left_record_type == MMDB_RECORD_TYPE_DATA) {
test_entry_data(mmdb, &node.left_record_entry, node_number, test_entry_data(
"left"); mmdb, &node.left_record_entry, node_number, "left");
} }
cmp_ok(node.right_record, "==", tests[i][3], cmp_ok(node.right_record,
"==",
tests[i][3],
"right record for node %i is %i - %i bit DB", "right record for node %i is %i - %i bit DB",
node_number, tests[i][3], record_size); node_number,
cmp_ok(node.right_record_type, "==", tests[i][4], tests[i][3],
"right record type for node %i is %i", node_number, record_size);
cmp_ok(node.right_record_type,
"==",
tests[i][4],
"right record type for node %i is %i",
node_number,
tests[i][4]); tests[i][4]);
if (node.right_record_type == MMDB_RECORD_TYPE_DATA) { if (node.right_record_type == MMDB_RECORD_TYPE_DATA) {
test_entry_data(mmdb, &node.right_record_entry, node_number, test_entry_data(
"right"); mmdb, &node.right_record_entry, node_number, "right");
} }
} else { } else {
diag("call to MMDB_read_node for node %i failed - %i bit DB", diag("call to MMDB_read_node for node %i failed - %i bit DB",
node_number, node_number,
record_size); record_size);
} }
} }
} }
void run_24_bit_record_tests(int mode, const char *mode_desc) void run_24_bit_record_tests(int mode, const char *mode_desc) {
{
const char *filename = "MaxMind-DB-test-mixed-24.mmdb"; const char *filename = "MaxMind-DB-test-mixed-24.mmdb";
const char *path = test_database_path(filename); const char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc); MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path); free((void *)path);
const uint32_t tests[7][5] = { const uint32_t tests[7][5] = {
{ 0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, {0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_EMPTY},
MMDB_RECORD_TYPE_EMPTY }, {
{ 80, 81, MMDB_RECORD_TYPE_SEARCH_NODE, 197, 80,
MMDB_RECORD_TYPE_SEARCH_NODE, }, 81,
{ 96, 97, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_SEARCH_NODE,
MMDB_RECORD_TYPE_EMPTY, }, 197,
{ 103, 242, MMDB_RECORD_TYPE_EMPTY, 104, MMDB_RECORD_TYPE_SEARCH_NODE,
MMDB_RECORD_TYPE_SEARCH_NODE, }, },
{ 127, 242, MMDB_RECORD_TYPE_EMPTY, 315, {
MMDB_RECORD_TYPE_DATA, }, 96,
{ 132, 329, MMDB_RECORD_TYPE_DATA, 242, 97,
MMDB_RECORD_TYPE_EMPTY, }, MMDB_RECORD_TYPE_SEARCH_NODE,
{ 241, 96, MMDB_RECORD_TYPE_SEARCH_NODE, 242, 242,
MMDB_RECORD_TYPE_EMPTY, } 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,
}};
run_read_node_tests(mmdb, tests, 7, 24); run_read_node_tests(mmdb, tests, 7, 24);
MMDB_close(mmdb); MMDB_close(mmdb);
free(mmdb); free(mmdb);
} }
void run_28_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 *filename = "MaxMind-DB-test-mixed-28.mmdb";
const char *path = test_database_path(filename); const char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc); MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path); free((void *)path);
const uint32_t tests[7][5] = { const uint32_t tests[7][5] = {
{ 0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, {0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_EMPTY},
MMDB_RECORD_TYPE_EMPTY }, {
{ 80, 81, MMDB_RECORD_TYPE_SEARCH_NODE, 197, 80,
MMDB_RECORD_TYPE_SEARCH_NODE, }, 81,
{ 96, 97, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_SEARCH_NODE,
MMDB_RECORD_TYPE_EMPTY, }, 197,
{ 103, 242, MMDB_RECORD_TYPE_EMPTY, 104, MMDB_RECORD_TYPE_SEARCH_NODE,
MMDB_RECORD_TYPE_SEARCH_NODE, }, },
{ 127, 242, MMDB_RECORD_TYPE_EMPTY, 315, {
MMDB_RECORD_TYPE_DATA, }, 96,
{ 132, 329, MMDB_RECORD_TYPE_DATA, 242, 97,
MMDB_RECORD_TYPE_EMPTY, }, MMDB_RECORD_TYPE_SEARCH_NODE,
{ 241, 96, MMDB_RECORD_TYPE_SEARCH_NODE, 242, 242,
MMDB_RECORD_TYPE_EMPTY, } 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,
}};
run_read_node_tests(mmdb, tests, 7, 28); run_read_node_tests(mmdb, tests, 7, 28);
MMDB_close(mmdb); MMDB_close(mmdb);
free(mmdb); free(mmdb);
} }
void run_32_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 *filename = "MaxMind-DB-test-mixed-32.mmdb";
const char *path = test_database_path(filename); const char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc); MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path); free((void *)path);
const uint32_t tests[7][5] = { const uint32_t tests[7][5] = {
{ 0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, {0, 1, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_EMPTY},
MMDB_RECORD_TYPE_EMPTY }, {
{ 80, 81, MMDB_RECORD_TYPE_SEARCH_NODE, 197, 80,
MMDB_RECORD_TYPE_SEARCH_NODE, }, 81,
{ 96, 97, MMDB_RECORD_TYPE_SEARCH_NODE, 242, MMDB_RECORD_TYPE_SEARCH_NODE,
MMDB_RECORD_TYPE_EMPTY, }, 197,
{ 103, 242, MMDB_RECORD_TYPE_EMPTY, 104, MMDB_RECORD_TYPE_SEARCH_NODE,
MMDB_RECORD_TYPE_SEARCH_NODE, }, },
{ 127, 242, MMDB_RECORD_TYPE_EMPTY, 315, {
MMDB_RECORD_TYPE_DATA, }, 96,
{ 132, 329, MMDB_RECORD_TYPE_DATA, 242, 97,
MMDB_RECORD_TYPE_EMPTY, }, MMDB_RECORD_TYPE_SEARCH_NODE,
{ 241, 96, MMDB_RECORD_TYPE_SEARCH_NODE, 242, 242,
MMDB_RECORD_TYPE_EMPTY, } 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,
}};
run_read_node_tests(mmdb, tests, 7, 32); run_read_node_tests(mmdb, tests, 7, 32);
MMDB_close(mmdb); MMDB_close(mmdb);
free(mmdb); free(mmdb);
} }
void run_tests(int mode, const char *mode_desc) void run_tests(int mode, const char *mode_desc) {
{
run_24_bit_record_tests(mode, mode_desc); run_24_bit_record_tests(mode, mode_desc);
run_28_bit_record_tests(mode, mode_desc); run_28_bit_record_tests(mode, mode_desc);
run_32_bit_record_tests(mode, mode_desc); run_32_bit_record_tests(mode, mode_desc);
} }
int main(void) int main(void) {
{
plan(NO_PLAN); plan(NO_PLAN);
for_all_modes(&run_tests); for_all_modes(&run_tests);
done_testing(); done_testing();
} }
 End of changes. 18 change blocks. 
82 lines changed or deleted 175 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)