a752c7ab
elopes
add first test an...
|
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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 "byteorder.h"
#include "net/ipv4/addr.h"
#include "tests-ipv4_addr.h"
static void test_ipv4_addr_equal__unequal(void)
{
ipv4_addr_t a = { { 1, 1, 1, 0 } };
ipv4_addr_t b = { { 1, 1, 1, 1 } };
TEST_ASSERT(!ipv4_addr_equal(&a, &b));
}
static void test_ipv4_addr_equal__equal(void)
{
ipv4_addr_t a = { { 1, 1, 1, 1 } };
ipv4_addr_t b = { { 1, 1, 1, 1 } };
TEST_ASSERT(ipv4_addr_equal(&a, &b));
}
static void test_ipv4_addr_to_str__string_too_short(void)
{
ipv4_addr_t a = { { 1, 1, 1, 1 } };
char result[1];
TEST_ASSERT_NULL(ipv4_addr_to_str(result, &a, sizeof(result)));
}
static void test_ipv4_addr_to_str__addr_NULL(void)
{
char result[IPV4_ADDR_MAX_STR_LEN];
TEST_ASSERT_NULL(ipv4_addr_to_str(result, NULL, sizeof(result)));
}
static void test_ipv4_addr_to_str__result_NULL(void)
{
ipv4_addr_t a;
TEST_ASSERT_NULL(ipv4_addr_to_str(NULL, &a, IPV4_ADDR_MAX_STR_LEN));
}
static void test_ipv4_addr_to_str__success(void)
{
ipv4_addr_t a = { { 1, 1, 1, 1 } };
char result[IPV4_ADDR_MAX_STR_LEN];
TEST_ASSERT_EQUAL_STRING("1.1.1.1", ipv4_addr_to_str(result, &a, sizeof(result)));
}
static void test_ipv4_addr_to_str__success2(void)
{
ipv4_addr_t a = { { 0, 1, 12, 123 } };
char result[IPV4_ADDR_MAX_STR_LEN];
TEST_ASSERT_EQUAL_STRING("0.1.12.123", ipv4_addr_to_str(result, &a, sizeof(result)));
}
static void test_ipv4_addr_from_str__dot_start(void)
{
ipv4_addr_t result;
TEST_ASSERT_NULL(ipv4_addr_from_str(&result, ".1.12.123"));
}
static void test_ipv4_addr_from_str__double_dot(void)
{
ipv4_addr_t result;
TEST_ASSERT_NULL(ipv4_addr_from_str(&result, "0..12.123"));
}
static void test_ipv4_addr_from_str__string_too_long(void)
{
ipv4_addr_t result;
TEST_ASSERT_NULL(ipv4_addr_from_str(&result, "255.255.255.255.255"));
}
static void test_ipv4_addr_from_str__illegal_chars(void)
{
ipv4_addr_t result;
TEST_ASSERT_NULL(ipv4_addr_from_str(&result, "0.::ab-)"));
}
static void test_ipv4_addr_from_str__addr_NULL(void)
{
ipv4_addr_t result;
TEST_ASSERT_NULL(ipv4_addr_from_str(&result, NULL));
}
static void test_ipv4_addr_from_str__result_NULL(void)
{
TEST_ASSERT_NULL(ipv4_addr_from_str(NULL, "::"));
}
static void test_ipv4_addr_from_str__success(void)
{
ipv4_addr_t a = { { 1, 1, 1, 1 } };
ipv4_addr_t result;
TEST_ASSERT_NOT_NULL(ipv4_addr_from_str(&result, "1.1.1.1"));
TEST_ASSERT(ipv4_addr_equal(&a, &result));
}
static void test_ipv4_addr_from_str__success2(void)
{
ipv4_addr_t a = { { 0, 1, 12, 123 } }, result;
TEST_ASSERT_NOT_NULL(ipv4_addr_from_str(&result, "0.1.12.123"));
TEST_ASSERT(ipv4_addr_equal(&a, &result));
}
Test *tests_ipv4_addr_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_ipv4_addr_equal__unequal),
new_TestFixture(test_ipv4_addr_equal__equal),
new_TestFixture(test_ipv4_addr_to_str__string_too_short),
new_TestFixture(test_ipv4_addr_to_str__addr_NULL),
new_TestFixture(test_ipv4_addr_to_str__result_NULL),
new_TestFixture(test_ipv4_addr_to_str__success),
new_TestFixture(test_ipv4_addr_to_str__success2),
new_TestFixture(test_ipv4_addr_from_str__dot_start),
new_TestFixture(test_ipv4_addr_from_str__double_dot),
new_TestFixture(test_ipv4_addr_from_str__string_too_long),
new_TestFixture(test_ipv4_addr_from_str__illegal_chars),
new_TestFixture(test_ipv4_addr_from_str__addr_NULL),
new_TestFixture(test_ipv4_addr_from_str__result_NULL),
new_TestFixture(test_ipv4_addr_from_str__success),
new_TestFixture(test_ipv4_addr_from_str__success2),
};
EMB_UNIT_TESTCALLER(ipv4_addr_tests, NULL, NULL, fixtures);
return (Test *)&ipv4_addr_tests;
}
void tests_ipv4_addr(void)
{
TESTS_RUN(tests_ipv4_addr_tests());
}
/** @} */
|