|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Arduino. All rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +/************************************************************************************** |
| 6 | + * INCLUDE |
| 7 | + **************************************************************************************/ |
| 8 | + |
| 9 | +#include <catch.hpp> |
| 10 | + |
| 11 | +#include <IPAddress.h> |
| 12 | + |
| 13 | +/************************************************************************************** |
| 14 | + * TEST CODE |
| 15 | + **************************************************************************************/ |
| 16 | + |
| 17 | +// These comparisons should always return false, as you can't compare an IPv6 to an int32_t |
| 18 | + |
| 19 | +TEST_CASE ("Testing implicit cast of IPv6 compatible (little endian) to uint32_t always false", "[IPAddress6-Operator-()-01]") |
| 20 | +{ |
| 21 | + // On little endian systems, considering only last four octets (ignoring the rest) |
| 22 | + arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); |
| 23 | + uint32_t const val_expected = ip; |
| 24 | + uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); |
| 25 | + REQUIRE((val_expected == val_actual) == false); |
| 26 | +} |
| 27 | + |
| 28 | +TEST_CASE ("Testing implicit cast of IPv6 full little endian to uint32_t always false", "[IPAddress6-Operator-()-01]") |
| 29 | +{ |
| 30 | + // On little endian systems (full value) |
| 31 | + arduino::IPAddress ip(129,168, 1,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0); |
| 32 | + uint32_t const val_expected = ip; |
| 33 | + uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); |
| 34 | + REQUIRE((val_expected == val_actual) == false); |
| 35 | +} |
| 36 | + |
| 37 | +TEST_CASE ("Testing implicit cast of IPv6 to uint32_t always false", "[IPAddress6-Operator-()-01]") |
| 38 | +{ |
| 39 | + // Actual value of the 128-bit IPv6 address, which is network byte order |
| 40 | + arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); |
| 41 | + uint32_t const val_expected = ip; |
| 42 | + uint32_t const val_actual = ((129 << 24) | (168 << 16) | (1 << 8) | 2); |
| 43 | + REQUIRE((val_expected == val_actual) == false); |
| 44 | +} |
0 commit comments