iptogeo/src/test.c

46 lines
1.2 KiB
C

/*
Copyright 2016 Grégory Soutadé
This file is part of iptogeo.
iptogeo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iptogeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iptogeo. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "ip_to_geo.h"
#define IP(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
static void do_test(int a, int b, int c, int d)
{
const uint8_t* cc;
uint8_t ip[4] = {a, b, c, d};
cc = ip_to_geo(ip, 4);
printf("IP %d.%d.%d.%d : %s\n", a, b, c, d, (cc)?(char*)get_country_code(cc):"<none>");
}
int self_test()
{
do_test(1,5,7,3);
do_test(1,5,255,4);
do_test(1,6,255,4);
do_test(2,0,0,0);
do_test(127,0,0,1);
do_test(1,55,3,12);
do_test(1,57,0,0);
return 0;
}