blob: 4376eee9fb7dfdd3335b5487a18630ee71d39a71 [file] [log] [blame]
Nikolai Artemiev702c58a2020-09-16 14:12:22 +10001/*
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
Edward O'Callaghan3cc70c22020-05-22 18:42:11 +100016#include <include/test.h>
17
18#include "flash.h"
19
20#include <stdint.h>
Edward O'Callaghan3cc70c22020-05-22 18:42:11 +100021
22void address_to_bits_test_success(void **state)
23{
24 (void) state; /* unused */
25 assert_int_equal(16, address_to_bits(0xAA55));
26}
27
28void bitcount_test_success(void **state)
29{
30 (void) state; /* unused */
31 assert_int_equal(4, bitcount(0xAA));
32}
33
34void minmax_test_success(void **state)
35{
36 (void) state; /* unused */
37 assert_int_equal(0x55, min(0xAA, 0x55));
38 assert_int_equal(0xAA, max(0xAA, 0x55));
39}
40
41void strcat_realloc_test_success(void **state)
42{
43 (void) state; /* unused */
44 const char src0[] = "hello";
45 const char src1[] = " world";
46 char *dest = calloc(1, 1);
47 dest = strcat_realloc(dest, src0);
48 dest = strcat_realloc(dest, src1);
49 assert_string_equal("hello world", dest);
50 free(dest);
51}
52
53void tolower_string_test_success(void **state)
54{
55 (void) state; /* unused */
56 char str[] = "HELLO AGAIN";
57 assert_string_equal("HELLO AGAIN", str);
58 tolower_string(str);
59 assert_string_equal("hello again", str);
60}
61
62void reverse_byte_test_success(void **state)
63{
64 (void) state; /* unused */
65 assert_int_equal(0x5A, reverse_byte(0x5A));
66 assert_int_equal(0x0F, reverse_byte(0xF0));
67}
68
69void reverse_bytes_test_success(void **state)
70{
71 (void) state; /* unused */
72 uint8_t src[] = { 0xAA, 0x55 };
73 uint8_t dst[2];
74 reverse_bytes(dst, src, 2);
75 assert_int_equal(src[0], dst[1]);
76 assert_int_equal(src[1], dst[0]);
77}