Skip to content

Commit

Permalink
enhanced build test environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Joungkyun committed Jul 9, 2016
1 parent a0ffa72 commit 8da352a
Show file tree
Hide file tree
Showing 5 changed files with 410 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/guess.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org/>
*
* This file is part of libipcalc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>
#include <ipcalc.h>

int main (void) {
const char * ip1 = "192.168.1.7";
const char * ip2 = "192.168.1.10";
ulong lmask = 4294967280UL;
short prefix = 28;
short decfix;
ulong decmask;
int ret = 0;

decfix = (ulong) guess_prefix (ip2long ((char *) ip1), ip2long ((char *) ip2));

if ( decfix == prefix ) {
printf (
"PASS: + guess_netmask (include 192.168.1.7 and 192.168.1.10 => %u)\n",
prefix
);
} else {
printf (
"FAIL: + guess_netmask (include 192.168.1.7 and 192.168.1.10 == %u, but result is %u)\n",
prefix,
decfix
);
ret = 1;
}

decmask = (ulong) guess_netmask (ip2long ((char *) ip1), ip2long ((char *) ip2));

if ( decmask == lmask ) {
printf (
"PASS: + guess_netmask (include 192.168.1.7 and 192.168.1.10 => %lu)\n",
lmask
);
} else {
printf (
"FAIL: + guess_netmask (include 192.168.1.7 and 192.168.1.10 == %lu, but result is %lu)\n",
lmask,
decmask
);
ret = 1;
}

return ret;
}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
54 changes: 54 additions & 0 deletions test/is_ipv4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org/>
*
* This file is part of libipcalc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>
#include <ipcalc.h>

int main (void) {
char rip[16] = { 0, };
char err[1024];
int ret = 0;

strcpy (rip, "256.0.0.1");
if ( valid_ip_address (rip, err) != 0 ) {
printf (
"PASS: + valid_ip_address (%s => %s)\n",
rip,
err
);
} else {
printf (
"PASS: + valid_ip_address (%s => must occur error. but no error!)\n",
rip
);
ret = 1;
}

return ret;
}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
79 changes: 79 additions & 0 deletions test/network.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org/>
*
* This file is part of libipcalc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>
#include <ipcalc.h>

int main (void) {
const char * ip1 = "192.168.1.7";
const char * net = "192.168.1.0";
const char * bcast = "192.168.1.15";
ulong lmask = 4294967280UL;
short prefix = 28;
char rip[16] = { 0, };
int ret = 0;

if ( strcmp (long2ip_r (network (ip2long((char *) ip1), lmask), rip), net) == 0 ) {
printf (
"PASS: + network (%s/%u => %s)\n",
ip1,
prefix,
rip
);
} else {
printf (
"FAIL: + network (%s/%u == %s, but result is %s)\n",
ip1,
prefix,
net,
rip
);
ret = 1;
}

if ( strcmp (long2ip_r (broadcast (ip2long((char *) ip1), lmask), rip), bcast) == 0 ) {
printf (
"PASS: + broadcast (%s/%u => %s)\n",
ip1,
prefix,
rip
);
} else {
printf (
"FAIL: + broadcast (%s/%u == %s, but result is %s)\n",
ip1,
prefix,
bcast,
rip
);
ret = 1;
}

return ret;
}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
75 changes: 75 additions & 0 deletions test/prefix_conv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org/>
*
* This file is part of libipcalc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>
#include <ipcalc.h>

int main (void) {
ulong lmask = 4294967280UL;
short prefix = 28;
short decfix;
ulong decmask;
int ret = 0;

decmask = prefix2long (prefix);
if ( decmask == lmask ) {
printf (
"PASS: + prefix2long (prefix %u => %lu)\n",
prefix,
decmask
);
} else {
printf (
"FAIL: + prefix2long (prefix %u == %lu, but result is %lu)\n",
prefix,
lmask,
decmask
);
ret = 1;
}

decfix = long2prefix (lmask);
if ( decfix == prefix ) {
printf (
"PASS: + long2prefix (decimal ip %lu => %u)\n",
lmask,
decfix
);
} else {
printf (
"FAIL: + long2prefix (decimal ip %lu == %u, but result is %u)\n",
lmask,
prefix,
decfix
);
ret = 1;
}

return ret;
}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
Loading

0 comments on commit 8da352a

Please sign in to comment.