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>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /tests/gtests/blenlib/BLI_stack_test.cc
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'tests/gtests/blenlib/BLI_stack_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_stack_test.cc299
1 files changed, 147 insertions, 152 deletions
diff --git a/tests/gtests/blenlib/BLI_stack_test.cc b/tests/gtests/blenlib/BLI_stack_test.cc
index 18188937355..a3fd5efadf0 100644
--- a/tests/gtests/blenlib/BLI_stack_test.cc
+++ b/tests/gtests/blenlib/BLI_stack_test.cc
@@ -15,209 +15,204 @@ extern "C" {
#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)
-
+#define BLI_stack_new(esize, descr) BLI_stack_new_ex(esize, descr, esize *STACK_CHUNK_SIZE)
TEST(stack, Empty)
{
- BLI_Stack *stack;
+ BLI_Stack *stack;
- stack = BLI_stack_new(sizeof(int), __func__);
- EXPECT_TRUE(BLI_stack_is_empty(stack));
- EXPECT_EQ(BLI_stack_count(stack), 0);
- BLI_stack_free(stack);
+ stack = BLI_stack_new(sizeof(int), __func__);
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_EQ(BLI_stack_count(stack), 0);
+ BLI_stack_free(stack);
}
TEST(stack, One)
{
- BLI_Stack *stack;
- unsigned int in = -1, out = 1;
-
- stack = BLI_stack_new(sizeof(in), __func__);
-
- BLI_stack_push(stack, (void *)&in);
- EXPECT_FALSE(BLI_stack_is_empty(stack));
- EXPECT_EQ(BLI_stack_count(stack), 1);
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_EQ(out, in);
- EXPECT_TRUE(BLI_stack_is_empty(stack));
- EXPECT_EQ(BLI_stack_count(stack), 0);
- BLI_stack_free(stack);
+ BLI_Stack *stack;
+ unsigned int in = -1, out = 1;
+
+ stack = BLI_stack_new(sizeof(in), __func__);
+
+ BLI_stack_push(stack, (void *)&in);
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ EXPECT_EQ(BLI_stack_count(stack), 1);
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_EQ(out, in);
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_EQ(BLI_stack_count(stack), 0);
+ BLI_stack_free(stack);
}
TEST(stack, Range)
{
- const int tot = SIZE;
- BLI_Stack *stack;
- int in, out;
-
- stack = BLI_stack_new(sizeof(in), __func__);
+ const int tot = SIZE;
+ BLI_Stack *stack;
+ int in, out;
- for (in = 0; in < tot; in++) {
- BLI_stack_push(stack, (void *)&in);
- }
+ stack = BLI_stack_new(sizeof(in), __func__);
- for (in = tot - 1; in >= 0; in--) {
- EXPECT_FALSE(BLI_stack_is_empty(stack));
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_EQ(out, in);
+ for (in = 0; in < tot; in++) {
+ BLI_stack_push(stack, (void *)&in);
+ }
- }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ for (in = tot - 1; in >= 0; in--) {
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_EQ(out, in);
+ }
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- BLI_stack_free(stack);
+ BLI_stack_free(stack);
}
TEST(stack, String)
{
- const int tot = SIZE;
- int i;
+ const int tot = SIZE;
+ int i;
- BLI_Stack *stack;
- char in[] = "hello world!";
- char out[sizeof(in)];
+ BLI_Stack *stack;
+ char in[] = "hello world!";
+ char out[sizeof(in)];
- stack = BLI_stack_new(sizeof(in), __func__);
+ stack = BLI_stack_new(sizeof(in), __func__);
- for (i = 0; i < tot; i++) {
- *((int *)in) = i;
- BLI_stack_push(stack, (void *)in);
- }
+ for (i = 0; i < tot; i++) {
+ *((int *)in) = i;
+ BLI_stack_push(stack, (void *)in);
+ }
- for (i = tot - 1; i >= 0; i--) {
- EXPECT_FALSE(BLI_stack_is_empty(stack));
- *((int *)in) = i;
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_STREQ(in, out);
- }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ for (i = tot - 1; i >= 0; i--) {
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ *((int *)in) = i;
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_STREQ(in, out);
+ }
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- BLI_stack_free(stack);
+ BLI_stack_free(stack);
}
TEST(stack, Peek)
{
- const int tot = SIZE;
- int i;
+ const int tot = SIZE;
+ int i;
- BLI_Stack *stack;
- const short in[] = {1, 10, 100, 1000};
+ BLI_Stack *stack;
+ const short in[] = {1, 10, 100, 1000};
- stack = BLI_stack_new(sizeof(*in), __func__);
+ stack = BLI_stack_new(sizeof(*in), __func__);
- for (i = 0; i < tot; i++) {
- BLI_stack_push(stack, &in[i % ARRAY_SIZE(in)]);
- }
+ for (i = 0; i < tot; i++) {
+ BLI_stack_push(stack, &in[i % ARRAY_SIZE(in)]);
+ }
- for (i = tot - 1; i >= 0; i--, BLI_stack_discard(stack)) {
- short *ret = (short *)BLI_stack_peek(stack);
- EXPECT_EQ(*ret, in[i % ARRAY_SIZE(in)]);
- }
+ for (i = tot - 1; i >= 0; i--, BLI_stack_discard(stack)) {
+ short *ret = (short *)BLI_stack_peek(stack);
+ EXPECT_EQ(*ret, in[i % ARRAY_SIZE(in)]);
+ }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- BLI_stack_free(stack);
+ BLI_stack_free(stack);
}
/* Check that clearing the stack leaves in it a correct state. */
TEST(stack, Clear)
{
- const int tot_rerun = 4;
- int rerun;
+ const int tot_rerun = 4;
+ int rerun;
- /* based on range test */
- int tot = SIZE;
- BLI_Stack *stack;
- int in, out;
+ /* 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__);
+ /* 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);
- }
+ for (rerun = 0; rerun < tot_rerun; rerun++) {
+ for (in = 0; in < tot; in++) {
+ BLI_stack_push(stack, (void *)&in);
+ }
- BLI_stack_clear(stack);
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ BLI_stack_clear(stack);
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- /* and again, this time check its valid */
- for (in = 0; in < tot; in++) {
- BLI_stack_push(stack, (void *)&in);
- }
+ /* 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_FALSE(BLI_stack_is_empty(stack));
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_EQ(out, in);
- }
+ for (in = tot - 1; in >= 0; in--) {
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_EQ(out, in);
+ }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- /* without this, we wont test case when mixed free/used */
- tot /= 2;
- }
+ /* without this, we wont test case when mixed free/used */
+ tot /= 2;
+ }
- BLI_stack_free(stack);
+ 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 out, i;
- int sum, sum_test;
-
- BLI_Stack *stack;
-
- stack = BLI_stack_new(sizeof(i), __func__);
-
- /* add a bunch of numbers, ensure we get same sum out */
- sum = 0;
- for (s = sizes; *s; s++) {
- for (i = *s; i != 0; i--) {
- BLI_stack_push(stack, (void *)&i);
- sum += i;
- }
- }
- sum_test = 0;
- while (!BLI_stack_is_empty(stack)) {
- BLI_stack_pop(stack, (void *)&out);
- sum_test += out;
- }
- EXPECT_EQ(sum, sum_test);
-
- /* add and remove all except last */
- for (s = sizes; *s; s++) {
- for (i = *s; i >= 0; i--) {
- BLI_stack_push(stack, (void *)&i);
- }
- for (i = *s; i > 0; i--) {
- BLI_stack_pop(stack, (void *)&out);
- }
- }
-
- i = ARRAY_SIZE(sizes) - 1;
- while (!BLI_stack_is_empty(stack)) {
- i--;
- BLI_stack_pop(stack, (void *)&sizes_test[i]);
- EXPECT_EQ(sizes_test[i], sizes[i]);
- EXPECT_GT(i, -1);
- }
- EXPECT_EQ(0, i);
- EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
-
-
- /* finally test BLI_stack_pop_n */
- for (i = ARRAY_SIZE(sizes); i--; ) {
- BLI_stack_push(stack, (void *)&sizes[i]);
- }
- EXPECT_EQ(BLI_stack_count(stack), ARRAY_SIZE(sizes));
- BLI_stack_pop_n(stack, (void *)sizes_test, ARRAY_SIZE(sizes));
- EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
-
- BLI_stack_free(stack);
+ 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 out, i;
+ int sum, sum_test;
+
+ BLI_Stack *stack;
+
+ stack = BLI_stack_new(sizeof(i), __func__);
+
+ /* add a bunch of numbers, ensure we get same sum out */
+ sum = 0;
+ for (s = sizes; *s; s++) {
+ for (i = *s; i != 0; i--) {
+ BLI_stack_push(stack, (void *)&i);
+ sum += i;
+ }
+ }
+ sum_test = 0;
+ while (!BLI_stack_is_empty(stack)) {
+ BLI_stack_pop(stack, (void *)&out);
+ sum_test += out;
+ }
+ EXPECT_EQ(sum, sum_test);
+
+ /* add and remove all except last */
+ for (s = sizes; *s; s++) {
+ for (i = *s; i >= 0; i--) {
+ BLI_stack_push(stack, (void *)&i);
+ }
+ for (i = *s; i > 0; i--) {
+ BLI_stack_pop(stack, (void *)&out);
+ }
+ }
+
+ i = ARRAY_SIZE(sizes) - 1;
+ while (!BLI_stack_is_empty(stack)) {
+ i--;
+ BLI_stack_pop(stack, (void *)&sizes_test[i]);
+ EXPECT_EQ(sizes_test[i], sizes[i]);
+ EXPECT_GT(i, -1);
+ }
+ EXPECT_EQ(0, i);
+ EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
+
+ /* finally test BLI_stack_pop_n */
+ for (i = ARRAY_SIZE(sizes); i--;) {
+ BLI_stack_push(stack, (void *)&sizes[i]);
+ }
+ EXPECT_EQ(BLI_stack_count(stack), ARRAY_SIZE(sizes));
+ BLI_stack_pop_n(stack, (void *)sizes_test, ARRAY_SIZE(sizes));
+ EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
+
+ BLI_stack_free(stack);
}