test_bitmanip.cpp
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #include <test.h>
23 #include <bitmanip.h>
24 
25 void
26 misc_ut::test_bitmanip_set_bit()
27 {
28  this->expect_true(set_bit(0x00000000U, 0) == 0x00000001U);
29  this->expect_true(set_bit(0x00000000U, 8) == 0x00000100U);
30 }
31 
32 void
33 misc_ut::test_bitmanip_clear_bit()
34 {
35  this->expect_true(clear_bit(0xFFFFFFFFU, 0) == 0xFFFFFFFEU);
36  this->expect_true(clear_bit(0xFFFFFFFFU, 8) == 0xFFFFFEFFU);
37 }
38 
39 void
40 misc_ut::test_bitmanip_get_bit()
41 {
42  this->expect_true(get_bit(0xFFFFFFFFU, 0) == 1);
43  this->expect_true(get_bit(0x00000000U, 0) == 0);
44  this->expect_true(get_bit(0xFFFFFFFFU, 8) == 1);
45  this->expect_true(get_bit(0x00000000U, 8) == 0);
46 }
47 
48 void
49 misc_ut::test_bitmanip_is_bit_set()
50 {
51  this->expect_true(is_bit_set(0xFFFFFFFFU, 0) == true);
52  this->expect_true(is_bit_set(0x00000000U, 0) == false);
53  this->expect_true(is_bit_set(0xFFFFFFFFU, 8) == true);
54  this->expect_true(is_bit_set(0x00000000U, 8) == false);
55 }
56 
57 void
58 misc_ut::test_bitmanip_is_bit_cleared()
59 {
60  this->expect_true(is_bit_cleared(0xFFFFFFFFU, 0) == false);
61  this->expect_true(is_bit_cleared(0x00000000U, 0) == true);
62  this->expect_true(is_bit_cleared(0xFFFFFFFFU, 8) == false);
63  this->expect_true(is_bit_cleared(0x00000000U, 8) == true);
64 }
65 
66 void
67 misc_ut::test_bitmanip_num_bits_set()
68 {
69  this->expect_true(num_bits_set(0xFFFFFFFFU) == 32);
70  this->expect_true(num_bits_set(0x00000000U) == 0);
71 }
72 
73 void
74 misc_ut::test_bitmanip_get_bits()
75 {
76  this->expect_true(get_bits(0xFFFFFFFFU, 0x11111111U) == 0x11111111U);
77  this->expect_true(get_bits(0x00000000U, 0x11111111U) == 0x00000000U);
78  this->expect_true(get_bits(0x88888888U, 0x11111111U) == 0x00000000U);
79  this->expect_true(get_bits(0xF0F0F0F0U, 0x11111111U) == 0x10101010U);
80 }
81 
82 void
83 misc_ut::test_bitmanip_set_bits()
84 {
85  this->expect_true(set_bits(0xFFFFFFFFU, 0x00111100U, 0x00000000U) == 0xFFEEEEFFU);
86  this->expect_true(set_bits(0x00000000U, 0x00111100U, 0xFFFFFFFFU) == 0x00111100U);
87  this->expect_true(set_bits(0x88888888U, 0x00111100U, 0x00111100U) == 0x88999988U);
88  this->expect_true(set_bits(0xF0F0F0F0U, 0x00111100U, 0x00111100U) == 0xF0F1F1F0U);
89 }
auto num_bits_set(T t) noexcept
Definition: bitmanip.h:59
auto get_bit(T t, B b) noexcept
Definition: bitmanip.h:42
auto is_bit_cleared(T t, B b) noexcept
Definition: bitmanip.h:54
auto clear_bit(T t, B b) noexcept
Definition: bitmanip.h:36
auto set_bit(T t, B b) noexcept
Definition: bitmanip.h:30
auto get_bits(T t, M m) noexcept
Definition: bitmanip.h:65
auto is_bit_set(T t, B b) noexcept
Definition: bitmanip.h:48
auto set_bits(T t, M m, V v) noexcept
Definition: bitmanip.h:72
#define expect_true(a)