Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdeabbb8

Browse files
committed
Test IPv6 comparison to int32_t (should always not match)
1 parent3f7f18b commitdeabbb8

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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::IPAddressip(0,0,0,0,0,0,0,0,0,0,0,0,129,168,1,2);
23+
uint32_tconst val_expected = ip;
24+
uint32_tconst 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::IPAddressip(129,168,1,2,0,0,0,0,0,0,0,0,0,0,0,0);
32+
uint32_tconst val_expected = ip;
33+
uint32_tconst 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::IPAddressip(0,0,0,0,0,0,0,0,0,0,0,0,129,168,1,2);
41+
uint32_tconst val_expected = ip;
42+
uint32_tconst val_actual = ((129 <<24) | (168 <<16) | (1 <<8) |2);
43+
REQUIRE((val_expected == val_actual) ==false);
44+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp