mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
Add copy constructors to the C++ Dawn interface
This removes the need for Clone() so it is removed and also adds tests for the new constructors. BUG=dawn:11 Change-Id: Ia45c765c2d30e40b0e036427793a62327b2008fc Reviewed-on: https://dawn-review.googlesource.com/c/1901 Reviewed-by: Stephen White <senorblanco@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
5aac265dcb
commit
aa7109c148
@@ -22,7 +22,7 @@ class Object : public dawn::ObjectBase<Object, int*> {
|
||||
using ObjectBase::operator=;
|
||||
|
||||
static void DawnReference(int* handle) {
|
||||
ASSERT_LT(0, *handle);
|
||||
ASSERT_LE(0, *handle);
|
||||
*handle += 1;
|
||||
}
|
||||
static void DawnRelease(int* handle) {
|
||||
@@ -52,16 +52,14 @@ TEST(ObjectBase, AcquireConstruction) {
|
||||
ASSERT_EQ(0, refcount);
|
||||
}
|
||||
|
||||
// Test that cloning takes a new ref. Also test .Get().
|
||||
TEST(ObjectBase, Clone) {
|
||||
// Test .Get().
|
||||
TEST(ObjectBase, Get) {
|
||||
int refcount = 1;
|
||||
{
|
||||
Object obj1(&refcount);
|
||||
Object obj2 = obj1.Clone();
|
||||
|
||||
ASSERT_EQ(3, refcount);
|
||||
ASSERT_EQ(2, refcount);
|
||||
ASSERT_EQ(&refcount, obj1.Get());
|
||||
ASSERT_EQ(&refcount, obj2.Get());
|
||||
}
|
||||
ASSERT_EQ(1, refcount);
|
||||
}
|
||||
@@ -91,6 +89,51 @@ TEST(ObjectBase, OperatorBool) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test the copy constructor of C++ objects
|
||||
TEST(ObjectBase, CopyConstructor) {
|
||||
int refcount = 1;
|
||||
|
||||
Object source(&refcount);
|
||||
Object destination(source);
|
||||
|
||||
ASSERT_EQ(source.Get(), &refcount);
|
||||
ASSERT_EQ(destination.Get(), &refcount);
|
||||
ASSERT_EQ(3, refcount);
|
||||
|
||||
destination = Object();
|
||||
ASSERT_EQ(refcount, 2);
|
||||
}
|
||||
|
||||
// Test the copy assignment of C++ objects
|
||||
TEST(ObjectBase, CopyAssignment) {
|
||||
int refcount = 1;
|
||||
Object source(&refcount);
|
||||
|
||||
Object destination;
|
||||
destination = source;
|
||||
|
||||
ASSERT_EQ(source.Get(), &refcount);
|
||||
ASSERT_EQ(destination.Get(), &refcount);
|
||||
ASSERT_EQ(3, refcount);
|
||||
|
||||
destination = Object();
|
||||
ASSERT_EQ(refcount, 2);
|
||||
}
|
||||
|
||||
// Test the copy assignment of C++ objects onto themselves
|
||||
TEST(ObjectBase, CopyAssignmentSelf) {
|
||||
int refcount = 1;
|
||||
|
||||
Object obj(&refcount);
|
||||
|
||||
// Fool the compiler to avoid a -Wself-assign-overload
|
||||
Object* objPtr = &obj;
|
||||
obj = *objPtr;
|
||||
|
||||
ASSERT_EQ(obj.Get(), &refcount);
|
||||
ASSERT_EQ(refcount, 2);
|
||||
}
|
||||
|
||||
// Test the move constructor of C++ objects
|
||||
TEST(ObjectBase, MoveConstructor) {
|
||||
int refcount = 1;
|
||||
@@ -121,3 +164,16 @@ TEST(ObjectBase, MoveAssignment) {
|
||||
ASSERT_EQ(refcount, 1);
|
||||
}
|
||||
|
||||
// Test the move assignment of C++ objects onto themselves
|
||||
TEST(ObjectBase, MoveAssignmentSelf) {
|
||||
int refcount = 1;
|
||||
|
||||
Object obj(&refcount);
|
||||
|
||||
// Fool the compiler to avoid a -Wself-move
|
||||
Object* objPtr = &obj;
|
||||
obj = std::move(*objPtr);
|
||||
|
||||
ASSERT_EQ(obj.Get(), &refcount);
|
||||
ASSERT_EQ(refcount, 2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user