Mercurial > paster
comparison tests/test-database.c @ 52:ef9f7f40abd1
tests: fix
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 21 Dec 2020 20:32:56 +0100 |
parents | 62361336c415 |
children | fba88439ec0a |
comparison
equal
deleted
inserted
replaced
51:07b6887d3557 | 52:ef9f7f40abd1 |
---|---|
68 struct paste one = { | 68 struct paste one = { |
69 .title = estrdup("test 1"), | 69 .title = estrdup("test 1"), |
70 .author = estrdup("unit test"), | 70 .author = estrdup("unit test"), |
71 .language = estrdup("cpp"), | 71 .language = estrdup("cpp"), |
72 .code = estrdup("int main() {}"), | 72 .code = estrdup("int main() {}"), |
73 .duration = PASTE_HOUR, | 73 .duration = PASTE_DURATION_HOUR, |
74 .visible = true | 74 .visible = true |
75 }; | 75 }; |
76 | 76 |
77 if (!database_insert(&one)) | 77 if (!database_insert(&one)) |
78 GREATEST_FAIL(); | 78 GREATEST_FAIL(); |
83 GREATEST_ASSERT(pastes[0].id); | 83 GREATEST_ASSERT(pastes[0].id); |
84 GREATEST_ASSERT_STR_EQ(pastes[0].title, "test 1"); | 84 GREATEST_ASSERT_STR_EQ(pastes[0].title, "test 1"); |
85 GREATEST_ASSERT_STR_EQ(pastes[0].author, "unit test"); | 85 GREATEST_ASSERT_STR_EQ(pastes[0].author, "unit test"); |
86 GREATEST_ASSERT_STR_EQ(pastes[0].language, "cpp"); | 86 GREATEST_ASSERT_STR_EQ(pastes[0].language, "cpp"); |
87 GREATEST_ASSERT_STR_EQ(pastes[0].code, "int main() {}"); | 87 GREATEST_ASSERT_STR_EQ(pastes[0].code, "int main() {}"); |
88 GREATEST_ASSERT_EQ(pastes[0].duration, PASTE_HOUR); | 88 GREATEST_ASSERT_EQ(pastes[0].duration, PASTE_DURATION_HOUR); |
89 GREATEST_ASSERT(pastes[0].visible); | 89 GREATEST_ASSERT(pastes[0].visible); |
90 GREATEST_PASS(); | 90 GREATEST_PASS(); |
91 } | 91 } |
92 | 92 |
93 | 93 |
99 struct paste one = { | 99 struct paste one = { |
100 .title = estrdup("test 1"), | 100 .title = estrdup("test 1"), |
101 .author = estrdup("unit test"), | 101 .author = estrdup("unit test"), |
102 .language = estrdup("cpp"), | 102 .language = estrdup("cpp"), |
103 .code = estrdup("int main() {}"), | 103 .code = estrdup("int main() {}"), |
104 .duration = PASTE_HOUR, | 104 .duration = PASTE_DURATION_HOUR, |
105 .visible = false | 105 .visible = false |
106 }; | 106 }; |
107 | 107 |
108 if (!database_insert(&one)) | 108 if (!database_insert(&one)) |
109 GREATEST_FAIL(); | 109 GREATEST_FAIL(); |
119 { | 119 { |
120 static const int expected[] = { 2, 1, 0 }; | 120 static const int expected[] = { 2, 1, 0 }; |
121 struct paste pastes[3]; | 121 struct paste pastes[3]; |
122 size_t max = 3; | 122 size_t max = 3; |
123 struct paste pastie = { | 123 struct paste pastie = { |
124 .duration = PASTE_HOUR, | 124 .duration = PASTE_DURATION_HOUR, |
125 .visible = true | 125 .visible = true |
126 }; | 126 }; |
127 | 127 |
128 for (int i = 0; i < 3; ++i) { | 128 for (int i = 0; i < 3; ++i) { |
129 pastie.title = estrdup(bprintf("test %d", i)); | 129 pastie.title = estrdup(bprintf("test %d", i)); |
151 GREATEST_ASSERT_STR_EQ(pastes[i].author, | 151 GREATEST_ASSERT_STR_EQ(pastes[i].author, |
152 bprintf("unit test %d", expected[i])); | 152 bprintf("unit test %d", expected[i])); |
153 GREATEST_ASSERT_STR_EQ(pastes[i].language, "cpp"); | 153 GREATEST_ASSERT_STR_EQ(pastes[i].language, "cpp"); |
154 GREATEST_ASSERT_STR_EQ(pastes[i].code, | 154 GREATEST_ASSERT_STR_EQ(pastes[i].code, |
155 bprintf("int main() { return %d; }", expected[i])); | 155 bprintf("int main() { return %d; }", expected[i])); |
156 GREATEST_ASSERT_EQ(pastes[i].duration, PASTE_HOUR); | 156 GREATEST_ASSERT_EQ(pastes[i].duration, PASTE_DURATION_HOUR); |
157 GREATEST_ASSERT(pastes[i].visible); | 157 GREATEST_ASSERT(pastes[i].visible); |
158 }; | 158 }; |
159 | 159 |
160 GREATEST_PASS(); | 160 GREATEST_PASS(); |
161 } | 161 } |
165 { | 165 { |
166 static const int expected[] = { 19, 18, 17 }; | 166 static const int expected[] = { 19, 18, 17 }; |
167 struct paste pastes[3]; | 167 struct paste pastes[3]; |
168 size_t max = 3; | 168 size_t max = 3; |
169 struct paste pastie = { | 169 struct paste pastie = { |
170 .duration = PASTE_HOUR, | 170 .duration = PASTE_DURATION_HOUR, |
171 .visible = true | 171 .visible = true |
172 }; | 172 }; |
173 | 173 |
174 for (int i = 0; i < 20; ++i) { | 174 for (int i = 0; i < 20; ++i) { |
175 pastie.title = estrdup(bprintf("test %d", i)); | 175 pastie.title = estrdup(bprintf("test %d", i)); |
197 GREATEST_ASSERT_STR_EQ(pastes[i].author, | 197 GREATEST_ASSERT_STR_EQ(pastes[i].author, |
198 bprintf("unit test %d", expected[i])); | 198 bprintf("unit test %d", expected[i])); |
199 GREATEST_ASSERT_STR_EQ(pastes[i].language, "cpp"); | 199 GREATEST_ASSERT_STR_EQ(pastes[i].language, "cpp"); |
200 GREATEST_ASSERT_STR_EQ(pastes[i].code, | 200 GREATEST_ASSERT_STR_EQ(pastes[i].code, |
201 bprintf("int main() { return %d; }", expected[i])); | 201 bprintf("int main() { return %d; }", expected[i])); |
202 GREATEST_ASSERT_EQ(pastes[i].duration, PASTE_HOUR); | 202 GREATEST_ASSERT_EQ(pastes[i].duration, PASTE_DURATION_HOUR); |
203 GREATEST_ASSERT(pastes[i].visible); | 203 GREATEST_ASSERT(pastes[i].visible); |
204 }; | 204 }; |
205 | 205 |
206 GREATEST_PASS(); | 206 GREATEST_PASS(); |
207 } | 207 } |
223 struct paste original = { | 223 struct paste original = { |
224 .title = estrdup("test 1"), | 224 .title = estrdup("test 1"), |
225 .author = estrdup("unit test"), | 225 .author = estrdup("unit test"), |
226 .language = estrdup("cpp"), | 226 .language = estrdup("cpp"), |
227 .code = estrdup("int main() {}"), | 227 .code = estrdup("int main() {}"), |
228 .duration = PASTE_HOUR, | 228 .duration = PASTE_DURATION_HOUR, |
229 .visible = false | 229 .visible = false |
230 }; | 230 }; |
231 struct paste new = { 0 }; | 231 struct paste new = { 0 }; |
232 | 232 |
233 if (!database_insert(&original)) | 233 if (!database_insert(&original)) |
274 { | 274 { |
275 .title = estrdup("This is in C"), | 275 .title = estrdup("This is in C"), |
276 .author = estrdup("markand"), | 276 .author = estrdup("markand"), |
277 .language = estrdup("cpp"), | 277 .language = estrdup("cpp"), |
278 .code = estrdup("int main(void) {}"), | 278 .code = estrdup("int main(void) {}"), |
279 .duration = PASTE_HOUR, | 279 .duration = PASTE_DURATION_HOUR, |
280 .visible = true | 280 .visible = true |
281 }, | 281 }, |
282 { | 282 { |
283 .title = estrdup("This is in shell"), | 283 .title = estrdup("This is in shell"), |
284 .author = estrdup("markand"), | 284 .author = estrdup("markand"), |
285 .language = estrdup("shell"), | 285 .language = estrdup("shell"), |
286 .code = estrdup("f() {}"), | 286 .code = estrdup("f() {}"), |
287 .duration = PASTE_HOUR, | 287 .duration = PASTE_DURATION_HOUR, |
288 .visible = true | 288 .visible = true |
289 }, | 289 }, |
290 { | 290 { |
291 .title = estrdup("This is in python"), | 291 .title = estrdup("This is in python"), |
292 .author = estrdup("NiReaS"), | 292 .author = estrdup("NiReaS"), |
293 .language = estrdup("python"), | 293 .language = estrdup("python"), |
294 .code = estrdup("f: pass"), | 294 .code = estrdup("f: pass"), |
295 .duration = PASTE_HOUR, | 295 .duration = PASTE_DURATION_HOUR, |
296 .visible = true | 296 .visible = true |
297 }, | 297 }, |
298 }; | 298 }; |
299 size_t max = 3; | 299 size_t max = 3; |
300 | 300 |
316 GREATEST_ASSERT(searched[0].id); | 316 GREATEST_ASSERT(searched[0].id); |
317 GREATEST_ASSERT_STR_EQ(searched[0].title, "This is in C"); | 317 GREATEST_ASSERT_STR_EQ(searched[0].title, "This is in C"); |
318 GREATEST_ASSERT_STR_EQ(searched[0].author, "markand"); | 318 GREATEST_ASSERT_STR_EQ(searched[0].author, "markand"); |
319 GREATEST_ASSERT_STR_EQ(searched[0].language, "cpp"); | 319 GREATEST_ASSERT_STR_EQ(searched[0].language, "cpp"); |
320 GREATEST_ASSERT_STR_EQ(searched[0].code, "int main(void) {}"); | 320 GREATEST_ASSERT_STR_EQ(searched[0].code, "int main(void) {}"); |
321 GREATEST_ASSERT_EQ(searched[0].duration, PASTE_HOUR); | 321 GREATEST_ASSERT_EQ(searched[0].duration, PASTE_DURATION_HOUR); |
322 GREATEST_ASSERT(searched[0].visible); | 322 GREATEST_ASSERT(searched[0].visible); |
323 GREATEST_PASS(); | 323 GREATEST_PASS(); |
324 } | 324 } |
325 | 325 |
326 GREATEST_TEST | 326 GREATEST_TEST |
330 struct paste original = { | 330 struct paste original = { |
331 .title = estrdup("This is in C"), | 331 .title = estrdup("This is in C"), |
332 .author = estrdup("markand"), | 332 .author = estrdup("markand"), |
333 .language = estrdup("cpp"), | 333 .language = estrdup("cpp"), |
334 .code = estrdup("int main(void) {}"), | 334 .code = estrdup("int main(void) {}"), |
335 .duration = PASTE_HOUR, | 335 .duration = PASTE_DURATION_HOUR, |
336 .visible = true | 336 .visible = true |
337 }; | 337 }; |
338 size_t max = 1; | 338 size_t max = 1; |
339 | 339 |
340 if (!database_insert(&original)) | 340 if (!database_insert(&original)) |
366 struct paste original = { | 366 struct paste original = { |
367 .title = estrdup("This is secret"), | 367 .title = estrdup("This is secret"), |
368 .author = estrdup("anonymous"), | 368 .author = estrdup("anonymous"), |
369 .language = estrdup("nohighlight"), | 369 .language = estrdup("nohighlight"), |
370 .code = estrdup("I love you, honey"), | 370 .code = estrdup("I love you, honey"), |
371 .duration = PASTE_HOUR, | 371 .duration = PASTE_DURATION_HOUR, |
372 .visible = false | 372 .visible = false |
373 }; | 373 }; |
374 size_t max = 1; | 374 size_t max = 1; |
375 | 375 |
376 if (!database_insert(&original)) | 376 if (!database_insert(&original)) |
431 { | 431 { |
432 .title = estrdup("This is in python"), | 432 .title = estrdup("This is in python"), |
433 .author = estrdup("NiReaS"), | 433 .author = estrdup("NiReaS"), |
434 .language = estrdup("python"), | 434 .language = estrdup("python"), |
435 .code = estrdup("f: pass"), | 435 .code = estrdup("f: pass"), |
436 .duration = PASTE_HOUR, | 436 .duration = PASTE_DURATION_HOUR, |
437 .visible = true | 437 .visible = true |
438 }, | 438 }, |
439 }; | 439 }; |
440 size_t max = 1; | 440 size_t max = 1; |
441 | 441 |
461 GREATEST_ASSERT(searched.id); | 461 GREATEST_ASSERT(searched.id); |
462 GREATEST_ASSERT_STR_EQ(searched.title, "This is in python"); | 462 GREATEST_ASSERT_STR_EQ(searched.title, "This is in python"); |
463 GREATEST_ASSERT_STR_EQ(searched.author, "NiReaS"); | 463 GREATEST_ASSERT_STR_EQ(searched.author, "NiReaS"); |
464 GREATEST_ASSERT_STR_EQ(searched.language, "python"); | 464 GREATEST_ASSERT_STR_EQ(searched.language, "python"); |
465 GREATEST_ASSERT_STR_EQ(searched.code, "f: pass"); | 465 GREATEST_ASSERT_STR_EQ(searched.code, "f: pass"); |
466 GREATEST_ASSERT_EQ(searched.duration, PASTE_HOUR); | 466 GREATEST_ASSERT_EQ(searched.duration, PASTE_DURATION_HOUR); |
467 GREATEST_ASSERT(searched.visible); | 467 GREATEST_ASSERT(searched.visible); |
468 GREATEST_PASS(); | 468 GREATEST_PASS(); |
469 } | 469 } |
470 | 470 |
471 GREATEST_SUITE(clear) | 471 GREATEST_SUITE(clear) |