From: Kevin Day Date: Tue, 5 Dec 2023 06:03:14 +0000 (-0600) Subject: Bugfix: Update unit tests and fix problems exposed after fixing unit tests for f_netw... X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=c433df5cdee21abf93f2bb285434725ec6dec48f;p=fll Bugfix: Update unit tests and fix problems exposed after fixing unit tests for f_network_is_ip_address(). This is a follow up to these commits: - 0e69871e03990990e0ebdf1b496ece67c40f4b5e - 309f2625e983ef164c52543b492365fe92eed6d5 Add additional tests. Fix bad test data, such as where the string lengths are incorrect. Perform tests when "where" parameter both is NULL or is a valid pointer. The tests now handle validating the "where" parameter, when specified. Add additional comments to better communicate the logic in f_network_is_ip_address(). Properly handle the "where" parameter assignment. --- diff --git a/level_0/f_network/c/network.c b/level_0/f_network/c/network.c index dd0f22a..9a6585f 100644 --- a/level_0/f_network/c/network.c +++ b/level_0/f_network/c/network.c @@ -139,13 +139,11 @@ extern "C" { if (isxdigit(address.string[i])) { if (address.string[i] < f_string_ascii_0_s.string[0] || address.string[i] > f_string_ascii_9_s.string[0]) { - flag |= 0x1; + flag = 0x1; } - if (!where) { - if (at.start_1 > at.stop_1) { - at.start_1 = at.stop_1 = i; - } + if (at.start_1 > at.stop_1) { + at.start_1 = at.stop_1 = i; } ++count; @@ -167,6 +165,12 @@ extern "C" { if (address.string[i] == f_string_ascii_colon_s.string[0]) { flag = 0x1; + count = 0; + + // Reset position to allow proper counting of double quotes in later loop. + if (i) { + --i; + } break; } @@ -178,7 +182,7 @@ extern "C" { return; } - flag |= 0x3; + flag = 0x3; break; } @@ -188,26 +192,21 @@ extern "C" { return; } // for - if (i >= address.used) { + if (i >= address.used || (flag & 0x2) && i + 1 >= address.used) { state->status = F_false; return; } - at.start_1 = i; + at.stop_1 = i; if (flag & 0x1) { + state->status = F_network_version_six_not; // IPv6 flag additions: 0x2 == has bracket open, 0x4 == has forward slash, 0x8 = has double-colon, 0x10 = has no leading digit and no bracket open. if (flag & 0x2) { - ++i; - } - - state->status = F_network_version_six_not; - - if (count > 4 || i == address.used) return; - - if (!count) { + at.start_1 = ++i; + count = 0; // Skip past NULL characters. for (; i < address.used && !address.string[i]; ++i) { @@ -222,11 +221,15 @@ extern "C" { } // for if (i == address.used) return; - if (!(flag & 0x2)) flag |= 0x10; - at.start_1 = i; + at.stop_1 = i; + } + else if (!count) { + flag |= 0x10; } + if (count > 4 || i == address.used) return; + // Process address, counting all sets. for (; i < address.used; ++i) { @@ -250,7 +253,6 @@ extern "C" { else if (address.string[i] == f_string_ascii_colon_s.string[0]) { if (flag & 0x4) return; - at.stop_1 = i; at.start_2 = i + 1; if (at.start_2 < address.used) { @@ -275,7 +277,7 @@ extern "C" { flag |= 0x8; // Skip past NULL characters. - for (; at.start_2 < address.used && !address.string[at.start_2]; ++at.start_2) { + for (++at.start_2; at.start_2 < address.used && !address.string[at.start_2]; ++at.start_2) { if (state->interrupt) { state->interrupt((void *) state, 0); @@ -293,7 +295,16 @@ extern "C" { // Colons must be followed by a hexidecimal digit. if (!isxdigit(address.string[at.start_2])) return; - i = at.stop_1 = at.start_2; + // When double-colons lead, then set the start position at this digit. + if (!count && !set) { + at.start_1 = at.stop_1 = at.start_2; + } + else { + at.stop_1 = at.start_2; + } + + // Reset before the digit so that the outer loop properly handles digit. + i = at.start_2 - 1; } else { @@ -301,9 +312,17 @@ extern "C" { return; } - if (++set > 7) return; + if (set) { + if (++set > 7) return; + } + else { + + // When set is first defined, be sure to include the first set to the left of the colon. + set = 2; + } count = 0; + at.start_2 = 1; } else if (address.string[i] == f_string_ascii_slash_forward_s.string[0]) { if (flag & 0x4) return; @@ -313,9 +332,7 @@ extern "C" { else if (address.string[i] == f_string_ascii_bracket_close_s.string[0]) { if (!(flag & 0x2)) return; - if (!where) { - at.stop_1 = i - 1; - } + at.stop_1 = i - 1; // Skip past NULL characters. for (at.start_2 = i + 1; at.start_2 < address.used && !address.string[at.start_2]; ++at.start_2) { @@ -360,14 +377,20 @@ extern "C" { } // for // The double colon either must exist when set is smaller than 7 or the double colon must not exist at all. - if (set < 7 && !(flag & 0x8) || set == 7 && (flag & 0x8)) return; + if (flag & 0x8) { + if (set == 7) return; + } + else if (set < 7) return; state->status = F_network_version_six; - } - else { - // Only a colon (and port number) may follow a valid close bracket. - return; + if (where) { + if (at.stop_2 == address.used) { + at.stop_2 = address.used - 1; + } + + *where = at; + } } } else if (count || set) { @@ -395,14 +418,20 @@ extern "C" { // The double colon either must exist when set is smaller than 7 or the double colon must not exist at all. if (set < 7 && !(flag & 0x8) || set == 7 && (flag & 0x8)) return; - // A close bracket must exist if there is an open bracket. + // A close bracket must exist if there is an open bracket and this line should not be reached if a valid close bracket is found. if (flag & 0x2) return; if (!(flag & 0x10) || set || count) { state->status = F_network_version_six; - at.start_2 = 1; - at.stop_2 = 0; + // When there is no port, then the address end is at the end of the string. + if (at.start_2 > at.stop_2) { + at.stop_1 = i - 1; + } + else { + at.start_2 = 1; + at.stop_2 = 0; + } if (where) { *where = at; @@ -452,6 +481,9 @@ extern "C" { else if (address.string[i] == f_string_ascii_colon_s.string[0]) { if (set != 3 || (flag & 0x2)) return; + // The address ends before the colon. + at.stop_1 = i - 1; + if (flag & 0x4) { flag |= 0x8; } @@ -470,7 +502,9 @@ extern "C" { if (i == address.used) return; flag |= 0x2; - at.start_2 = i + 1; // Save the position that might represent the start of the port number. + + // Save the position that might represent the start of the port number. + at.start_2 = i + 1; } else if (address.string[i] == f_string_ascii_slash_forward_s.string[0]) { if ((flag & 0x4) || set != 3) return; @@ -484,6 +518,12 @@ extern "C" { } // for if (set == 3) { + + // When there is no port, then the address end is at the end of the string. + if (at.start_2 > at.stop_2) { + at.stop_1 = i - 1; + } + if (where) { *where = at; } diff --git a/level_0/f_network/c/network.h b/level_0/f_network/c/network.h index a3b7dd5..6521574 100644 --- a/level_0/f_network/c/network.h +++ b/level_0/f_network/c/network.h @@ -196,7 +196,7 @@ extern "C" { * * This alters state.status: * F_data_not on success but there is nothing to process (address.used is 0). - * F_false on success, but this is not an IP Address. + * F_false on success, but this is not an IP Address (could still look close to an IPv4 or IPv6 address). * F_network_version_four_not on success, but this is not an IP Address but looks close to a IPv4 address. * F_network_version_six_not on success, but this is not an IP Address but looks close to a IPv6 address. * F_network_version_four on success and this is an IPv4 address. diff --git a/level_0/f_network/tests/unit/c/test-network-is_ip_address.c b/level_0/f_network/tests/unit/c/test-network-is_ip_address.c index 99ec1b0..b092d02 100644 --- a/level_0/f_network/tests/unit/c/test-network-is_ip_address.c +++ b/level_0/f_network/tests/unit/c/test-network-is_ip_address.c @@ -8,8 +8,28 @@ extern "C" { void test__f_network_is_ip_address__returns_data_not(void **state) { f_state_t state_data = f_state_t_initialize; + f_range_double_t where = f_range_double_t_initialize; + + { + state_data.status = F_okay; + where.start_1 = 1; + where.start_2 = 1; + where.stop_1 = 0; + where.stop_2 = 0; + + f_network_is_ip_address(f_string_empty_s, &where, &state_data); + + assert_int_equal(state_data.status, F_data_not); + assert_int_equal(where.start_1, 1); + assert_int_equal(where.stop_1, 0); + assert_int_equal(where.start_2, 1); + assert_int_equal(where.stop_2, 0); + + } { + state_data.status = F_okay; + f_network_is_ip_address(f_string_empty_s, 0, &state_data); assert_int_equal(state_data.status, F_data_not); @@ -28,9 +48,26 @@ void test__f_network_is_ip_address__returns_false(void **state) { macro_f_string_static_t_initialize_1("localhost", 0, 9), macro_f_string_static_t_initialize_1("___", 0, 3), macro_f_string_static_t_initialize_1("]", 0, 1), + macro_f_string_static_t_initialize_1("[", 0, 1), }; - for (uint8_t i = 0; i < 7; ++i) { + f_range_double_t where = f_range_double_t_initialize; + + for (uint8_t i = 0; i < 8; ++i) { + + state_data.status = F_okay; + where.start_1 = 1; + where.start_2 = 1; + where.stop_1 = 0; + where.stop_2 = 0; + + f_network_is_ip_address(ips[i], &where, &state_data); + + assert_int_equal(state_data.status, F_false); + assert_int_equal(where.start_1, 1); + assert_int_equal(where.stop_1, 0); + assert_int_equal(where.start_2, 1); + assert_int_equal(where.stop_2, 0); state_data.status = F_okay; @@ -51,11 +88,11 @@ void test__f_network_is_ip_address__returns_network_version_four(void **state) { macro_f_string_static_t_initialize_1("127.0.0.1/24:80", 0, 15), }; - const f_number_unsigned_t port_starts[] = { - 0, - 0, - 10, - 13, + const f_range_double_t wheres[] = { + { .start_1 = 0, .stop_1 = 8, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 0, .stop_1 = 11, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 0, .stop_1 = 8, .start_2 = 10, .stop_2 = 11 }, + { .start_1 = 0, .stop_1 = 11, .start_2 = 13, .stop_2 = 14 }, }; f_range_double_t where = f_range_double_t_initialize; @@ -70,9 +107,17 @@ void test__f_network_is_ip_address__returns_network_version_four(void **state) { f_network_is_ip_address(ips[i], &where, &state_data); - // @todo this needs to test start and stop of both address and port. assert_int_equal(state_data.status, F_network_version_four); - assert_int_equal(where.start_2, (port_starts[i] ? port_starts[i] : 1)); + assert_int_equal(where.start_1, wheres[i].start_1); + assert_int_equal(where.stop_1, wheres[i].stop_1); + assert_int_equal(where.start_2, wheres[i].start_2); + assert_int_equal(where.stop_2, wheres[i].stop_2); + + state_data.status = F_okay; + + f_network_is_ip_address(ips[i], 0, &state_data); + + assert_int_equal(state_data.status, F_network_version_four); } // for } @@ -100,9 +145,25 @@ void test__f_network_is_ip_address__returns_network_version_four_not(void **stat macro_f_string_static_t_initialize_1(".127.0.0.1", 0, 10), }; + f_range_double_t where = f_range_double_t_initialize; + for (uint8_t i = 0; i < 17; ++i) { state_data.status = F_okay; + where.start_1 = 1; + where.start_2 = 1; + where.stop_1 = 0; + where.stop_2 = 0; + + f_network_is_ip_address(ips[i], &where, &state_data); + + assert_int_equal(state_data.status, F_network_version_four_not); + assert_int_equal(where.start_1, 1); + assert_int_equal(where.stop_1, 0); + assert_int_equal(where.start_2, 1); + assert_int_equal(where.stop_2, 0); + + state_data.status = F_okay; f_network_is_ip_address(ips[i], 0, &state_data); @@ -135,19 +196,19 @@ void test__f_network_is_ip_address__returns_network_version_six_not(void **state macro_f_string_static_t_initialize_1("::example/24", 0, 12), macro_f_string_static_t_initialize_1(":example/2a", 0, 11), macro_f_string_static_t_initialize_1("::example/2a", 0, 12), - macro_f_string_static_t_initialize_1("[:", 0, 1), - macro_f_string_static_t_initialize_1("[::", 0, 2), - macro_f_string_static_t_initialize_1("[:/24", 0, 4), - macro_f_string_static_t_initialize_1("[::/24", 0, 5), - macro_f_string_static_t_initialize_1("[:/2a", 0, 4), - macro_f_string_static_t_initialize_1("[::/2a", 0, 5), - macro_f_string_static_t_initialize_1("[:1/24", 0, 5), - macro_f_string_static_t_initialize_1("[::1/24", 0, 6), - macro_f_string_static_t_initialize_1("[:12345", 0, 6), - macro_f_string_static_t_initialize_1("[::12345", 0, 7), - macro_f_string_static_t_initialize_1("[:12345/24", 0, 9), - macro_f_string_static_t_initialize_1("[::12345/24", 0, 10), - macro_f_string_static_t_initialize_1("[::1/1234", 0, 8), + macro_f_string_static_t_initialize_1("[:", 0, 2), + macro_f_string_static_t_initialize_1("[::", 0, 3), + macro_f_string_static_t_initialize_1("[:/24", 0, 5), + macro_f_string_static_t_initialize_1("[::/24", 0, 6), + macro_f_string_static_t_initialize_1("[:/2a", 0, 5), + macro_f_string_static_t_initialize_1("[::/2a", 0, 6), + macro_f_string_static_t_initialize_1("[:1/24", 0, 6), + macro_f_string_static_t_initialize_1("[::1/24", 0, 7), + macro_f_string_static_t_initialize_1("[:12345", 0, 7), + macro_f_string_static_t_initialize_1("[::12345", 0, 8), + macro_f_string_static_t_initialize_1("[:12345/24", 0, 10), + macro_f_string_static_t_initialize_1("[::12345/24", 0, 11), + macro_f_string_static_t_initialize_1("[::1/1234", 0, 9), macro_f_string_static_t_initialize_1("[::1", 0, 4), macro_f_string_static_t_initialize_1("[::1/24", 0, 7), macro_f_string_static_t_initialize_1("[:example", 0, 9), @@ -156,7 +217,7 @@ void test__f_network_is_ip_address__returns_network_version_six_not(void **state macro_f_string_static_t_initialize_1("[::example/24", 0, 13), macro_f_string_static_t_initialize_1("[:example/2a", 0, 12), macro_f_string_static_t_initialize_1("[::example/2a", 0, 13), - macro_f_string_static_t_initialize_1("[:]", 0, 1), + macro_f_string_static_t_initialize_1("[:]", 0, 3), macro_f_string_static_t_initialize_1("[:1/24]", 0, 7), macro_f_string_static_t_initialize_1("[:1]/24", 0, 7), macro_f_string_static_t_initialize_1("[:1/2a]", 0, 7), @@ -185,6 +246,7 @@ void test__f_network_is_ip_address__returns_network_version_six_not(void **state macro_f_string_static_t_initialize_1("[::example/2a]", 0, 14), macro_f_string_static_t_initialize_1("[:example]/2a", 0, 13), macro_f_string_static_t_initialize_1("[::example]/2a", 0, 14), + macro_f_string_static_t_initialize_1("[::example]:80_map", 0, 18), macro_f_string_static_t_initialize_1("1234::example", 0, 13), macro_f_string_static_t_initialize_1("1234:example", 0, 12), macro_f_string_static_t_initialize_1("1234:1234:1234:1234:1234:1234:1234:1234:1234", 0, 44), @@ -213,9 +275,39 @@ void test__f_network_is_ip_address__returns_network_version_six_not(void **state macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567:89AB:CDEF]/24", 0, 40), macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567:89AB:CDEF]/2a", 0, 40), macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567:89AB:CDEF]/1234", 0, 42), + macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567:89AB:CDEF]:80_map", 0, 44), + macro_f_string_static_t_initialize_1("[::1]:80not", 0, 11), + macro_f_string_static_t_initialize_1("[::1/24]:80ton", 0, 14), + macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567:89AB:CDEF]:80ton", 0, 43), + macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567::CDEF]:80not", 0, 39), + macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123::CDEF]:80otn", 0, 34), + macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30::CDEF]:80nto", 0, 30), + macro_f_string_static_t_initialize_1("[2001:0DB8:0::CDEF]:80ttt", 0, 25), + macro_f_string_static_t_initialize_1("[2001:0DB8::CDEF]:80ooo", 0, 23), + macro_f_string_static_t_initialize_1("[2001::CDEF]:80nnn", 0, 18), + macro_f_string_static_t_initialize_1("[2001::0DB8:CDEF]:80_to", 0, 23), + macro_f_string_static_t_initialize_1("[2001:0DB8::0:CDEF]:80_no", 0, 25), + macro_f_string_static_t_initialize_1("[2001::0DB8:0:CD30:CDEF]:80*to", 0, 30), + macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30::123:4567:CDEF]:80$ot", 0, 39), }; - for (uint8_t i = 0; i < 98; ++i) { + f_range_double_t where = f_range_double_t_initialize; + + for (uint8_t i = 0; i < 112; ++i) { + + state_data.status = F_okay; + where.start_1 = 1; + where.start_2 = 1; + where.stop_1 = 0; + where.stop_2 = 0; + + f_network_is_ip_address(ips[i], &where, &state_data); + + assert_int_equal(state_data.status, F_network_version_six_not); + assert_int_equal(where.start_1, 1); + assert_int_equal(where.stop_1, 0); + assert_int_equal(where.start_2, 1); + assert_int_equal(where.stop_2, 0); state_data.status = F_okay; @@ -236,12 +328,12 @@ void test__f_network_is_ip_address__returns_network_version_six(void **state) { macro_f_string_static_t_initialize_1("::1/24", 0, 6), macro_f_string_static_t_initialize_1("[::1/24]", 0, 8), macro_f_string_static_t_initialize_1("[::1/24]:80", 0, 11), - macro_f_string_static_t_initialize_1("2001:0DB8:0:CD30:123:4567:89AB:CDEF", 0, 35), - macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567:89AB:CDEF]", 0, 37), - macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567:89AB:CDEF]:80", 0, 40), - macro_f_string_static_t_initialize_1("2001:0DB8:0:CD30:123:4567::CDEF", 0, 31), - macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567::CDEF]", 0, 33), - macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123:4567::CDEF]:80", 0, 36), + macro_f_string_static_t_initialize_1("2001:0DB8:CD30:123:4567:89AB:CDEF", 0, 33), + macro_f_string_static_t_initialize_1("[2001:0DB8:CD30:123:4567:89AB:CDEF]", 0, 35), + macro_f_string_static_t_initialize_1("[2001:0DB8:CD30:123:4567:89AB:CDEF]:80", 0, 38), + macro_f_string_static_t_initialize_1("2001:0DB8:CD30:123:4567::CDEF", 0, 29), + macro_f_string_static_t_initialize_1("[2001:0DB8:CD30:123:4567::CDEF]", 0, 31), + macro_f_string_static_t_initialize_1("[2001:0DB8:CD30:123:4567::CDEF]:80", 0, 34), macro_f_string_static_t_initialize_1("2001:0DB8:0:CD30:123::CDEF", 0, 26), macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123::CDEF]", 0, 28), macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30:123::CDEF]:80", 0, 31), @@ -269,54 +361,54 @@ void test__f_network_is_ip_address__returns_network_version_six(void **state) { macro_f_string_static_t_initialize_1("2001:0DB8:0:CD30::123:CDEF", 0, 26), macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30::123:CDEF]", 0, 28), macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30::123:CDEF]:80", 0, 31), - macro_f_string_static_t_initialize_1("2001:0DB8:0:CD30::123:4567:CDEF", 0, 31), - macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30::123:4567:CDEF]", 0, 33), - macro_f_string_static_t_initialize_1("[2001:0DB8:0:CD30::123:4567:CDEF]:80", 0, 36), + macro_f_string_static_t_initialize_1("2001:0DB8:CD30::123:4567:CDEF", 0, 29), + macro_f_string_static_t_initialize_1("[2001:0DB8:CD30::123:4567:CDEF]", 0, 31), + macro_f_string_static_t_initialize_1("[2001:0DB8:CD30::123:4567:CDEF]:80", 0, 34), }; - const f_number_unsigned_t port_starts[] = { - 0, - 0, - 6, - 0, - 0, - 9, - 0, - 0, - 38, - 0, - 0, - 34, - 0, - 0, - 29, - 0, - 0, - 25, - 0, - 0, - 20, - 0, - 0, - 18, - 0, - 0, - 13, - 0, - 0, - 18, - 0, - 0, - 20, - 0, - 0, - 25, - 0, - 0, - 29, - 0, - 0, - 34, + const f_range_double_t wheres[] = { + { .start_1 = 2, .stop_1 = 2, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 3, .stop_1 = 3, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 3, .stop_1 = 3, .start_2 = 6, .stop_2 = 7 }, + { .start_1 = 2, .stop_1 = 5, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 3, .stop_1 = 6, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 3, .stop_1 = 6, .start_2 = 9, .stop_2 = 10 }, + { .start_1 = 0, .stop_1 = 32, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 33, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 33, .start_2 = 36, .stop_2 = 37 }, + { .start_1 = 0, .stop_1 = 28, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 29, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 29, .start_2 = 32, .stop_2 = 33 }, + { .start_1 = 0, .stop_1 = 25, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 26, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 26, .start_2 = 29, .stop_2 = 30 }, + { .start_1 = 0, .stop_1 = 21, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 22, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 22, .start_2 = 25, .stop_2 = 26 }, + { .start_1 = 0, .stop_1 = 16, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 17, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 17, .start_2 = 20, .stop_2 = 21 }, + { .start_1 = 0, .stop_1 = 14, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 15, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 15, .start_2 = 18, .stop_2 = 19 }, + { .start_1 = 0, .stop_1 = 9, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 10, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 10, .start_2 = 13, .stop_2 = 14 }, + { .start_1 = 0, .stop_1 = 14, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 15, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 15, .start_2 = 18, .stop_2 = 19 }, + { .start_1 = 0, .stop_1 = 16, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 17, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 17, .start_2 = 20, .stop_2 = 21 }, + { .start_1 = 0, .stop_1 = 21, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 22, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 22, .start_2 = 25, .stop_2 = 26 }, + { .start_1 = 0, .stop_1 = 25, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 26, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 26, .start_2 = 29, .stop_2 = 30 }, + { .start_1 = 0, .stop_1 = 28, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 29, .start_2 = 1, .stop_2 = 0 }, + { .start_1 = 1, .stop_1 = 29, .start_2 = 32, .stop_2 = 33 }, }; f_range_double_t where = f_range_double_t_initialize; @@ -331,9 +423,17 @@ void test__f_network_is_ip_address__returns_network_version_six(void **state) { f_network_is_ip_address(ips[i], &where, &state_data); - // @todo this needs to test start and stop of both address and port. assert_int_equal(state_data.status, F_network_version_six); - assert_int_equal(where.start_2, (port_starts[i] ? port_starts[i] : 1)); + assert_int_equal(where.start_1, wheres[i].start_1); + assert_int_equal(where.stop_1, wheres[i].stop_1); + assert_int_equal(where.start_2, wheres[i].start_2); + assert_int_equal(where.stop_2, wheres[i].stop_2); + + state_data.status = F_okay; + + f_network_is_ip_address(ips[i], 0, &state_data); + + assert_int_equal(state_data.status, F_network_version_six); } // for }