| ... | ... |
@@ -8,11 +8,24 @@ |
| 8 | 8 |
|
| 9 | 9 |
#include "greatest/greatest.h" |
| 10 | 10 |
|
| 11 |
+#define ASSERT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d") |
|
| 12 |
+ |
|
| 11 | 13 |
static options_t default_options; |
| 14 |
+static choices_t choices; |
|
| 15 |
+ |
|
| 16 |
+static void setup(void *udata) {
|
|
| 17 |
+ (void)udata; |
|
| 18 |
+ |
|
| 19 |
+ options_init(&default_options); |
|
| 20 |
+ choices_init(&choices, &default_options); |
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+static void teardown(void *udata) {
|
|
| 24 |
+ (void)udata; |
|
| 25 |
+ choices_destroy(&choices); |
|
| 26 |
+} |
|
| 12 | 27 |
|
| 13 | 28 |
TEST test_choices_empty() {
|
| 14 |
- choices_t choices; |
|
| 15 |
- choices_init(&choices, &default_options); |
|
| 16 | 29 |
ASSERT_EQ(0, choices.size); |
| 17 | 30 |
ASSERT_EQ(0, choices.available); |
| 18 | 31 |
ASSERT_EQ(0, choices.selection); |
| ... | ... |
@@ -23,14 +36,10 @@ TEST test_choices_empty() {
|
| 23 | 36 |
choices_next(&choices); |
| 24 | 37 |
ASSERT_EQ(0, choices.selection); |
| 25 | 38 |
|
| 26 |
- choices_destroy(&choices); |
|
| 27 |
- |
|
| 28 | 39 |
PASS(); |
| 29 | 40 |
} |
| 30 | 41 |
|
| 31 | 42 |
TEST test_choices_1() {
|
| 32 |
- choices_t choices; |
|
| 33 |
- choices_init(&choices, &default_options); |
|
| 34 | 43 |
choices_add(&choices, "tags"); |
| 35 | 44 |
|
| 36 | 45 |
choices_search(&choices, ""); |
| ... | ... |
@@ -50,14 +59,10 @@ TEST test_choices_1() {
|
| 50 | 59 |
ASSERT(!strcmp(choices_get(&choices, 0), "tags")); |
| 51 | 60 |
ASSERT_EQ(NULL, choices_get(&choices, 1)); |
| 52 | 61 |
|
| 53 |
- choices_destroy(&choices); |
|
| 54 |
- |
|
| 55 | 62 |
PASS(); |
| 56 | 63 |
} |
| 57 | 64 |
|
| 58 | 65 |
TEST test_choices_2() {
|
| 59 |
- choices_t choices; |
|
| 60 |
- choices_init(&choices, &default_options); |
|
| 61 | 66 |
choices_add(&choices, "tags"); |
| 62 | 67 |
choices_add(&choices, "test"); |
| 63 | 68 |
|
| ... | ... |
@@ -100,17 +105,12 @@ TEST test_choices_2() {
|
| 100 | 105 |
ASSERT_STR_EQ("test", choices_get(&choices, 0));
|
| 101 | 106 |
ASSERT_STR_EQ("tags", choices_get(&choices, 1));
|
| 102 | 107 |
|
| 103 |
- choices_destroy(&choices); |
|
| 104 |
- |
|
| 105 | 108 |
PASS(); |
| 106 | 109 |
} |
| 107 | 110 |
|
| 108 | 111 |
TEST test_choices_without_search() {
|
| 109 | 112 |
/* Before a search is run, it should return no results */ |
| 110 | 113 |
|
| 111 |
- choices_t choices; |
|
| 112 |
- choices_init(&choices, &default_options); |
|
| 113 |
- |
|
| 114 | 114 |
ASSERT_EQ(0, choices.available); |
| 115 | 115 |
ASSERT_EQ(0, choices.selection); |
| 116 | 116 |
ASSERT_EQ(0, choices.size); |
| ... | ... |
@@ -123,27 +123,18 @@ TEST test_choices_without_search() {
|
| 123 | 123 |
ASSERT_EQ(1, choices.size); |
| 124 | 124 |
ASSERT_EQ(NULL, choices_get(&choices, 0)); |
| 125 | 125 |
|
| 126 |
- choices_destroy(&choices); |
|
| 127 |
- |
|
| 128 | 126 |
PASS(); |
| 129 | 127 |
} |
| 130 | 128 |
|
| 131 | 129 |
/* Regression test for segfault */ |
| 132 | 130 |
TEST test_choices_unicode() {
|
| 133 |
- choices_t choices; |
|
| 134 |
- choices_init(&choices, &default_options); |
|
| 135 |
- |
|
| 136 | 131 |
choices_add(&choices, "Edmund Husserl - Méditations cartésiennes - Introduction a la phénoménologie.pdf"); |
| 137 | 132 |
choices_search(&choices, "e"); |
| 138 | 133 |
|
| 139 |
- choices_destroy(&choices); |
|
| 140 | 134 |
PASS(); |
| 141 | 135 |
} |
| 142 | 136 |
|
| 143 | 137 |
TEST test_choices_large_input() {
|
| 144 |
- choices_t choices; |
|
| 145 |
- choices_init(&choices, &default_options); |
|
| 146 |
- |
|
| 147 | 138 |
int N = 100000; |
| 148 | 139 |
char *strings[N]; |
| 149 | 140 |
|
| ... | ... |
@@ -163,13 +154,12 @@ TEST test_choices_large_input() {
|
| 163 | 154 |
free(strings[i]); |
| 164 | 155 |
} |
| 165 | 156 |
|
| 166 |
- choices_destroy(&choices); |
|
| 167 |
- |
|
| 168 | 157 |
PASS(); |
| 169 | 158 |
} |
| 170 | 159 |
|
| 171 | 160 |
SUITE(choices_suite) {
|
| 172 |
- options_init(&default_options); |
|
| 161 |
+ SET_SETUP(setup, NULL); |
|
| 162 |
+ SET_TEARDOWN(teardown, NULL); |
|
| 173 | 163 |
|
| 174 | 164 |
RUN_TEST(test_choices_empty); |
| 175 | 165 |
RUN_TEST(test_choices_1); |
| ... | ... |
@@ -133,6 +133,7 @@ static theft_trial_res prop_positions_should_match_characters_in_string(char *ne |
| 133 | 133 |
} |
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 |
+ /* Matching characters must be in returned positions */ |
|
| 136 | 137 |
for (int i = 0; i < n; i++) {
|
| 137 | 138 |
if (toupper(needle[i]) != toupper(haystack[positions[i]])) {
|
| 138 | 139 |
return THEFT_TRIAL_FAIL; |