Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-06-03 11:09:12 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-06-03 11:09:12 +0300
commit6fbb580e515c0ac0d4c04af81967a09c6b1bd94e (patch)
treec7036c4d8f045f343258c329b687c6168eb655a1
parent1dbcccf5f965187532a7fc543ca85bdbf79e99f5 (diff)
BLI_stack: gtest for clear
-rw-r--r--tests/gtests/blenlib/BLI_stack_test.cc54
1 files changed, 52 insertions, 2 deletions
diff --git a/tests/gtests/blenlib/BLI_stack_test.cc b/tests/gtests/blenlib/BLI_stack_test.cc
index 08701356816..44956a589dc 100644
--- a/tests/gtests/blenlib/BLI_stack_test.cc
+++ b/tests/gtests/blenlib/BLI_stack_test.cc
@@ -11,6 +11,14 @@ extern "C" {
#define SIZE 1024
+/* number of items per chunk. use a small value to expose bugs */
+#define STACK_CHUNK_SIZE 8
+
+/* Ensure block size is set to #STACK_NEW_EX_ARGS */
+#define BLI_stack_new(esize, descr) \
+ BLI_stack_new_ex(esize, descr, esize * STACK_CHUNK_SIZE)
+
+
TEST(stack, Empty)
{
BLI_Stack *stack;
@@ -110,18 +118,60 @@ TEST(stack, Peek)
EXPECT_EQ(BLI_stack_is_empty(stack), true);
}
+/* Check that clearing the stack leaves in it a correct state. */
+TEST(stack, Clear)
+{
+ const int tot_rerun = 4;
+ int rerun;
+
+ /* based on range test */
+ int tot = SIZE;
+ BLI_Stack *stack;
+ int in, out;
+
+ /* use a small chunk size to ensure we test */
+ stack = BLI_stack_new(sizeof(in), __func__);
+
+ for (rerun = 0; rerun < tot_rerun; rerun++) {
+ for (in = 0; in < tot; in++) {
+ BLI_stack_push(stack, (void *)&in);
+ }
+
+ BLI_stack_clear(stack);
+ EXPECT_EQ(BLI_stack_is_empty(stack), true);
+
+ /* and again, this time check its valid */
+ for (in = 0; in < tot; in++) {
+ BLI_stack_push(stack, (void *)&in);
+ }
+
+ for (in = tot - 1; in >= 0; in--) {
+ EXPECT_EQ(BLI_stack_is_empty(stack), false);
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_EQ(in, out);
+ }
+
+ EXPECT_EQ(BLI_stack_is_empty(stack), true);
+
+ /* without this, we wont test case when mixed free/used */
+ tot /= 2;
+ }
+
+ BLI_stack_free(stack);
+}
+
TEST(stack, Reuse)
{
const int sizes[] = {3, 11, 81, 400, 999, 12, 1, 9721, 7, 99, 5, 0};
int sizes_test[ARRAY_SIZE(sizes)];
const int *s;
- int in, out, i;
+ int out, i;
int sum, sum_test;
BLI_Stack *stack;
- stack = BLI_stack_new(sizeof(in), __func__);
+ stack = BLI_stack_new(sizeof(i), __func__);
/* add a bunch of numbers, ensure we get same sum out */
sum = 0;