summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-31 14:56:07 +0100
committerDavid Robillard <d@drobilla.net>2020-12-31 15:21:10 +0100
commit841c766d86dc35ab37c4fef8ec866d06c41bc383 (patch)
tree3959f9290e8b48f801cae52b7397eaa249c6e5cb /test
parent5ca5c874e2409b32fbdc4b46a1ba3b5a9200542f (diff)
downloadzix-841c766d86dc35ab37c4fef8ec866d06c41bc383.tar.gz
zix-841c766d86dc35ab37c4fef8ec866d06c41bc383.tar.bz2
zix-841c766d86dc35ab37c4fef8ec866d06c41bc383.zip
Avoid "else" after "return"
Diffstat (limited to 'test')
-rw-r--r--test/.clang-tidy1
-rw-r--r--test/bitset_test.c4
-rw-r--r--test/btree_test.c80
-rw-r--r--test/hash_test.c4
-rw-r--r--test/test_malloc.c4
5 files changed, 67 insertions, 26 deletions
diff --git a/test/.clang-tidy b/test/.clang-tidy
index aa81243..dc7dbc4 100644
--- a/test/.clang-tidy
+++ b/test/.clang-tidy
@@ -1,6 +1,5 @@
Checks: >
*,
- -*-else-after-return,
-*-magic-numbers,
-*-uppercase-literal-suffix,
-android-cloexec-fopen,
diff --git a/test/bitset_test.c b/test/bitset_test.c
index 554e238..8fa610f 100644
--- a/test/bitset_test.c
+++ b/test/bitset_test.c
@@ -53,7 +53,9 @@ main(void)
const size_t count = zix_bitset_count_up_to(b, t, N_BITS);
if (count != i + 1) {
return test_fail("Count %zu != %zu\n", count, i + 1);
- } else if (!zix_bitset_get(b, i)) {
+ }
+
+ if (!zix_bitset_get(b, i)) {
return test_fail("Bit %zu is not set\n", i);
}
}
diff --git a/test/btree_test.c b/test/btree_test.c
index ad6b6b7..3336d91 100644
--- a/test/btree_test.c
+++ b/test/btree_test.c
@@ -89,21 +89,24 @@ wildcard_cmp(const void* a, const void* b, const void* user_data)
const unsigned test_num = ctx->test_num;
const uintptr_t ia = (uintptr_t)a;
const uintptr_t ib = (uintptr_t)b;
+
if (ia == 0) {
if (ib >= wildcard_cut(test_num, n_elems)) {
return 0; // Wildcard match
- } else {
- return 1; // Wildcard a > b
}
- } else if (ib == 0) {
+
+ return 1; // Wildcard a > b
+ }
+
+ if (ib == 0) {
if (ia >= wildcard_cut(test_num, n_elems)) {
return 0; // Wildcard match
- } else {
- return -1; // Wildcard b > a
}
- } else {
- return int_cmp(a, b, user_data);
+
+ return -1; // Wildcard b > a
}
+
+ return int_cmp(a, b, user_data);
}
ZIX_LOG_FUNC(2, 3)
@@ -142,11 +145,16 @@ stress(const unsigned test_num, const size_t n_elems)
ZixBTreeIter* end = zix_btree_end(t);
if (!ti) {
return test_fail(t, "Failed to allocate iterator\n");
- } else if (!zix_btree_iter_is_end(ti)) {
+ }
+
+ if (!zix_btree_iter_is_end(ti)) {
return test_fail(t, "Begin iterator on empty tree is not end\n");
- } else if (!zix_btree_iter_equals(ti, end)) {
+ }
+
+ if (!zix_btree_iter_equals(ti, end)) {
return test_fail(t, "Begin and end of empty tree are not equal\n");
}
+
zix_btree_iter_free(end);
zix_btree_iter_free(ti);
@@ -159,7 +167,9 @@ stress(const unsigned test_num, const size_t n_elems)
r = ith_elem(test_num, n_elems, i);
if (!zix_btree_find(t, (void*)r, &ti)) {
return test_fail(t, "%" PRIuPTR " already in tree\n", (uintptr_t)r);
- } else if ((st = zix_btree_insert(t, (void*)r))) {
+ }
+
+ if ((st = zix_btree_insert(t, (void*)r))) {
return test_fail(t, "Insert %" PRIuPTR " failed (%s)\n",
(uintptr_t)r, zix_strerror(st));
}
@@ -191,10 +201,13 @@ stress(const unsigned test_num, const size_t n_elems)
r = ith_elem(test_num, n_elems, i);
if (zix_btree_find(t, (void*)r, &ti)) {
return test_fail(t, "Find %" PRIuPTR " @ %zu failed\n", (uintptr_t)r, i);
- } else if ((uintptr_t)zix_btree_get(ti) != r) {
+ }
+
+ if ((uintptr_t)zix_btree_get(ti) != r) {
return test_fail(t, "Search data corrupt (%" PRIuPTR " != %" PRIuPTR ")\n",
(uintptr_t)zix_btree_get(ti), r);
}
+
zix_btree_iter_free(ti);
}
@@ -208,13 +221,18 @@ stress(const unsigned test_num, const size_t n_elems)
if (zix_btree_lower_bound(t, (void*)r, &ti)) {
return test_fail(t, "Lower bound %" PRIuPTR " @ %zu failed\n",
(uintptr_t)r, i);
- } else if (zix_btree_iter_is_end(ti)) {
+ }
+
+ if (zix_btree_iter_is_end(ti)) {
return test_fail(t, "Lower bound %" PRIuPTR " @ %zu hit end\n",
(uintptr_t)r, i);
- } else if ((uintptr_t)zix_btree_get(ti) != r) {
+ }
+
+ if ((uintptr_t)zix_btree_get(ti) != r) {
return test_fail(t, "Lower bound corrupt (%" PRIuPTR " != %" PRIuPTR "\n",
(uintptr_t)zix_btree_get(ti), r);
}
+
zix_btree_iter_free(ti);
}
@@ -276,11 +294,15 @@ stress(const unsigned test_num, const size_t n_elems)
if (zix_btree_remove(t, (void*)r, (void**)&removed, &next)) {
return test_fail(t, "Error removing item %" PRIuPTR "\n",
(uintptr_t)r);
- } else if (removed != r) {
+ }
+
+ if (removed != r) {
return test_fail(t,
"Removed wrong item %" PRIuPTR " != %" PRIuPTR "\n",
removed, (uintptr_t)r);
- } else if (test_num == 0) {
+ }
+
+ if (test_num == 0) {
const uintptr_t next_value = ith_elem(test_num, n_elems, e + 1);
if (!((zix_btree_iter_is_end(next) && e == n_elems - 1) ||
(uintptr_t)zix_btree_get(next) == next_value)) {
@@ -329,10 +351,14 @@ stress(const unsigned test_num, const size_t n_elems)
uintptr_t removed;
if (zix_btree_remove(t, (void*)r, (void**)&removed, &next)) {
return test_fail(t, "Deletion of %" PRIuPTR " failed\n", (uintptr_t)r);
- } else if (removed != r) {
+ }
+
+ if (removed != r) {
return test_fail(t, "Removed wrong item %" PRIuPTR " != %" PRIuPTR "\n",
removed, (uintptr_t)r);
- } else if (test_num == 0) {
+ }
+
+ if (test_num == 0) {
const uintptr_t next_value = ith_elem(test_num, n_elems, e + 1);
if (!zix_btree_iter_is_end(next) &&
(uintptr_t)zix_btree_get(next) == next_value) {
@@ -370,10 +396,14 @@ stress(const unsigned test_num, const size_t n_elems)
if (zix_btree_remove(t, zix_btree_get(next), (void**)&removed, &next)) {
return test_fail(t, "Error removing next item %" PRIuPTR "\n",
(uintptr_t)r);
- } else if (removed != value) {
+ }
+
+ if (removed != value) {
return test_fail(t, "Removed wrong next item %" PRIuPTR " != %" PRIuPTR "\n",
removed, (uintptr_t)value);
- } else if (removed < last_value) {
+ }
+
+ if (removed < last_value) {
return test_fail(t, "Removed unordered next item %" PRIuPTR " < %" PRIuPTR "\n",
removed, (uintptr_t)value);
}
@@ -408,7 +438,9 @@ stress(const unsigned test_num, const size_t n_elems)
const uintptr_t wildcard = 0;
if (zix_btree_lower_bound(t, (void*)wildcard, &ti)) {
return test_fail(t, "Lower bound failed\n");
- } else if (zix_btree_iter_is_end(ti)) {
+ }
+
+ if (zix_btree_iter_is_end(ti)) {
return test_fail(t, "Lower bound reached end\n");
}
@@ -418,7 +450,9 @@ stress(const unsigned test_num, const size_t n_elems)
if (iter_data != cut) {
return test_fail(t, "Lower bound %" PRIuPTR " != %" PRIuPTR "\n",
iter_data, cut);
- } else if (wildcard_cmp((void*)wildcard, (void*)iter_data, &ctx)) {
+ }
+
+ if (wildcard_cmp((void*)wildcard, (void*)iter_data, &ctx)) {
return test_fail(t, "Wildcard lower bound %" PRIuPTR " != %" PRIuPTR "\n",
iter_data, cut);
}
@@ -429,7 +463,9 @@ stress(const unsigned test_num, const size_t n_elems)
const uintptr_t max = (uintptr_t)-1;
if (zix_btree_lower_bound(t, (void*)max, &ti)) {
return test_fail(t, "Lower bound failed\n");
- } else if (!zix_btree_iter_is_end(ti)) {
+ }
+
+ if (!zix_btree_iter_is_end(ti)) {
return test_fail(t, "Lower bound of maximum value is not end\n");
}
diff --git a/test/hash_test.c b/test/hash_test.c
index 91c0127..bfddc49 100644
--- a/test/hash_test.c
+++ b/test/hash_test.c
@@ -102,7 +102,9 @@ stress(void)
ZixStatus st = zix_hash_insert(hash, &strings[i], &inserted);
if (st) {
return test_fail("Failed to insert `%s'\n", strings[i]);
- } else if (*(const void*const*)inserted != strings[i]) {
+ }
+
+ if (*(const void*const*)inserted != strings[i]) {
return test_fail("Corrupt insertion %s != %s\n",
strings[i], *(const char*const*)inserted);
}
diff --git a/test/test_malloc.c b/test/test_malloc.c
index 7be62ff..1138502 100644
--- a/test/test_malloc.c
+++ b/test/test_malloc.c
@@ -36,7 +36,9 @@ test_malloc(size_t size)
{
if (in_test_malloc_init) {
return NULL; // dlsym is asking for memory, but handles this fine
- } else if (!test_malloc_sys_malloc) {
+ }
+
+ if (!test_malloc_sys_malloc) {
test_malloc_init();
}