// Copyright 2017 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <thread> #include <utility> #include "dawn/common/Ref.h" #include "dawn/common/RefCounted.h" #include "gtest/gtest.h" #include "partition_alloc/pointers/raw_ptr.h" namespace dawn { namespace { class RCTest : public RefCounted { … }; struct RCTestDerived : public RCTest { … }; TEST(RefCount, Increment) { … } // Test that RCs start with one ref, and removing it destroys the object. TEST(RefCounted, StartsWithOneRef) { … } // Test adding refs keep the RC alive. TEST(RefCounted, AddingRefKeepsAlive) { … } // Test that AddRef and Release atomically change the refcount. TEST(RefCounted, RaceOnAddRefRelease) { … } // Test Ref remove reference when going out of scope TEST(Ref, EndOfScopeRemovesRef) { … } // Test getting pointer out of the Ref TEST(Ref, Gets) { … } // Test Refs default to null TEST(Ref, DefaultsToNull) { … } // Test Ref's copy constructor TEST(Ref, CopyConstructor) { … } // Test Ref's copy assignment TEST(Ref, CopyAssignment) { … } // Test Ref's move constructor TEST(Ref, MoveConstructor) { … } // Test Ref's move assignment TEST(Ref, MoveAssignment) { … } // Test move assigment where the destination and source // point to the same underlying object. TEST(Ref, MoveAssignmentSameObject) { … } // Test the payload initial value is set correctly TEST(Ref, InitialPayloadValue) { … } // Test that the payload survives ref and release operations TEST(Ref, PayloadUnchangedByRefCounting) { … } // Test that Detach pulls out the pointer and stops tracking it. TEST(Ref, Detach) { … } // Test constructor passed a derived pointer TEST(Ref, DerivedPointerConstructor) { … } // Test copy constructor of derived class TEST(Ref, DerivedCopyConstructor) { … } // Test Ref constructed with nullptr TEST(Ref, ConstructedWithNullptr) { … } // Test Ref's copy assignment with derived class TEST(Ref, CopyAssignmentDerived) { … } // Test Ref's move constructor with derived class TEST(Ref, MoveConstructorDerived) { … } // Test Ref's move assignment with derived class TEST(Ref, MoveAssignmentDerived) { … } // Test Ref's InitializeInto. TEST(Ref, InitializeInto) { … } } // anonymous namespace } // namespace dawn