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
address_to_bits_test_success(void ** state)23 void address_to_bits_test_success(void **state)
24 {
25 (void) state; /* unused */
26 assert_int_equal(16, address_to_bits(0xAA55));
27 }
28
bitcount_test_success(void ** state)29 void bitcount_test_success(void **state)
30 {
31 (void) state; /* unused */
32 assert_int_equal(4, bitcount(0xAA));
33 }
34
minmax_test_success(void ** state)35 void minmax_test_success(void **state)
36 {
37 (void) state; /* unused */
38 assert_int_equal(0x55, min(0xAA, 0x55));
39 assert_int_equal(0xAA, max(0xAA, 0x55));
40 }
41
strcat_realloc_test_success(void ** state)42 void strcat_realloc_test_success(void **state)
43 {
44 (void) state; /* unused */
45 const char src0[] = "hello";
46 const char src1[] = " world";
47 char *dest = calloc(1, 1);
48 assert_non_null(dest);
49 dest = strcat_realloc(dest, src0);
50 dest = strcat_realloc(dest, src1);
51 assert_string_equal("hello world", dest);
52 free(dest);
53 }
54
tolower_string_test_success(void ** state)55 void tolower_string_test_success(void **state)
56 {
57 (void) state; /* unused */
58 char str[] = "HELLO AGAIN";
59 assert_string_equal("HELLO AGAIN", str);
60 tolower_string(str);
61 assert_string_equal("hello again", str);
62 }
63
reverse_byte_test_success(void ** state)64 void reverse_byte_test_success(void **state)
65 {
66 (void) state; /* unused */
67 assert_int_equal(0x5A, reverse_byte(0x5A));
68 assert_int_equal(0x0F, reverse_byte(0xF0));
69 }
70
reverse_bytes_test_success(void ** state)71 void reverse_bytes_test_success(void **state)
72 {
73 (void) state; /* unused */
74 uint8_t src[] = { 0xAA, 0x55 };
75 uint8_t dst[2];
76 reverse_bytes(dst, src, 2);
77 assert_int_equal(src[0], dst[1]);
78 assert_int_equal(src[1], dst[0]);
79 }
80