mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-02-02 07:00:42 +00:00
🐛 Fix Flags<N> data storage width (#26995)
* Fix Flags and associated unit tests
This commit is contained in:
parent
556da2b3fc
commit
d773570cd6
2 changed files with 15 additions and 26 deletions
|
@ -159,7 +159,7 @@ template <class L, class R> struct IF<true, L, R> { typedef L type; };
|
|||
// General Flags for some number of states
|
||||
template<size_t N>
|
||||
struct Flags {
|
||||
typedef uvalue_t(N) flagbits_t;
|
||||
typedef bits_t(N) flagbits_t;
|
||||
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1; } N8;
|
||||
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1, b8:1, b9:1, b10:1, b11:1, b12:1, b13:1, b14:1, b15:1; } N16;
|
||||
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1, b8:1, b9:1, b10:1, b11:1, b12:1, b13:1, b14:1, b15:1,
|
||||
|
|
|
@ -71,7 +71,7 @@ MARLIN_TEST(types, XYval_magnitude) {
|
|||
|
||||
MARLIN_TEST(types, XYval_small_large) {
|
||||
XYval<int> xy;
|
||||
|
||||
|
||||
xy.set(3, 4);
|
||||
TEST_ASSERT_EQUAL(3, xy.small());
|
||||
TEST_ASSERT_EQUAL(4, xy.large());
|
||||
|
@ -187,7 +187,7 @@ MARLIN_TEST(types, XYZval_magnitude) {
|
|||
|
||||
MARLIN_TEST(types, XYZval_small_large) {
|
||||
XYZval<int> xyz;
|
||||
|
||||
|
||||
xyz.set(3, 4, 5);
|
||||
TEST_ASSERT_EQUAL(3, xyz.small());
|
||||
TEST_ASSERT_EQUAL(5, xyz.large());
|
||||
|
@ -325,7 +325,7 @@ MARLIN_TEST(types, XYZEval_magnitude) {
|
|||
|
||||
MARLIN_TEST(types, XYZEval_small_large) {
|
||||
XYZEval<int> xyze;
|
||||
|
||||
|
||||
xyze.set(3, 4, 5, 6);
|
||||
TEST_ASSERT_EQUAL(3, xyze.small());
|
||||
TEST_ASSERT_EQUAL(6, xyze.large());
|
||||
|
@ -484,26 +484,23 @@ MARLIN_TEST(types, Flags_16) {
|
|||
|
||||
flags.set(0, true);
|
||||
flags.set(15, true);
|
||||
// BUG: The storage can only contain 8 bits!
|
||||
// TEST_ASSERT_EQUAL(32769, flags.b);
|
||||
TEST_ASSERT_EQUAL(1, flags.b);
|
||||
TEST_ASSERT_EQUAL(32769, flags.b);
|
||||
|
||||
flags.clear(0);
|
||||
TEST_ASSERT_EQUAL(0, flags.b);
|
||||
TEST_ASSERT_EQUAL(32768, flags.b);
|
||||
|
||||
flags.reset();
|
||||
flags.set(7, true);
|
||||
flags.set(15, true);
|
||||
TEST_ASSERT_EQUAL(true, flags.test(7));
|
||||
// BUG: This can't store a value above bit 7 right now
|
||||
TEST_ASSERT_EQUAL(false, flags.test(15));
|
||||
TEST_ASSERT_EQUAL(false, flags.test(8));
|
||||
TEST_ASSERT_EQUAL(true, flags.test(15));
|
||||
|
||||
TEST_ASSERT_EQUAL(true, flags[7]);
|
||||
// BUG: This can't store a value above bit 7 right now
|
||||
TEST_ASSERT_EQUAL(false, flags[15]);
|
||||
TEST_ASSERT_EQUAL(false, flags[8]);
|
||||
TEST_ASSERT_EQUAL(true, flags[15]);
|
||||
|
||||
// BUG: This size should be 2, but is incorrectly 1
|
||||
TEST_ASSERT_EQUAL(1, flags.size());
|
||||
TEST_ASSERT_EQUAL(2, flags.size());
|
||||
}
|
||||
|
||||
MARLIN_TEST(types, Flags_32) {
|
||||
|
@ -514,9 +511,7 @@ MARLIN_TEST(types, Flags_32) {
|
|||
|
||||
flags.set(0, true);
|
||||
flags.set(31, true);
|
||||
// BUG: The storage can only contain 8 bits!
|
||||
//TEST_ASSERT_EQUAL(2147483649, flags.b);
|
||||
TEST_ASSERT_EQUAL(1, flags.b);
|
||||
TEST_ASSERT_EQUAL(2147483649, flags.b);
|
||||
|
||||
flags.clear(0);
|
||||
flags.clear(31);
|
||||
|
@ -525,22 +520,16 @@ MARLIN_TEST(types, Flags_32) {
|
|||
flags.set(0, true);
|
||||
flags.set(31, true);
|
||||
TEST_ASSERT_EQUAL(true, flags.test(0));
|
||||
// BUG: This can't store a value above bit 7 right now
|
||||
TEST_ASSERT_EQUAL(false, flags.test(31));
|
||||
// TEST_ASSERT_EQUAL(true, flags.test(31));
|
||||
TEST_ASSERT_EQUAL(true, flags.test(31));
|
||||
TEST_ASSERT_EQUAL(false, flags.test(1));
|
||||
TEST_ASSERT_EQUAL(false, flags.test(30));
|
||||
|
||||
TEST_ASSERT_EQUAL(true, flags[0]);
|
||||
// BUG: This can't store a value above bit 7 right now
|
||||
TEST_ASSERT_EQUAL(false, flags[31]);
|
||||
// TEST_ASSERT_EQUAL(true, flags[31]);
|
||||
TEST_ASSERT_EQUAL(true, flags[31]);
|
||||
TEST_ASSERT_EQUAL(false, flags[1]);
|
||||
TEST_ASSERT_EQUAL(false, flags[30]);
|
||||
|
||||
// BUG: This size should be 4, but is incorrectly 1
|
||||
TEST_ASSERT_EQUAL(1, flags.size());
|
||||
// TEST_ASSERT_EQUAL(4, flags.size());
|
||||
TEST_ASSERT_EQUAL(4, flags.size());
|
||||
}
|
||||
|
||||
MARLIN_TEST(types, AxisFlags_const_as_bools) {
|
||||
|
|
Loading…
Reference in a new issue