foxBMS - Unit Tests
1.4.0
The foxBMS Unit Tests API Documentation
test_mxm_bitextract.c
Go to the documentation of this file.
1
/**
2
*
3
* @copyright © 2010 - 2022, 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 2022-07-28 (date of last update)
47
* @version v1.4.0
48
* @ingroup UNIT_TEST_IMPLEMENTATION
49
* @prefix TEST
50
*
51
* @brief Test for test_mxm_bitextract.c
52
*
53
* @details def
54
*
55
*/
56
57
/*========== Includes =======================================================*/
58
#include "unity.h"
59
60
#include "
mxm_bitextract.h
"
61
62
/*========== Definitions and Implementations for Unit Test ==================*/
63
64
/*========== Setup and Teardown =============================================*/
65
void
setUp
(
void
) {
66
}
67
68
void
tearDown
(
void
) {
69
}
70
71
/*========== Test Cases =====================================================*/
72
/*
73
* tests for write function
74
*/
75
void
testWriteValuePositionZero
(
void
) {
76
uint8_t reg = 0u;
77
TEST_ASSERT_EQUAL(1u,
mxm_41bWriteValue
(1u, 1, 0, reg));
78
}
79
80
void
testWriteValuePositionOne
(
void
) {
81
uint8_t reg = 0u;
82
TEST_ASSERT_EQUAL(2u,
mxm_41bWriteValue
(1u, 1, 1, reg));
83
}
84
85
void
testWriteValuePositionOneWithBitZeroInRegister
(
void
) {
86
uint8_t reg = 1u;
87
TEST_ASSERT_EQUAL(3u,
mxm_41bWriteValue
(1u, 1, 1, reg));
88
}
89
90
void
testWriteValueTXPreambles
(
void
) {
91
uint8_t reg = 0u;
92
TEST_ASSERT_EQUAL((1u << 5u),
mxm_41bWriteValue
(1u, 1,
MXM_41B_TX_PREAMBLES
, reg));
93
}
94
95
void
testWriteValueKeepAlive
(
void
) {
96
uint8_t reg = 0u;
97
TEST_ASSERT_EQUAL(0xFu,
mxm_41bWriteValue
(0xFu, 4,
MXM_41B_KEEP_ALIVE
, reg));
98
}
99
100
void
testWriteValueRXErrorInt
(
void
) {
101
uint8_t reg = 0u;
102
TEST_ASSERT_EQUAL(128u,
mxm_41bWriteValue
(1u, 1,
MXM_41B_RX_ERROR
, reg));
103
}
104
105
void
testWriteValueOverflowInt
(
void
) {
106
uint8_t reg = 0u;
107
TEST_ASSERT_EQUAL(8u,
mxm_41bWriteValue
(1u, 1,
MXM_41B_RX_OVERFLOW_INT_ENABLE
, reg));
108
}
109
110
/*
111
* tests for read function
112
*/
113
void
testReadValuePositionZero
(
void
) {
114
uint8_t reg = 1u;
115
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 0));
116
}
117
118
void
testReadValuePositionZeroWithMoreBits
(
void
) {
119
uint8_t reg = 0xFu;
120
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 0));
121
}
122
123
void
testReadValuePositionOne
(
void
) {
124
uint8_t reg = 2u;
125
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 1));
126
}
127
128
void
testReadValuePositionOneWithMoreBits
(
void
) {
129
uint8_t reg = 7u;
130
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1, 1));
131
}
132
133
void
testReadValueTXPreambles
(
void
) {
134
uint8_t reg = 0b100000;
135
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_TX_PREAMBLES
));
136
}
137
138
void
testReadValueKeepAlive
(
void
) {
139
uint8_t reg = 0b1111;
140
TEST_ASSERT_EQUAL(0xFu,
mxm_41bReadValue
(reg, 4,
MXM_41B_KEEP_ALIVE
));
141
}
142
143
void
testReadValueKeepAliveOne
(
void
) {
144
uint8_t reg = 0b1;
145
TEST_ASSERT_EQUAL(0x1u,
mxm_41bReadValue
(reg, 4,
MXM_41B_KEEP_ALIVE
));
146
}
147
148
void
testReadValueKeepAliveFiveBits
(
void
) {
149
uint8_t reg = 0b11111;
150
TEST_ASSERT_EQUAL(0xFu,
mxm_41bReadValue
(reg, 4,
MXM_41B_KEEP_ALIVE
));
151
}
152
153
void
testReadValueRXError
(
void
) {
154
uint8_t reg = 0b10000000;
155
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_ERROR
));
156
}
157
158
void
testReadValueRXOverflowStatus
(
void
) {
159
uint8_t reg = 0b1000;
160
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_OVERFLOW_INT_ENABLE
));
161
}
162
163
void
testReadValueRXBusy
(
void
) {
164
uint8_t reg = 0b100000;
165
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_BUSY_STATUS
));
166
}
167
168
void
testReadValueRXEmptyStatus
(
void
) {
169
uint8_t reg = 0b1;
170
TEST_ASSERT_EQUAL(1u,
mxm_41bReadValue
(reg, 1,
MXM_41B_RX_EMPTY_STATUS
));
171
}
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:114
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:106
mxm_bitextract.h
Bit extraction function for MXM_17841b.
MXM_41B_KEEP_ALIVE
#define MXM_41B_KEEP_ALIVE
Definition:
mxm_bitextract.h:122
MXM_41B_RX_BUSY_STATUS
#define MXM_41B_RX_BUSY_STATUS
Definition:
mxm_bitextract.h:126
MXM_41B_RX_EMPTY_STATUS
#define MXM_41B_RX_EMPTY_STATUS
Definition:
mxm_bitextract.h:134
MXM_41B_RX_OVERFLOW_INT_ENABLE
#define MXM_41B_RX_OVERFLOW_INT_ENABLE
Definition:
mxm_bitextract.h:128
MXM_41B_RX_ERROR
#define MXM_41B_RX_ERROR
Definition:
mxm_bitextract.h:124
MXM_41B_TX_PREAMBLES
#define MXM_41B_TX_PREAMBLES
Definition:
mxm_bitextract.h:120
testReadValueRXOverflowStatus
void testReadValueRXOverflowStatus(void)
Definition:
test_mxm_bitextract.c:158
testReadValuePositionOneWithMoreBits
void testReadValuePositionOneWithMoreBits(void)
Definition:
test_mxm_bitextract.c:128
testWriteValueKeepAlive
void testWriteValueKeepAlive(void)
Definition:
test_mxm_bitextract.c:95
testReadValueKeepAliveFiveBits
void testReadValueKeepAliveFiveBits(void)
Definition:
test_mxm_bitextract.c:148
testReadValuePositionZero
void testReadValuePositionZero(void)
Definition:
test_mxm_bitextract.c:113
testWriteValuePositionOne
void testWriteValuePositionOne(void)
Definition:
test_mxm_bitextract.c:80
setUp
void setUp(void)
Definition:
test_mxm_bitextract.c:65
tearDown
void tearDown(void)
Definition:
test_mxm_bitextract.c:68
testWriteValueRXErrorInt
void testWriteValueRXErrorInt(void)
Definition:
test_mxm_bitextract.c:100
testReadValueKeepAliveOne
void testReadValueKeepAliveOne(void)
Definition:
test_mxm_bitextract.c:143
testWriteValuePositionOneWithBitZeroInRegister
void testWriteValuePositionOneWithBitZeroInRegister(void)
Definition:
test_mxm_bitextract.c:85
testWriteValueOverflowInt
void testWriteValueOverflowInt(void)
Definition:
test_mxm_bitextract.c:105
testReadValueRXEmptyStatus
void testReadValueRXEmptyStatus(void)
Definition:
test_mxm_bitextract.c:168
testWriteValueTXPreambles
void testWriteValueTXPreambles(void)
Definition:
test_mxm_bitextract.c:90
testReadValueTXPreambles
void testReadValueTXPreambles(void)
Definition:
test_mxm_bitextract.c:133
testWriteValuePositionZero
void testWriteValuePositionZero(void)
Definition:
test_mxm_bitextract.c:75
testReadValuePositionZeroWithMoreBits
void testReadValuePositionZeroWithMoreBits(void)
Definition:
test_mxm_bitextract.c:118
testReadValueRXError
void testReadValueRXError(void)
Definition:
test_mxm_bitextract.c:153
testReadValueKeepAlive
void testReadValueKeepAlive(void)
Definition:
test_mxm_bitextract.c:138
testReadValuePositionOne
void testReadValuePositionOne(void)
Definition:
test_mxm_bitextract.c:123
testReadValueRXBusy
void testReadValueRXBusy(void)
Definition:
test_mxm_bitextract.c:163
tests
unit
app
driver
afe
maxim
common
test_mxm_bitextract.c
Generated by
1.9.1