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:
Diffstat (limited to 'tests/gtests/blenlib/BLI_stack_cxx_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_stack_cxx_test.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/gtests/blenlib/BLI_stack_cxx_test.cc b/tests/gtests/blenlib/BLI_stack_cxx_test.cc
new file mode 100644
index 00000000000..436f1f307b9
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_stack_cxx_test.cc
@@ -0,0 +1,63 @@
+#include "testing/testing.h"
+#include "BLI_stack_cxx.h"
+
+using BLI::Stack;
+using IntStack = Stack<int>;
+
+TEST(stack, DefaultConstructor)
+{
+ IntStack stack;
+ EXPECT_EQ(stack.size(), 0);
+ EXPECT_TRUE(stack.empty());
+}
+
+TEST(stack, ArrayRefConstructor)
+{
+ std::array<int, 3> array = {4, 7, 2};
+ IntStack stack(array);
+ EXPECT_EQ(stack.size(), 3);
+ EXPECT_EQ(stack.pop(), 2);
+ EXPECT_EQ(stack.pop(), 7);
+ EXPECT_EQ(stack.pop(), 4);
+ EXPECT_TRUE(stack.empty());
+}
+
+TEST(stack, Push)
+{
+ IntStack stack;
+ EXPECT_EQ(stack.size(), 0);
+ stack.push(3);
+ EXPECT_EQ(stack.size(), 1);
+ stack.push(5);
+ EXPECT_EQ(stack.size(), 2);
+}
+
+TEST(stack, Pop)
+{
+ IntStack stack;
+ stack.push(4);
+ stack.push(6);
+ EXPECT_EQ(stack.pop(), 6);
+ EXPECT_EQ(stack.pop(), 4);
+}
+
+TEST(stack, Peek)
+{
+ IntStack stack;
+ stack.push(3);
+ stack.push(4);
+ EXPECT_EQ(stack.peek(), 4);
+ EXPECT_EQ(stack.peek(), 4);
+ stack.pop();
+ EXPECT_EQ(stack.peek(), 3);
+}
+
+TEST(stack, UniquePtrValues)
+{
+ Stack<std::unique_ptr<int>> stack;
+ stack.push(std::unique_ptr<int>(new int()));
+ stack.push(std::unique_ptr<int>(new int()));
+ std::unique_ptr<int> a = stack.pop();
+ std::unique_ptr<int> &b = stack.peek();
+ UNUSED_VARS(a, b);
+}