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