[Bf-blender-cvs] [8c95d025042] functions: more tests
Jacques Lucke
noreply at git.blender.org
Tue Aug 20 18:45:30 CEST 2019
Commit: 8c95d0250422406a1c4e9db1c20cba5413c543e5
Author: Jacques Lucke
Date: Tue Aug 20 18:45:26 2019 +0200
Branches: functions
https://developer.blender.org/rB8c95d0250422406a1c4e9db1c20cba5413c543e5
more tests
===================================================================
M tests/gtests/blenlib/BLI_refcount_test.cc
M tests/gtests/blenlib/BLI_string_map_test.cc
===================================================================
diff --git a/tests/gtests/blenlib/BLI_refcount_test.cc b/tests/gtests/blenlib/BLI_refcount_test.cc
index b18d7eb54d9..b127f487eec 100644
--- a/tests/gtests/blenlib/BLI_refcount_test.cc
+++ b/tests/gtests/blenlib/BLI_refcount_test.cc
@@ -34,13 +34,13 @@ using namespace BLI;
using SharedClass = AutoRefCount<MyTestClass>;
-TEST(shared, OneReferenceAfterConstruction)
+TEST(ref_count, OneReferenceAfterConstruction)
{
SharedClass obj = SharedClass::New();
ASSERT_EQ(obj->refcount(), 1);
}
-TEST(shared, CopyConstructorIncreasesRefCount)
+TEST(ref_count, CopyConstructorIncreasesRefCount)
{
SharedClass obj1 = SharedClass::New();
ASSERT_EQ(obj1->refcount(), 1);
@@ -49,13 +49,13 @@ TEST(shared, CopyConstructorIncreasesRefCount)
ASSERT_EQ(obj2->refcount(), 2);
}
-TEST(shared, MoveConstructorKeepsRefCount)
+TEST(ref_count, MoveConstructorKeepsRefCount)
{
SharedClass obj(SharedClass::New());
ASSERT_EQ(obj->refcount(), 1);
}
-TEST(shared, DecreasedWhenScopeEnds)
+TEST(ref_count, DecreasedWhenScopeEnds)
{
SharedClass obj1 = SharedClass::New();
ASSERT_EQ(obj1->refcount(), 1);
@@ -67,19 +67,19 @@ TEST(shared, DecreasedWhenScopeEnds)
ASSERT_EQ(obj1->refcount(), 1);
}
-TEST(shared, DefaultConstructorCalled)
+TEST(ref_count, DefaultConstructorCalled)
{
SharedClass obj = SharedClass::New();
ASSERT_EQ(obj->m_value, DEFAULT_VALUE);
}
-TEST(shared, OtherConstructorCalled)
+TEST(ref_count, OtherConstructorCalled)
{
SharedClass obj = SharedClass::New(123);
ASSERT_EQ(obj->m_value, 123);
}
-TEST(shared, DestructorCalled)
+TEST(ref_count, DestructorCalled)
{
bool alive = false;
{
@@ -89,7 +89,7 @@ TEST(shared, DestructorCalled)
ASSERT_FALSE(alive);
}
-TEST(shared, CustomIncRef)
+TEST(ref_count, CustomIncRef)
{
auto *ptr = new MyTestClass();
ASSERT_EQ(ptr->refcount(), 1);
@@ -99,7 +99,7 @@ TEST(shared, CustomIncRef)
ptr->decref();
}
-TEST(shared, CustomDecRef)
+TEST(ref_count, CustomDecRef)
{
auto *ptr = new MyTestClass();
ptr->incref();
@@ -109,7 +109,7 @@ TEST(shared, CustomDecRef)
ptr->decref();
}
-TEST(shared, ExtractRefCounted)
+TEST(ref_count, ExtractRefCounted)
{
SharedClass obj = SharedClass::New();
MyTestClass *ptr = obj.ptr();
@@ -119,7 +119,7 @@ TEST(shared, ExtractRefCounted)
ptr->decref();
}
-TEST(shared, DecRefToZero)
+TEST(ref_count, DecRefToZero)
{
bool alive = false;
auto *ptr = new MyTestClass(&alive);
@@ -128,7 +128,7 @@ TEST(shared, DecRefToZero)
ASSERT_FALSE(alive);
}
-TEST(shared, Empty)
+TEST(ref_count, Empty)
{
SharedClass obj;
ASSERT_EQ(obj.ptr(), nullptr);
diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc
index 753ef4876e7..96ed0e9b8fd 100644
--- a/tests/gtests/blenlib/BLI_string_map_test.cc
+++ b/tests/gtests/blenlib/BLI_string_map_test.cc
@@ -10,6 +10,39 @@ TEST(string_map, DefaultConstructor)
EXPECT_EQ(map.size(), 0);
}
+TEST(string_map, CopyConstructor)
+{
+ StringMap<Vector<int, 4>> map1;
+ map1.add_new("A", {1, 2, 3});
+ map1.add_new("B", {1, 2, 3, 4, 5, 6});
+
+ StringMap<Vector<int>> map2(map1);
+
+ EXPECT_EQ(map1.size(), 2);
+ EXPECT_EQ(map2.size(), 2);
+ EXPECT_EQ(map1.lookup("A")[1], 2);
+ EXPECT_EQ(map2.lookup("A")[1], 2);
+ EXPECT_EQ(map1.lookup("B")[5], 6);
+ EXPECT_EQ(map2.lookup("B")[5], 6);
+}
+
+TEST(string_map, MoveConstructor)
+{
+ StringMap<Vector<int, 4>> map1;
+ map1.add_new("A", {1, 2, 3});
+ map1.add_new("B", {1, 2, 3, 4, 5, 6});
+
+ StringMap<Vector<int>> map2(std::move(map1));
+
+ EXPECT_EQ(map1.size(), 0);
+ EXPECT_FALSE(map1.contains("A"));
+ EXPECT_FALSE(map1.contains("B"));
+
+ EXPECT_EQ(map2.size(), 2);
+ EXPECT_EQ(map2.lookup("A")[1], 2);
+ EXPECT_EQ(map2.lookup("B")[5], 6);
+}
+
TEST(string_map, AddNew)
{
StringMap<int> map;
@@ -156,3 +189,13 @@ TEST(string_map, ForeachKeyValuePair)
EXPECT_EQ(values[keys.index("B")], 5);
EXPECT_EQ(values[keys.index("C")], 1);
}
+
+TEST(string_map, WithVectors)
+{
+ StringMap<Vector<int>> map;
+ map.add_new("A", {1, 2, 3});
+ map.add_new("B", {1, 2, 3, 4, 5, 6, 7});
+ EXPECT_EQ(map.size(), 2);
+ EXPECT_EQ(map.lookup("A").size(), 3);
+ EXPECT_EQ(map.lookup("B").size(), 7);
+}
More information about the Bf-blender-cvs
mailing list