Debian Codegraph @

tests/flashrom.c

raw
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 <stdlib.h>
17
18 #include <include/test.h>
19 #include "tests.h"
20 #include "programmer.h"
21
22 #define assert_equal_and_free(text, expected) \
23 do { \
24 assert_string_equal(text, expected); \
25 free(text); \
26 } while (0)
27
28 #define assert_not_equal_and_free(text, expected) \
29 do { \
30 assert_string_not_equal(text, expected); \
31 free(text); \
32 } while (0)
33
34
35 void flashbuses_to_text_test_success(void **state)
36 {
37 (void) state; /* unused */
38
39 enum chipbustype bustype;
40 char *text;
41
42 bustype = BUS_NONSPI;
43 text = flashbuses_to_text(bustype);
44 assert_equal_and_free(text, "Non-SPI");
45
46 bustype |= BUS_PARALLEL;
47 text = flashbuses_to_text(bustype);
48 assert_not_equal_and_free(text, "Non-SPI, Parallel");
49
50 bustype = BUS_PARALLEL;
51 bustype |= BUS_LPC;
52 text = flashbuses_to_text(bustype);
53 assert_equal_and_free(text, "Parallel, LPC");
54
55 bustype |= BUS_FWH;
56 //BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
57 text = flashbuses_to_text(bustype);
58 assert_equal_and_free(text, "Non-SPI");
59
60 bustype |= BUS_SPI;
61 text = flashbuses_to_text(bustype);
62 assert_equal_and_free(text, "Parallel, LPC, FWH, SPI");
63
64 bustype |= BUS_PROG;
65 text = flashbuses_to_text(bustype);
66 assert_equal_and_free(text,
67 "Parallel, LPC, FWH, SPI, Programmer-specific");
68
69 bustype = BUS_NONE;
70 text = flashbuses_to_text(bustype);
71 assert_equal_and_free(text, "None");
72 }