| 1 |
/* |
| 2 |
* This file is part of the flashrom project. |
| 3 |
* |
| 4 |
* Copyright 2020 Google LLC |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; version 2 of the License. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
*/ |
| 15 |
|
| 16 |
#include <include/test.h> |
| 17 |
|
| 18 |
#include "tests.h" |
| 19 |
#include "flash.h" |
| 20 |
|
| 21 |
#include <stdint.h> |
| 22 |
#include <stdlib.h> |
| 23 |
|
| 24 |
void address_to_bits_test_success(void **state) |
| 25 |
{ |
| 26 |
(void) state; /* unused */ |
| 27 |
assert_int_equal(16, address_to_bits(0xAA55)); |
| 28 |
} |
| 29 |
|
| 30 |
void bitcount_test_success(void **state) |
| 31 |
{ |
| 32 |
(void) state; /* unused */ |
| 33 |
assert_int_equal(4, bitcount(0xAA)); |
| 34 |
} |
| 35 |
|
| 36 |
void minmax_test_success(void **state) |
| 37 |
{ |
| 38 |
(void) state; /* unused */ |
| 39 |
assert_int_equal(0x55, min(0xAA, 0x55)); |
| 40 |
assert_int_equal(0xAA, max(0xAA, 0x55)); |
| 41 |
} |
| 42 |
|
| 43 |
void strcat_realloc_test_success(void **state) |
| 44 |
{ |
| 45 |
(void) state; /* unused */ |
| 46 |
const char src0[] = "hello"; |
| 47 |
const char src1[] = " world"; |
| 48 |
char *dest = calloc(1, 1); |
| 49 |
assert_non_null(dest); |
| 50 |
dest = strcat_realloc(dest, src0); |
| 51 |
dest = strcat_realloc(dest, src1); |
| 52 |
assert_string_equal("hello world", dest); |
| 53 |
free(dest); |
| 54 |
} |
| 55 |
|
| 56 |
void tolower_string_test_success(void **state) |
| 57 |
{ |
| 58 |
(void) state; /* unused */ |
| 59 |
char str[] = "HELLO AGAIN"; |
| 60 |
assert_string_equal("HELLO AGAIN", str); |
| 61 |
tolower_string(str); |
| 62 |
assert_string_equal("hello again", str); |
| 63 |
} |
| 64 |
|
| 65 |
void reverse_byte_test_success(void **state) |
| 66 |
{ |
| 67 |
(void) state; /* unused */ |
| 68 |
assert_int_equal(0x5A, reverse_byte(0x5A)); |
| 69 |
assert_int_equal(0x0F, reverse_byte(0xF0)); |
| 70 |
} |
| 71 |
|
| 72 |
void reverse_bytes_test_success(void **state) |
| 73 |
{ |
| 74 |
(void) state; /* unused */ |
| 75 |
uint8_t src[] = { 0xAA, 0x55 }; |
| 76 |
uint8_t dst[2]; |
| 77 |
reverse_bytes(dst, src, 2); |
| 78 |
assert_int_equal(src[0], dst[1]); |
| 79 |
assert_int_equal(src[1], dst[0]); |
| 80 |
} |