fb11e647
vrobic
reseau statique a...
|
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
* Copyright (C) 2014, 2015 Martine Lenders <mail@martine-lenders.eu>
* * 2015 Freie Universitรคt Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
*
* @file
*/
#include <errno.h>
#include <stdint.h>
#include "embUnit/embUnit.h"
#include "net/gnrc/pkt.h"
#include "net/gnrc/nettype.h"
#include "unittests-constants.h"
#include "tests-pkt.h"
#define _INIT_ELEM(len, data, next) \
{ 1, (next), (data), (len), GNRC_NETTYPE_UNDEF }
#define _INIT_ELEM_STATIC_DATA(data, next) _INIT_ELEM(sizeof(data), data, next)
static void test_pkt_len__NULL(void)
{
TEST_ASSERT_EQUAL_INT(0, gnrc_pkt_len(NULL));
}
static void test_pkt_len__1_elem__size_MAX(void)
{
gnrc_pktsnip_t snip = _INIT_ELEM(SIZE_MAX, NULL, NULL);
TEST_ASSERT_EQUAL_INT(SIZE_MAX, gnrc_pkt_len(&snip));
}
static void test_pkt_len__1_elem__size_0(void)
{
gnrc_pktsnip_t snip = _INIT_ELEM(0, NULL, NULL);
TEST_ASSERT_EQUAL_INT(0, gnrc_pkt_len(&snip));
}
static void test_pkt_len__1_elem__size_data(void)
{
gnrc_pktsnip_t snip = _INIT_ELEM_STATIC_DATA(TEST_STRING8, NULL);
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), gnrc_pkt_len(&snip));
}
static void test_pkt_len__2_elem(void)
{
gnrc_pktsnip_t snip1 = _INIT_ELEM_STATIC_DATA(TEST_STRING8, NULL);
gnrc_pktsnip_t snip2 = _INIT_ELEM_STATIC_DATA(TEST_STRING12, &snip1);
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8) + sizeof(TEST_STRING12),
gnrc_pkt_len(&snip2));
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), gnrc_pkt_len(&snip1));
}
static void test_pkt_len__2_elem__overflow(void)
{
gnrc_pktsnip_t snip1 = _INIT_ELEM_STATIC_DATA(TEST_STRING8, NULL);
gnrc_pktsnip_t snip2 = _INIT_ELEM(SIZE_MAX, NULL, &snip1);
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8) - 1, gnrc_pkt_len(&snip2));
/* size should overflow */
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), gnrc_pkt_len(&snip1));
}
static void test_pkt_len__3_elem(void)
{
gnrc_pktsnip_t snip1 = _INIT_ELEM_STATIC_DATA(TEST_STRING8, NULL);
gnrc_pktsnip_t snip2 = _INIT_ELEM_STATIC_DATA(TEST_STRING12, &snip1);
gnrc_pktsnip_t snip3 = _INIT_ELEM(sizeof("a"), "a", &snip2);
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8) + sizeof(TEST_STRING12) + sizeof("a"),
gnrc_pkt_len(&snip3));
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8) + sizeof(TEST_STRING12), gnrc_pkt_len(&snip2));
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), gnrc_pkt_len(&snip1));
}
static void test_pkt_count__1_elem(void)
{
gnrc_pktsnip_t snip1 = _INIT_ELEM_STATIC_DATA(TEST_STRING8, NULL);
TEST_ASSERT_EQUAL_INT(1, gnrc_pkt_count(&snip1));
}
static void test_pkt_count__5_elem(void)
{
gnrc_pktsnip_t snip1 = _INIT_ELEM_STATIC_DATA(TEST_STRING8, NULL);
gnrc_pktsnip_t snip2 = _INIT_ELEM_STATIC_DATA(TEST_STRING12, &snip1);
gnrc_pktsnip_t snip3 = _INIT_ELEM(sizeof("a"), "a", &snip2);
gnrc_pktsnip_t snip4 = _INIT_ELEM_STATIC_DATA(TEST_STRING8, &snip3);
gnrc_pktsnip_t snip5 = _INIT_ELEM_STATIC_DATA(TEST_STRING8, &snip4);
TEST_ASSERT_EQUAL_INT(5, gnrc_pkt_count(&snip5));
}
static void test_pkt_count__null(void)
{
TEST_ASSERT_EQUAL_INT(0, gnrc_pkt_count(NULL));
}
Test *tests_pkt_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_pkt_len__NULL),
new_TestFixture(test_pkt_len__1_elem__size_MAX),
new_TestFixture(test_pkt_len__1_elem__size_0),
new_TestFixture(test_pkt_len__1_elem__size_data),
new_TestFixture(test_pkt_len__2_elem),
new_TestFixture(test_pkt_len__2_elem__overflow),
new_TestFixture(test_pkt_len__3_elem),
new_TestFixture(test_pkt_count__1_elem),
new_TestFixture(test_pkt_count__5_elem),
new_TestFixture(test_pkt_count__null),
};
EMB_UNIT_TESTCALLER(pkt_tests, NULL, NULL, fixtures);
return (Test *)&pkt_tests;
}
void tests_pkt(void)
{
TESTS_RUN(tests_pkt_tests());
}
/** @} */
|