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:
authorJacques Lucke <jacques@blender.org>2020-06-09 11:10:56 +0300
committerJacques Lucke <jacques@blender.org>2020-06-09 11:15:43 +0300
commitd8678e02ecec9375bec1dcf1388c6fc8b4ce3ad2 (patch)
tree6e7d2a7452091877f73d413d830e6cb12e86745f /tests/gtests/blenlib/BLI_array_test.cc
parent50258d55e7c1360274d40e303386cf70b16c8b2f (diff)
BLI: generally improve C++ data structures
The main focus here was to improve the docs significantly. Furthermore, I reimplemented `Set`, `Map` and `VectorSet`. They are now (usually) faster, simpler and more customizable. I also rewrote `Stack` to make it more efficient by avoiding unnecessary copies. Thanks to everyone who helped with constructive feedback. Approved by brecht and sybren. Differential Revision: https://developer.blender.org/D7931
Diffstat (limited to 'tests/gtests/blenlib/BLI_array_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_array_test.cc27
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/gtests/blenlib/BLI_array_test.cc b/tests/gtests/blenlib/BLI_array_test.cc
index b1aa24aa808..66f69f5c309 100644
--- a/tests/gtests/blenlib/BLI_array_test.cc
+++ b/tests/gtests/blenlib/BLI_array_test.cc
@@ -1,4 +1,5 @@
#include "BLI_array.hh"
+#include "BLI_strict_flags.h"
#include "testing/testing.h"
using namespace BLI;
@@ -7,12 +8,14 @@ TEST(array, DefaultConstructor)
{
Array<int> array;
EXPECT_EQ(array.size(), 0);
+ EXPECT_TRUE(array.is_empty());
}
TEST(array, SizeConstructor)
{
Array<int> array(5);
EXPECT_EQ(array.size(), 5);
+ EXPECT_FALSE(array.is_empty());
}
TEST(array, FillConstructor)
@@ -55,7 +58,7 @@ TEST(array, CopyConstructor)
EXPECT_EQ(array.size(), 4);
EXPECT_EQ(new_array.size(), 4);
- EXPECT_NE(array.begin(), new_array.begin());
+ EXPECT_NE(array.data(), new_array.data());
EXPECT_EQ(new_array[0], 5);
EXPECT_EQ(new_array[1], 6);
EXPECT_EQ(new_array[2], 7);
@@ -83,7 +86,7 @@ TEST(array, CopyAssignment)
new_array = array;
EXPECT_EQ(new_array.size(), 3);
EXPECT_EQ(array.size(), 3);
- EXPECT_NE(array.begin(), new_array.begin());
+ EXPECT_NE(array.data(), new_array.data());
EXPECT_EQ(new_array[0], 1);
EXPECT_EQ(new_array[1], 2);
EXPECT_EQ(new_array[2], 3);
@@ -101,3 +104,23 @@ TEST(array, MoveAssignment)
EXPECT_EQ(new_array[1], 2);
EXPECT_EQ(new_array[2], 3);
}
+
+/**
+ * Tests that the trivially constructible types are not zero-initialized. We do not want that for
+ * performance reasons.
+ */
+TEST(array, TrivialTypeSizeConstructor)
+{
+ Array<char, 1> *array = new Array<char, 1>(1);
+ char *ptr = &(*array)[0];
+ array->~Array();
+
+ const char magic = 42;
+ *ptr = magic;
+ EXPECT_EQ(*ptr, magic);
+
+ new (array) Array<char, 1>(1);
+ EXPECT_EQ((*array)[0], magic);
+ EXPECT_EQ(*ptr, magic);
+ delete array;
+}