Browse code

Fix warnings due to types in test

John Hawthorn authored on 27/04/2017 01:09:45
Showing 2 changed files

... ...
@@ -8,7 +8,7 @@
8 8
 
9 9
 #include "greatest/greatest.h"
10 10
 
11
-#define ASSERT_INT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d")
11
+#define ASSERT_SIZE_T_EQ(a,b) ASSERT_EQ_FMT((size_t)(a), (b), "%zu")
12 12
 
13 13
 static options_t default_options;
14 14
 static choices_t choices;
... ...
@@ -26,15 +26,15 @@ static void teardown(void *udata) {
26 26
 }
27 27
 
28 28
 TEST test_choices_empty() {
29
-	ASSERT_INT_EQ(0, choices.size);
30
-	ASSERT_INT_EQ(0, choices.available);
31
-	ASSERT_INT_EQ(0, choices.selection);
29
+	ASSERT_SIZE_T_EQ(0, choices.size);
30
+	ASSERT_SIZE_T_EQ(0, choices.available);
31
+	ASSERT_SIZE_T_EQ(0, choices.selection);
32 32
 
33 33
 	choices_prev(&choices);
34
-	ASSERT_INT_EQ(0, choices.selection);
34
+	ASSERT_SIZE_T_EQ(0, choices.selection);
35 35
 
36 36
 	choices_next(&choices);
37
-	ASSERT_INT_EQ(0, choices.selection);
37
+	ASSERT_SIZE_T_EQ(0, choices.selection);
38 38
 
39 39
 	PASS();
40 40
 }
... ...
@@ -43,21 +43,21 @@ TEST test_choices_1() {
43 43
 	choices_add(&choices, "tags");
44 44
 
45 45
 	choices_search(&choices, "");
46
-	ASSERT_INT_EQ(1, choices.available);
47
-	ASSERT_INT_EQ(0, choices.selection);
46
+	ASSERT_SIZE_T_EQ(1, choices.available);
47
+	ASSERT_SIZE_T_EQ(0, choices.selection);
48 48
 
49 49
 	choices_search(&choices, "t");
50
-	ASSERT_INT_EQ(1, choices.available);
51
-	ASSERT_INT_EQ(0, choices.selection);
50
+	ASSERT_SIZE_T_EQ(1, choices.available);
51
+	ASSERT_SIZE_T_EQ(0, choices.selection);
52 52
 
53 53
 	choices_prev(&choices);
54
-	ASSERT_INT_EQ(0, choices.selection);
54
+	ASSERT_SIZE_T_EQ(0, choices.selection);
55 55
 
56 56
 	choices_next(&choices);
57
-	ASSERT_INT_EQ(0, choices.selection);
57
+	ASSERT_SIZE_T_EQ(0, choices.selection);
58 58
 
59 59
 	ASSERT(!strcmp(choices_get(&choices, 0), "tags"));
60
-	ASSERT_INT_EQ(NULL, choices_get(&choices, 1));
60
+	ASSERT_EQ(NULL, choices_get(&choices, 1));
61 61
 
62 62
 	PASS();
63 63
 }
... ...
@@ -68,40 +68,40 @@ TEST test_choices_2() {
68 68
 
69 69
 	/* Empty search */
70 70
 	choices_search(&choices, "");
71
-	ASSERT_INT_EQ(0, choices.selection);
72
-	ASSERT_INT_EQ(2, choices.available);
71
+	ASSERT_SIZE_T_EQ(0, choices.selection);
72
+	ASSERT_SIZE_T_EQ(2, choices.available);
73 73
 
74 74
 	choices_next(&choices);
75
-	ASSERT_INT_EQ(1, choices.selection);
75
+	ASSERT_SIZE_T_EQ(1, choices.selection);
76 76
 	choices_next(&choices);
77
-	ASSERT_INT_EQ(0, choices.selection);
77
+	ASSERT_SIZE_T_EQ(0, choices.selection);
78 78
 
79 79
 	choices_prev(&choices);
80
-	ASSERT_INT_EQ(1, choices.selection);
80
+	ASSERT_SIZE_T_EQ(1, choices.selection);
81 81
 	choices_prev(&choices);
82
-	ASSERT_INT_EQ(0, choices.selection);
82
+	ASSERT_SIZE_T_EQ(0, choices.selection);
83 83
 
84 84
 	/* Filtered search */
85 85
 	choices_search(&choices, "te");
86
-	ASSERT_INT_EQ(1, choices.available);
87
-	ASSERT_INT_EQ(0, choices.selection);
86
+	ASSERT_SIZE_T_EQ(1, choices.available);
87
+	ASSERT_SIZE_T_EQ(0, choices.selection);
88 88
 	ASSERT_STR_EQ("test", choices_get(&choices, 0));
89 89
 
90 90
 	choices_next(&choices);
91
-	ASSERT_INT_EQ(0, choices.selection);
91
+	ASSERT_SIZE_T_EQ(0, choices.selection);
92 92
 
93 93
 	choices_prev(&choices);
94
-	ASSERT_INT_EQ(0, choices.selection);
94
+	ASSERT_SIZE_T_EQ(0, choices.selection);
95 95
 
96 96
 	/* No results */
97 97
 	choices_search(&choices, "foobar");
98
-	ASSERT_INT_EQ(0, choices.available);
99
-	ASSERT_INT_EQ(0, choices.selection);
98
+	ASSERT_SIZE_T_EQ(0, choices.available);
99
+	ASSERT_SIZE_T_EQ(0, choices.selection);
100 100
 
101 101
 	/* Different order due to scoring */
102 102
 	choices_search(&choices, "ts");
103
-	ASSERT_INT_EQ(2, choices.available);
104
-	ASSERT_INT_EQ(0, choices.selection);
103
+	ASSERT_SIZE_T_EQ(2, choices.available);
104
+	ASSERT_SIZE_T_EQ(0, choices.selection);
105 105
 	ASSERT_STR_EQ("test", choices_get(&choices, 0));
106 106
 	ASSERT_STR_EQ("tags", choices_get(&choices, 1));
107 107
 
... ...
@@ -111,17 +111,17 @@ TEST test_choices_2() {
111 111
 TEST test_choices_without_search() {
112 112
 	/* Before a search is run, it should return no results */
113 113
 
114
-	ASSERT_INT_EQ(0, choices.available);
115
-	ASSERT_INT_EQ(0, choices.selection);
116
-	ASSERT_INT_EQ(0, choices.size);
117
-	ASSERT_INT_EQ(NULL, choices_get(&choices, 0));
114
+	ASSERT_SIZE_T_EQ(0, choices.available);
115
+	ASSERT_SIZE_T_EQ(0, choices.selection);
116
+	ASSERT_SIZE_T_EQ(0, choices.size);
117
+	ASSERT_EQ(NULL, choices_get(&choices, 0));
118 118
 
119 119
 	choices_add(&choices, "test");
120 120
 
121
-	ASSERT_INT_EQ(0, choices.available);
122
-	ASSERT_INT_EQ(0, choices.selection);
123
-	ASSERT_INT_EQ(1, choices.size);
124
-	ASSERT_INT_EQ(NULL, choices_get(&choices, 0));
121
+	ASSERT_SIZE_T_EQ(0, choices.available);
122
+	ASSERT_SIZE_T_EQ(0, choices.selection);
123
+	ASSERT_SIZE_T_EQ(1, choices.size);
124
+	ASSERT_EQ(NULL, choices_get(&choices, 0));
125 125
 
126 126
 	PASS();
127 127
 }
... ...
@@ -146,7 +146,7 @@ TEST test_choices_large_input() {
146 146
 	choices_search(&choices, "12");
147 147
 
148 148
 	/* Must match `seq 0 99999 | grep '.*1.*2.*' | wc -l` */
149
-	ASSERT_INT_EQ(8146, choices.available);
149
+	ASSERT_SIZE_T_EQ(8146, choices.available);
150 150
 
151 151
 	ASSERT_STR_EQ("12", choices_get(&choices, 0));
152 152
 
... ...
@@ -7,7 +7,7 @@
7 7
 
8 8
 #define SCORE_TOLERANCE 0.000001
9 9
 #define ASSERT_SCORE_EQ(a,b) ASSERT_IN_RANGE((a), (b), SCORE_TOLERANCE)
10
-#define ASSERT_INT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d")
10
+#define ASSERT_SIZE_T_EQ(a,b) ASSERT_EQ_FMT((size_t)(a), (b), "%zu")
11 11
 
12 12
 /* has_match(char *needle, char *haystack) */
13 13
 TEST exact_match_should_return_true() {
... ...
@@ -134,9 +134,9 @@ TEST score_dot() {
134 134
 TEST positions_consecutive() {
135 135
 	size_t positions[3];
136 136
 	match_positions("amo", "app/models/foo", positions);
137
-	ASSERT_INT_EQ(0, positions[0]);
138
-	ASSERT_INT_EQ(4, positions[1]);
139
-	ASSERT_INT_EQ(5, positions[2]);
137
+	ASSERT_SIZE_T_EQ(0, positions[0]);
138
+	ASSERT_SIZE_T_EQ(4, positions[1]);
139
+	ASSERT_SIZE_T_EQ(5, positions[2]);
140 140
 
141 141
 	PASS();
142 142
 }
... ...
@@ -148,10 +148,10 @@ TEST positions_start_of_word() {
148 148
 	 */
149 149
 	size_t positions[4];
150 150
 	match_positions("amor", "app/models/order", positions);
151
-	ASSERT_INT_EQ(0, positions[0]);
152
-	ASSERT_INT_EQ(4, positions[1]);
153
-	ASSERT_INT_EQ(11, positions[2]);
154
-	ASSERT_INT_EQ(12, positions[3]);
151
+	ASSERT_SIZE_T_EQ(0, positions[0]);
152
+	ASSERT_SIZE_T_EQ(4, positions[1]);
153
+	ASSERT_SIZE_T_EQ(11, positions[2]);
154
+	ASSERT_SIZE_T_EQ(12, positions[3]);
155 155
 
156 156
 	PASS();
157 157
 }
... ...
@@ -159,12 +159,12 @@ TEST positions_start_of_word() {
159 159
 TEST positions_no_bonuses() {
160 160
 	size_t positions[2];
161 161
 	match_positions("as", "tags", positions);
162
-	ASSERT_INT_EQ(1, positions[0]);
163
-	ASSERT_INT_EQ(3, positions[1]);
162
+	ASSERT_SIZE_T_EQ(1, positions[0]);
163
+	ASSERT_SIZE_T_EQ(3, positions[1]);
164 164
 
165 165
 	match_positions("as", "examples.txt", positions);
166
-	ASSERT_INT_EQ(2, positions[0]);
167
-	ASSERT_INT_EQ(7, positions[1]);
166
+	ASSERT_SIZE_T_EQ(2, positions[0]);
167
+	ASSERT_SIZE_T_EQ(7, positions[1]);
168 168
 
169 169
 	PASS();
170 170
 }
... ...
@@ -172,9 +172,9 @@ TEST positions_no_bonuses() {
172 172
 TEST positions_multiple_candidates_start_of_words() {
173 173
 	size_t positions[3];
174 174
 	match_positions("abc", "a/a/b/c/c", positions);
175
-	ASSERT_INT_EQ(2, positions[0]);
176
-	ASSERT_INT_EQ(4, positions[1]);
177
-	ASSERT_INT_EQ(6, positions[2]);
175
+	ASSERT_SIZE_T_EQ(2, positions[0]);
176
+	ASSERT_SIZE_T_EQ(4, positions[1]);
177
+	ASSERT_SIZE_T_EQ(6, positions[2]);
178 178
 
179 179
 	PASS();
180 180
 }
... ...
@@ -182,9 +182,9 @@ TEST positions_multiple_candidates_start_of_words() {
182 182
 TEST positions_exact_match() {
183 183
 	size_t positions[3];
184 184
 	match_positions("foo", "foo", positions);
185
-	ASSERT_INT_EQ(0, positions[0]);
186
-	ASSERT_INT_EQ(1, positions[1]);
187
-	ASSERT_INT_EQ(2, positions[2]);
185
+	ASSERT_SIZE_T_EQ(0, positions[0]);
186
+	ASSERT_SIZE_T_EQ(1, positions[1]);
187
+	ASSERT_SIZE_T_EQ(2, positions[2]);
188 188
 
189 189
 	PASS();
190 190
 }