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