summaryrefslogtreecommitdiff
path: root/test/test_choices.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2017-04-05 01:18:19 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2017-04-05 01:18:19 -0700
commitdf0725ee30698f6c14f6788ed5b5121abbb008c9 (patch)
tree38a6af4ec69afe95ca6ade6ec728a3411fd4fc36 /test/test_choices.c
parent99b13923e34ed2e957a75d8fd237dc413ed6ab30 (diff)
Use setup and teardown in choices suite
Diffstat (limited to 'test/test_choices.c')
-rw-r--r--test/test_choices.c44
1 files changed, 17 insertions, 27 deletions
diff --git a/test/test_choices.c b/test/test_choices.c
index c6a8d64..9e4b025 100644
--- a/test/test_choices.c
+++ b/test/test_choices.c
@@ -8,11 +8,24 @@
#include "greatest/greatest.h"
+#define ASSERT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d")
+
static options_t default_options;
+static choices_t choices;
+
+static void setup(void *udata) {
+ (void)udata;
+
+ options_init(&default_options);
+ choices_init(&choices, &default_options);
+}
+
+static void teardown(void *udata) {
+ (void)udata;
+ choices_destroy(&choices);
+}
TEST test_choices_empty() {
- choices_t choices;
- choices_init(&choices, &default_options);
ASSERT_EQ(0, choices.size);
ASSERT_EQ(0, choices.available);
ASSERT_EQ(0, choices.selection);
@@ -23,14 +36,10 @@ TEST test_choices_empty() {
choices_next(&choices);
ASSERT_EQ(0, choices.selection);
- choices_destroy(&choices);
-
PASS();
}
TEST test_choices_1() {
- choices_t choices;
- choices_init(&choices, &default_options);
choices_add(&choices, "tags");
choices_search(&choices, "");
@@ -50,14 +59,10 @@ TEST test_choices_1() {
ASSERT(!strcmp(choices_get(&choices, 0), "tags"));
ASSERT_EQ(NULL, choices_get(&choices, 1));
- choices_destroy(&choices);
-
PASS();
}
TEST test_choices_2() {
- choices_t choices;
- choices_init(&choices, &default_options);
choices_add(&choices, "tags");
choices_add(&choices, "test");
@@ -100,17 +105,12 @@ TEST test_choices_2() {
ASSERT_STR_EQ("test", choices_get(&choices, 0));
ASSERT_STR_EQ("tags", choices_get(&choices, 1));
- choices_destroy(&choices);
-
PASS();
}
TEST test_choices_without_search() {
/* Before a search is run, it should return no results */
- choices_t choices;
- choices_init(&choices, &default_options);
-
ASSERT_EQ(0, choices.available);
ASSERT_EQ(0, choices.selection);
ASSERT_EQ(0, choices.size);
@@ -123,27 +123,18 @@ TEST test_choices_without_search() {
ASSERT_EQ(1, choices.size);
ASSERT_EQ(NULL, choices_get(&choices, 0));
- choices_destroy(&choices);
-
PASS();
}
/* Regression test for segfault */
TEST test_choices_unicode() {
- choices_t choices;
- choices_init(&choices, &default_options);
-
choices_add(&choices, "Edmund Husserl - Méditations cartésiennes - Introduction a la phénoménologie.pdf");
choices_search(&choices, "e");
- choices_destroy(&choices);
PASS();
}
TEST test_choices_large_input() {
- choices_t choices;
- choices_init(&choices, &default_options);
-
int N = 100000;
char *strings[N];
@@ -163,13 +154,12 @@ TEST test_choices_large_input() {
free(strings[i]);
}
- choices_destroy(&choices);
-
PASS();
}
SUITE(choices_suite) {
- options_init(&default_options);
+ SET_SETUP(setup, NULL);
+ SET_TEARDOWN(teardown, NULL);
RUN_TEST(test_choices_empty);
RUN_TEST(test_choices_1);