Browse Source

Update testcases to work with current Check API

Some calls of the Check API (fail_unless(), fail_if(), ...) were
 deprecated long ago and no longer compile correctly (#980607).  This
 patch works in the new calls and adds some polish where needed.
 .
 test/srunner.c: The Check API was apparently changed at some point to
 derive testcase names from function names plus a "_fn" suffix which
 breaks an old testcase.  Test for that and use the old name for now.
 .
 Patch from Dennis Filder <d.filder@web.de>.
tags/1.171
Francisco Vilmar Cardoso Ruviaro 3 months ago
parent
commit
880e903c45
No known key found for this signature in database GPG Key ID: 82FBF7060B2F7D00
7 changed files with 65 additions and 48 deletions
  1. +19
    -2
      test/srunner.c
  2. +4
    -4
      test/test_inet_mton.c
  3. +5
    -5
      test/test_inet_ptom.c
  4. +1
    -1
      test/test_nc_v6_interface_configured.c
  5. +8
    -8
      test/test_netcfg_gateway_reachable.c
  6. +8
    -8
      test/test_netcfg_network_address.c
  7. +20
    -20
      test/test_netcfg_parse_cidr_address.c

+ 19
- 2
test/srunner.c View File

@@ -49,22 +49,39 @@ int main(int argc, char *argv[])
void srunner_mock_path(const char *testcase)
{
char *new_path;
char *testcasedir;
unsigned int new_path_len;
unsigned int l;
original_path = strdup(getenv("PATH"));
testcasedir = strdup(testcase);
if (testcasedir && (l=strlen(testcasedir)) >= 3 \
&& testcasedir[l-3]=='_' \
&& testcasedir[l-2]=='f' \
&& testcasedir[l-1]=='n')
testcasedir[l-3]='\0'; /* prune "_fn" suffix */
else {
if (testcasedir)
free(testcasedir);
testcasedir = NULL;
}
new_path_len = strlen(test_run_root)
+ 12 /* /mock_paths/ */
+ strlen(testcase) + 1 /* : */
+ strlen(testcasedir?testcasedir:testcase) + 1 /* : */
+ strlen(original_path) + 1 /* \0 */;
new_path = malloc(new_path_len);
snprintf(new_path, new_path_len, "%s/mock_paths/%s:%s", test_run_root, testcase, original_path);
snprintf(new_path, new_path_len, "%s/mock_paths/%s:%s",
test_run_root, testcasedir?testcasedir:testcase,
original_path);
setenv("PATH", new_path, 1);
free(new_path);
if (testcasedir)
free(testcasedir);
}

void srunner_reset_path()


+ 4
- 4
test/test_inet_mton.c View File

@@ -8,7 +8,7 @@ START_TEST(test_inet_mton_v4_24)
inet_mton(AF_INET, 24, &addr);
fail_unless (memcmp(expected, &(addr.s_addr), 4) == 0,
ck_assert_msg (memcmp(expected, &(addr.s_addr), 4) == 0,
"Mask address wasn't 24 bits");
}
END_TEST
@@ -20,7 +20,7 @@ START_TEST(test_inet_mton_v4_22)
inet_mton(AF_INET, 22, &addr);
fail_unless (memcmp(expected, &(addr.s_addr), 4) == 0,
ck_assert_msg (memcmp(expected, &(addr.s_addr), 4) == 0,
"Mask address wasn't 22 bits");
}
END_TEST
@@ -34,7 +34,7 @@ START_TEST(test_inet_mton_v6_64)
inet_mton(AF_INET6, 64, &addr);
fail_unless (memcmp(expected, addr.s6_addr, 16) == 0,
ck_assert_msg (memcmp(expected, addr.s6_addr, 16) == 0,
"Mask address wasn't 64 bits");
}
END_TEST
@@ -48,7 +48,7 @@ START_TEST(test_inet_mton_v6_60)
inet_mton(AF_INET6, 60, &addr);

fail_unless (memcmp(expected, addr.s6_addr, 16) == 0,
ck_assert_msg (memcmp(expected, addr.s6_addr, 16) == 0,
"Mask address wasn't 60 bits");
}
END_TEST


+ 5
- 5
test/test_inet_ptom.c View File

@@ -7,7 +7,7 @@ START_TEST(test_inet_ptom_v4_24)
inet_ptom(AF_INET, "255.255.255.0", &masklen);
fail_unless (24 == masklen, "Expected masklen == 24, masklen was %i", masklen);
ck_assert_msg (24 == masklen, "Expected masklen == 24, masklen was %i", masklen);
}
END_TEST

@@ -17,7 +17,7 @@ START_TEST(test_inet_ptom_v4_22)
inet_ptom(AF_INET, "255.255.252.0", &masklen);
fail_unless (22 == masklen, "Expected masklen == 22, masklen was %i", masklen);
ck_assert_msg (22 == masklen, "Expected masklen == 22, masklen was %i", masklen);
}
END_TEST

@@ -27,7 +27,7 @@ START_TEST(test_inet_ptom_v6_64)
inet_ptom(AF_INET6, "ffff:ffff:ffff:ffff::", &masklen);
fail_unless (64 == masklen, "Expected masklen == 64, masklen was %i", masklen);
ck_assert_msg (64 == masklen, "Expected masklen == 64, masklen was %i", masklen);
}
END_TEST

@@ -37,7 +37,7 @@ START_TEST(test_inet_ptom_v6_60)
inet_ptom(AF_INET6, "ffff:ffff:ffff:fff0::", &masklen);
fail_unless (60 == masklen, "Expected masklen == 60, masklen was %i", masklen);
ck_assert_msg (60 == masklen, "Expected masklen == 60, masklen was %i", masklen);
}
END_TEST

@@ -51,7 +51,7 @@ START_TEST(test_inet_ptom_v6_60_with_scraps)
*/
inet_ptom(AF_INET6, "ffff:ffff:ffff:fff0:ffff::", &masklen);
fail_unless (60 == masklen, "Expected masklen == 60, masklen was %i", masklen);
ck_assert_msg (60 == masklen, "Expected masklen == 60, masklen was %i", masklen);
}
END_TEST



+ 1
- 1
test/test_nc_v6_interface_configured.c View File

@@ -15,7 +15,7 @@ START_TEST(test_nc_v6_interface_configured_simple)
rv = nc_v6_interface_configured(&iface, 0);
fail_unless(rv == 1, "Didn't find SLAAC");
ck_assert_msg(rv == 1, "Didn't find SLAAC");
srunner_reset_path();
}


+ 8
- 8
test/test_netcfg_gateway_reachable.c View File

@@ -11,12 +11,12 @@ START_TEST(test_netcfg_gateway_reachable_v4_24)
iface.masklen = 24;
iface.address_family = AF_INET;
fail_unless (netcfg_gateway_reachable(&iface),
ck_assert_msg (netcfg_gateway_reachable(&iface),
"Gateway erroneously unreachable");

strcpy(iface.gateway, "192.168.2.254");
fail_if (netcfg_gateway_reachable(&iface),
ck_assert_msg (!netcfg_gateway_reachable(&iface),
"Gateway erroneously reachable");
}
END_TEST
@@ -31,12 +31,12 @@ START_TEST(test_netcfg_gateway_reachable_v4_22)
iface.masklen = 22;
iface.address_family = AF_INET;
fail_unless (netcfg_gateway_reachable(&iface),
ck_assert_msg (netcfg_gateway_reachable(&iface),
"Gateway erroneously unreachable");

strcpy(iface.gateway, "192.168.4.254");
fail_if (netcfg_gateway_reachable(&iface),
ck_assert_msg (!netcfg_gateway_reachable(&iface),
"Gateway erroneously reachable");
}
END_TEST
@@ -51,12 +51,12 @@ START_TEST(test_netcfg_gateway_reachable_v6_64)
iface.masklen = 64;
iface.address_family = AF_INET6;
fail_unless (netcfg_gateway_reachable(&iface),
ck_assert_msg (netcfg_gateway_reachable(&iface),
"Gateway erroneously unreachable");

strcpy(iface.gateway, "2001:3:5::1");
fail_if (netcfg_gateway_reachable(&iface),
ck_assert_msg (!netcfg_gateway_reachable(&iface),
"Gateway erroneously reachable");
}
END_TEST
@@ -71,12 +71,12 @@ START_TEST(test_netcfg_gateway_reachable_v6_48)
iface.masklen = 48;
iface.address_family = AF_INET6;
fail_unless (netcfg_gateway_reachable(&iface),
ck_assert_msg (netcfg_gateway_reachable(&iface),
"Gateway erroneously unreachable");

strcpy(iface.gateway, "2001:3:6::1");
fail_if (netcfg_gateway_reachable(&iface),
ck_assert_msg (!netcfg_gateway_reachable(&iface),
"Gateway erroneously reachable");
}
END_TEST


+ 8
- 8
test/test_netcfg_network_address.c View File

@@ -13,8 +13,8 @@ START_TEST(test_netcfg_network_address_v4_24)
netcfg_network_address(&iface, network);
fail_unless (strcmp("192.168.1.0", network) == 0,
"Network address wrong; expected 192.168.1.0, got %s");
ck_assert_msg (strcmp("192.168.1.0", network) == 0,
"Network address wrong; expected 192.168.1.0, got %s", network);
}
END_TEST

@@ -30,8 +30,8 @@ START_TEST(test_netcfg_network_address_v4_22)
netcfg_network_address(&iface, network);
fail_unless (strcmp("192.168.16.0", network) == 0,
"Network address wrong; expected 192.168.16.0, got %s");
ck_assert_msg (strcmp("192.168.16.0", network) == 0,
"Network address wrong; expected 192.168.16.0, got %s", network);
}
END_TEST

@@ -47,8 +47,8 @@ START_TEST(test_netcfg_network_address_v6_64)
netcfg_network_address(&iface, network);
fail_unless (strcmp("2001:3:5:7::", network) == 0,
"Network address wrong; expected 2001:3:5:7::, got %s");
ck_assert_msg (strcmp("2001:3:5:7::", network) == 0,
"Network address wrong; expected 2001:3:5:7::, got %s", network);
}
END_TEST

@@ -64,8 +64,8 @@ START_TEST(test_netcfg_network_address_v6_48)
netcfg_network_address(&iface, network);
fail_unless (strcmp("2001:3:5::", network) == 0,
"Network address wrong; expected 2001:3:5::, got %s");
ck_assert_msg (strcmp("2001:3:5::", network) == 0,
"Network address wrong; expected 2001:3:5::, got %s", network);
}
END_TEST



+ 20
- 20
test/test_netcfg_parse_cidr_address.c View File

@@ -10,18 +10,18 @@ START_TEST(test_parse_standalone_v4_address)
interface.masklen = 7;
rv = netcfg_parse_cidr_address("192.0.2.12", &interface);

fail_unless (rv,
ck_assert_msg (rv,
"parsing failed, rv = %i", rv);
fail_unless (interface.masklen == 0,
ck_assert_msg (interface.masklen == 0,
"masklen was %i, should have been 0",
interface.masklen);

fail_unless (strcmp("192.0.2.12", interface.ipaddress) == 0,
ck_assert_msg (strcmp("192.0.2.12", interface.ipaddress) == 0,
"IP address was %s, should have been 192.10.2.12",
interface.ipaddress);

fail_unless (interface.address_family == AF_INET,
ck_assert_msg (interface.address_family == AF_INET,
"Address family should have been AF_INET");
}
END_TEST
@@ -35,18 +35,18 @@ START_TEST(test_parse_cidr_v4_address)
interface.masklen = 7;
rv = netcfg_parse_cidr_address("192.0.2.12/24", &interface);

fail_unless (rv,
ck_assert_msg (rv,
"parsing failed, rv = %i", rv);
fail_unless (interface.masklen == 24,
ck_assert_msg (interface.masklen == 24,
"masklen was %i, should have been 24",
interface.masklen);

fail_unless (strcmp("192.0.2.12", interface.ipaddress) == 0,
ck_assert_msg (strcmp("192.0.2.12", interface.ipaddress) == 0,
"IP address was %s, should have been 192.10.2.12",
interface.ipaddress);

fail_unless (interface.address_family == AF_INET,
ck_assert_msg (interface.address_family == AF_INET,
"Address family should have been AF_INET");
}
END_TEST
@@ -60,18 +60,18 @@ START_TEST(test_parse_standalone_v6_address)
interface.masklen = 7;
rv = netcfg_parse_cidr_address("fd80:0:0::2", &interface);

fail_unless (rv,
ck_assert_msg (rv,
"parsing failed, rv = %i", rv);
fail_unless (interface.masklen == 0,
ck_assert_msg (interface.masklen == 0,
"masklen was %i, should have been 0",
interface.masklen);

fail_unless (strcmp("fd80::2", interface.ipaddress) == 0,
ck_assert_msg (strcmp("fd80::2", interface.ipaddress) == 0,
"IP address was %s, should have been fd80::2",
interface.ipaddress);

fail_unless (interface.address_family == AF_INET6,
ck_assert_msg (interface.address_family == AF_INET6,
"Address family should have been AF_INET6");
}
END_TEST
@@ -85,18 +85,18 @@ START_TEST(test_parse_cidr_v6_address)
interface.masklen = 7;
rv = netcfg_parse_cidr_address("fd80:0::4/64", &interface);

fail_unless (rv,
ck_assert_msg (rv,
"parsing failed, rv = %i", rv);
fail_unless (interface.masklen == 64,
ck_assert_msg (interface.masklen == 64,
"masklen was %i, should have been 26",
interface.masklen);

fail_unless (strcmp("fd80::4", interface.ipaddress) == 0,
ck_assert_msg (strcmp("fd80::4", interface.ipaddress) == 0,
"IP address was %s, should have been fd80::4",
interface.ipaddress);

fail_unless (interface.address_family == AF_INET6,
ck_assert_msg (interface.address_family == AF_INET6,
"Address family should have been AF_INET6");
}
END_TEST
@@ -110,18 +110,18 @@ START_TEST(test_parse_cidr_ignore_leading_trailing_spaces)
interface.masklen = 7;
rv = netcfg_parse_cidr_address(" 192.0.2.12 ", &interface);

fail_unless (rv,
ck_assert_msg (rv,
"parsing failed, rv = %i", rv);

fail_unless (interface.masklen == 0,
ck_assert_msg (interface.masklen == 0,
"masklen was %i, should have been 0",
interface.masklen);

fail_unless (strcmp("192.0.2.12", interface.ipaddress) == 0,
ck_assert_msg (strcmp("192.0.2.12", interface.ipaddress) == 0,
"IP address was %s, should have been 192.10.2.12",
interface.ipaddress);

fail_unless (interface.address_family == AF_INET,
ck_assert_msg (interface.address_family == AF_INET,
"Address family should have been AF_INET");
}
END_TEST


Loading…
Cancel
Save