Line data Source code
1 : /* 2 : Copyright (C) 2020 Red Hat, Inc. 3 : 4 : This library is free software; you can redistribute it and/or 5 : modify it under the terms of the GNU Lesser General Public 6 : License as published by the Free Software Foundation; either 7 : version 2.1 of the License, or (at your option) any later version. 8 : 9 : This library is distributed in the hope that it will be useful, 10 : but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : Lesser General Public License for more details. 13 : 14 : You should have received a copy of the GNU Lesser General Public 15 : License along with this library; if not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : /* Test that tests some utils.h functions */ 18 : #undef NDEBUG 19 : #include <config.h> 20 : #include <assert.h> 21 : #include <string.h> 22 : 23 : #include <common/utils.h> 24 : 25 1 : int main(void) 26 : { 27 : unsigned int i; 28 : uint8_t bytes[64]; 29 : 30 1 : memset(bytes, 0, sizeof(bytes)); 31 : 32 : // some early bytes 33 1 : set_bitmap(10, bytes); 34 1 : assert(bytes[1] == 0x4); 35 : 36 1 : assert(test_bitmap(10, bytes)); 37 1 : assert(!test_bitmap(12, bytes)); 38 : 39 1 : set_bitmap(12, bytes); 40 1 : assert(bytes[1] == 0x14); 41 : 42 1 : assert(test_bitmap(10, bytes)); 43 1 : assert(test_bitmap(12, bytes)); 44 : 45 : // some higher bytes, to check truncation 46 1 : assert(!test_bitmap(363, bytes)); 47 1 : assert(!test_bitmap(367, bytes)); 48 : 49 1 : set_bitmap(367, bytes); 50 1 : assert(!test_bitmap(363, bytes)); 51 1 : assert(test_bitmap(367, bytes)); 52 : 53 1 : set_bitmap(363, bytes); 54 1 : assert(test_bitmap(363, bytes)); 55 1 : assert(test_bitmap(367, bytes)); 56 : 57 : // check all bytes are zeroes except one set above 58 1 : bytes[1] = 0; 59 1 : bytes[45] = 0; 60 65 : for (i = 0; i < sizeof(bytes); ++i) { 61 64 : assert(bytes[i] == 0); 62 : } 63 : 64 1 : return 0; 65 : }