"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/test-geoip.c" between
GeoIP-1.6.11.tar.gz and GeoIP-1.6.12.tar.gz

About: GeoIP is a C library that enables the user to find the country that any IP address or hostname originates from (contains an initial free GeoIP Country database).

test-geoip.c  (GeoIP-1.6.11):test-geoip.c  (GeoIP-1.6.12)
skipping to change at line 18 skipping to change at line 18
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 2.1 of the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US A * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "GeoIP.h" #include "GeoIP.h"
int main() int main(void) {
{
FILE *f; FILE *f;
char *db_info; char *db_info;
char ipAddress[30]; char ipAddress[30];
char expectedCountry[3]; char expectedCountry[3];
char expectedCountry3[4]; char expectedCountry3[4];
const char *returnedCountry; const char *returnedCountry;
GeoIP *gi; GeoIP *gi;
int failed = 0; int failed = 0;
int test_num = 1; int test_num = 1;
skipping to change at line 53 skipping to change at line 52
gi = GeoIP_open(SRCDIR "/data/GeoIP.dat", GEOIP_MEMORY_CACHE); gi = GeoIP_open(SRCDIR "/data/GeoIP.dat", GEOIP_MEMORY_CACHE);
} }
if (gi == NULL) { if (gi == NULL) {
fprintf(stderr, "Error opening database\n"); fprintf(stderr, "Error opening database\n");
exit(1); exit(1);
} }
db_info = GeoIP_database_info(gi); db_info = GeoIP_database_info(gi);
if (!db_info || strcmp(db_info, if (!db_info || strcmp(db_info,
"GEO-106 20160621 Build 1 Copyright (c) 2016 MaxM "GEO-106 20160621 Build 1 Copyright (c) 2016 "
ind Inc All Rights Reserved")) "MaxMind Inc All Rights Reserved")) {
{
fprintf(stderr, "Error reading database info (got %s).\n", db_info); fprintf(stderr, "Error reading database info (got %s).\n", db_info);
free(db_info); free(db_info);
failed = 1; failed = 1;
} }
/* make sure GeoIP deals with invalid query gracefully */ /* make sure GeoIP deals with invalid query gracefully */
returnedCountry = GeoIP_country_code_by_addr(gi, NULL); returnedCountry = GeoIP_country_code_by_addr(gi, NULL);
if (returnedCountry != NULL) { if (returnedCountry != NULL) {
fprintf(stderr, fprintf(stderr,
"Invalid Query test failed, got non NULL, expected NULL\n"); "Invalid Query test failed, got non NULL, expected NULL\n");
skipping to change at line 77 skipping to change at line 76
returnedCountry = GeoIP_country_code_by_name(gi, NULL); returnedCountry = GeoIP_country_code_by_name(gi, NULL);
if (returnedCountry != NULL) { if (returnedCountry != NULL) {
fprintf(stderr, fprintf(stderr,
"Invalid Query test failed, got non NULL, expected NULL\n"); "Invalid Query test failed, got non NULL, expected NULL\n");
failed = 1; failed = 1;
} }
f = fopen(SRCDIR "/test/country_test.txt", "r"); f = fopen(SRCDIR "/test/country_test.txt", "r");
while (fscanf(f, "%s%s%s", ipAddress, expectedCountry, expectedCountry3) while (
!= EOF) { fscanf(f, "%s%s%s", ipAddress, expectedCountry, expectedCountry3) !=
EOF) {
returnedCountry = GeoIP_country_code_by_addr(gi, ipAddress); returnedCountry = GeoIP_country_code_by_addr(gi, ipAddress);
if (returnedCountry == NULL if (returnedCountry == NULL ||
|| strcmp(returnedCountry, expectedCountry) != 0) { strcmp(returnedCountry, expectedCountry) != 0) {
fprintf(stderr, fprintf(stderr,
"Test addr %d for %s failed, got %s, expected %s\n", "Test addr %d for %s failed, got %s, expected %s\n",
test_num, ipAddress, returnedCountry, expectedCountry); test_num,
ipAddress,
returnedCountry,
expectedCountry);
failed = 1; failed = 1;
} }
returnedCountry = GeoIP_country_code_by_name(gi, ipAddress); returnedCountry = GeoIP_country_code_by_name(gi, ipAddress);
if (returnedCountry == NULL if (returnedCountry == NULL ||
|| strcmp(returnedCountry, expectedCountry) != 0) { strcmp(returnedCountry, expectedCountry) != 0) {
fprintf(stderr, fprintf(stderr,
"Test name %d for %s failed, got %s, expected %s\n", "Test name %d for %s failed, got %s, expected %s\n",
test_num, ipAddress, returnedCountry, expectedCountry); test_num,
ipAddress,
returnedCountry,
expectedCountry);
failed = 1; failed = 1;
} }
returnedCountry = GeoIP_country_code3_by_addr(gi, ipAddress); returnedCountry = GeoIP_country_code3_by_addr(gi, ipAddress);
if (returnedCountry == NULL if (returnedCountry == NULL ||
|| strcmp(returnedCountry, expectedCountry3) != 0) { strcmp(returnedCountry, expectedCountry3) != 0) {
fprintf(stderr, fprintf(stderr,
"Test addr %d for %s failed, got %s, expected %s\n", "Test addr %d for %s failed, got %s, expected %s\n",
test_num, ipAddress, returnedCountry, expectedCountry); test_num,
ipAddress,
returnedCountry,
expectedCountry);
failed = 1; failed = 1;
} }
returnedCountry = GeoIP_country_code3_by_name(gi, ipAddress); returnedCountry = GeoIP_country_code3_by_name(gi, ipAddress);
if (returnedCountry == NULL if (returnedCountry == NULL ||
|| strcmp(returnedCountry, expectedCountry3) != 0) { strcmp(returnedCountry, expectedCountry3) != 0) {
fprintf(stderr, fprintf(stderr,
"Test name %d for %s failed, got %s, expected %s\n", "Test name %d for %s failed, got %s, expected %s\n",
test_num, ipAddress, returnedCountry, expectedCountry); test_num,
ipAddress,
returnedCountry,
expectedCountry);
failed = 1; failed = 1;
} }
test_num++; test_num++;
} }
fclose(f); fclose(f);
f = fopen(SRCDIR "/test/country_test2.txt", "r"); f = fopen(SRCDIR "/test/country_test2.txt", "r");
while (fscanf(f, "%s%s", ipAddress, expectedCountry) != EOF) { while (fscanf(f, "%s%s", ipAddress, expectedCountry) != EOF) {
returnedCountry = GeoIP_country_code_by_addr(gi, ipAddress); returnedCountry = GeoIP_country_code_by_addr(gi, ipAddress);
if (returnedCountry == NULL if (returnedCountry == NULL ||
|| strcmp(returnedCountry, expectedCountry) != 0) { strcmp(returnedCountry, expectedCountry) != 0) {
fprintf(stderr, "Test addr %d %s failed, got %s, expected %s\n", fprintf(stderr,
test_num, ipAddress, returnedCountry, expectedCountry); "Test addr %d %s failed, got %s, expected %s\n",
test_num,
ipAddress,
returnedCountry,
expectedCountry);
failed = 1; failed = 1;
} }
test_num++; test_num++;
} }
fclose(f); fclose(f);
GeoIP_delete(gi); GeoIP_delete(gi);
} }
return failed; return failed;
} }
 End of changes. 13 change blocks. 
24 lines changed or deleted 39 lines changed or added

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