foxBMS - Unit Tests
1.2.1
The foxBMS Unit Tests API Documentation
test_mxm_bitextract.c
Go to the documentation of this file.
1
/**
2
*
3
* @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4
* All rights reserved.
5
*
6
* SPDX-License-Identifier: BSD-3-Clause
7
*
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are met:
10
*
11
* 1. Redistributions of source code must retain the above copyright notice, this
12
* list of conditions and the following disclaimer.
13
*
14
* 2. Redistributions in binary form must reproduce the above copyright notice,
15
* this list of conditions and the following disclaimer in the documentation
16
* and/or other materials provided with the distribution.
17
*
18
* 3. Neither the name of the copyright holder nor the names of its
19
* contributors may be used to endorse or promote products derived from
20
* this software without specific prior written permission.
21
*
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
*
33
* We kindly request you to use one or more of the following phrases to refer to
34
* foxBMS in your hardware, software, documentation or advertising materials:
35
*
36
* - ″This product uses parts of foxBMS®″
37
* - ″This product includes parts of foxBMS®″
38
* - ″This product is derived from foxBMS®″
39
*
40
*/
41
42
/**
43
* @file test_mxm_bitextract.c
44
* @author foxBMS Team
45
* @date 2020-04-07 (date of creation)
46
* @updated 2020-05-14 (date of last update)
47
* @ingroup UNIT_TEST_IMPLEMENTATION
48
* @prefix TEST
49
*
50
* @brief Test for test_mxm_bitextract.c
51
*
52
* @details def
53
*
54
*/
55
56
/*========== Includes =======================================================*/
57
#include "unity.h"
58
59
#include "
mxm_bitextract.h
"
60
61
/*========== Definitions and Implementations for Unit Test ==================*/
62
63
/*========== Setup and Teardown =============================================*/
64
void
setUp
(
void
) {
65
}
66
67
void
tearDown
(
void
) {
68
}
69
70
/*========== Test Cases =====================================================*/
71
/*
72
* tests for write function
73
*/
74
void
testWriteValuePositionZero
(
void
) {
75
uint8_t reg = 0u;
76
TEST_ASSERT_EQUAL(1u,
mxm_41bWriteValue
(1u, 1, 0, reg));
77
}
78
79
void
testWriteValuePositionOne
(
void
) {
80
uint8_t reg = 0u;
81
TEST_ASSERT_EQUAL(2u,
mxm_41bWriteValue
(1u, 1, 1, reg));
82
}
83
84
void
testWriteValuePositionOneWithBitZeroInRegister
(
void
) {
85
uint8_t reg = 1u;
86
TEST_ASSERT_EQUAL(3u,
mxm_41bWriteValue
(1u, 1, 1, reg));
87
}
88
89
void
testWriteValueTXPreambles
(
void
) {
90
uint8_t reg = 0u;
91
TEST_ASSERT_EQUAL((1u << 5u),
mxm_41bWriteValue
(1u, 1,
MXM_41B_TX_PREAMBLES
, reg));
92
}
93
94
void
testWriteValueKeepAlive
(
void
) {
95
uint8_t reg = 0u;
96
TEST_ASSERT_EQUAL(0xFu,
mxm_41bWriteValue
(0xFu, 4,
MXM_41B_KEEP_ALIVE
, reg));
97
}
98
99
void
testWriteValueRXErrorInt
(
void
) {
100
uint8_t reg = 0u;
101
TEST_ASSERT_EQUAL(128u,
mxm_41bWriteValue
(1u, 1,
MXM_41B_RX_ERROR
, reg));
102
}
103
104
void
testWriteValueOverflowInt
(
void
) {
105
uint8_t reg = 0u;
106
TEST_ASSERT_EQUAL(8u,
mxm_41bWriteValue
(1u, 1,
MXM_41B_RX_OVERFLOW_INT_ENABLE
, reg));
107
}
108
109
/*
110
* tests for read function
111
*/
112
void
testReadValuePositionZero
(
void
) {
113
uint8_t reg = 1u;
114
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 0));
115
}
116
117
void
testReadValuePositionZeroWithMoreBits
(
void
) {
118
uint8_t reg = 0xFu;
119
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 0));
120
}
121
122
void
testReadValuePositionOne
(
void
) {
123
uint8_t reg = 2u;
124
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 1));
125
}
126
127
void
testReadValuePositionOneWithMoreBits
(
void
) {
128
uint8_t reg = 7u;
129
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 1));
130
}
131
132
void
testReadValueTXPreambles
(
void
) {
133
uint8_t reg = 0b100000;
134
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_TX_PREAMBLES
));
135
}
136
137
void
testReadValueKeepAlive
(
void
) {
138
uint8_t reg = 0b1111;
139
TEST_ASSERT_EQUAL(0xFu,
mxm_41bReadValue
(reg, 4,
MXM_41B_KEEP_ALIVE
));
140
}
141
142
void
testReadValueKeepAliveOne
(
void
) {
143
uint8_t reg = 0b1;
144
TEST_ASSERT_EQUAL(0x1u,
mxm_41bReadValue
(reg, 4,
MXM_41B_KEEP_ALIVE
));
145
}
146
147
void
testReadValueKeepAliveFiveBits
(
void
) {
148
uint8_t reg = 0b11111;
149
TEST_ASSERT_EQUAL(0xFu,
mxm_41bReadValue
(reg, 4,
MXM_41B_KEEP_ALIVE
));
150
}
151
152
void
testReadValueRXError
(
void
) {
153
uint8_t reg = 0b10000000;
154
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_ERROR
));
155
}
156
157
void
testReadValueRXOverflowStatus
(
void
) {
158
uint8_t reg = 0b1000;
159
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_OVERFLOW_INT_ENABLE
));
160
}
161
162
void
testReadValueRXBusy
(
void
) {
163
uint8_t reg = 0b100000;
164
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_BUSY_STATUS
));
165
}
166
167
void
testReadValueRXEmptyStatus
(
void
) {
168
uint8_t reg = 0b1;
169
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_EMPTY_STATUS
));
170
}
mxm_41bWriteValue
MXM_41B_REG_BIT_VALUE mxm_41bWriteValue(MXM_41B_REG_BIT_VALUE value, uint8_t numberOfBits, MXM_41B_REG_BITS shift, uint8_t reg)
write a value to a register supplied as variable
Definition:
mxm_bitextract.c:105
mxm_41bReadValue
MXM_41B_REG_BIT_VALUE mxm_41bReadValue(uint8_t reg, uint8_t numberOfBits, MXM_41B_REG_BITS position)
read a value from a register supplied as variable
Definition:
mxm_bitextract.c:101
mxm_bitextract.h
Bit extraction function for MXM_17841b.
MXM_41B_KEEP_ALIVE
#define MXM_41B_KEEP_ALIVE
Definition:
mxm_bitextract.h:121
MXM_41B_RX_BUSY_STATUS
#define MXM_41B_RX_BUSY_STATUS
Definition:
mxm_bitextract.h:125
MXM_41B_RX_EMPTY_STATUS
#define MXM_41B_RX_EMPTY_STATUS
Definition:
mxm_bitextract.h:133
MXM_41B_RX_OVERFLOW_INT_ENABLE
#define MXM_41B_RX_OVERFLOW_INT_ENABLE
Definition:
mxm_bitextract.h:127
MXM_41B_RX_ERROR
#define MXM_41B_RX_ERROR
Definition:
mxm_bitextract.h:123
MXM_41B_TX_PREAMBLES
#define MXM_41B_TX_PREAMBLES
Definition:
mxm_bitextract.h:119
testReadValueRXOverflowStatus
void testReadValueRXOverflowStatus(void)
Definition:
test_mxm_bitextract.c:157
testReadValuePositionOneWithMoreBits
void testReadValuePositionOneWithMoreBits(void)
Definition:
test_mxm_bitextract.c:127
testWriteValueKeepAlive
void testWriteValueKeepAlive(void)
Definition:
test_mxm_bitextract.c:94
testReadValueKeepAliveFiveBits
void testReadValueKeepAliveFiveBits(void)
Definition:
test_mxm_bitextract.c:147
testReadValuePositionZero
void testReadValuePositionZero(void)
Definition:
test_mxm_bitextract.c:112
testWriteValuePositionOne
void testWriteValuePositionOne(void)
Definition:
test_mxm_bitextract.c:79
setUp
void setUp(void)
Definition:
test_mxm_bitextract.c:64
tearDown
void tearDown(void)
Definition:
test_mxm_bitextract.c:67
testWriteValueRXErrorInt
void testWriteValueRXErrorInt(void)
Definition:
test_mxm_bitextract.c:99
testReadValueKeepAliveOne
void testReadValueKeepAliveOne(void)
Definition:
test_mxm_bitextract.c:142
testWriteValuePositionOneWithBitZeroInRegister
void testWriteValuePositionOneWithBitZeroInRegister(void)
Definition:
test_mxm_bitextract.c:84
testWriteValueOverflowInt
void testWriteValueOverflowInt(void)
Definition:
test_mxm_bitextract.c:104
testReadValueRXEmptyStatus
void testReadValueRXEmptyStatus(void)
Definition:
test_mxm_bitextract.c:167
testWriteValueTXPreambles
void testWriteValueTXPreambles(void)
Definition:
test_mxm_bitextract.c:89
testReadValueTXPreambles
void testReadValueTXPreambles(void)
Definition:
test_mxm_bitextract.c:132
testWriteValuePositionZero
void testWriteValuePositionZero(void)
Definition:
test_mxm_bitextract.c:74
testReadValuePositionZeroWithMoreBits
void testReadValuePositionZeroWithMoreBits(void)
Definition:
test_mxm_bitextract.c:117
testReadValueRXError
void testReadValueRXError(void)
Definition:
test_mxm_bitextract.c:152
testReadValueKeepAlive
void testReadValueKeepAlive(void)
Definition:
test_mxm_bitextract.c:137
testReadValuePositionOne
void testReadValuePositionOne(void)
Definition:
test_mxm_bitextract.c:122
testReadValueRXBusy
void testReadValueRXBusy(void)
Definition:
test_mxm_bitextract.c:162
tests
unit
app
driver
afe
maxim
common
test_mxm_bitextract.c
Generated by
1.9.1