"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "t/get_value_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).

get_value_t.c  (libmaxminddb-1.5.0):get_value_t.c  (libmaxminddb-1.5.2)
#include "maxminddb_test_helper.h" #include "maxminddb_test_helper.h"
void test_array_0_result(int status, MMDB_entry_data_s entry_data, void test_array_0_result(int status,
char *function) MMDB_entry_data_s entry_data,
{ char *function) {
cmp_ok(status, "==", MMDB_SUCCESS, cmp_ok(status,
"status for %s() is MMDB_SUCCESS - array[0]", function); "==",
MMDB_SUCCESS,
"status for %s() is MMDB_SUCCESS - array[0]",
function);
ok(entry_data.has_data, "found a value for array[0]"); ok(entry_data.has_data, "found a value for array[0]");
cmp_ok(entry_data.type, "==", MMDB_DATA_TYPE_UINT32, cmp_ok(entry_data.type,
"==",
MMDB_DATA_TYPE_UINT32,
"returned entry type is uint32 - array[0]"); "returned entry type is uint32 - array[0]");
cmp_ok(entry_data.uint32, "==", 1, "entry value is 1 - array[0]"); cmp_ok(entry_data.uint32, "==", 1, "entry value is 1 - array[0]");
} }
void test_array_2_result(int status, MMDB_entry_data_s entry_data, void test_array_2_result(int status,
char *function) MMDB_entry_data_s entry_data,
{ char *function) {
cmp_ok(status, "==", MMDB_SUCCESS, cmp_ok(status,
"status for %s() is MMDB_SUCCESS - array[2]", function); "==",
MMDB_SUCCESS,
"status for %s() is MMDB_SUCCESS - array[2]",
function);
ok(entry_data.has_data, "found a value for array[2]"); ok(entry_data.has_data, "found a value for array[2]");
cmp_ok(entry_data.type, "==", MMDB_DATA_TYPE_UINT32, cmp_ok(entry_data.type,
"==",
MMDB_DATA_TYPE_UINT32,
"returned entry type is uint32 - array[2]"); "returned entry type is uint32 - array[2]");
cmp_ok(entry_data.uint32, "==", 3, "entry value is 3 - array[2]"); cmp_ok(entry_data.uint32, "==", 3, "entry value is 3 - array[2]");
} }
void test_array_minus_3_result(int status, MMDB_entry_data_s entry_data, void test_array_minus_3_result(int status,
char *function) MMDB_entry_data_s entry_data,
{ char *function) {
cmp_ok(status, "==", MMDB_SUCCESS, cmp_ok(status,
"status for %s() is MMDB_SUCCESS - array[-3]", function); "==",
MMDB_SUCCESS,
"status for %s() is MMDB_SUCCESS - array[-3]",
function);
ok(entry_data.has_data, "found a value for array[-3]"); ok(entry_data.has_data, "found a value for array[-3]");
cmp_ok(entry_data.type, "==", MMDB_DATA_TYPE_UINT32, cmp_ok(entry_data.type,
"==",
MMDB_DATA_TYPE_UINT32,
"returned entry type is uint32 - array[-3]"); "returned entry type is uint32 - array[-3]");
cmp_ok(entry_data.uint32, "==", 1, "entry value is 1 - array[-3]"); cmp_ok(entry_data.uint32, "==", 1, "entry value is 1 - array[-3]");
} }
void test_array_minus_1_result(int status, MMDB_entry_data_s entry_data, void test_array_minus_1_result(int status,
char *function) MMDB_entry_data_s entry_data,
{ char *function) {
cmp_ok(status, "==", MMDB_SUCCESS, cmp_ok(status,
"status for %s() is MMDB_SUCCESS - array[-1]", function); "==",
MMDB_SUCCESS,
"status for %s() is MMDB_SUCCESS - array[-1]",
function);
ok(entry_data.has_data, "found a value for array[-1]"); ok(entry_data.has_data, "found a value for array[-1]");
cmp_ok(entry_data.type, "==", MMDB_DATA_TYPE_UINT32, cmp_ok(entry_data.type,
"==",
MMDB_DATA_TYPE_UINT32,
"returned entry type is uint32 - array[-1]"); "returned entry type is uint32 - array[-1]");
cmp_ok(entry_data.uint32, "==", 3, "entry value is 3 - array[-1]"); cmp_ok(entry_data.uint32, "==", 3, "entry value is 3 - array[-1]");
} }
int call_vget_value(MMDB_entry_s *entry, MMDB_entry_data_s *entry_data, ...) int call_vget_value(MMDB_entry_s *entry, MMDB_entry_data_s *entry_data, ...) {
{
va_list keys; va_list keys;
va_start(keys, entry_data); va_start(keys, entry_data);
int status = MMDB_vget_value(entry, entry_data, keys); int status = MMDB_vget_value(entry, entry_data, keys);
va_end(keys); va_end(keys);
return status; return status;
} }
void test_simple_structure(int mode, const char *mode_desc) void test_simple_structure(int mode, const char *mode_desc) {
{
const char *filename = "MaxMind-DB-test-decoder.mmdb"; const char *filename = "MaxMind-DB-test-decoder.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 char *ip = "1.1.1.1"; const char *ip = "1.1.1.1";
MMDB_lookup_result_s result = MMDB_lookup_result_s result =
lookup_string_ok(mmdb, ip, filename, mode_desc); lookup_string_ok(mmdb, ip, filename, mode_desc);
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = { "array", "0", NULL }; const char *lookup_path[] = {"array", "0", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_array_0_result(status, entry_data, "MMDB_aget_value"); test_array_0_result(status, entry_data, "MMDB_aget_value");
status = MMDB_get_value(&result.entry, &entry_data, "array", "0", NULL); status = MMDB_get_value(&result.entry, &entry_data, "array", "0", NULL);
test_array_0_result(status, entry_data, "MMDB_get_value"); test_array_0_result(status, entry_data, "MMDB_get_value");
status = status =
call_vget_value(&result.entry, &entry_data, "array", "0", NULL); call_vget_value(&result.entry, &entry_data, "array", "0", NULL);
test_array_0_result(status, entry_data, "MMDB_vget_value"); test_array_0_result(status, entry_data, "MMDB_vget_value");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = { "array", "2", NULL }; const char *lookup_path[] = {"array", "2", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_array_2_result(status, entry_data, "MMDB_aget_value"); test_array_2_result(status, entry_data, "MMDB_aget_value");
status = MMDB_get_value(&result.entry, &entry_data, "array", "2", NULL); status = MMDB_get_value(&result.entry, &entry_data, "array", "2", NULL);
test_array_2_result(status, entry_data, "MMDB_get_value"); test_array_2_result(status, entry_data, "MMDB_get_value");
status = status =
call_vget_value(&result.entry, &entry_data, "array", "2", NULL); call_vget_value(&result.entry, &entry_data, "array", "2", NULL);
test_array_2_result(status, entry_data, "MMDB_vget_value"); test_array_2_result(status, entry_data, "MMDB_vget_value");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
int status = MMDB_get_value(&result.entry, &entry_data, "array", "zero", int status =
NULL); MMDB_get_value(&result.entry, &entry_data, "array", "zero", NULL);
cmp_ok(status, "==", MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR, cmp_ok(status,
"==",
MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR,
"MMDB_get_value() returns error on non-integer array index"); "MMDB_get_value() returns error on non-integer array index");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = { "array", "-1", NULL }; const char *lookup_path[] = {"array", "-1", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_array_minus_1_result(status, entry_data, "MMDB_aget_value"); test_array_minus_1_result(status, entry_data, "MMDB_aget_value");
status = status =
MMDB_get_value(&result.entry, &entry_data, "array", "-1", NULL); MMDB_get_value(&result.entry, &entry_data, "array", "-1", NULL);
test_array_minus_1_result(status, entry_data, "MMDB_get_value"); test_array_minus_1_result(status, entry_data, "MMDB_get_value");
status = status =
call_vget_value(&result.entry, &entry_data, "array", "-1", NULL); call_vget_value(&result.entry, &entry_data, "array", "-1", NULL);
test_array_minus_1_result(status, entry_data, "MMDB_vget_value"); test_array_minus_1_result(status, entry_data, "MMDB_vget_value");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = { "array", "-3", NULL }; const char *lookup_path[] = {"array", "-3", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_array_minus_3_result(status, entry_data, "MMDB_aget_value"); test_array_minus_3_result(status, entry_data, "MMDB_aget_value");
status = status =
MMDB_get_value(&result.entry, &entry_data, "array", "-3", NULL); MMDB_get_value(&result.entry, &entry_data, "array", "-3", NULL);
test_array_minus_3_result(status, entry_data, "MMDB_get_value"); test_array_minus_3_result(status, entry_data, "MMDB_get_value");
status = status =
call_vget_value(&result.entry, &entry_data, "array", "-3", NULL); call_vget_value(&result.entry, &entry_data, "array", "-3", NULL);
test_array_minus_3_result(status, entry_data, "MMDB_vget_value"); test_array_minus_3_result(status, entry_data, "MMDB_vget_value");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
int status = MMDB_get_value(&result.entry, &entry_data, "array", "-4", int status =
NULL); MMDB_get_value(&result.entry, &entry_data, "array", "-4", NULL);
cmp_ok(status, "==", MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR, cmp_ok(status,
"==",
MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR,
"MMDB_get_value() returns error on too large negative integer"); "MMDB_get_value() returns error on too large negative integer");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
int status = int status = MMDB_get_value(
MMDB_get_value(&result.entry, &entry_data, "array", &result.entry, &entry_data, "array", "-18446744073709551616", NULL);
"-18446744073709551616", cmp_ok(
NULL); status,
cmp_ok(status, "==", MMDB_INVALID_LOOKUP_PATH_ERROR, "==",
"MMDB_get_value() returns error on integer smaller than LONG_MIN" MMDB_INVALID_LOOKUP_PATH_ERROR,
); "MMDB_get_value() returns error on integer smaller than LONG_MIN");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
int status = int status = MMDB_get_value(
MMDB_get_value(&result.entry, &entry_data, "array", &result.entry, &entry_data, "array", "18446744073709551616", NULL);
"18446744073709551616", cmp_ok(
NULL); status,
cmp_ok(status, "==", MMDB_INVALID_LOOKUP_PATH_ERROR, "==",
"MMDB_get_value() returns error on integer larger than LONG_MAX") MMDB_INVALID_LOOKUP_PATH_ERROR,
; "MMDB_get_value() returns error on integer larger than LONG_MAX");
} }
MMDB_close(mmdb); MMDB_close(mmdb);
free(mmdb); free(mmdb);
} }
void test_complex_map_a_result(int status, MMDB_entry_data_s entry_data, void test_complex_map_a_result(int status,
char *function) MMDB_entry_data_s entry_data,
{ char *function) {
cmp_ok(status, "==", MMDB_SUCCESS, cmp_ok(status,
"==",
MMDB_SUCCESS,
"status for %s() is MMDB_SUCCESS - map1{map2}{array}[0]{map3}{a}", "status for %s() is MMDB_SUCCESS - map1{map2}{array}[0]{map3}{a}",
function); function);
ok(entry_data.has_data, ok(entry_data.has_data, "found a value for map1{map2}{array}[0]{map3}{a}");
"found a value for map1{map2}{array}[0]{map3}{a}"); cmp_ok(entry_data.type,
cmp_ok(entry_data.type, "==", MMDB_DATA_TYPE_UINT32, "==",
MMDB_DATA_TYPE_UINT32,
"returned entry type is uint32 - map1{map2}{array}[0]{map3}{a}"); "returned entry type is uint32 - map1{map2}{array}[0]{map3}{a}");
cmp_ok(entry_data.uint32, "==", 1, cmp_ok(entry_data.uint32,
"==",
1,
"entry value is 1 - map1{map2}{array}[0]{map3}{a}"); "entry value is 1 - map1{map2}{array}[0]{map3}{a}");
} }
void test_complex_map_c_result(int status, MMDB_entry_data_s entry_data, void test_complex_map_c_result(int status,
char *function) MMDB_entry_data_s entry_data,
{ char *function) {
cmp_ok( cmp_ok(status,
status, "==", MMDB_SUCCESS, "==",
"status for %s() is MMDB_SUCCESS - map1{map2}{array}[0]{map3}{c}", MMDB_SUCCESS,
function); "status for %s() is MMDB_SUCCESS - map1{map2}{array}[0]{map3}{c}",
ok(entry_data.has_data, function);
"found a value for map1{map2}{array}[0]{map3}{c}"); ok(entry_data.has_data, "found a value for map1{map2}{array}[0]{map3}{c}");
cmp_ok(entry_data.type, "==", MMDB_DATA_TYPE_UINT32, cmp_ok(entry_data.type,
"==",
MMDB_DATA_TYPE_UINT32,
"returned entry type is uint32 - map1{map2}{array}[0]{map3}{c}"); "returned entry type is uint32 - map1{map2}{array}[0]{map3}{c}");
cmp_ok(entry_data.uint32, "==", 3, cmp_ok(entry_data.uint32,
"==",
3,
"entry value is 3 - map1{map2}{array}[0]{map3}{c}"); "entry value is 3 - map1{map2}{array}[0]{map3}{c}");
} }
void test_no_result(int status, MMDB_entry_data_s entry_data, char *function, void test_no_result(int status,
char *path_description) MMDB_entry_data_s entry_data,
{ char *function,
cmp_ok(status, "==", MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR, char *path_description) {
cmp_ok(status,
"==",
MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR,
"status for %s() is MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR - %s", "status for %s() is MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR - %s",
function, path_description); function,
path_description);
ok(!entry_data.has_data, "did not find a value for %s", path_description); ok(!entry_data.has_data, "did not find a value for %s", path_description);
} }
void test_nested_structure(int mode, const char *mode_desc) void test_nested_structure(int mode, const char *mode_desc) {
{
const char *filename = "MaxMind-DB-test-nested.mmdb"; const char *filename = "MaxMind-DB-test-nested.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 char *ip = "1.1.1.1"; const char *ip = "1.1.1.1";
MMDB_lookup_result_s result = MMDB_lookup_result_s result =
lookup_string_ok(mmdb, ip, filename, mode_desc); lookup_string_ok(mmdb, ip, filename, mode_desc);
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = const char *lookup_path[] = {
{ "map1", "map2", "array", "0", "map3", "a", NULL }; "map1", "map2", "array", "0", "map3", "a", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_complex_map_a_result(status, entry_data, "MMDB_aget_value"); test_complex_map_a_result(status, entry_data, "MMDB_aget_value");
status = MMDB_get_value(&result.entry, &entry_data, status = MMDB_get_value(&result.entry,
"map1", "map2", "array", "0", "map3", "a", &entry_data,
"map1",
"map2",
"array",
"0",
"map3",
"a",
NULL); NULL);
test_complex_map_a_result(status, entry_data, "MMDB_get_value"); test_complex_map_a_result(status, entry_data, "MMDB_get_value");
status = call_vget_value(&result.entry, &entry_data, status = call_vget_value(&result.entry,
"map1", "map2", "array", "0", "map3", "a", &entry_data,
"map1",
"map2",
"array",
"0",
"map3",
"a",
NULL); NULL);
test_complex_map_a_result(status, entry_data, "MMDB_vget_value"); test_complex_map_a_result(status, entry_data, "MMDB_vget_value");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = const char *lookup_path[] = {
{ "map1", "map2", "array", "0", "map3", "c", NULL }; "map1", "map2", "array", "0", "map3", "c", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_complex_map_c_result(status, entry_data, "MMDB_aget_value"); test_complex_map_c_result(status, entry_data, "MMDB_aget_value");
status = MMDB_get_value(&result.entry, &entry_data, status = MMDB_get_value(&result.entry,
"map1", "map2", "array", "0", "map3", "c", &entry_data,
"map1",
"map2",
"array",
"0",
"map3",
"c",
NULL); NULL);
test_complex_map_c_result(status, entry_data, "MMDB_get_value"); test_complex_map_c_result(status, entry_data, "MMDB_get_value");
status = call_vget_value(&result.entry, &entry_data, status = call_vget_value(&result.entry,
"map1", "map2", "array", "0", "map3", "c", &entry_data,
"map1",
"map2",
"array",
"0",
"map3",
"c",
NULL); NULL);
test_complex_map_c_result(status, entry_data, "MMDB_vget_value"); test_complex_map_c_result(status, entry_data, "MMDB_vget_value");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = const char *lookup_path[] = {
{ "map1", "map42", "array", "0", "map3", "c", NULL }; "map1", "map42", "array", "0", "map3", "c", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_no_result(status, entry_data, "MMDB_aget_value", test_no_result(status,
entry_data,
"MMDB_aget_value",
"map1{map42}{array}[0]{map3}{c}"); "map1{map42}{array}[0]{map3}{c}");
status = MMDB_get_value(&result.entry, &entry_data, status = MMDB_get_value(&result.entry,
"map1", "map42", "array", "0", "map3", "c", &entry_data,
"map1",
"map42",
"array",
"0",
"map3",
"c",
NULL); NULL);
test_no_result(status, entry_data, "MMDB_get_value", test_no_result(status,
entry_data,
"MMDB_get_value",
"map1{map42}{array}[0]{map3}{c}"); "map1{map42}{array}[0]{map3}{c}");
status = call_vget_value(&result.entry, &entry_data, status = call_vget_value(&result.entry,
"map1", "map42", "array", "0", "map3", "c", &entry_data,
"map1",
"map42",
"array",
"0",
"map3",
"c",
NULL); NULL);
test_no_result(status, entry_data, "MMDB_vget_value", test_no_result(status,
entry_data,
"MMDB_vget_value",
"map1{map42}{array}[0]{map3}{c}"); "map1{map42}{array}[0]{map3}{c}");
} }
{ {
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
const char *lookup_path[] = const char *lookup_path[] = {
{ "map1", "map2", "array", "9", "map3", "c", NULL }; "map1", "map2", "array", "9", "map3", "c", NULL};
int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path); int status = MMDB_aget_value(&result.entry, &entry_data, lookup_path);
test_no_result(status, entry_data, "MMDB_aget_value", test_no_result(status,
entry_data,
"MMDB_aget_value",
"map1{map42}{array}[9]{map3}{c}"); "map1{map42}{array}[9]{map3}{c}");
status = MMDB_get_value(&result.entry, &entry_data, status = MMDB_get_value(&result.entry,
"map1", "map2", "array", "9", "map3", "c", &entry_data,
"map1",
"map2",
"array",
"9",
"map3",
"c",
NULL); NULL);
test_no_result(status, entry_data, "MMDB_get_value", test_no_result(status,
entry_data,
"MMDB_get_value",
"map1{map42}{array}[9]{map3}{c}"); "map1{map42}{array}[9]{map3}{c}");
status = call_vget_value(&result.entry, &entry_data, status = call_vget_value(&result.entry,
"map1", "map2", "array", "9", "map3", "c", &entry_data,
"map1",
"map2",
"array",
"9",
"map3",
"c",
NULL); NULL);
test_no_result(status, entry_data, "MMDB_vget_value", test_no_result(status,
entry_data,
"MMDB_vget_value",
"map1{map42}{array}[9]{map3}{c}"); "map1{map42}{array}[9]{map3}{c}");
} }
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) {
{
test_simple_structure(mode, mode_desc); test_simple_structure(mode, mode_desc);
test_nested_structure(mode, mode_desc); test_nested_structure(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. 46 change blocks. 
112 lines changed or deleted 204 lines changed or added

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