Add BitfieldPack implementation.

This commit is contained in:
King_DuckZ 2018-11-20 08:56:43 +00:00
parent 4eb4209409
commit a7d0cefbb9
3 changed files with 189 additions and 0 deletions

View file

@ -6,6 +6,7 @@ add_executable(${PROJECT_NAME}
endianness_test.cpp
int_conv_test.cpp
reversed_sized_array_test.cpp
bitfield_pack_test.cpp
)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

View file

@ -0,0 +1,35 @@
/* Copyright 2016-2018 Michele Santullo
* This file is part of "duckhandy".
*
* "duckhandy" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "duckhandy" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "duckhandy". If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "duckhandy/bitfield_pack.hpp"
#include <cstdint>
TEST_CASE ("Check correctness in BitfieldPack", "[BitfieldPack][containers]") {
dhandy::BitfieldPack<uint8_t, 4, 7, 1> pack(0xAA);
CHECK(sizeof(pack) == sizeof(uint8_t) * 2);
CHECK(dhandy::get<0>(pack) == 0b1010U);
CHECK(dhandy::get<1>(pack) == 0b0101010U);
CHECK(dhandy::get<2>(pack) == 0b1U);
dhandy::set<0>(pack, 2);
CHECK(dhandy::get<0>(pack) == 2);
dhandy::set<1>(pack, 50);
CHECK(dhandy::get<1>(pack) == 50);
CHECK(dhandy::get<2>(pack) == 0b1U);
}